Skip to content

Commit d91016b

Browse files
MajorChumpclemahieu
authored andcommitted
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.
1 parent 97a79d7 commit d91016b

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

nano/core_test/active_transactions.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ TEST (active_transactions, dropped_cleanup)
613613
ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
614614

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

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

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

637637
// Block cleared from active
638638
ASSERT_EQ (0, node.active.blocks.count (block->hash ()));
@@ -1525,6 +1525,8 @@ TEST (active_transactions, fifo)
15251525
ASSERT_TIMELY (1s, node.active.election (receive1->qualified_root ()) != nullptr);
15261526
// Ensure excess transactions get trimmed
15271527
ASSERT_TIMELY (1s, node.active.size () == 1);
1528+
// Ensure overflow stats have been incremented
1529+
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop_overflow));
15281530
// Ensure the surviving transaction is the least recently inserted
15291531
ASSERT_TIMELY (1s, node.active.election (receive1->qualified_root ()) != nullptr);
15301532
}

nano/lib/stats.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,14 @@ std::string nano::stat::detail_to_string (uint32_t key)
739739
case nano::stat::detail::election_difficulty_update:
740740
res = "election_difficulty_update";
741741
break;
742-
case nano::stat::detail::election_drop:
743-
res = "election_drop";
742+
case nano::stat::detail::election_drop_expired:
743+
res = "election_drop_expired";
744+
break;
745+
case nano::stat::detail::election_drop_overflow:
746+
res = "election_drop_overflow";
747+
break;
748+
case nano::stat::detail::election_drop_all:
749+
res = "election_drop_all";
744750
break;
745751
case nano::stat::detail::election_restart:
746752
res = "election_restart";

nano/lib/stats.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ class stat final
318318
election_start,
319319
election_block_conflict,
320320
election_difficulty_update,
321-
election_drop,
321+
election_drop_expired,
322+
election_drop_overflow,
323+
election_drop_all,
322324
election_restart,
323325

324326
// udp

nano/node/active_transactions.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ void nano::active_transactions::request_confirm (nano::unique_lock<nano::mutex>
316316
for (auto const & election_l : elections_l)
317317
{
318318
bool const confirmed_l (election_l->confirmed ());
319+
unconfirmed_count_l += !confirmed_l;
319320

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

332333
// Locks active mutex, cleans up the election and erases it from the main container
334+
if (!confirmed_l)
335+
{
336+
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_expired);
337+
}
333338
erase (election_l->qualified_root);
334339
}
335340
}
@@ -349,7 +354,7 @@ void nano::active_transactions::cleanup_election (nano::unique_lock<nano::mutex>
349354
{
350355
if (!election.confirmed ())
351356
{
352-
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop);
357+
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_all);
353358
}
354359

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

0 commit comments

Comments
 (0)