Selaa lähdekoodia

commit for note

main
VirgilZhu 8 kuukautta sitten
vanhempi
commit
5f7d8de5d3
7 muutettua tiedostoa jossa 19 lisäystä ja 13 poistoa
  1. +4
    -0
      benchmarks/db_bench.cc
  2. +7
    -3
      db/db_impl.cc
  3. +0
    -5
      db/log_format.h
  4. +2
    -0
      db/vlog_reader.cc
  5. +1
    -0
      db/vlog_reader.h
  6. +1
    -1
      include/leveldb/options.h
  7. +4
    -4
      test/bench_test.cc

+ 4
- 0
benchmarks/db_bench.cc Näytä tiedosto

@ -50,6 +50,8 @@ static const char* FLAGS_benchmarks =
"fillsync,"
"fillrandom,"
"overwrite,"
"deleteseq,"
"deleterandom,"
"readrandom,"
"readrandom," // Extra run to allow previous compactions to quiesce
"readseq,"
@ -59,6 +61,8 @@ static const char* FLAGS_benchmarks =
"findkeysbyfield,"
"readseq,"
"readreverse,"
"seekrandom,"
"seekordered,"
"fill100K,";
// "crc32c,"
// "snappycomp,"

+ 7
- 3
db/db_impl.cc Näytä tiedosto

@ -954,8 +954,8 @@ void DBImpl::MaybeScheduleGarbageCollection() {
// 如果后台线程出错,也不调度。
} else {
//设置调度变量,通过detach线程调度;detach线程即使主线程退出,依然可以正常执行完成
background_GarbageCollection_scheduled_ = true;
env_->ScheduleForGarbageCollection(&DBImpl::GarbageCollectionBGWork, this);
// background_GarbageCollection_scheduled_ = true;
// env_->ScheduleForGarbageCollection(&DBImpl::GarbageCollectionBGWork, this);
}
}
// 后台gc线程中执行的任务
@ -1441,6 +1441,7 @@ int64_t DBImpl::TEST_MaxNextLevelOverlappingBytes() {
return versions_->MaxNextLevelOverlappingBytes();
}
/* 从 VlogReader 读取的 VLog kv 数据对中解析出 value */
bool DBImpl::ParseVlogValue(Slice key_value, Slice key,
std::string& value, uint64_t val_size) {
Slice k_v = key_value;
@ -1564,9 +1565,12 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key,
uint64_t val_size;
size_t key_size = key.size();
/* 已知该 value 保存在 VLog,解码出 vlog_ptr(fid, offset, val_size)*/
GetVarint64(&vlog_ptr, &file_no);
GetVarint64(&vlog_ptr, &offset);
GetVarint64(&vlog_ptr, &val_size);
/* VLog 内部 kv 对的编码长度,1B 为 type */
uint64_t encoded_len = 1 + VarintLength(key_size) + key.size() + VarintLength(val_size) + val_size;
std::string fname = LogFileName(dbname_, file_no);
@ -2022,7 +2026,7 @@ Status DB::Open(const Options& options, const std::string& dbname, DB** dbptr) {
impl->RemoveObsoleteFiles();
impl->MaybeScheduleCompaction();
}
// TODO beigin 开始全盘的回收。
// TODO begin 开始全盘的回收。
if( s.ok() && impl->options_.start_garbage_collection ){
if( s.ok() ){

+ 0
- 5
db/log_format.h Näytä tiedosto

@ -29,11 +29,6 @@ static const int kBlockSize = 32768;
// Header is checksum (4 bytes), length (2 bytes), type (1 byte).
static const int kHeaderSize = 4 + 2 + 1;
/* 需要再研究下 */
//4M vlog GC
//static const int vBlockSize = 4*1024*1024;
// VlogHeader length (4 bytes).
static const int vHeaderSize = 4;
// write_batch Header

+ 2
- 0
db/vlog_reader.cc Näytä tiedosto

@ -30,6 +30,7 @@ bool VlogReader::ReadValue(uint64_t offset, size_t length, Slice *key_value, cha
if (file_random_ == nullptr) {
return false;
}
/* 随机读取一个 RandomAccessFile,使用对应的读接口 Read 函数 */
Status status = file_random_->Read(offset, length, key_value, scratch);
if (!status.ok()) {
return false;
@ -60,6 +61,7 @@ bool VlogReader::ReadPhysicalRecord(std::string *result) {
buffer_.clear();
char* tmp_head = new char[vHeaderSize];
/* 顺序读取一个 SequentialFile,使用对应的读接口 Read 函数 */
Status status = file_->Read(vHeaderSize, &buffer_, tmp_head);
if (!status.ok()) {
buffer_.clear();

+ 1
- 0
db/vlog_reader.h Näytä tiedosto

@ -22,6 +22,7 @@ class VlogReader {
virtual void Corruption(size_t bytes, const Status& status) = 0;
};
//
explicit VlogReader(SequentialFile* file, Reporter* reporter);
explicit VlogReader(RandomAccessFile* file, Reporter* reporter);

+ 1
- 1
include/leveldb/options.h Näytä tiedosto

@ -177,7 +177,7 @@ struct LEVELDB_EXPORT ReadOptions {
// Options that control write operations
struct LEVELDB_EXPORT WriteOptions {
explicit WriteOptions(size_t separateThreshold = 16)
explicit WriteOptions(size_t separateThreshold = 32)
: separate_threshold(separateThreshold) {}
// WriteOptions() = default;

+ 4
- 4
test/bench_test.cc Näytä tiedosto

@ -153,11 +153,11 @@ void RunBenchmark(const char* name, Func func, bool setup_data = true, bool setu
delete db;
}
// TEST(BenchTest, PutLatency) { RunBenchmark("Put", InsertData, false, false); }
// TEST(BenchTest, PutFieldsLatency) { RunBenchmark("PutFields", InsertFields, false, false); }
TEST(BenchTest, PutLatency) { RunBenchmark("Put", InsertData, false, false); }
TEST(BenchTest, PutFieldsLatency) { RunBenchmark("PutFields", InsertFields, false, false); }
// TEST(BenchTest, GetLatency) { RunBenchmark("Get", GetData, true, false); }
// TEST(BenchTest, IteratorLatency) { RunBenchmark("Iterator", ReadOrdered, true, false); }
TEST(BenchTest, GetLatency) { RunBenchmark("Get", GetData, true, false); }
TEST(BenchTest, IteratorLatency) { RunBenchmark("Iterator", ReadOrdered, true, false); }
TEST(BenchTest, FindKeysByFieldLatency) {
RunBenchmark("FindKeysByFields", FindKeys, false, true);

Ladataan…
Peruuta
Tallenna