From 3ebe2fbfb874a98293830844727a1fb4ea429d96 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Fri, 5 Jul 2024 12:39:27 +0100 Subject: [PATCH] Use TransactionDB rather than OptimisticTransactionDB. --- nano/secure/ledger.cpp | 4 ++-- nano/store/rocksdb/rocksdb.cpp | 3 ++- nano/store/rocksdb/rocksdb.hpp | 4 ++-- nano/store/rocksdb/transaction.cpp | 6 +++--- nano/store/rocksdb/transaction_impl.hpp | 6 +++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index de111070d3..c0f5313d2d 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1242,7 +1242,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p // Open rocksdb database nano::rocksdb_config rocksdb_config; rocksdb_config.enable = true; - rocksdb_config.memory_multiplier = std::numeric_limits::max (); + //rocksdb_config.memory_multiplier = 4; auto rocksdb_store = nano::make_store (logger, data_path_a, nano::dev::constants, false, true, rocksdb_config); if (!rocksdb_store->init_error ()) @@ -1250,7 +1250,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p auto table_size = store.count (store.tx_begin_read (), tables::blocks); logger.info (nano::log::type::ledger, "Step 1 of 7: Converting {} million entries from blocks table", table_size / 1000000); std::atomic count = 0; - auto refresh_interval = 20ms; + auto refresh_interval = 100ms; store.block.for_each_par ( [&] (store::read_transaction const & /*unused*/, auto i, auto n) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::blocks })); diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index c804ddeade..59b337ae32 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -193,7 +193,8 @@ 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); + ::rocksdb::TransactionDBOptions options; + s = ::rocksdb::TransactionDB::Open (options_a, options, path_a.string (), column_families, &handles_l, &optimistic_db); if (optimistic_db) { db.reset (optimistic_db); diff --git a/nano/store/rocksdb/rocksdb.hpp b/nano/store/rocksdb/rocksdb.hpp index d526099697..9c22391cde 100644 --- a/nano/store/rocksdb/rocksdb.hpp +++ b/nano/store/rocksdb/rocksdb.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace nano { @@ -106,7 +106,7 @@ class component : public nano::store::component nano::logger & logger; nano::ledger_constants & constants; // Optimistic transactions are used in write mode - ::rocksdb::OptimisticTransactionDB * optimistic_db = nullptr; + ::rocksdb::TransactionDB * optimistic_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..a2bf93ffe8 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); } @@ -76,7 +76,7 @@ void nano::store::rocksdb::write_transaction_impl::commit () 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..b9d5afe40b 100644 --- a/nano/store/rocksdb/transaction_impl.hpp +++ b/nano/store/rocksdb/transaction_impl.hpp @@ -4,7 +4,7 @@ #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;