From fe90ed7a70b6cda47ef970375e74b9a0b486cab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Gra=CC=88tzer?= Date: Wed, 19 Jun 2019 08:02:21 -0700 Subject: [PATCH] Replace Corruption with TryAgain status when new tail is not visible to TransactionLogIterator (#5474) Summary: When tailing the WAL with TransactionLogIterator, it used to return Corruption status to indicate that the WAL has new tail that is not visible to the iterator, which is a misleading status. The patch replaces it with TryAgain which is more descriptive of a status, indicating that the user needs to create a new iterator to fetch the recent tail. Fixes https://github.com/facebook/rocksdb/issues/5455 Pull Request resolved: https://github.com/facebook/rocksdb/pull/5474 Differential Revision: D15898953 Pulled By: maysamyabandeh fbshipit-source-id: 40966f6457cb539e1aeb104daeada6b0e46059fc --- HISTORY.md | 1 + db/transaction_log_impl.cc | 3 ++- db/wal_manager_test.cc | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 18feefafc..825c1def4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -29,6 +29,7 @@ * Fix a bug in WAL replay of secondary instance by skipping write batches with older sequence numbers than the current last sequence number. * Fix flush's/compaction's merge processing logic which allowed `Put`s covered by range tombstones to reappear. Note `Put`s may exist even if the user only ever called `Merge()` due to an internal conversion during compaction to the bottommost level. * Fix/improve memtable earliest sequence assignment and WAL replay so that WAL entries of unflushed column families will not be skipped after replaying the MANIFEST and increasing db sequence due to another flushed/compacted column family. +* Return TryAgain status in place of Corruption when new tail is not visible to TransactionLogIterator. * Fix a bug caused by secondary not skipping the beginning of new MANIFEST. ## 6.2.0 (4/30/2019) diff --git a/db/transaction_log_impl.cc b/db/transaction_log_impl.cc index 2e4475bb6..8c526af12 100644 --- a/db/transaction_log_impl.cc +++ b/db/transaction_log_impl.cc @@ -199,7 +199,8 @@ void TransactionLogIteratorImpl::NextImpl(bool internal) { if (current_last_seq_ == versions_->LastSequence()) { current_status_ = Status::OK(); } else { - current_status_ = Status::Corruption("NO MORE DATA LEFT"); + const char* msg = "Create a new iterator to fetch the new tail."; + current_status_ = Status::TryAgain(msg); } return; } diff --git a/db/wal_manager_test.cc b/db/wal_manager_test.cc index 1bc6a8afe..671dc84e1 100644 --- a/db/wal_manager_test.cc +++ b/db/wal_manager_test.cc @@ -293,6 +293,29 @@ TEST_F(WalManagerTest, TransactionLogIteratorJustEmptyFile) { // Check that an empty iterator is returned ASSERT_TRUE(!iter->Valid()); } + +TEST_F(WalManagerTest, TransactionLogIteratorNewFileWhileScanning) { + Init(); + CreateArchiveLogs(2, 100); + auto iter = OpenTransactionLogIter(0); + CreateArchiveLogs(1, 100); + int i = 0; + for (; iter->Valid(); iter->Next()) { + i++; + } + ASSERT_EQ(i, 200); + // A new log file was added after the iterator was created. + // TryAgain indicates a new iterator is needed to fetch the new data + ASSERT_TRUE(iter->status().IsTryAgain()); + + iter = OpenTransactionLogIter(0); + i = 0; + for (; iter->Valid(); iter->Next()) { + i++; + } + ASSERT_EQ(i, 300); + ASSERT_TRUE(iter->status().ok()); +} } // namespace rocksdb