From 89d989ed75ed89e756156d1f82e123b24591be8c Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Thu, 29 Mar 2018 14:30:37 -0700 Subject: [PATCH] WritePrepared Txn: fix a bug in publishing recoverable state seq Summary: When using two_write_queue, the published seq and the last allocated sequence could be ahead of the LastSequence, even if both write queues are stopped as in WriteRecoverableState. The patch fixes a bug in WriteRecoverableState in which LastSequence was used as a reference but the result was applied to last fetched sequence and last published seq. Closes https://github.com/facebook/rocksdb/pull/3665 Differential Revision: D7446099 Pulled By: maysamyabandeh fbshipit-source-id: 1449bed9aed8e9db6af85946efd347cb8efd3c0b --- db/db_impl_write.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/db/db_impl_write.cc b/db/db_impl_write.cc index 3fb61010a..0e249cb40 100644 --- a/db/db_impl_write.cc +++ b/db/db_impl_write.cc @@ -965,7 +965,12 @@ Status DBImpl::WriteRecoverableState() { if (two_write_queues_) { log_write_mutex_.Lock(); } - SequenceNumber seq = versions_->LastSequence(); + SequenceNumber seq; + if (two_write_queues_) { + seq = versions_->FetchAddLastAllocatedSequence(0); + } else { + seq = versions_->LastSequence(); + } WriteBatchInternal::SetSequence(&cached_recoverable_state_, seq + 1); auto status = WriteBatchInternal::InsertInto( &cached_recoverable_state_, column_family_memtables_.get(), @@ -975,9 +980,9 @@ Status DBImpl::WriteRecoverableState() { auto last_seq = next_seq - 1; if (two_write_queues_) { versions_->FetchAddLastAllocatedSequence(last_seq - seq); + versions_->SetLastPublishedSequence(last_seq); } versions_->SetLastSequence(last_seq); - versions_->SetLastPublishedSequence(last_seq); if (two_write_queues_) { log_write_mutex_.Unlock(); } -- GitLab