Move store::write_queue from nano::node to nano::store::component
This commit is contained in:
		
					parent
					
						
							
								24a55d8f6b
							
						
					
				
			
			
				commit
				
					
						dc6da93655
					
				
			
		
					 11 changed files with 25 additions and 21 deletions
				
			
		| 
						 | 
				
			
			@ -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 ()));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,11 +3,11 @@
 | 
			
		|||
#include <nano/store/lmdb/lmdb.hpp>
 | 
			
		||||
#include <nano/store/rocksdb/rocksdb.hpp>
 | 
			
		||||
 | 
			
		||||
std::unique_ptr<nano::store::component> 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::store::component> 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<nano::store::rocksdb::component> (logger, add_db_postfix ? path / "rocksdb" : path, constants, rocksdb_config, read_only);
 | 
			
		||||
		return std::make_unique<nano::store::rocksdb::component> (logger, add_db_postfix ? path / "rocksdb" : path, constants, rocksdb_config, read_only, force_use_write_queue);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return std::make_unique<nano::store::lmdb::component> (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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,5 +22,5 @@ class component;
 | 
			
		|||
 | 
			
		||||
namespace nano
 | 
			
		||||
{
 | 
			
		||||
std::unique_ptr<nano::store::component> 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<nano::store::component> 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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -135,7 +135,6 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> 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<boost::asio::io_context> 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<nano::mdb_wallets_store> (application_path_a / "wallets.ldb", config_a.lmdb_config)),
 | 
			
		||||
| 
						 | 
				
			
			@ -171,8 +170,8 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
 | 
			
		|||
	tcp_listener{ std::make_shared<nano::transport::tcp_listener> (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<nano::confirming_set> (ledger, write_queue, config.confirming_set_batch_time) },
 | 
			
		||||
	block_processor (*this, store.write_queue),
 | 
			
		||||
	confirming_set_impl{ std::make_unique<nano::confirming_set> (ledger, store.write_queue, config.confirming_set_batch_time) },
 | 
			
		||||
	confirming_set{ *confirming_set_impl },
 | 
			
		||||
	active_impl{ std::make_unique<nano::active_transactions> (*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)
 | 
			
		||||
			{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,6 @@
 | 
			
		|||
#include <nano/node/wallet.hpp>
 | 
			
		||||
#include <nano/node/websocket.hpp>
 | 
			
		||||
#include <nano/secure/utility.hpp>
 | 
			
		||||
#include <nano/store/write_queue.hpp>
 | 
			
		||||
 | 
			
		||||
#include <boost/program_options.hpp>
 | 
			
		||||
#include <boost/thread/latch.hpp>
 | 
			
		||||
| 
						 | 
				
			
			@ -138,7 +137,6 @@ public:
 | 
			
		|||
 | 
			
		||||
public:
 | 
			
		||||
	const nano::keypair node_id;
 | 
			
		||||
	nano::store::write_queue write_queue;
 | 
			
		||||
	std::shared_ptr<boost::asio::io_context> io_ctx_shared;
 | 
			
		||||
	boost::asio::io_context & io_ctx;
 | 
			
		||||
	boost::latch node_initialized_latch;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@
 | 
			
		|||
#include <nano/store/confirmation_height.hpp>
 | 
			
		||||
#include <nano/store/rep_weight.hpp>
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,7 @@
 | 
			
		|||
#include <nano/store/tables.hpp>
 | 
			
		||||
#include <nano/store/transaction.hpp>
 | 
			
		||||
#include <nano/store/versioning.hpp>
 | 
			
		||||
#include <nano/store/write_queue.hpp>
 | 
			
		||||
 | 
			
		||||
#include <boost/endian/conversion.hpp>
 | 
			
		||||
#include <boost/polymorphic_cast.hpp>
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<nano::tables> const & tables_requiring_lock = {}, std::vector<nano::tables> const & tables_no_lock = {}) override;
 | 
			
		||||
	store::read_transaction tx_begin_read () const override;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue