Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client/db/bolt: more aggressive DB compaction
This makes the DB compaction smarter, considering all free/unused bytes regardless of their sources. Previously it was only considering FreePageN, which can be was only a small part of the unused space, making compaction very unlikely for most DBs in practice. This also creates a relative free space threshold (5%) in addition to an absolute bytes free space threshold (256 KiB). Free space must exceed *both* thresholds to trigger a compaction. This is to spare long and large compactions happening too frequently for very large DB files. The logging that reports the percent space reclaimed is also fixed since it was reporting 1-pct instead of pct. Example of new checks and logs with a large testnet DB: CORE[DB]: Total DB size 1057017856 bytes, 328340544 bytes unused (31.06%) CORE[DB]: Compacting database to reclaim at least 328340544 bytes... CORE[DB]: Compacted database file from 1057017856 => 507797504 bytes (51.96% reduction) In this case, the actual reclaimed amount was larger than the estimate from the unused amount reported by bolt, presumably because of orphaned junk sectors of the file created due to crashes. However, testing with repeated compactions and other databases indicates the actual reduction amounts are almost exactly the estimates. Also, the percentages logged are now correct.
- Loading branch information