From cb885bccfe76df524cf40bc703efc479b0529956 Mon Sep 17 00:00:00 2001 From: Aaron Gao Date: Thu, 20 Apr 2017 19:44:55 -0700 Subject: [PATCH] set compaction_iterator earliest_snapshot to max if no snapshot Summary: It is a potential bug that will be triggered if we ingest files before inserting the first key into an empty db. 0 is a special value reserved to indicate the concept of non-existence. But not good for seqno in this case because 0 is a valid seqno for ingestion(bulk loading) Closes https://github.com/facebook/rocksdb/pull/2183 Differential Revision: D4919827 Pulled By: lightmark fbshipit-source-id: 237eea40f88bd6487b66806109d90065dc02c362 --- db/compaction_iterator.cc | 4 ++-- db/db_compaction_filter_test.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/compaction_iterator.cc b/db/compaction_iterator.cc index 2031331ca..a69c62578 100644 --- a/db/compaction_iterator.cc +++ b/db/compaction_iterator.cc @@ -82,7 +82,7 @@ CompactionIterator::CompactionIterator( if (snapshots_->size() == 0) { // optimize for fast path if there are no snapshots visible_at_tip_ = true; - earliest_snapshot_ = last_sequence; + earliest_snapshot_ = kMaxSequenceNumber; latest_snapshot_ = 0; } else { visible_at_tip_ = false; @@ -543,7 +543,7 @@ void CompactionIterator::PrepareOutput() { // This is safe for TransactionDB write-conflict checking since transactions // only care about sequence number larger than any active snapshots. - if (bottommost_level_ && valid_ && ikey_.sequence < earliest_snapshot_ && + if (bottommost_level_ && valid_ && ikey_.sequence <= earliest_snapshot_ && ikey_.type != kTypeMerge && !cmp_->Equal(compaction_->GetLargestUserKey(), ikey_.user_key)) { assert(ikey_.type != kTypeDeletion && ikey_.type != kTypeSingleDeletion); diff --git a/db/db_compaction_filter_test.cc b/db/db_compaction_filter_test.cc index db1bd3fb8..4e68c1dbe 100644 --- a/db/db_compaction_filter_test.cc +++ b/db/db_compaction_filter_test.cc @@ -626,7 +626,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilterContextManual) { iter->Next(); } ASSERT_EQ(total, 700); - ASSERT_EQ(count, 2); + ASSERT_EQ(count, 1); } } #endif // ROCKSDB_LITE