From 3c058fedd083574f57b88e79a28ac4bd247619f2 Mon Sep 17 00:00:00 2001 From: cyq <1056374449@qq.com> Date: Tue, 29 Oct 2024 23:11:45 +0800 Subject: [PATCH] pass all the test --- db/builder.cc | 11 +++++++++++ db/db_impl.cc | 12 ++++++++++-- test/ttl_test.cc | 5 +++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/db/builder.cc b/db/builder.cc index 5a0e07f..3d1ca0e 100644 --- a/db/builder.cc +++ b/db/builder.cc @@ -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 "<smallest_deadtime = std::min(meta->smallest_deadtime,parsed.deadTime); meta->largest_deadtime = std::max(meta->largest_deadtime,parsed.deadTime); } diff --git a/db/db_impl.cc b/db/db_impl.cc index 6513f89..28ef225 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -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 "<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) { diff --git a/test/ttl_test.cc b/test/ttl_test.cc index fb91b86..40d38d4 100644 --- a/test/ttl_test.cc +++ b/test/ttl_test.cc @@ -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);