Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag to enable compaction during initial sync #115

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -154,7 +154,7 @@ impl DB {
}

pub fn write(&self, mut rows: Vec<DBRow>, flush: DBFlush) {
debug!(
log::trace!(
"writing {} rows to {:?}, flush={:?}",
rows.len(),
self.db,
Expand Down
1 change: 1 addition & 0 deletions src/new_index/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fn bitcoind_fetcher(
sender
.send(block_entries)
.expect("failed to send fetched blocks");
log::debug!("last fetch {:?}", entries.last());
}
}),
))
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
Loading