Add missing Auto-Compaction for cache_db #171
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Electrs has three RocksDB databases:
During initial sync, auto-compaction is disabled for faster bulk writes. After sync completes, the indexer calls start_auto_compactions() to:
The Bug
In src/new_index/schema.rs around line 285-294, the update() method calls:
self.start_auto_compactions(&self.store.txstore_db); // ✓ Called
// ... processing ...
self.start_auto_compactions(&self.store.history_db); // ✓ Called
// MISSING: self.start_auto_compactions(&self.store.cache_db); // ✗ Never called
Result: cache_db never gets compacted and accumulates L0 files indefinitely.
Root Cause
Git history analysis (commit 2699560 from Jan 31, 2019):
Impact
Example from production system:
Problems:
Proposed Fix
Add the following to schema.rs after line 294:
self.start_auto_compactions(&self.store.cache_db);
Why This Matters
NOTE:
On upgrade, this would:
1. Detect no marker key (first time)
2. Block for 10-60 seconds doing full compaction of cache_db
3. Write marker key
4. Enable auto-compaction
5. Future restarts are instant