From ecc571ca6dd075549b89c356ff7a2579d666ccaa Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Tue, 14 May 2019 14:47:46 +0300 Subject: [PATCH] Prevent dropping of unchecked on restart if high unchecked (#1965) * Prevent dropping of unchecked on restart if high unchecked * Don't start unchecked cleanup if unchcked count >= 10% of total blocks count * Fix node.unchecked_cleanup test --- nano/node/lmdb.cpp | 6 +++++- nano/node/node.cpp | 16 ++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/nano/node/lmdb.cpp b/nano/node/lmdb.cpp index b7ae9f68b..ec9c18dc3 100644 --- a/nano/node/lmdb.cpp +++ b/nano/node/lmdb.cpp @@ -832,6 +832,7 @@ txn_tracking_enabled (txn_tracking_config_a.enable) if (!error_a) { auto is_fully_upgraded (false); + bool is_unchecked_drop_required (false); { auto transaction (tx_begin_read ()); auto err = mdb_dbi_open (env.tx (transaction), "meta", 0, &meta); @@ -853,14 +854,17 @@ txn_tracking_enabled (txn_tracking_config_a.enable) { error_a |= do_upgrades (transaction, batch_size); } + is_unchecked_drop_required = (block_count (transaction).sum () / 10) > unchecked_count (transaction) && unchecked_count (transaction) != 0; } else { auto transaction (tx_begin_read ()); open_databases (error_a, transaction, 0); + is_unchecked_drop_required = (block_count (transaction).sum () / 10) > unchecked_count (transaction) && unchecked_count (transaction) != 0; } - if (!error_a && drop_unchecked) + // Delete unchecked blocks at node start (if node initial synchronization is mostly completed) + if (!error_a && drop_unchecked && is_unchecked_drop_required) { auto transaction (tx_begin_write ()); unchecked_clear (transaction); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index a86e1805f..63e1bd674 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1803,14 +1803,18 @@ void nano::node::unchecked_cleanup () { auto now (nano::seconds_since_epoch ()); auto transaction (store.tx_begin_read ()); - // Max 128k records to clean, max 2 minutes reading to prevent slow i/o systems start issues - for (auto i (store.unchecked_begin (transaction)), n (store.unchecked_end ()); i != n && cleaning_list.size () < 128 * 1024 && nano::seconds_since_epoch () - now < 120; ++i) + // Don't start cleanup if unchecked count > 10% of total blocks count + if ((store.block_count (transaction).sum () / 10) + 1 >= store.unchecked_count (transaction)) { - nano::unchecked_key key (i->first); - nano::unchecked_info info (i->second); - if ((now - info.modified) > static_cast (config.unchecked_cutoff_time.count ())) + // Max 128k records to clean, max 2 minutes reading to prevent slow i/o systems start issues + for (auto i (store.unchecked_begin (transaction)), n (store.unchecked_end ()); i != n && cleaning_list.size () < 128 * 1024 && nano::seconds_since_epoch () - now < 120; ++i) { - cleaning_list.push_back (key); + nano::unchecked_key key (i->first); + nano::unchecked_info info (i->second); + if ((now - info.modified) > static_cast (config.unchecked_cutoff_time.count ())) + { + cleaning_list.push_back (key); + } } } }