Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rocksdb tx cleanup #4737

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nano/core_test/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ TEST (active_elections, bound_election_winners)

{
// Prevent cementing of confirmed blocks
auto guard = node.ledger.tx_begin_write ({}, nano::store::writer::testing);
auto guard = node.ledger.tx_begin_write (nano::store::writer::testing);

// Ensure that when the number of election winners reaches the limit, AEC vacancy reflects that
ASSERT_TRUE (node.active.vacancy (nano::election_behavior::priority) > 0);
Expand Down
2 changes: 0 additions & 2 deletions nano/core_test/confirming_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ TEST (confirmation_callback, confirmed_history)
{
nano::test::system system;
nano::node_flags node_flags;
node_flags.force_use_write_queue = true;
node_flags.disable_ascending_bootstrap = true;
nano::node_config node_config = system.default_config ();
node_config.backlog_population.enable = false;
Expand Down Expand Up @@ -194,7 +193,6 @@ TEST (confirmation_callback, dependent_election)
{
nano::test::system system;
nano::node_flags node_flags;
node_flags.force_use_write_queue = true;
nano::node_config node_config = system.default_config ();
node_config.backlog_population.enable = false;
auto node = system.add_node (node_config, node_flags);
Expand Down
8 changes: 4 additions & 4 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5819,21 +5819,21 @@ TEST (ledger_transaction, write_wait_order)
std::latch latch3{ 1 };

auto fut1 = std::async (std::launch::async, [&] {
auto tx = ctx.ledger ().tx_begin_write ({}, nano::store::writer::generic);
auto tx = ctx.ledger ().tx_begin_write (nano::store::writer::generic);
acquired1 = true;
latch1.wait (); // Wait for the signal to drop tx
});
WAIT (250ms); // Allow thread to start

auto fut2 = std::async (std::launch::async, [&ctx, &acquired2, &latch2] {
auto tx = ctx.ledger ().tx_begin_write ({}, nano::store::writer::blockprocessor);
auto tx = ctx.ledger ().tx_begin_write (nano::store::writer::blockprocessor);
acquired2 = true;
latch2.wait (); // Wait for the signal to drop tx
});
WAIT (250ms); // Allow thread to start

auto fut3 = std::async (std::launch::async, [&ctx, &acquired3, &latch3] {
auto tx = ctx.ledger ().tx_begin_write ({}, nano::store::writer::confirmation_height);
auto tx = ctx.ledger ().tx_begin_write (nano::store::writer::confirmation_height);
acquired3 = true;
latch3.wait (); // Wait for the signal to drop tx
});
Expand All @@ -5855,4 +5855,4 @@ TEST (ledger_transaction, write_wait_order)

// Signal to continue and drop the third transaction
latch3.count_down ();
}
}
4 changes: 2 additions & 2 deletions nano/core_test/ledger_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ TEST (ledger_confirm, pruned_source)
ASSERT_TRUE (!store->init_error ());
nano::ledger ledger (*store, system.stats, nano::dev::constants);
ledger.pruning = true;
nano::store::write_queue write_queue (false);
nano::store::write_queue write_queue;
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::keypair key1, key2;
nano::block_builder builder;
Expand Down Expand Up @@ -868,7 +868,7 @@ TEST (ledger_confirmDeathTest, rollback_added_block)
auto store = nano::make_store (system.logger, path, nano::dev::constants);
ASSERT_TRUE (!store->init_error ());
nano::ledger ledger (*store, system.stats, nano::dev::constants);
nano::store::write_queue write_queue (false);
nano::store::write_queue write_queue;
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::keypair key1;
nano::block_builder builder;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ auto nano::block_processor::process_batch (nano::unique_lock<nano::mutex> & lock

lock.unlock ();

auto transaction = node.ledger.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }, nano::store::writer::blockprocessor);
auto transaction = node.ledger.tx_begin_write (nano::store::writer::blockprocessor);

nano::timer<std::chrono::milliseconds> timer;
timer.start ();
Expand Down
2 changes: 1 addition & 1 deletion nano/node/confirming_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void nano::confirming_set::run_batch (std::unique_lock<std::mutex> & lock)
};

{
auto transaction = ledger.tx_begin_write ({ nano::tables::confirmation_height }, nano::store::writer::confirmation_height);
auto transaction = ledger.tx_begin_write (nano::store::writer::confirmation_height);
for (auto const & hash : batch)
{
do
Expand Down
4 changes: 2 additions & 2 deletions nano/node/make_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, bool force_use_write_queue)
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)
{
if (rocksdb_config.enable)
{
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::rocksdb::component> (logger, add_db_postfix ? path / "rocksdb" : path, constants, rocksdb_config, read_only);
}

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);
Expand Down
2 changes: 1 addition & 1 deletion nano/node/make_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, bool force_use_write_queue = 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);
}
12 changes: 6 additions & 6 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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, flags.force_use_write_queue)),
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 (*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)),
Expand Down Expand Up @@ -323,7 +323,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy

