Refine compaction (#1916)

## Proposed Changes

In an attempt to fix OOM issues and database consistency issues observed by some users after the introduction of compaction in v0.3.4, this PR makes the following changes:

* Run compaction less often: roughly every 1024 epochs, including after long periods of non-finality. I think the division check proposed by Paul is pretty solid, and ensures we don't miss any events where we should be compacting. LevelDB lacks an easy way to check the size of the DB, which would be another good trigger.
* Make it possible to disable the compaction on finalization using `--auto-compact-db=false`
* Make it possible to trigger a manual, single-threaded foreground compaction on start-up using `--compact-db`
* Downgrade the pruning log to `DEBUG`, as it's particularly noisy during sync

I would like to ship these changes to affected users ASAP, and will document them further in the Advanced Database section of the book if they prove effective.
This commit is contained in:
Michael Sproul
2020-11-17 09:10:53 +00:00
parent ecff8807a5
commit a60ab4eff2
6 changed files with 176 additions and 27 deletions

View File

@@ -297,13 +297,26 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
)
/*
* Purge.
* Database purging and compaction.
*/
.arg(
Arg::with_name("purge-db")
.long("purge-db")
.help("If present, the chain database will be deleted. Use with caution.")
)
.arg(
Arg::with_name("compact-db")
.long("compact-db")
.help("If present, apply compaction to the database on start-up. Use with caution. \
It is generally not recommended unless auto-compaction is disabled.")
)
.arg(
Arg::with_name("auto-compact-db")
.long("auto-compact-db")
.help("Enable or disable automatic compaction of the database on finalization.")
.takes_value(true)
.default_value("true")
)
/*
* Misc.

View File

@@ -218,6 +218,13 @@ pub fn get_config<E: EthSpec>(
.map_err(|_| "block-cache-size is not a valid integer".to_string())?;
}
client_config.store.compact_on_init = cli_args.is_present("compact-db");
if let Some(compact_on_prune) = cli_args.value_of("auto-compact-db") {
client_config.store.compact_on_prune = compact_on_prune
.parse()
.map_err(|_| "auto-compact-db takes a boolean".to_string())?;
}
/*
* Zero-ports
*