From 9320e81fb569d74fc36d91548f6747ddc0f89c6f Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sat, 28 Sep 2024 13:51:57 +0100 Subject: [PATCH] Add single transaction sanity check. --- nano/store/rocksdb/transaction.cpp | 8 ++++++++ nano/store/rocksdb/transaction_impl.hpp | 2 ++ 2 files changed, 10 insertions(+) diff --git a/nano/store/rocksdb/transaction.cpp b/nano/store/rocksdb/transaction.cpp index 5642029cc4..c812eaa71e 100644 --- a/nano/store/rocksdb/transaction.cpp +++ b/nano/store/rocksdb/transaction.cpp @@ -35,6 +35,7 @@ void * nano::store::rocksdb::read_transaction_impl::get_handle () const nano::store::rocksdb::write_transaction_impl::write_transaction_impl (::rocksdb::TransactionDB * db_a) : db (db_a) { + debug_assert (check_no_write_tx ()); ::rocksdb::TransactionOptions txn_options; txn_options.set_snapshot = true; txn = db->BeginTransaction (::rocksdb::WriteOptions (), txn_options); @@ -73,3 +74,10 @@ bool nano::store::rocksdb::write_transaction_impl::contains (nano::tables table_ { return true; } + +bool nano::store::rocksdb::write_transaction_impl::check_no_write_tx () const +{ + std::vector<::rocksdb::Transaction *> transactions; + db->GetAllPreparedTransactions (&transactions); + return transactions.empty (); +} diff --git a/nano/store/rocksdb/transaction_impl.hpp b/nano/store/rocksdb/transaction_impl.hpp index 9ccbedc184..8d795322a6 100644 --- a/nano/store/rocksdb/transaction_impl.hpp +++ b/nano/store/rocksdb/transaction_impl.hpp @@ -34,6 +34,8 @@ class write_transaction_impl final : public store::write_transaction_impl bool contains (nano::tables table_a) const override; private: + bool check_no_write_tx () const; + ::rocksdb::Transaction * txn; ::rocksdb::TransactionDB * db; bool active{ true };