From 59244447e3123da87fc3f3ade859d85f69165f40 Mon Sep 17 00:00:00 2001 From: Ming Zhao Date: Fri, 1 Feb 2019 09:19:09 -0800 Subject: [PATCH] Zero seqnum of final key / drop final tombstone when compacting to bottommost level Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/4927 Differential Revision: D13889458 Pulled By: mzhaom fbshipit-source-id: d6b66db85901a9eb90748fba6a9dc4e7457b9c5e --- db/compaction_iterator.cc | 3 +-- db/compaction_job_test.cc | 14 +++++++------- db/db_compaction_filter_test.cc | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/db/compaction_iterator.cc b/db/compaction_iterator.cc index 675e88d63..8721634f8 100644 --- a/db/compaction_iterator.cc +++ b/db/compaction_iterator.cc @@ -634,8 +634,7 @@ void CompactionIterator::PrepareOutput() { // KeyNotExistsBeyondOutputLevel() return true? if ((compaction_ != nullptr && !compaction_->allow_ingest_behind()) && ikeyNotNeededForIncrementalSnapshot() && bottommost_level_ && valid_ && - IN_EARLIEST_SNAPSHOT(ikey_.sequence) && ikey_.type != kTypeMerge && - !cmp_->Equal(compaction_->GetLargestUserKey(), ikey_.user_key)) { + IN_EARLIEST_SNAPSHOT(ikey_.sequence) && ikey_.type != kTypeMerge) { assert(ikey_.type != kTypeDeletion && ikey_.type != kTypeSingleDeletion); ikey_.sequence = 0; current_key_.UpdateInternalKey(0, ikey_.type); diff --git a/db/compaction_job_test.cc b/db/compaction_job_test.cc index 16114ccaa..d41b4d1ac 100644 --- a/db/compaction_job_test.cc +++ b/db/compaction_job_test.cc @@ -172,7 +172,7 @@ class CompactionJobTest : public testing::Test { // This is how the key will look like once it's written in bottommost // file InternalKey bottommost_internal_key( - key, (key == "9999") ? sequence_number : 0, kTypeValue); + key, 0, kTypeValue); if (corrupt_id(k)) { test::CorruptKeyType(&internal_key); @@ -379,7 +379,7 @@ TEST_F(CompactionJobTest, SimpleOverwrite) { auto expected_results = mock::MakeMockFile({{KeyStr("a", 0U, kTypeValue), "val2"}, - {KeyStr("b", 4U, kTypeValue), "val3"}}); + {KeyStr("b", 0U, kTypeValue), "val3"}}); SetLastSequence(4U); auto files = cfd_->current()->storage_info()->LevelFiles(0); @@ -432,7 +432,7 @@ TEST_F(CompactionJobTest, SimpleMerge) { auto expected_results = mock::MakeMockFile({{KeyStr("a", 0U, kTypeValue), "3,4,5"}, - {KeyStr("b", 2U, kTypeValue), "1,2"}}); + {KeyStr("b", 0U, kTypeValue), "1,2"}}); SetLastSequence(5U); auto files = cfd_->current()->storage_info()->LevelFiles(0); @@ -456,7 +456,7 @@ TEST_F(CompactionJobTest, NonAssocMerge) { auto expected_results = mock::MakeMockFile({{KeyStr("a", 0U, kTypeValue), "3,4,5"}, - {KeyStr("b", 2U, kTypeValue), "1,2"}}); + {KeyStr("b", 0U, kTypeValue), "1,2"}}); SetLastSequence(5U); auto files = cfd_->current()->storage_info()->LevelFiles(0); @@ -483,7 +483,7 @@ TEST_F(CompactionJobTest, MergeOperandFilter) { auto expected_results = mock::MakeMockFile({{KeyStr("a", 0U, kTypeValue), test::EncodeInt(8U)}, - {KeyStr("b", 2U, kTypeValue), test::EncodeInt(2U)}}); + {KeyStr("b", 0U, kTypeValue), test::EncodeInt(2U)}}); SetLastSequence(5U); auto files = cfd_->current()->storage_info()->LevelFiles(0); @@ -746,7 +746,7 @@ TEST_F(CompactionJobTest, SingleDeleteZeroSeq) { AddMockFile(file2); auto expected_results = mock::MakeMockFile({ - {KeyStr("dummy", 5U, kTypeValue), "val2"}, + {KeyStr("dummy", 0U, kTypeValue), "val2"}, }); SetLastSequence(22U); @@ -930,7 +930,7 @@ TEST_F(CompactionJobTest, CorruptionAfterDeletion) { mock::MakeMockFile({{test::KeyStr("A", 0U, kTypeValue), "val3"}, {test::KeyStr("a", 0U, kTypeValue, true), "val"}, {test::KeyStr("b", 0U, kTypeValue, true), "val"}, - {test::KeyStr("c", 1U, kTypeValue), "val2"}}); + {test::KeyStr("c", 0U, kTypeValue), "val2"}}); SetLastSequence(6U); auto files = cfd_->current()->storage_info()->LevelFiles(0); diff --git a/db/db_compaction_filter_test.cc b/db/db_compaction_filter_test.cc index 25045d01d..a19fde0b7 100644 --- a/db/db_compaction_filter_test.cc +++ b/db/db_compaction_filter_test.cc @@ -357,7 +357,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilter) { } } ASSERT_EQ(total, 100000); - ASSERT_EQ(count, 1); + ASSERT_EQ(count, 0); // overwrite all the 100K keys once again. for (int i = 0; i < 100000; i++) { @@ -664,7 +664,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilterContextManual) { iter->Next(); } ASSERT_EQ(total, 700); - ASSERT_EQ(count, 1); + ASSERT_EQ(count, 0); } } #endif // ROCKSDB_LITE