diff --git a/db/db_impl.cc b/db/db_impl.cc index 008d28d5f..570d04bd7 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -549,13 +549,13 @@ Status DBImpl::Recover(VersionEdit* edit, MemTable* external_table, // update the file number allocation counter in VersionSet. versions_->MarkFileNumberUsed(logs[i]); } - // This could be the last_flushed_sequence as the next sequences will be - // greater than this. - last_flushed_sequence_ = max_sequence; if (s.ok()) { if (versions_->LastSequence() < max_sequence) { versions_->SetLastSequence(max_sequence); + last_flushed_sequence_ = max_sequence; + } else { + last_flushed_sequence_ = versions_->LastSequence(); } } } diff --git a/db/db_test.cc b/db/db_test.cc index a5f1c1b66..15c0c6083 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -2688,6 +2688,18 @@ TEST(DBTest, TransactionLogIteratorJustEmptyFile) { Status status = dbfull()->GetUpdatesSince(0, &iter); ASSERT_TRUE(!status.ok()); } + +TEST(DBTest, TransactionLogIteratorCheckAfterRestart) { + Options options = OptionsForLogIterTest(); + DestroyAndReopen(&options); + Put("key1", DummyString(1024)); + Put("key2", DummyString(1023)); + dbfull()->Flush(FlushOptions()); + Reopen(&options); + auto iter = OpenTransactionLogIter(0); + ExpectRecords(2, iter); +} + TEST(DBTest, ReadCompaction) { std::string value(4096, '4'); // a string of size 4K {