Explorar el Código

Merge branch 'main' into wesley

main
李畅 hace 8 meses
padre
commit
2e031d6c63
Se han modificado 6 ficheros con 39 adiciones y 9 borrados
  1. +19
    -3
      benchmarks/db_bench.cc
  2. +14
    -3
      db/db_impl.cc
  3. +2
    -0
      db/filename.cc
  4. +2
    -1
      db/filename.h
  5. +1
    -1
      include/leveldb/options.h
  6. +1
    -1
      test/test_basicio.cc

+ 19
- 3
benchmarks/db_bench.cc Ver fichero

@ -74,7 +74,7 @@ static int FLAGS_reads = -1;
static int FLAGS_threads = 1; static int FLAGS_threads = 1;
// Size of each value // Size of each value
static int FLAGS_value_size = 100;
static int FLAGS_value_size = 1000;
// Arrange to generate values that shrink to this fraction of // Arrange to generate values that shrink to this fraction of
// their original size after compression // their original size after compression
@ -134,6 +134,15 @@ namespace leveldb {
namespace { namespace {
leveldb::Env* g_env = nullptr; leveldb::Env* g_env = nullptr;
void EncodeNonIndexValue(const Slice& value, std::string* res) {
enum Type : unsigned char {
kNonIndexValue = 2,
};
res->push_back(kNonIndexValue);
res->append(value.ToString());
}
class CountComparator : public Comparator { class CountComparator : public Comparator {
public: public:
CountComparator(const Comparator* wrapped) : wrapped_(wrapped) {} CountComparator(const Comparator* wrapped) : wrapped_(wrapped) {}
@ -852,8 +861,15 @@ class Benchmark {
for (int j = 0; j < entries_per_batch_; j++) { for (int j = 0; j < entries_per_batch_; j++) {
const int k = seq ? i + j : thread->rand.Uniform(FLAGS_num); const int k = seq ? i + j : thread->rand.Uniform(FLAGS_num);
key.Set(k); key.Set(k);
batch.Put(key.slice(), gen.Generate(value_size_));
bytes += value_size_ + key.slice().size();
auto value = gen.Generate(value_size_);
FieldArray field_array = {
{"1", value.ToString()},
};
auto field_str = Fields(field_array).Serialize();
std::string encoded_value;
EncodeNonIndexValue(field_str, &encoded_value);
batch.Put(key.slice(), Slice(encoded_value));
bytes += encoded_value.size() + key.slice().size();
thread->stats.FinishedSingleOp(); thread->stats.FinishedSingleOp();
} }
s = db_->Write(write_options_, &batch); s = db_->Write(write_options_, &batch);

+ 14
- 3
db/db_impl.cc Ver fichero

@ -260,6 +260,9 @@ void DBImpl::RemoveObsoleteFiles() {
case kTableFile: case kTableFile:
keep = (live.find(number) != live.end()); keep = (live.find(number) != live.end());
break; break;
case kVTableFile:
keep = (live.find(number) != live.end());
break;
case kTempFile: case kTempFile:
// Any temp files that are currently being written to must // Any temp files that are currently being written to must
// be recorded in pending_outputs_, which is inserted into "live" // be recorded in pending_outputs_, which is inserted into "live"
@ -1215,8 +1218,12 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key,
if (s.ok()) { if (s.ok()) {
s = DecodeValue(value); s = DecodeValue(value);
} }
auto fields = Fields(Slice(*value));
*value = fields["1"];
if (s.ok()) {
auto fields = Fields(Slice(*value));
*value = fields["1"];
} else {
*value = "";
}
mutex_.Lock(); mutex_.Lock();
} }
@ -1268,7 +1275,11 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key,
if (s.ok()) { if (s.ok()) {
s = DecodeValue(value); s = DecodeValue(value);
} }
*fields = Fields(Slice(*value));
if (s.ok()) {
*fields = Fields(Slice(*value));
} else {
*fields = Fields();
}
mutex_.Lock(); mutex_.Lock();
} }

+ 2
- 0
db/filename.cc Ver fichero

@ -117,6 +117,8 @@ bool ParseFileName(const std::string& filename, uint64_t* number,
*type = kTableFile; *type = kTableFile;
} else if (suffix == Slice(".dbtmp")) { } else if (suffix == Slice(".dbtmp")) {
*type = kTempFile; *type = kTempFile;
} else if (suffix == Slice(".vrb")) {
*type = kVTableFile;
} else { } else {
return false; return false;
} }

+ 2
- 1
db/filename.h Ver fichero

@ -25,7 +25,8 @@ enum FileType {
kDescriptorFile, kDescriptorFile,
kCurrentFile, kCurrentFile,
kTempFile, kTempFile,
kInfoLogFile // Either the current one, or an old one
kInfoLogFile,
kVTableFile// Either the current one, or an old one
}; };
// Return the name of the log file with the specified number // Return the name of the log file with the specified number

+ 1
- 1
include/leveldb/options.h Ver fichero

@ -101,7 +101,7 @@ struct LEVELDB_EXPORT Options {
size_t block_size = 4 * 1024; size_t block_size = 4 * 1024;
// Threshold of value size that decide whether to separate the key and value // Threshold of value size that decide whether to separate the key and value
size_t kv_sep_size = 1;
size_t kv_sep_size = 100;
// Number of keys between restart points for delta encoding of keys. // Number of keys between restart points for delta encoding of keys.
// This parameter can be changed dynamically. Most clients should // This parameter can be changed dynamically. Most clients should

+ 1
- 1
test/test_basicio.cc Ver fichero

@ -3,7 +3,7 @@
#include "leveldb/db.h" #include "leveldb/db.h"
using namespace leveldb; using namespace leveldb;
constexpr int value_size = 2000;
constexpr int value_size = 2048;
constexpr int data_size = 128 << 20; constexpr int data_size = 128 << 20;
std::map<std::string, std::string> data; std::map<std::string, std::string> data;

Cargando…
Cancelar
Guardar