Skip to content

Commit

Permalink
Add single transaction sanity check.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 28, 2024
1 parent dbdf1b1 commit 9320e81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nano/store/rocksdb/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ();
}
2 changes: 2 additions & 0 deletions nano/store/rocksdb/transaction_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit 9320e81

Please sign in to comment.