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

Vote generator write queue #4556

Merged
merged 2 commits into from
Apr 13, 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
1 change: 1 addition & 0 deletions nano/node/vote_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void nano::vote_generator::process_batch (std::deque<queue_entry_t> & batch)
{
std::deque<candidate_t> candidates_new;
{
auto guard = ledger.store.write_queue.wait (is_final ? nano::store::writer::voting_final : nano::store::writer::voting);
auto transaction = ledger.store.tx_begin_write ({ tables::final_votes });

for (auto & [root, hash] : batch)
Expand Down
8 changes: 2 additions & 6 deletions nano/store/write_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,14 @@ nano::store::write_guard nano::store::write_queue::wait (writer writer)
}

nano::unique_lock<nano::mutex> lk (mutex);
debug_assert (std::none_of (queue.cbegin (), queue.cend (), [writer] (auto const & item) { return item == writer; }));
// Add writer to the end of the queue if it's not already waiting
auto exists = std::find (queue.cbegin (), queue.cend (), writer) != queue.cend ();
if (!exists)
{
queue.push_back (writer);
}

while (queue.front () != writer)
{
cv.wait (lk);
}

cv.wait (lk, [&] () { return queue.front () == writer; });
return write_guard (guard_finish_callback);
}

Expand Down
2 changes: 2 additions & 0 deletions nano/store/write_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ enum class writer
confirmation_height,
process_batch,
pruning,
voting,
voting_final,
testing // Used in tests to emulate a write lock
};

Expand Down
Loading