mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-07-06 04:01:13 +02:00
coins: compact chainstate in background
Full chainstate compaction can take minutes on large databases. Move `CCoinsViewDB::CompactFull()` to a named `utxocompact` one-shot background thread so validation only schedules the work. When validation selects compaction after a full flush, the chainstate was just written and another write is less likely to be needed immediately. The coins view destructor waits for completion, and a mutex prevents compaction from using `m_db` while `ResizeCache()` replaces it. Co-authored-by: Andrew Toth <andrewstoth@gmail.com>
This commit is contained in:
@@ -2838,9 +2838,11 @@ bool Chainstate::FlushStateToDisk(
|
||||
m_chainman.m_options.signals->ChainStateFlushed(this->GetRole(), GetLocator(m_chain.Tip()));
|
||||
}
|
||||
|
||||
if (!m_chainman.m_interrupt && m_chainman.m_chainstates.size() == 1) { // Skip AssumeUTXO
|
||||
if (ShouldCompactChainstate(m_chainman.IsInitialBlockDownload())) {
|
||||
if (!m_chainman.m_interrupt && ShouldCompactChainstate(m_chainman.IsInitialBlockDownload())) {
|
||||
try {
|
||||
CoinsDB().CompactFull();
|
||||
} catch (const std::exception& e) {
|
||||
LogWarning("Failed to start chainstate compaction (%s)", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user