if (!is_initialized && !flags.read_only)
{
auto const transaction (store.tx_begin_write ({ tables::accounts, tables::blocks, tables::confirmation_height, tables::rep_weights }));
auto const transaction = store.tx_begin_write ();
// Store was empty meaning we just created it, add the genesis block
store.initialize (transaction, ledger.cache, ledger.constants);
}
Expand Down Expand Up @@ -572,7 +572,7 @@ void nano::node::process_active (std::shared_ptr<nano::block> const & incoming)

nano::block_status nano::node::process (std::shared_ptr<nano::block> block)
{
auto const transaction = ledger.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }, nano::store::writer::node);
auto const transaction = ledger.tx_begin_write (nano::store::writer::node);
return process (transaction, block);
}

Expand Down Expand Up @@ -787,7 +787,7 @@ nano::uint128_t nano::node::minimum_principal_weight ()
void nano::node::long_inactivity_cleanup ()
{
bool perform_cleanup = false;
auto const transaction (store.tx_begin_write ({ tables::online_weight, tables::peers }));
auto const transaction = store.tx_begin_write ();
if (store.online_weight.count (transaction) > 0)
{
auto sample (store.online_weight.rbegin (transaction));
Expand Down Expand Up @@ -994,7 +994,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 write_transaction = ledger.tx_begin_write ({ tables::blocks, tables::pruned }, nano::store::writer::pruning);
auto write_transaction = ledger.tx_begin_write (nano::store::writer::pruning);
while (!pruning_targets.empty () && transaction_write_count < batch_size_a && !stopped)
{
auto const & pruning_hash (pruning_targets.front ());
Expand Down Expand Up @@ -1348,4 +1348,4 @@ nano::keypair nano::load_or_create_node_id (std::filesystem::path const & applic
release_assert (!ofs.fail ());
return kp;
}
}
}
1 change: 0 additions & 1 deletion nano/node/nodeconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ 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_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 };
Expand Down
2 changes: 1 addition & 1 deletion nano/node/online_reps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void nano::online_reps::sample ()
lock.unlock ();
nano::uint128_t trend_l;
{
auto transaction (ledger.store.tx_begin_write ({ tables::online_weight }));
auto transaction = ledger.store.tx_begin_write ();
// Discard oldest entries
while (ledger.store.online_weight.count (transaction) >= config.network_params.node.max_weight_samples)
{
Expand Down
2 changes: 1 addition & 1 deletion nano/node/peer_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void nano::peer_history::run ()
void nano::peer_history::run_one ()
{
auto live_peers = network.list ();
auto transaction = store.tx_begin_write ({ tables::peers });
auto transaction = store.tx_begin_write ();

// Add or update live peers
for (auto const & peer : live_peers)
Expand Down
2 changes: 1 addition & 1 deletion nano/node/vote_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void nano::vote_generator::process_batch (std::deque<queue_entry_t> & batch)

if (is_final)
{
transaction_variant_t transaction_variant{ ledger.tx_begin_write ({ tables::final_votes }, nano::store::writer::voting_final) };
transaction_variant_t transaction_variant{ ledger.tx_begin_write (nano::store::writer::voting_final) };

verify_batch (transaction_variant, batch);

Expand Down
18 changes: 9 additions & 9 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,10 @@ nano::ledger::~ledger ()
{
}

auto nano::ledger::tx_begin_write (std::vector<nano::tables> const & tables_to_lock, nano::store::writer guard_type) const -> secure::write_transaction
auto nano::ledger::tx_begin_write (nano::store::writer guard_type) const -> secure::write_transaction
{
auto guard = store.write_queue.wait (guard_type);
auto txn = store.tx_begin_write (tables_to_lock);
auto txn = store.tx_begin_write ();
return secure::write_transaction{ std::move (txn), std::move (guard) };
}

Expand Down Expand Up @@ -1292,7 +1292,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
std::atomic<std::size_t> count = 0;
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 }));
auto rocksdb_transaction = rocksdb_store->tx_begin_write ();
for (; i != n; ++i)
{
rocksdb_transaction.refresh_if_needed ();
Expand All @@ -1317,7 +1317,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
count = 0;
store.pending.for_each_par (
[&] (store::read_transaction const & /*unused*/, auto i, auto n) {
auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::pending }));
auto rocksdb_transaction = rocksdb_store->tx_begin_write ();
for (; i != n; ++i)
{
rocksdb_transaction.refresh_if_needed ();
Expand All @@ -1335,7 +1335,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
count = 0;
store.confirmation_height.for_each_par (
[&] (store::read_transaction const & /*unused*/, auto i, auto n) {
auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::confirmation_height }));
auto rocksdb_transaction = rocksdb_store->tx_begin_write ();
for (; i != n; ++i)
{
rocksdb_transaction.refresh_if_needed ();
Expand All @@ -1353,7 +1353,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
count = 0;
store.account.for_each_par (
[&] (store::read_transaction const & /*unused*/, auto i, auto n) {
auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::accounts }));
auto rocksdb_transaction = rocksdb_store->tx_begin_write ();
for (; i != n; ++i)
{
rocksdb_transaction.refresh_if_needed ();
Expand All @@ -1371,7 +1371,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
count = 0;
store.rep_weight.for_each_par (
[&] (store::read_transaction const & /*unused*/, auto i, auto n) {
auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::rep_weights }));
auto rocksdb_transaction = rocksdb_store->tx_begin_write ();
for (; i != n; ++i)
{
rocksdb_transaction.refresh_if_needed ();
Expand All @@ -1389,7 +1389,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
count = 0;
store.pruned.for_each_par (
[&] (store::read_transaction const & /*unused*/, auto i, auto n) {
auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::pruned }));
auto rocksdb_transaction = rocksdb_store->tx_begin_write ();
for (; i != n; ++i)
{
rocksdb_transaction.refresh_if_needed ();
Expand All @@ -1407,7 +1407,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
count = 0;
store.final_vote.for_each_par (
[&] (store::read_transaction const & /*unused*/, auto i, auto n) {
auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::final_votes }));
auto rocksdb_transaction = rocksdb_store->tx_begin_write ();
for (; i != n; ++i)
{
rocksdb_transaction.refresh_if_needed ();
Expand Down
2 changes: 1 addition & 1 deletion nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ledger final
~ledger ();

/** Start read-write transaction */
secure::write_transaction tx_begin_write (std::vector<nano::tables> const & tables_to_lock = {}, nano::store::writer guard_type = nano::store::writer::generic) const;
secure::write_transaction tx_begin_write (nano::store::writer guard_type = nano::store::writer::generic) const;
/** Start read-only transaction */
secure::read_transaction tx_begin_read () const;

Expand Down
4 changes: 2 additions & 2 deletions nano/slow_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,13 @@ TEST (confirmation_height, many_accounts_send_receive_self_no_elections)
ASSERT_TRUE (!store->init_error ());
nano::stats stats{ logger };
nano::ledger ledger (*store, stats, nano::dev::constants);
nano::store::write_queue write_database_queue (false);
nano::store::write_queue write_database_queue;
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
std::atomic<bool> stopped{ false };
boost::latch initialized_latch{ 0 };

nano::block_hash block_hash_being_processed{ 0 };
nano::store::write_queue write_queue{ false };
nano::store::write_queue write_queue;
nano::confirming_set_config confirming_set_config{};
nano::confirming_set confirming_set{ confirming_set_config, ledger, stats };

Expand Down
3 changes: 1 addition & 2 deletions nano/store/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, bool use_noops_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) :
block (block_store_a),
account (account_store_a),
pending (pending_store_a),
Expand All @@ -17,7 +17,6 @@ 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)
{
}
Expand Down
5 changes: 2 additions & 3 deletions nano/store/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ namespace store
nano::store::confirmation_height &,
nano::store::final_vote &,
nano::store::version &,
nano::store::rep_weight &,
bool use_noops_a
nano::store::rep_weight &
);
// clang-format on
virtual ~component () = default;
Expand Down Expand Up @@ -97,7 +96,7 @@ namespace store
virtual bool init_error () const = 0;

