mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 21:52:53 +02:00
validation: randomly compact chainstate
Full chainstate flushes are convenient maintenance points for long-term LevelDB cleanup because the chainstate was just written. Randomize the trigger so nodes that flush near the same height do not compact together. Add blocking chainstate compaction through `CCoinsViewDB::CompactFull()` and give each post-IBD full flush on the normal chainstate a 1/320 chance to start compaction. With hourly flushes this averages roughly every two weeks and makes a six-month miss about one in a million. This keeps the schedule stateless and leaves last-compaction height or timestamp bookkeeping out of chainstate metadata. Co-authored-by: Andrew Toth <andrewstoth@gmail.com>
This commit is contained in:
@@ -256,7 +256,7 @@ CDBWrapper::CDBWrapper(const DBParams& params)
|
||||
|
||||
if (params.options.force_compact) {
|
||||
LogInfo("Starting database compaction of %s", fs::PathToString(params.path));
|
||||
DBContext().pdb->CompactRange(nullptr, nullptr);
|
||||
CompactFull();
|
||||
LogInfo("Finished database compaction of %s", fs::PathToString(params.path));
|
||||
}
|
||||
|
||||
@@ -307,6 +307,8 @@ std::optional<std::string> CDBWrapper::GetProperty(const std::string& property)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void CDBWrapper::CompactFull() { DBContext().pdb->CompactRange(nullptr, nullptr); }
|
||||
|
||||
size_t CDBWrapper::DynamicMemoryUsage() const
|
||||
{
|
||||
std::optional<size_t> parsed;
|
||||
|
||||
Reference in New Issue
Block a user