Skip to content

Commit

Permalink
Flag to enable compaction during initial sync
Browse files Browse the repository at this point in the history
While compaction during initial sync makes thing much slower, it may be
preferred to not require to size the disk the double of the final
required space.
  • Loading branch information
RCasatta committed Sep 24, 2024
1 parent 3bb331d commit f122121
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ pub struct Config {
pub electrum_banner: String,
pub electrum_rpc_logging: Option<RpcLogging>,

/// Enable compaction during initial sync
///
/// By default compaction is off until initial sync is finished for performance reasons,
/// however, this requires much more disk space.
pub initial_sync_compaction: bool,

#[cfg(feature = "liquid")]
pub parent_network: BNetwork,
#[cfg(feature = "liquid")]
Expand Down Expand Up @@ -191,6 +197,10 @@ impl Config {
.long("electrum-rpc-logging")
.help(&rpc_logging_help)
.takes_value(true),
).arg(
Arg::with_name("initial_sync_compaction")
.long("initial-sync-compaction")
.help("Perform compaction during initial sync (slower but less disk space required)")
);

#[cfg(unix)]
Expand Down Expand Up @@ -403,6 +413,7 @@ impl Config {
index_unspendables: m.is_present("index_unspendables"),
cors: m.value_of("cors").map(|s| s.to_string()),
precache_scripts: m.value_of("precache_scripts").map(|s| s.to_string()),
initial_sync_compaction: m.is_present("initial_sync_compaction"),

#[cfg(feature = "liquid")]
parent_network,
Expand Down
2 changes: 1 addition & 1 deletion src/new_index/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl DB {
db_opts.set_compression_type(rocksdb::DBCompressionType::Snappy);
db_opts.set_target_file_size_base(1_073_741_824);
db_opts.set_write_buffer_size(256 << 20);
db_opts.set_disable_auto_compactions(true); // for initial bulk load
db_opts.set_disable_auto_compactions(!config.initial_sync_compaction); // for initial bulk load

// db_opts.set_advise_random_on_open(???);
db_opts.set_compaction_readahead_size(1 << 20);
Expand Down
1 change: 1 addition & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl TestRunner {
asset_db_path: None, // XXX
#[cfg(feature = "liquid")]
parent_network: bitcoin::Network::Regtest,
initial_sync_compaction: false,
//#[cfg(feature = "electrum-discovery")]
//electrum_public_hosts: Option<crate::electrum::ServerHosts>,
//#[cfg(feature = "electrum-discovery")]
Expand Down

0 comments on commit f122121

Please sign in to comment.