mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 01:43:29 +01:00
Apply full-compaction after non-bulk initial indexing
This commit is contained in:
parent
ac819af52e
commit
2260fdc1a4
@ -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)?;
|
||||
|
10
src/bulk.rs
10
src/bulk.rs
@ -244,11 +244,7 @@ pub fn index(daemon: &Daemon, metrics: &Metrics, store: DBStore) -> Result<DBSto
|
||||
.expect("indexing failed")
|
||||
});
|
||||
store.write(vec![parser.last_indexed_row()]);
|
||||
store.flush();
|
||||
|
||||
let store = store.compact(); // will take a while.
|
||||
store.put(FINISH_MARKER, b"");
|
||||
Ok(store)
|
||||
Ok(store.compact())
|
||||
}).join()
|
||||
.expect("writer panicked")
|
||||
} else {
|
||||
@ -258,9 +254,9 @@ pub fn index(daemon: &Daemon, metrics: &Metrics, store: DBStore) -> Result<DBSto
|
||||
result.map(|store| store.enable_compaction())
|
||||
}
|
||||
|
||||
pub fn skip(store: DBStore) -> Result<DBStore> {
|
||||
pub fn compact(store: DBStore) -> Result<DBStore> {
|
||||
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())
|
||||
}
|
||||
|
11
src/store.rs
11
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]) {
|
||||
|
Loading…
Reference in New Issue
Block a user