Split election drop stats to be either overflow or expired (#3297)

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.
This commit is contained in:
MajorChump 2021-05-28 13:53:32 +01:00 committed by GitHub
commit ebde1c8bcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 6 deletions

View file

@ -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 ()));
@ -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 ()));
@ -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);
}

View file

@ -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";

View file

@ -318,7 +318,9 @@ public:
election_start,
election_block_conflict,
election_difficulty_update,
election_drop,
election_drop_expired,
election_drop_overflow,
election_drop_all,
election_restart,
// udp

View file

@ -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))
{
@ -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);
}
}
@ -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 ();
@ -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);
}