Skip to content

Commit

Permalink
Split election drop stats to be either overflow or expired (#3297)
Browse files Browse the repository at this point in the history
At the moment it's not clear if elections are simply expiring after 5 minutes or being dropped due to the container overflowing. This should give us a better insight and allow us to monitor the situation.
  • Loading branch information
MajorChump authored and clemahieu committed Jun 11, 2021
1 parent 97a79d7 commit d91016b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 4 additions & 2 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ TEST (active_transactions, dropped_cleanup)
ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));

// An election was recently dropped
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop));
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop_all));

// Block cleared from active
ASSERT_EQ (0, node.active.blocks.count (block->hash ()));
Expand All @@ -632,7 +632,7 @@ TEST (active_transactions, dropped_cleanup)
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));

// Not dropped
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop));
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop_all));

// Block cleared from active
ASSERT_EQ (0, node.active.blocks.count (block->hash ()));
Expand Down Expand Up @@ -1525,6 +1525,8 @@ TEST (active_transactions, fifo)
ASSERT_TIMELY (1s, node.active.election (receive1->qualified_root ()) != nullptr);
// Ensure excess transactions get trimmed
ASSERT_TIMELY (1s, node.active.size () == 1);
// Ensure overflow stats have been incremented
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop_overflow));
// Ensure the surviving transaction is the least recently inserted
ASSERT_TIMELY (1s, node.active.election (receive1->qualified_root ()) != nullptr);
}
10 changes: 8 additions & 2 deletions nano/lib/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,14 @@ std::string nano::stat::detail_to_string (uint32_t key)
case nano::stat::detail::election_difficulty_update:
res = "election_difficulty_update";
break;
case nano::stat::detail::election_drop:
res = "election_drop";
case nano::stat::detail::election_drop_expired:
res = "election_drop_expired";
break;
case nano::stat::detail::election_drop_overflow:
res = "election_drop_overflow";
break;
case nano::stat::detail::election_drop_all:
res = "election_drop_all";
break;
case nano::stat::detail::election_restart:
res = "election_restart";
Expand Down
4 changes: 3 additions & 1 deletion nano/lib/stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ class stat final
election_start,
election_block_conflict,
election_difficulty_update,
election_drop,
election_drop_expired,
election_drop_overflow,
election_drop_all,
election_restart,

// udp
Expand Down
8 changes: 7 additions & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ void nano::active_transactions::request_confirm (nano::unique_lock<nano::mutex>
for (auto const & election_l : elections_l)
{
bool const confirmed_l (election_l->confirmed ());
unconfirmed_count_l += !confirmed_l;

if (election_l->transition_time (solicitor))
{
Expand All @@ -330,6 +331,10 @@ void nano::active_transactions::request_confirm (nano::unique_lock<nano::mutex>
}

// Locks active mutex, cleans up the election and erases it from the main container
if (!confirmed_l)
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_expired);
}
erase (election_l->qualified_root);
}
}
Expand All @@ -349,7 +354,7 @@ void nano::active_transactions::cleanup_election (nano::unique_lock<nano::mutex>
{
if (!election.confirmed ())
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop);
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_all);
}

auto blocks_l = election.blocks ();
Expand Down Expand Up @@ -1049,6 +1054,7 @@ void nano::active_transactions::erase_oldest ()
nano::unique_lock<nano::mutex> lock (mutex);
if (!roots.empty ())
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_overflow);
auto item = roots.get<tag_random_access> ().front ();
cleanup_election (lock, *item.election);
}
Expand Down

0 comments on commit d91016b

Please sign in to comment.