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
This commit is contained in:
Sergey Kroshnin 2019-05-14 14:47:46 +03:00 committed by GitHub
commit ecc571ca6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View file

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

View file

@ -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<uint64_t> (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<uint64_t> (config.unchecked_cutoff_time.count ()))
{
cleaning_list.push_back (key);
}
}
}
}