diff --git a/db/builder.cc b/db/builder.cc index e6329e0..d6e60f8 100644 --- a/db/builder.cc +++ b/db/builder.cc @@ -32,8 +32,15 @@ Status BuildTable(const std::string& dbname, Env* env, const Options& options, meta->smallest.DecodeFrom(iter->key()); Slice key; for (; iter->Valid(); iter->Next()) { - key = iter->key(); - builder->Add(key, iter->value()); + // std::string value; + // uint64_t ddl; + // value = iter->value().ToString(); + // DecodeDeadLineValue(&value, ddl); + // if (ddl > std::time(nullptr)) { + // TTL: only liver remains + key = iter->key(); + builder->Add(key, iter->value()); + // } } if (!key.empty()) { meta->largest.DecodeFrom(key); diff --git a/db/db_impl.cc b/db/db_impl.cc index 9c9f3f5..b6fc925 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -594,7 +594,7 @@ void DBImpl::CompactRange(const Slice* begin, const Slice* end) { } } 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 + 1; level++) { TEST_CompactRange(level, begin, end); } } @@ -602,7 +602,11 @@ void DBImpl::CompactRange(const Slice* begin, const Slice* end) { void DBImpl::TEST_CompactRange(int level, const Slice* begin, const Slice* end) { assert(level >= 0); - assert(level + 1 < config::kNumLevels); + assert(level <= config::kNumLevels); + + if (level == config::kNumLevels) { + return; + } InternalKey begin_storage, end_storage; @@ -966,6 +970,11 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { last_sequence_for_key = kMaxSequenceNumber; } + std::string value = input->value().ToString(); + uint64_t ddl; + DecodeDeadLineValue(&value, ddl); + + if (last_sequence_for_key <= compact->smallest_snapshot) { // Hidden by an newer entry for same user key drop = true; // (A) @@ -980,6 +989,9 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { // few iterations of this loop (by rule (A) above). // Therefore this deletion marker is obsolete and can be dropped. drop = true; + } else if (ddl <= std::time(nullptr)) { + // TTL: data expired + drop = true; } last_sequence_for_key = ikey.sequence;