From 0ed98bf89e77f1966893979e79ebe717188c709f Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Mon, 7 Jan 2019 14:53:26 -0800 Subject: [PATCH] WritePrepared: fix snapshot sequence in rollback (#4851) Summary: The rollback algorithm in WritePrepared transactions requires reading the values before the transaction start. Currently it uses the prepare_seq -1 as the snapshot sequence number for the read. This is not correct since the passed sequence number must be for a valid snapshot. The patch fixes it by passing kMaxSequenceNumber instead. This is fine since all the writes done by the aborted transaction will be skipped during the read anyway. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4851 Differential Revision: D13592773 Pulled By: maysamyabandeh fbshipit-source-id: ff1bf92ea9909d4cccb173bdff49febc0e9eb7a2 --- utilities/transactions/write_prepared_txn.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utilities/transactions/write_prepared_txn.cc b/utilities/transactions/write_prepared_txn.cc index 0245f3138..ed3c72ccb 100644 --- a/utilities/transactions/write_prepared_txn.cc +++ b/utilities/transactions/write_prepared_txn.cc @@ -218,8 +218,7 @@ Status WritePreparedTxn::RollbackInternal() { assert(GetId() > 0); auto cf_map_shared_ptr = wpt_db_->GetCFHandleMap(); auto cf_comp_map_shared_ptr = wpt_db_->GetCFComparatorMap(); - // In WritePrepared, the txn is is the same as prepare seq - auto last_visible_txn = GetId() - 1; + auto read_at_seq = kMaxSequenceNumber; struct RollbackWriteBatchBuilder : public WriteBatch::Handler { DBImpl* db_; ReadOptions roptions; @@ -308,7 +307,7 @@ Status WritePreparedTxn::RollbackInternal() { protected: virtual bool WriteAfterCommit() const override { return false; } - } rollback_handler(db_impl_, wpt_db_, last_visible_txn, &rollback_batch, + } rollback_handler(db_impl_, wpt_db_, read_at_seq, &rollback_batch, *cf_comp_map_shared_ptr.get(), *cf_map_shared_ptr.get(), wpt_db_->txn_db_options_.rollback_merge_operands); auto s = GetWriteBatch()->GetWriteBatch()->Iterate(&rollback_handler);