From 2260fdc1a457bf44369f374996726cf24c33b437 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sun, 5 Aug 2018 15:52:33 +0300 Subject: [PATCH] Apply full-compaction after non-bulk initial indexing --- src/bin/electrs.rs | 6 +++--- src/bulk.rs | 10 +++------- src/store.rs | 11 ++++++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/bin/electrs.rs b/src/bin/electrs.rs index 52820ee..1e0364e 100644 --- a/src/bin/electrs.rs +++ b/src/bin/electrs.rs @@ -30,10 +30,10 @@ fn run_server(config: &Config) -> Result<()> { let store = DBStore::open(&config.db_path); let index = Index::load(&store, &daemon, &metrics, config.index_batch_size)?; let store = if config.skip_bulk_import { - index.update(&store, &signal)?; - bulk::skip(store) + index.update(&store, &signal)?; // slower: uses JSONRPC for fetching blocks + bulk::compact(store) } else { - bulk::index(&daemon, &metrics, store) + bulk::index(&daemon, &metrics, store) // faster, but uses more memory }?; let app = App::new(store, index, daemon)?; diff --git a/src/bulk.rs b/src/bulk.rs index 77bc078..32a84c4 100644 --- a/src/bulk.rs +++ b/src/bulk.rs @@ -244,11 +244,7 @@ pub fn index(daemon: &Daemon, metrics: &Metrics, store: DBStore) -> Result Result Result { +pub fn compact(store: DBStore) -> Result { store.flush(); + let store = store.compact(); // will take a while. store.put(FINISH_MARKER, b""); - warn!("skipping bulk import of blk*.dat files'"); Ok(store.enable_compaction()) } diff --git a/src/store.rs b/src/store.rs index a82abd2..014c115 100644 --- a/src/store.rs +++ b/src/store.rs @@ -69,9 +69,14 @@ impl DBStore { pub fn enable_compaction(self) -> Self { let mut opts = self.opts.clone(); - opts.bulk_import = false; - drop(self); // DB must be closed before being re-opened - DBStore::open_opts(opts) + if opts.bulk_import == true { + opts.bulk_import = false; + drop(self); // DB must be closed before being re-opened + info!("enabling auto-compactions"); + DBStore::open_opts(opts) + } else { + self + } } pub fn put(&self, key: &[u8], value: &[u8]) {