diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index d605e742e5..6ae1f43d99 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -193,10 +193,10 @@ void nano::store::rocksdb::component::open (bool & error_a, std::filesystem::pat } else { - s = ::rocksdb::OptimisticTransactionDB::Open (options_a, path_a.string (), column_families, &handles_l, &optimistic_db); - if (optimistic_db) + s = ::rocksdb::TransactionDB::Open (options_a, ::rocksdb::TransactionDBOptions{}, path_a.string (), column_families, &handles_l, &transaction_db); + if (transaction_db) { - db.reset (optimistic_db); + db.reset (transaction_db); } } @@ -489,15 +489,15 @@ std::vector nano::store::rocksdb::component::cr nano::store::write_transaction nano::store::rocksdb::component::tx_begin_write (std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a) { std::unique_ptr txn; - release_assert (optimistic_db != nullptr); + release_assert (db != nullptr); if (tables_requiring_locks_a.empty () && tables_no_locks_a.empty ()) { // Use all tables if none are specified - txn = std::make_unique (optimistic_db, all_tables (), tables_no_locks_a, write_lock_mutexes); + txn = std::make_unique (transaction_db, all_tables (), tables_no_locks_a, write_lock_mutexes); } else { - txn = std::make_unique (optimistic_db, tables_requiring_locks_a, tables_no_locks_a, write_lock_mutexes); + txn = std::make_unique (transaction_db, tables_requiring_locks_a, tables_no_locks_a, write_lock_mutexes); } // Tables must be kept in alphabetical order. These can be used for mutex locking, so order is important to prevent deadlocking diff --git a/nano/store/rocksdb/rocksdb.hpp b/nano/store/rocksdb/rocksdb.hpp index d526099697..0b6f11cb85 100644 --- a/nano/store/rocksdb/rocksdb.hpp +++ b/nano/store/rocksdb/rocksdb.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace nano { @@ -105,8 +105,7 @@ class component : public nano::store::component bool error{ false }; nano::logger & logger; nano::ledger_constants & constants; - // Optimistic transactions are used in write mode - ::rocksdb::OptimisticTransactionDB * optimistic_db = nullptr; + ::rocksdb::TransactionDB * transaction_db = nullptr; std::unique_ptr<::rocksdb::DB> db; std::vector> handles; std::shared_ptr<::rocksdb::TableFactory> small_table_factory; diff --git a/nano/store/rocksdb/transaction.cpp b/nano/store/rocksdb/transaction.cpp index 0974eeca62..abccc8bf6f 100644 --- a/nano/store/rocksdb/transaction.cpp +++ b/nano/store/rocksdb/transaction.cpp @@ -32,14 +32,14 @@ void * nano::store::rocksdb::read_transaction_impl::get_handle () const return (void *)&options; } -nano::store::rocksdb::write_transaction_impl::write_transaction_impl (::rocksdb::OptimisticTransactionDB * db_a, std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a, std::unordered_map & mutexes_a) : +nano::store::rocksdb::write_transaction_impl::write_transaction_impl (::rocksdb::TransactionDB * db_a, std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a, std::unordered_map & mutexes_a) : db (db_a), tables_requiring_locks (tables_requiring_locks_a), tables_no_locks (tables_no_locks_a), mutexes (mutexes_a) { lock (); - ::rocksdb::OptimisticTransactionOptions txn_options; + ::rocksdb::TransactionOptions txn_options; txn_options.set_snapshot = true; txn = db->BeginTransaction (::rocksdb::WriteOptions (), txn_options); } @@ -56,27 +56,14 @@ void nano::store::rocksdb::write_transaction_impl::commit () if (active) { auto status = txn->Commit (); - - // If there are no available memtables try again a few more times - constexpr auto num_attempts = 10; - auto attempt_num = 0; - while (status.IsTryAgain () && attempt_num < num_attempts) - { - status = txn->Commit (); - ++attempt_num; - } - - if (!status.ok ()) - { - release_assert (false && "Unable to write to the RocksDB database", status.ToString ()); - } + release_assert (status.ok () && "Unable to write to the RocksDB database", status.ToString ()); active = false; } } void nano::store::rocksdb::write_transaction_impl::renew () { - ::rocksdb::OptimisticTransactionOptions txn_options; + ::rocksdb::TransactionOptions txn_options; txn_options.set_snapshot = true; db->BeginTransaction (::rocksdb::WriteOptions (), txn_options, txn); active = true; diff --git a/nano/store/rocksdb/transaction_impl.hpp b/nano/store/rocksdb/transaction_impl.hpp index ce3f531f94..ab9429fcd8 100644 --- a/nano/store/rocksdb/transaction_impl.hpp +++ b/nano/store/rocksdb/transaction_impl.hpp @@ -4,8 +4,8 @@ #include #include -#include #include +#include namespace nano::store::rocksdb { @@ -26,7 +26,7 @@ class read_transaction_impl final : public store::read_transaction_impl class write_transaction_impl final : public store::write_transaction_impl { public: - write_transaction_impl (::rocksdb::OptimisticTransactionDB * db_a, std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a, std::unordered_map & mutexes_a); + write_transaction_impl (::rocksdb::TransactionDB * db_a, std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a, std::unordered_map & mutexes_a); ~write_transaction_impl (); void commit () override; void renew () override; @@ -35,7 +35,7 @@ class write_transaction_impl final : public store::write_transaction_impl private: ::rocksdb::Transaction * txn; - ::rocksdb::OptimisticTransactionDB * db; + ::rocksdb::TransactionDB * db; std::vector tables_requiring_locks; std::vector tables_no_locks; std::unordered_map & mutexes;