Browse Source

pass all the test

pull/1/head^2
cyq 3 weeks 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; return s;
} }
time_t nowTime;
time(&nowTime);
assert(nowTime > 0);
TableBuilder* builder = new TableBuilder(options, file); TableBuilder* builder = new TableBuilder(options, file);
meta->smallest.DecodeFrom(iter->key()); meta->smallest.DecodeFrom(iter->key());
Slice key; Slice key;
@ -41,6 +45,13 @@ Status BuildTable(const std::string& dbname, Env* env, const Options& options,
//这里要注意internalkey和metadata中对于没有生存期的表示的转换 //这里要注意internalkey和metadata中对于没有生存期的表示的转换
ParseInternalKey(key,&parsed); ParseInternalKey(key,&parsed);
if(parsed.deadTime == 0) parsed.deadTime = UINT64_MAX; 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->smallest_deadtime = std::min(meta->smallest_deadtime,parsed.deadTime);
meta->largest_deadtime = std::max(meta->largest_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 TEST_CompactMemTable(); // TODO(sanjay): Skip if memtable does not overlap
for (int level = 0; level < max_level_with_files; level++) { for (int level = 0; level < max_level_with_files; level++) {
TEST_CompactRange(level, begin, end); TEST_CompactRange(level, begin, end);
@ -951,11 +952,20 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
// Handle key/value, add to state, etc. // Handle key/value, add to state, etc.
bool drop = false; bool drop = false;
time_t nowTime;
time(&nowTime);
if (!ParseInternalKey(key, &ikey)) { if (!ParseInternalKey(key, &ikey)) {
// Do not hide error keys // Do not hide error keys
current_user_key.clear(); current_user_key.clear();
has_current_user_key = false; has_current_user_key = false;
last_sequence_for_key = kMaxSequenceNumber; 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 { } else {
if (!has_current_user_key || if (!has_current_user_key ||
user_comparator()->Compare(ikey.user_key, Slice(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. // Therefore this deletion marker is obsolete and can be dropped.
drop = true; drop = true;
} }
last_sequence_for_key = ikey.sequence; last_sequence_for_key = ikey.sequence;
} }
#if 0 #if 0
@ -993,7 +1002,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
compact->compaction->IsBaseLevelForKey(ikey.user_key), compact->compaction->IsBaseLevelForKey(ikey.user_key),
(int)last_sequence_for_key, (int)compact->smallest_snapshot); (int)last_sequence_for_key, (int)compact->smallest_snapshot);
#endif #endif
if (!drop) { if (!drop) {
// Open output file if necessary // Open output file if necessary
if (compact->builder == nullptr) { if (compact->builder == nullptr) {

+ 3
- 2
test/ttl_test.cc View File

@ -92,7 +92,7 @@ TEST(TestTTL, CompactionTTL) {
abort(); abort();
} }
uint64_t ttl = 20;
uint64_t ttl = 10;
InsertData(db, ttl); InsertData(db, ttl);
leveldb::Range ranges[1]; leveldb::Range ranges[1];
@ -101,7 +101,8 @@ TEST(TestTTL, CompactionTTL) {
db->GetApproximateSizes(ranges, 1, sizes); db->GetApproximateSizes(ranges, 1, sizes);
ASSERT_GT(sizes[0], 0); 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); db->CompactRange(nullptr, nullptr);

Loading…
Cancel
Save