Skip to content

Commit

Permalink
Graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Sep 5, 2024
1 parent 1e39c88 commit 5e40e54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions nano/node/confirming_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ void nano::confirming_set::run_batch (std::unique_lock<std::mutex> & lock)
notification.already_cemented.swap (already);

std::unique_lock lock{ mutex };

while (notification_workers.num_queued_tasks () >= config.max_queued_notifications)
{
stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cooldown);
condition.wait_for (lock, 100ms, [this] { return stopped; });
condition.wait_for (lock, 100ms, [this] { return stopped.load (); });
if (stopped)
{
return;
Expand Down Expand Up @@ -168,11 +169,17 @@ void nano::confirming_set::run_batch (std::unique_lock<std::mutex> & lock)
{
transaction.refresh_if_needed ();

stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cementing);
// Cementing deep dependency chains might take a long time, allow for graceful shutdown, ignore notifications
if (stopped)
{
break;
}

// Issue notifications here, so that `cemented` set is not too large before we add more blocks
notify_maybe (transaction);

stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cementing);

auto added = ledger.confirm (transaction, hash, config.max_blocks);
if (!added.empty ())
{
Expand Down
2 changes: 1 addition & 1 deletion nano/node/confirming_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class confirming_set final

nano::thread_pool notification_workers;

bool stopped{ false };
std::atomic<bool> stopped{ false };
mutable std::mutex mutex;
std::condition_variable condition;
std::thread thread;
Expand Down

0 comments on commit 5e40e54

Please sign in to comment.