diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index 4b5b8676b4..7cc7ae91f6 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -18,15 +18,13 @@ using namespace std::chrono_literals; TEST (confirming_set, construction) { auto ctx = nano::test::context::ledger_empty (); - nano::write_database_queue write_queue{ false }; - nano::confirming_set confirming_set (ctx.ledger (), write_queue); + nano::confirming_set confirming_set (ctx.ledger ()); } TEST (confirming_set, add_exists) { auto ctx = nano::test::context::ledger_send_receive (); - nano::write_database_queue write_queue{ false }; - nano::confirming_set confirming_set (ctx.ledger (), write_queue); + nano::confirming_set confirming_set (ctx.ledger ()); auto send = ctx.blocks ()[0]; confirming_set.add (send->hash ()); ASSERT_TRUE (confirming_set.exists (send->hash ())); @@ -35,8 +33,7 @@ TEST (confirming_set, add_exists) TEST (confirming_set, process_one) { auto ctx = nano::test::context::ledger_send_receive (); - nano::write_database_queue write_queue{ false }; - nano::confirming_set confirming_set (ctx.ledger (), write_queue); + nano::confirming_set confirming_set (ctx.ledger ()); std::atomic count = 0; std::mutex mutex; std::condition_variable condition; @@ -52,8 +49,7 @@ TEST (confirming_set, process_one) TEST (confirming_set, process_multiple) { auto ctx = nano::test::context::ledger_send_receive (); - nano::write_database_queue write_queue{ false }; - nano::confirming_set confirming_set (ctx.ledger (), write_queue); + nano::confirming_set confirming_set (ctx.ledger ()); std::atomic count = 0; std::mutex mutex; std::condition_variable condition; @@ -118,7 +114,7 @@ TEST (confirmation_callback, confirmed_history) { nano::test::system system; nano::node_flags node_flags; - node_flags.force_use_write_database_queue = true; + node_flags.force_use_write_queue = true; node_flags.disable_ascending_bootstrap = true; nano::node_config node_config = system.default_config (); node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; @@ -155,7 +151,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_database_queue.wait (nano::writer::testing); + auto write_guard = node->store.write_queue.wait (nano::store::writer::testing); // Confirm send1 election->force_confirm (); @@ -166,13 +162,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_database_queue.contains (nano::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_database_queue.contains (nano::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 ())); @@ -196,7 +192,7 @@ TEST (confirmation_callback, dependent_election) { nano::test::system system; nano::node_flags node_flags; - node_flags.force_use_write_database_queue = true; + node_flags.force_use_write_queue = true; nano::node_config node_config = system.default_config (); node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; auto node = system.add_node (node_config, node_flags); diff --git a/nano/core_test/ledger_confirm.cpp b/nano/core_test/ledger_confirm.cpp index dc6e55c37a..45dccb0f1f 100644 --- a/nano/core_test/ledger_confirm.cpp +++ b/nano/core_test/ledger_confirm.cpp @@ -784,7 +784,7 @@ TEST (ledger_confirm, pruned_source) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - nano::write_database_queue write_database_queue (false); + nano::store::write_queue write_queue (false); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1, key2; nano::block_builder builder; @@ -868,7 +868,7 @@ TEST (ledger_confirmDeathTest, rollback_added_block) ASSERT_TRUE (!store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - nano::write_database_queue write_database_queue (false); + nano::store::write_queue write_queue (false); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1; nano::block_builder builder; diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index ba48a347cb..b9c14f7a87 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -2663,7 +2663,7 @@ TEST (node, block_processor_full) { nano::test::system system; nano::node_flags node_flags; - node_flags.force_use_write_database_queue = true; + node_flags.force_use_write_queue = true; node_flags.block_processor_full_size = 3; auto & node = *system.add_node (nano::node_config (system.get_available_port ()), node_flags); nano::state_block_builder builder; @@ -2709,7 +2709,7 @@ TEST (node, block_processor_half_full) nano::test::system system; nano::node_flags node_flags; node_flags.block_processor_full_size = 6; - node_flags.force_use_write_database_queue = true; + node_flags.force_use_write_queue = true; auto & node = *system.add_node (nano::node_config (system.get_available_port ()), node_flags); nano::state_block_builder builder; auto send1 = builder.make_block () @@ -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_database_queue.wait (nano::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_database_queue.wait (nano::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/CMakeLists.txt b/nano/node/CMakeLists.txt index c50f4393bf..77f60640b9 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -180,8 +180,6 @@ add_library( websocketconfig.cpp websocket_stream.hpp websocket_stream.cpp - write_database_queue.hpp - write_database_queue.cpp messages.hpp messages.cpp xorshift.hpp) diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 8443493557..bc10d115c8 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -37,10 +37,9 @@ void nano::block_processor::context::set_result (result_t const & result) * block_processor */ -nano::block_processor::block_processor (nano::node & node_a, nano::write_database_queue & write_database_queue_a) : +nano::block_processor::block_processor (nano::node & node_a) : config{ node_a.config.block_processor }, node (node_a), - write_database_queue (write_database_queue_a), next_log (std::chrono::steady_clock::now ()) { batch_processed.add ([this] (auto const & items) { @@ -300,7 +299,7 @@ auto nano::block_processor::process_batch (nano::unique_lock & lock { processed_batch_t processed; - auto scoped_write_guard = write_database_queue.wait (nano::writer::process_batch); + auto scoped_write_guard = node.store.write_queue.wait (nano::store::writer::process_batch); auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights })); nano::timer timer_l; @@ -509,4 +508,4 @@ nano::error nano::block_processor_config::deserialize (nano::tomlconfig & toml) toml.get ("priority_local", priority_local); return toml.get_error (); -} \ No newline at end of file +} diff --git a/nano/node/blockprocessor.hpp b/nano/node/blockprocessor.hpp index a1537092f0..2e01d591ca 100644 --- a/nano/node/blockprocessor.hpp +++ b/nano/node/blockprocessor.hpp @@ -14,7 +14,6 @@ namespace nano { class block; class node; -class write_database_queue; } namespace nano::store @@ -86,7 +85,7 @@ class block_processor final }; public: - block_processor (nano::node &, nano::write_database_queue &); + block_processor (nano::node &); ~block_processor (); void start (); @@ -127,7 +126,6 @@ class block_processor final private: // Dependencies block_processor_config const & config; nano::node & node; - nano::write_database_queue & write_database_queue; private: nano::fair_queue queue; diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index 5db631aed3..f9c9101e57 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -1,12 +1,11 @@ #include #include -#include #include #include +#include -nano::confirming_set::confirming_set (nano::ledger & ledger, nano::write_database_queue & write_queue, std::chrono::milliseconds batch_time) : +nano::confirming_set::confirming_set (nano::ledger & ledger, std::chrono::milliseconds batch_time) : ledger{ ledger }, - write_queue{ write_queue }, batch_time{ batch_time } { } @@ -72,7 +71,7 @@ void nano::confirming_set::run () for (auto i = processing.begin (), n = processing.end (); !stopped && i != n;) { lock.unlock (); // Waiting for db write is potentially slow - auto guard = write_queue.wait (nano::writer::confirmation_height); + auto guard = ledger.store.write_queue.wait (nano::store::writer::confirmation_height); auto tx = ledger.store.tx_begin_write ({ nano::tables::confirmation_height }); lock.lock (); // Process items in the back buffer within a single transaction for a limited amount of time diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 5c5de14bd5..06feb52e11 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -13,7 +13,6 @@ namespace nano { class block; class ledger; -class write_database_queue; } namespace nano @@ -27,7 +26,7 @@ class confirming_set final friend class confirmation_height_pruned_source_Test; public: - confirming_set (nano::ledger & ledger, nano::write_database_queue & write_queue, std::chrono::milliseconds batch_time = std::chrono::milliseconds{ 500 }); + confirming_set (nano::ledger & ledger, std::chrono::milliseconds batch_time = std::chrono::milliseconds{ 500 }); ~confirming_set (); // Adds a block to the set of blocks to be confirmed void add (nano::block_hash const & hash); @@ -45,7 +44,6 @@ class confirming_set final private: void run (); nano::ledger & ledger; - nano::write_database_queue & write_queue; std::chrono::milliseconds batch_time; std::unordered_set set; std::unordered_set processing; diff --git a/nano/node/make_store.cpp b/nano/node/make_store.cpp index 87c15700fe..9122a23d07 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 5f5b5f9372..d66db5cbfb 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 10a710f608..ad80e5e040 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_database_queue (!flags_a.force_use_write_database_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_database_queue), - confirming_set_impl{ std::make_unique (ledger, write_database_queue, config.confirming_set_batch_time) }, + block_processor (*this), + confirming_set_impl{ std::make_unique (ledger, 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_database_queue.wait (nano::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 53ba1f69a9..c5df2fea11 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -138,7 +137,6 @@ class node final : public std::enable_shared_from_this public: const nano::keypair node_id; - nano::write_database_queue write_database_queue; std::shared_ptr io_ctx_shared; boost::asio::io_context & io_ctx; boost::latch node_initialized_latch; diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index b8c953b270..db09480e35 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -171,7 +171,7 @@ class node_flags final bool allow_bootstrap_peers_duplicates{ false }; bool disable_max_peers_per_ip{ false }; // For testing only bool disable_max_peers_per_subnetwork{ false }; // For testing only - bool force_use_write_database_queue{ false }; // For testing only. RocksDB does not use the database queue, but some tests rely on it being used. + bool force_use_write_queue{ false }; // For testing only. RocksDB does not use the database queue, but some tests rely on it being used. bool disable_search_pending{ false }; // For testing only bool enable_pruning{ false }; bool fast_bootstrap{ false }; diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 78f50fd464..a1a1230831 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -1136,14 +1136,14 @@ TEST (confirmation_height, many_accounts_send_receive_self_no_elections) ASSERT_TRUE (!store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - nano::write_database_queue write_database_queue (false); + nano::store::write_queue write_database_queue (false); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; std::atomic stopped{ false }; boost::latch initialized_latch{ 0 }; nano::block_hash block_hash_being_processed{ 0 }; - nano::write_database_queue write_queue{ false }; - nano::confirming_set confirming_set{ ledger, write_queue }; + nano::store::write_queue write_queue{ false }; + nano::confirming_set confirming_set{ ledger }; auto const num_accounts = 100000; diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index 794f6c0535..68cde103a1 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -92,7 +92,9 @@ add_library( rocksdb/version.cpp transaction.cpp version.cpp - versioning.cpp) + versioning.cpp + write_queue.hpp + write_queue.cpp) target_link_libraries( nano_store diff --git a/nano/store/component.cpp b/nano/store/component.cpp index 5d8c8bec20..815f3e5950 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 9ba94029af..7cdd7d1fff 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 122bf55a98..e5d2f448bc 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 d9fb4e3164..92fafe6934 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -35,7 +35,7 @@ class event_listener : public rocksdb::EventListener }; } -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 8a71cf2b12..d526099697 100644 --- a/nano/store/rocksdb/rocksdb.hpp +++ b/nano/store/rocksdb/rocksdb.hpp @@ -64,7 +64,7 @@ class component : public nano::store::component 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; diff --git a/nano/node/write_database_queue.cpp b/nano/store/write_queue.cpp similarity index 72% rename from nano/node/write_database_queue.cpp rename to nano/store/write_queue.cpp index 8bb42fe322..cdc7f41ff8 100644 --- a/nano/node/write_database_queue.cpp +++ b/nano/store/write_queue.cpp @@ -1,15 +1,15 @@ #include #include -#include +#include #include -nano::write_guard::write_guard (std::function guard_finish_callback_a) : +nano::store::write_guard::write_guard (std::function guard_finish_callback_a) : guard_finish_callback (guard_finish_callback_a) { } -nano::write_guard::write_guard (nano::write_guard && write_guard_a) noexcept : +nano::store::write_guard::write_guard (write_guard && write_guard_a) noexcept : guard_finish_callback (std::move (write_guard_a.guard_finish_callback)), owns (write_guard_a.owns) { @@ -17,7 +17,7 @@ nano::write_guard::write_guard (nano::write_guard && write_guard_a) noexcept : write_guard_a.guard_finish_callback = nullptr; } -nano::write_guard & nano::write_guard::operator= (nano::write_guard && write_guard_a) noexcept +nano::store::write_guard & nano::store::write_guard::operator= (write_guard && write_guard_a) noexcept { owns = write_guard_a.owns; guard_finish_callback = std::move (write_guard_a.guard_finish_callback); @@ -27,7 +27,7 @@ nano::write_guard & nano::write_guard::operator= (nano::write_guard && write_gua return *this; } -nano::write_guard::~write_guard () +nano::store::write_guard::~write_guard () { if (owns) { @@ -35,12 +35,12 @@ nano::write_guard::~write_guard () } } -bool nano::write_guard::is_owned () const +bool nano::store::write_guard::is_owned () const { return owns; } -void nano::write_guard::release () +void nano::store::write_guard::release () { debug_assert (owns); if (owns) @@ -50,7 +50,7 @@ void nano::write_guard::release () owns = false; } -nano::write_database_queue::write_database_queue (bool use_noops_a) : +nano::store::write_queue::write_queue (bool use_noops_a) : guard_finish_callback ([use_noops_a, &queue = queue, &mutex = mutex, &cv = cv] () { if (!use_noops_a) { @@ -65,7 +65,7 @@ nano::write_database_queue::write_database_queue (bool use_noops_a) : { } -nano::write_guard nano::write_database_queue::wait (nano::writer writer) +nano::store::write_guard nano::store::write_queue::wait (writer writer) { if (use_noops) { @@ -88,14 +88,14 @@ nano::write_guard nano::write_database_queue::wait (nano::writer writer) return write_guard (guard_finish_callback); } -bool nano::write_database_queue::contains (nano::writer writer) +bool nano::store::write_queue::contains (writer writer) { debug_assert (!use_noops); nano::lock_guard guard (mutex); return std::find (queue.cbegin (), queue.cend (), writer) != queue.cend (); } -bool nano::write_database_queue::process (nano::writer writer) +bool nano::store::write_queue::process (writer writer) { if (use_noops) { @@ -123,7 +123,7 @@ bool nano::write_database_queue::process (nano::writer writer) return result; } -nano::write_guard nano::write_database_queue::pop () +nano::store::write_guard nano::store::write_queue::pop () { return write_guard (guard_finish_callback); } diff --git a/nano/node/write_database_queue.hpp b/nano/store/write_queue.hpp similarity index 83% rename from nano/node/write_database_queue.hpp rename to nano/store/write_queue.hpp index d6c6883ea6..674a7742bc 100644 --- a/nano/node/write_database_queue.hpp +++ b/nano/store/write_queue.hpp @@ -6,7 +6,7 @@ #include #include -namespace nano +namespace nano::store { /** Distinct areas write locking is done, order is irrelevant */ enum class writer @@ -20,7 +20,7 @@ enum class writer class write_guard final { public: - write_guard (std::function guard_finish_callback_a); + explicit write_guard (std::function guard_finish_callback_a); void release (); ~write_guard (); write_guard (write_guard const &) = delete; @@ -38,27 +38,27 @@ class write_guard final * Allocates database write access in a fair maner rather than directly waiting for mutex aquisition * Users should wait() for access to database write transaction and hold the write_guard until complete */ -class write_database_queue final +class write_queue final { public: - write_database_queue (bool use_noops_a); + explicit write_queue (bool use_noops_a); /** Blocks until we are at the head of the queue and blocks other waiters until write_guard goes out of scope */ - [[nodiscard ("write_guard blocks other waiters")]] write_guard wait (nano::writer writer); + [[nodiscard ("write_guard blocks other waiters")]] write_guard wait (writer writer); /** Returns true if this writer is now at the front of the queue */ - bool process (nano::writer writer); + bool process (writer writer); /** Returns true if this writer is anywhere in the queue. Currently only used in tests */ - bool contains (nano::writer writer); + bool contains (writer writer); /** Doesn't actually pop anything until the returned write_guard is out of scope */ write_guard pop (); private: - std::deque queue; + std::deque queue; nano::mutex mutex; nano::condition_variable cv; std::function guard_finish_callback; bool use_noops; }; -} +} // namespace nano::store