From 17c6325e8a6b5bc1489ff7a422a15ec81720efbb Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Fri, 6 Oct 2017 20:53:52 -0700 Subject: [PATCH] WritePrepare Txn: Cancel flush/compaction before destruction Summary: On WritePreparedTxnDB destruct there could be running compaction/flush holding a SnapshotChecker, which holds a pointer back to WritePreparedTxnDB. Make sure those jobs finished before destructing WritePreparedTxnDB. This is caught by TransactionTest::SeqAdvanceTest. Closes https://github.com/facebook/rocksdb/pull/2982 Differential Revision: D6002957 Pulled By: yiwu-arbug fbshipit-source-id: f1e70390c9798d1bd7959f5c8e2a1c14100773c3 --- utilities/transactions/pessimistic_transaction_db.cc | 7 +++++++ utilities/transactions/pessimistic_transaction_db.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/utilities/transactions/pessimistic_transaction_db.cc b/utilities/transactions/pessimistic_transaction_db.cc index 4cc2f0915..cf336106a 100644 --- a/utilities/transactions/pessimistic_transaction_db.cc +++ b/utilities/transactions/pessimistic_transaction_db.cc @@ -954,5 +954,12 @@ bool WritePreparedTxnDB::MaybeUpdateOldCommitMap( return next_is_larger; } +WritePreparedTxnDB::~WritePreparedTxnDB() { + // At this point there could be running compaction/flush holding a + // SnapshotChecker, which holds a pointer back to WritePreparedTxnDB. + // Make sure those jobs finished before destructing WritePreparedTxnDB. + db_impl_->CancelAllBackgroundWork(true/*wait*/); +} + } // namespace rocksdb #endif // ROCKSDB_LITE diff --git a/utilities/transactions/pessimistic_transaction_db.h b/utilities/transactions/pessimistic_transaction_db.h index 9e9d65849..b67d35c03 100644 --- a/utilities/transactions/pessimistic_transaction_db.h +++ b/utilities/transactions/pessimistic_transaction_db.h @@ -191,7 +191,7 @@ class WritePreparedTxnDB : public PessimisticTransactionDB { Init(txn_db_options); } - virtual ~WritePreparedTxnDB() {} + virtual ~WritePreparedTxnDB(); virtual Status Initialize( const std::vector& compaction_enabled_cf_indices,