Browse Source

pass all the test

pull/1/head^2
cyq 1 month ago
parent
commit
3c058fedd0
3 changed files with 24 additions and 4 deletions
  1. +11
    -0
      db/builder.cc
  2. +10
    -2
      db/db_impl.cc
  3. +3
    -2
      test/ttl_test.cc

+ 11
- 0
db/builder.cc View File

@ -28,6 +28,10 @@ Status BuildTable(const std::string& dbname, Env* env, const Options& options,
return s;
}
time_t nowTime;
time(&nowTime);
assert(nowTime > 0);
TableBuilder* builder = new TableBuilder(options, file);
meta->smallest.DecodeFrom(iter->key());
Slice key;
@ -41,6 +45,13 @@ Status BuildTable(const std::string& dbname, Env* env, const Options& options,
//这里要注意internalkey和metadata中对于没有生存期的表示的转换
ParseInternalKey(key,&parsed);
if(parsed.deadTime == 0) parsed.deadTime = UINT64_MAX;
if(parsed.deadTime < nowTime) {
static int count = 0;
if(count % 1000 == 0) {
std::cout<<"count "<<count++<<" drop dead in L0: "<<parsed.user_key.ToString()<<" "<<parsed.deadTime<<std::endl;
}
continue;
}
meta->smallest_deadtime = std::min(meta->smallest_deadtime,parsed.deadTime);
meta->largest_deadtime = std::max(meta->largest_deadtime,parsed.deadTime);
}

+ 10
- 2
db/db_impl.cc View File

@ -591,6 +591,7 @@ void DBImpl::CompactRange(const Slice* begin, const Slice* end) {
}
}
}
max_level_with_files = config::kNumLevels - 1; //TODO:强制合并所有level中的sst,但是这么做不是很优雅
TEST_CompactMemTable(); // TODO(sanjay): Skip if memtable does not overlap
for (int level = 0; level < max_level_with_files; level++) {
TEST_CompactRange(level, begin, end);
@ -951,11 +952,20 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
// Handle key/value, add to state, etc.
bool drop = false;
time_t nowTime;
time(&nowTime);
if (!ParseInternalKey(key, &ikey)) {
// Do not hide error keys
current_user_key.clear();
has_current_user_key = false;
last_sequence_for_key = kMaxSequenceNumber;
} else if(ikey.deadTime != 0 && ikey.deadTime < nowTime){
static int count = 0;
if(count % 1000 == 0) {
std::cout<<"count "<<count<<" drop dead in Compaction: "<<ikey.user_key.ToString()<<" "<<ikey.deadTime<<std::endl;
count ++;
}
drop = true;
} else {
if (!has_current_user_key ||
user_comparator()->Compare(ikey.user_key, Slice(current_user_key)) !=
@ -981,7 +991,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
// Therefore this deletion marker is obsolete and can be dropped.
drop = true;
}
last_sequence_for_key = ikey.sequence;
}
#if 0
@ -993,7 +1002,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
compact->compaction->IsBaseLevelForKey(ikey.user_key),
(int)last_sequence_for_key, (int)compact->smallest_snapshot);
#endif
if (!drop) {
// Open output file if necessary
if (compact->builder == nullptr) {

+ 3
- 2
test/ttl_test.cc View File

@ -92,7 +92,7 @@ TEST(TestTTL, CompactionTTL) {
abort();
}
uint64_t ttl = 20;
uint64_t ttl = 10;
InsertData(db, ttl);
leveldb::Range ranges[1];
@ -101,7 +101,8 @@ TEST(TestTTL, CompactionTTL) {
db->GetApproximateSizes(ranges, 1, sizes);
ASSERT_GT(sizes[0], 0);
Env::Default()->SleepForMicroseconds(ttl * 1000000);
Env::Default()->SleepForMicroseconds((ttl+1) * 1000000);
// Env::Default()->SleepForMicroseconds(ttl * 1000000);
db->CompactRange(nullptr, nullptr);

Loading…
Cancel
Save