From 908b1ee64e5d6036f5f3cc3285b11f91e9e459a3 Mon Sep 17 00:00:00 2001 From: Manuel Ung Date: Thu, 13 Feb 2020 18:50:01 -0800 Subject: [PATCH] WriteUnPrepared: Fix assertion during recovery (#6419) Summary: During recovery, multiple (un)prepared batches could exist in the same WAL record due to group commit. This breaks an assertion in `MemTableInserter::MarkBeginPrepare`. To fix, reset unprepared_batch_ to false after `MarkEndPrepare`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6419 Differential Revision: D19896148 Pulled By: lth fbshipit-source-id: b1a32ef88f775a0881264a18bd1a4a5b8c85eee3 --- db/write_batch.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/write_batch.cc b/db/write_batch.cc index 5988a9beb..43dbd995b 100644 --- a/db/write_batch.cc +++ b/db/write_batch.cc @@ -1828,8 +1828,9 @@ class MemTableInserter : public WriteBatch::Handler { // we are now iterating through a prepared section rebuilding_trx_ = new WriteBatch(); rebuilding_trx_seq_ = sequence_; - // We only call MarkBeginPrepare once per batch, and unprepared_batch_ - // is initialized to false by default. + // Verify that we have matching MarkBeginPrepare/MarkEndPrepare markers. + // unprepared_batch_ should be false because it is false by default, and + // gets reset to false in MarkEndPrepare. assert(!unprepared_batch_); unprepared_batch_ = unprepare; @@ -1854,6 +1855,7 @@ class MemTableInserter : public WriteBatch::Handler { db_->InsertRecoveredTransaction(recovering_log_number_, name.ToString(), rebuilding_trx_, rebuilding_trx_seq_, batch_cnt, unprepared_batch_); + unprepared_batch_ = false; rebuilding_trx_ = nullptr; } else { assert(rebuilding_trx_ == nullptr);