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,