diff --git a/benchmarks/db_bench.cc b/benchmarks/db_bench.cc index 8e3f4e7..5e7f944 100644 --- a/benchmarks/db_bench.cc +++ b/benchmarks/db_bench.cc @@ -74,7 +74,7 @@ static int FLAGS_reads = -1; static int FLAGS_threads = 1; // 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 // their original size after compression @@ -134,6 +134,15 @@ namespace leveldb { namespace { 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 { public: CountComparator(const Comparator* wrapped) : wrapped_(wrapped) {} @@ -852,8 +861,15 @@ class Benchmark { for (int j = 0; j < entries_per_batch_; j++) { const int k = seq ? i + j : thread->rand.Uniform(FLAGS_num); 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(); } s = db_->Write(write_options_, &batch); diff --git a/db/db_impl.cc b/db/db_impl.cc index 535a1d3..299b249 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -260,6 +260,9 @@ void DBImpl::RemoveObsoleteFiles() { case kTableFile: keep = (live.find(number) != live.end()); break; + case kVTableFile: + keep = (live.find(number) != live.end()); + break; case kTempFile: // Any temp files that are currently being written to must // 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()) { 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(); } @@ -1268,7 +1275,11 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key, if (s.ok()) { s = DecodeValue(value); } - *fields = Fields(Slice(*value)); + if (s.ok()) { + *fields = Fields(Slice(*value)); + } else { + *fields = Fields(); + } mutex_.Lock(); } diff --git a/db/filename.cc b/db/filename.cc index 21c306a..baaa512 100644 --- a/db/filename.cc +++ b/db/filename.cc @@ -117,6 +117,8 @@ bool ParseFileName(const std::string& filename, uint64_t* number, *type = kTableFile; } else if (suffix == Slice(".dbtmp")) { *type = kTempFile; + } else if (suffix == Slice(".vrb")) { + *type = kVTableFile; } else { return false; } diff --git a/db/filename.h b/db/filename.h index 06cf019..f777104 100644 --- a/db/filename.h +++ b/db/filename.h @@ -25,7 +25,8 @@ enum FileType { kDescriptorFile, kCurrentFile, 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 diff --git a/include/leveldb/options.h b/include/leveldb/options.h index 067947d..2185d86 100644 --- a/include/leveldb/options.h +++ b/include/leveldb/options.h @@ -101,7 +101,7 @@ struct LEVELDB_EXPORT Options { size_t block_size = 4 * 1024; // 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. // This parameter can be changed dynamically. Most clients should diff --git a/test/test_basicio.cc b/test/test_basicio.cc index 5510c66..2654077 100644 --- a/test/test_basicio.cc +++ b/test/test_basicio.cc @@ -3,7 +3,7 @@ #include "leveldb/db.h" using namespace leveldb; -constexpr int value_size = 2000; +constexpr int value_size = 2048; constexpr int data_size = 128 << 20; std::map data;