瀏覽代碼

Merge branch 'main' into wesley

main
李畅 8 月之前
父節點
當前提交
2e031d6c63
共有 6 個檔案被更改,包括 39 行新增9 行删除
  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 查看文件

@ -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);

+ 14
- 3
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();
}

+ 2
- 0
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;
}

+ 2
- 1
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

+ 1
- 1
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

+ 1
- 1
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<std::string, std::string> data;

Loading…
取消
儲存