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
This commit is contained in:
Aaron Gao 2017-04-20 19:44:55 -07:00 committed by Facebook Github Bot
parent 7534ba7bde
commit cb885bccfe
2 changed files with 3 additions and 3 deletions

View file

@ -82,7 +82,7 @@ CompactionIterator::CompactionIterator(
if (snapshots_->size() == 0) { if (snapshots_->size() == 0) {
// optimize for fast path if there are no snapshots // optimize for fast path if there are no snapshots
visible_at_tip_ = true; visible_at_tip_ = true;
earliest_snapshot_ = last_sequence; earliest_snapshot_ = kMaxSequenceNumber;
latest_snapshot_ = 0; latest_snapshot_ = 0;
} else { } else {
visible_at_tip_ = false; visible_at_tip_ = false;
@ -543,7 +543,7 @@ void CompactionIterator::PrepareOutput() {
// This is safe for TransactionDB write-conflict checking since transactions // This is safe for TransactionDB write-conflict checking since transactions
// only care about sequence number larger than any active snapshots. // 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 && ikey_.type != kTypeMerge &&
!cmp_->Equal(compaction_->GetLargestUserKey(), ikey_.user_key)) { !cmp_->Equal(compaction_->GetLargestUserKey(), ikey_.user_key)) {
assert(ikey_.type != kTypeDeletion && ikey_.type != kTypeSingleDeletion); assert(ikey_.type != kTypeDeletion && ikey_.type != kTypeSingleDeletion);

View file

@ -626,7 +626,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilterContextManual) {
iter->Next(); iter->Next();
} }
ASSERT_EQ(total, 700); ASSERT_EQ(total, 700);
ASSERT_EQ(count, 2); ASSERT_EQ(count, 1);
} }
} }
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE