From 1118a1c75c6a63760165a7c06862080977be697d Mon Sep 17 00:00:00 2001 From: Arcueid <981354012@qq.com> Date: Tue, 24 Dec 2024 21:57:23 -0800 Subject: [PATCH] some fix --- .idea/misc.xml | 6 ------ benchmarks/db_bench.cc | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 12c8875..0b76fe5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,11 +1,5 @@ - - diff --git a/benchmarks/db_bench.cc b/benchmarks/db_bench.cc index 8e3f4e7..f12f214 100644 --- a/benchmarks/db_bench.cc +++ b/benchmarks/db_bench.cc @@ -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);