From dc6da9365519563013c9b3d07a4c9d7ddb3fd2bd Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 4 Apr 2024 12:53:29 +0200 Subject: [PATCH] Move store::write_queue from nano::node to nano::store::component --- nano/core_test/confirming_set.cpp | 6 +++--- nano/core_test/node.cpp | 4 ++-- nano/node/make_store.cpp | 4 ++-- nano/node/make_store.hpp | 2 +- nano/node/node.cpp | 9 ++++----- nano/node/node.hpp | 2 -- nano/store/component.cpp | 3 ++- nano/store/component.hpp | 6 +++++- nano/store/lmdb/lmdb.cpp | 3 ++- nano/store/rocksdb/rocksdb.cpp | 5 +++-- nano/store/rocksdb/rocksdb.hpp | 2 +- 11 files changed, 25 insertions(+), 21 deletions(-) diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index 7a68c075d..f1e0d310f 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -155,7 +155,7 @@ TEST (confirmation_callback, confirmed_history) ASSERT_TIMELY (5s, election = nano::test::start_election (system, *node, send1->hash ())); { // The write guard prevents the confirmation height processor doing any writes - auto write_guard = node->write_queue.wait (nano::store::writer::testing); + auto write_guard = node->store.write_queue.wait (nano::store::writer::testing); // Confirm send1 election->force_confirm (); @@ -166,13 +166,13 @@ TEST (confirmation_callback, confirmed_history) auto transaction = node->store.tx_begin_read (); ASSERT_FALSE (node->ledger.block_confirmed (transaction, send->hash ())); - ASSERT_TIMELY (10s, node->write_queue.contains (nano::store::writer::confirmation_height)); + ASSERT_TIMELY (10s, node->store.write_queue.contains (nano::store::writer::confirmation_height)); // Confirm that no inactive callbacks have been called when the confirmation height processor has already iterated over it, waiting to write ASSERT_EQ (0, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); } - ASSERT_TIMELY (10s, !node->write_queue.contains (nano::store::writer::confirmation_height)); + ASSERT_TIMELY (10s, !node->store.write_queue.contains (nano::store::writer::confirmation_height)); auto transaction = node->store.tx_begin_read (); ASSERT_TRUE (node->ledger.block_confirmed (transaction, send->hash ())); diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index c353c48c2..b9c14f7a8 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -2740,7 +2740,7 @@ TEST (node, block_processor_half_full) .work (*node.work_generate_blocking (send2->hash ())) .build (); // The write guard prevents block processor doing any writes - auto write_guard = node.write_queue.wait (nano::store::writer::testing); + auto write_guard = node.store.write_queue.wait (nano::store::writer::testing); node.block_processor.add (send1); ASSERT_FALSE (node.block_processor.half_full ()); node.block_processor.add (send2); @@ -3097,7 +3097,7 @@ TEST (node, rollback_vote_self) { // The write guard prevents the block processor from performing the rollback - auto write_guard = node.write_queue.wait (nano::store::writer::testing); + auto write_guard = node.store.write_queue.wait (nano::store::writer::testing); ASSERT_EQ (0, election->votes_with_weight ().size ()); // Vote with key to switch the winner diff --git a/nano/node/make_store.cpp b/nano/node/make_store.cpp index 87c15700f..9122a23d0 100644 --- a/nano/node/make_store.cpp +++ b/nano/node/make_store.cpp @@ -3,11 +3,11 @@ #include #include -std::unique_ptr nano::make_store (nano::logger & logger, std::filesystem::path const & path, nano::ledger_constants & constants, bool read_only, bool add_db_postfix, nano::rocksdb_config const & rocksdb_config, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, nano::lmdb_config const & lmdb_config_a, bool backup_before_upgrade) +std::unique_ptr nano::make_store (nano::logger & logger, std::filesystem::path const & path, nano::ledger_constants & constants, bool read_only, bool add_db_postfix, nano::rocksdb_config const & rocksdb_config, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, nano::lmdb_config const & lmdb_config_a, bool backup_before_upgrade, bool force_use_write_queue) { if (rocksdb_config.enable) { - return std::make_unique (logger, add_db_postfix ? path / "rocksdb" : path, constants, rocksdb_config, read_only); + return std::make_unique (logger, add_db_postfix ? path / "rocksdb" : path, constants, rocksdb_config, read_only, force_use_write_queue); } return std::make_unique (logger, add_db_postfix ? path / "data.ldb" : path, constants, txn_tracking_config_a, block_processor_batch_max_time_a, lmdb_config_a, backup_before_upgrade); diff --git a/nano/node/make_store.hpp b/nano/node/make_store.hpp index 5f5b5f937..d66db5cbf 100644 --- a/nano/node/make_store.hpp +++ b/nano/node/make_store.hpp @@ -22,5 +22,5 @@ class component; namespace nano { -std::unique_ptr make_store (nano::logger &, std::filesystem::path const & path, nano::ledger_constants & constants, bool open_read_only = false, bool add_db_postfix = true, nano::rocksdb_config const & rocksdb_config = nano::rocksdb_config{}, nano::txn_tracking_config const & txn_tracking_config_a = nano::txn_tracking_config{}, std::chrono::milliseconds block_processor_batch_max_time_a = std::chrono::milliseconds (5000), nano::lmdb_config const & lmdb_config_a = nano::lmdb_config{}, bool backup_before_upgrade = false); +std::unique_ptr make_store (nano::logger &, std::filesystem::path const & path, nano::ledger_constants & constants, bool open_read_only = false, bool add_db_postfix = true, nano::rocksdb_config const & rocksdb_config = nano::rocksdb_config{}, nano::txn_tracking_config const & txn_tracking_config_a = nano::txn_tracking_config{}, std::chrono::milliseconds block_processor_batch_max_time_a = std::chrono::milliseconds (5000), nano::lmdb_config const & lmdb_config_a = nano::lmdb_config{}, bool backup_before_upgrade = false, bool force_use_write_queue = false); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index d2245f6dd..951af4bf8 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -135,7 +135,6 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy io_ctx_shared{ io_ctx_a }, io_ctx{ *io_ctx_shared }, node_id{ load_or_create_node_id (application_path_a) }, - write_queue (!flags_a.force_use_write_queue && (config_a.rocksdb_config.enable)), node_initialized_latch (1), config (config_a), network_params{ config.network_params }, @@ -146,7 +145,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy flags (flags_a), work (work_a), distributed_work (*this), - store_impl (nano::make_store (logger, application_path_a, network_params.ledger, flags.read_only, true, config_a.rocksdb_config, config_a.diagnostics_config.txn_tracking, config_a.block_processor_batch_max_time, config_a.lmdb_config, config_a.backup_before_upgrade)), + store_impl (nano::make_store (logger, application_path_a, network_params.ledger, flags.read_only, true, config_a.rocksdb_config, config_a.diagnostics_config.txn_tracking, config_a.block_processor_batch_max_time, config_a.lmdb_config, config_a.backup_before_upgrade, flags.force_use_write_queue)), store (*store_impl), unchecked{ config.max_unchecked_blocks, stats, flags.disable_block_processor_unchecked_deletion }, wallets_store_impl (std::make_unique (application_path_a / "wallets.ldb", config_a.lmdb_config)), @@ -171,8 +170,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy tcp_listener{ std::make_shared (network.port, *this, config.tcp_incoming_connections_max) }, application_path (application_path_a), port_mapping (*this), - block_processor (*this, write_queue), - confirming_set_impl{ std::make_unique (ledger, write_queue, config.confirming_set_batch_time) }, + block_processor (*this, store.write_queue), + confirming_set_impl{ std::make_unique (ledger, store.write_queue, config.confirming_set_batch_time) }, confirming_set{ *confirming_set_impl }, active_impl{ std::make_unique (*this, confirming_set, block_processor) }, active{ *active_impl }, @@ -1005,7 +1004,7 @@ void nano::node::ledger_pruning (uint64_t const batch_size_a, bool bootstrap_wei transaction_write_count = 0; if (!pruning_targets.empty () && !stopped) { - auto scoped_write_guard = write_queue.wait (nano::store::writer::pruning); + auto scoped_write_guard = store.write_queue.wait (nano::store::writer::pruning); auto write_transaction (store.tx_begin_write ({ tables::blocks, tables::pruned })); while (!pruning_targets.empty () && transaction_write_count < batch_size_a && !stopped) { diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 25f36af51..c5df2fea1 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -138,7 +137,6 @@ public: public: const nano::keypair node_id; - nano::store::write_queue write_queue; std::shared_ptr io_ctx_shared; boost::asio::io_context & io_ctx; boost::latch node_initialized_latch; diff --git a/nano/store/component.cpp b/nano/store/component.cpp index 5d8c8bec2..815f3e595 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -7,7 +7,7 @@ #include #include -nano::store::component::component (nano::store::block & block_store_a, nano::store::account & account_store_a, nano::store::pending & pending_store_a, nano::store::online_weight & online_weight_store_a, nano::store::pruned & pruned_store_a, nano::store::peer & peer_store_a, nano::store::confirmation_height & confirmation_height_store_a, nano::store::final_vote & final_vote_store_a, nano::store::version & version_store_a, nano::store::rep_weight & rep_weight_a) : +nano::store::component::component (nano::store::block & block_store_a, nano::store::account & account_store_a, nano::store::pending & pending_store_a, nano::store::online_weight & online_weight_store_a, nano::store::pruned & pruned_store_a, nano::store::peer & peer_store_a, nano::store::confirmation_height & confirmation_height_store_a, nano::store::final_vote & final_vote_store_a, nano::store::version & version_store_a, nano::store::rep_weight & rep_weight_a, bool use_noops_a) : block (block_store_a), account (account_store_a), pending (pending_store_a), @@ -17,6 +17,7 @@ nano::store::component::component (nano::store::block & block_store_a, nano::sto confirmation_height (confirmation_height_store_a), final_vote (final_vote_store_a), version (version_store_a), + write_queue (use_noops_a), rep_weight (rep_weight_a) { } diff --git a/nano/store/component.hpp b/nano/store/component.hpp index 9ba94029a..7cdd7d1ff 100644 --- a/nano/store/component.hpp +++ b/nano/store/component.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,8 @@ namespace store nano::store::confirmation_height &, nano::store::final_vote &, nano::store::version &, - nano::store::rep_weight & + nano::store::rep_weight &, + bool use_noops_a ); // clang-format on virtual ~component () = default; @@ -79,6 +81,8 @@ namespace store store::final_vote & final_vote; store::version & version; + store::write_queue write_queue; + virtual unsigned max_block_write_batch_num () const = 0; virtual bool copy_db (std::filesystem::path const & destination) = 0; diff --git a/nano/store/lmdb/lmdb.cpp b/nano/store/lmdb/lmdb.cpp index 122bf55a9..e5d2f448b 100644 --- a/nano/store/lmdb/lmdb.cpp +++ b/nano/store/lmdb/lmdb.cpp @@ -26,7 +26,8 @@ nano::store::lmdb::component::component (nano::logger & logger_a, std::filesyste confirmation_height_store, final_vote_store, version_store, - rep_weight_store + rep_weight_store, + false // write_queue use_noops }, // clang-format on block_store{ *this }, diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index d9fb4e316..92fafe693 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -35,7 +35,7 @@ private: }; } -nano::store::rocksdb::component::component (nano::logger & logger_a, std::filesystem::path const & path_a, nano::ledger_constants & constants, nano::rocksdb_config const & rocksdb_config_a, bool open_read_only_a) : +nano::store::rocksdb::component::component (nano::logger & logger_a, std::filesystem::path const & path_a, nano::ledger_constants & constants, nano::rocksdb_config const & rocksdb_config_a, bool open_read_only_a, bool force_use_write_queue) : // clang-format off nano::store::component{ block_store, @@ -47,7 +47,8 @@ nano::store::rocksdb::component::component (nano::logger & logger_a, std::filesy confirmation_height_store, final_vote_store, version_store, - rep_weight_store + rep_weight_store, + !force_use_write_queue // write_queue use_noops }, // clang-format on block_store{ *this }, diff --git a/nano/store/rocksdb/rocksdb.hpp b/nano/store/rocksdb/rocksdb.hpp index 8a71cf2b1..d52609969 100644 --- a/nano/store/rocksdb/rocksdb.hpp +++ b/nano/store/rocksdb/rocksdb.hpp @@ -64,7 +64,7 @@ public: friend class nano::store::rocksdb::version; friend class nano::store::rocksdb::rep_weight; - explicit component (nano::logger &, std::filesystem::path const &, nano::ledger_constants & constants, nano::rocksdb_config const & = nano::rocksdb_config{}, bool open_read_only = false); + explicit component (nano::logger &, std::filesystem::path const &, nano::ledger_constants & constants, nano::rocksdb_config const & = nano::rocksdb_config{}, bool open_read_only = false, bool force_use_write_queue = false); store::write_transaction tx_begin_write (std::vector const & tables_requiring_lock = {}, std::vector const & tables_no_lock = {}) override; store::read_transaction tx_begin_read () const override;