/** Start read-write transaction */
virtual write_transaction tx_begin_write (std::vector<nano::tables> const & tables_to_lock = {}, std::vector<nano::tables> const & tables_no_lock = {}) = 0;
virtual write_transaction tx_begin_write () = 0;

/** Start read-only transaction */
virtual read_transaction tx_begin_read () const = 0;
Expand Down
5 changes: 2 additions & 3 deletions nano/store/lmdb/lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ nano::store::lmdb::component::component (nano::logger & logger_a, std::filesyste
confirmation_height_store,
final_vote_store,
version_store,
rep_weight_store,
false // write_queue use_noops
rep_weight_store
},
// clang-format on
block_store{ *this },
Expand Down Expand Up @@ -163,7 +162,7 @@ void nano::store::lmdb::component::serialize_memory_stats (boost::property_tree:
json.put ("page_size", stats.ms_psize);
}

nano::store::write_transaction nano::store::lmdb::component::tx_begin_write (std::vector<nano::tables> const &, std::vector<nano::tables> const &)
nano::store::write_transaction nano::store::lmdb::component::tx_begin_write ()
{
return env.tx_begin_write (create_txn_callbacks ());
}
Expand Down
2 changes: 1 addition & 1 deletion nano/store/lmdb/lmdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class component : public nano::store::component

public:
component (nano::logger &, std::filesystem::path const &, nano::ledger_constants & constants, 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);
store::write_transaction tx_begin_write (std::vector<nano::tables> const & tables_requiring_lock = {}, std::vector<nano::tables> const & tables_no_lock = {}) override;
store::write_transaction tx_begin_write () override;
store::read_transaction tx_begin_read () const override;

std::string vendor_get () const override;
Expand Down
Loading
Loading