Skip to content

Commit

Permalink
Remove table locking argument as write_guard provides exclusive write…
Browse files Browse the repository at this point in the history
… access.
  • Loading branch information
clemahieu committed Sep 27, 2024
1 parent 68d47e3 commit dbdf1b1
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 32 deletions.
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
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 ();
}
}
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
10 changes: 5 additions & 5 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
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;
}
}
}
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
2 changes: 1 addition & 1 deletion nano/store/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,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
2 changes: 1 addition & 1 deletion nano/store/lmdb/lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,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
4 changes: 2 additions & 2 deletions nano/store/rocksdb/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ std::vector<rocksdb::ColumnFamilyDescriptor> nano::store::rocksdb::component::cr
return column_families;
}

nano::store::write_transaction nano::store::rocksdb::component::tx_begin_write (std::vector<nano::tables> const &, std::vector<nano::tables> const &)
nano::store::write_transaction nano::store::rocksdb::component::tx_begin_write ()
{
release_assert (db != nullptr);
release_assert (transaction_db != nullptr);
return store::write_transaction{ std::make_unique<nano::store::rocksdb::write_transaction_impl> (transaction_db) };
}

Expand Down
2 changes: 1 addition & 1 deletion nano/store/rocksdb/rocksdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class component : public nano::store::component

explicit component (nano::logger &, std::filesystem::path const &, nano::ledger_constants & constants, nano::rocksdb_config const & = nano::rocksdb_config{}, bool open_read_only = 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
2 changes: 1 addition & 1 deletion nano/test_common/testutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ nano::account nano::test::random_account ()

bool nano::test::process (nano::node & node, std::vector<std::shared_ptr<nano::block>> blocks)
{
auto const transaction = node.ledger.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights });
auto const transaction = node.ledger.tx_begin_write ();
for (auto & block : blocks)
{
auto result = node.process (transaction, block);
Expand Down

0 comments on commit dbdf1b1

Please sign in to comment.