1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00

Skip WAL during indexing writes

Flush should make sure everything is written to disk.
This commit is contained in:
Roman Zeyde 2018-06-12 17:11:40 +03:00
parent eb91f08b75
commit 61fbd4d3ca
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 4 additions and 34 deletions

View File

@ -9,7 +9,6 @@ use crypto::sha2::Sha256;
use std::collections::HashMap;
use std::iter::FromIterator;
use std::sync::RwLock;
use std::time::{Duration, Instant};
use daemon::Daemon;
use signal::Waiter;
@ -320,7 +319,6 @@ impl Index {
let mut stats = Stats::new();
let mut bar = util::new_progress_bar(new_headers.len());
bar.message("Blocks: ");
let mut buf = BufferedWriter::new(store);
let headers_map: HashMap<Sha256dHash, &HeaderEntry> =
HashMap::from_iter(new_headers.iter().map(|h| (*h.hash(), h)));
for chunk in new_headers.chunks(100) {
@ -342,7 +340,7 @@ impl Index {
timer.tick("index");
// Write to DB
buf.write(rows);
store.write(rows);
timer.tick("write");
stats.update(block);
}
@ -350,7 +348,7 @@ impl Index {
debug!("index update {:?} {:?}", stats, timer);
}
}
buf.flush(); // make sure no row is left behind
store.flush(); // make sure no row is left behind
timer.tick("write");
bar.finish();
debug!("index update {:?} {:?}", stats, timer);
@ -360,33 +358,3 @@ impl Index {
Ok(tip)
}
}
struct BufferedWriter<'a> {
batch: Vec<Row>,
start: Instant,
store: &'a WriteStore,
}
impl<'a> BufferedWriter<'a> {
fn new(store: &'a WriteStore) -> BufferedWriter {
BufferedWriter {
batch: vec![],
start: Instant::now(),
store,
}
}
fn write(&mut self, mut rows: Vec<Row>) {
self.batch.append(&mut rows);
if self.batch.len() > 10_000_000 || self.start.elapsed() > Duration::from_secs(60) {
self.store.write(self.batch.split_off(0));
self.start = Instant::now();
}
}
fn flush(&mut self) {
self.store.write(self.batch.split_off(0));
self.start = Instant::now();
self.store.flush(); // sync DB to disk
}
}

View File

@ -98,12 +98,14 @@ impl WriteStore for DBStore {
}
let mut opts = rocksdb::WriteOptions::new();
opts.set_sync(false);
opts.disable_wal(true);
self.db.write_opt(batch, &opts).unwrap();
}
fn flush(&self) {
let mut opts = rocksdb::WriteOptions::new();
opts.set_sync(true);
opts.disable_wal(false);
self.db
.write_opt(rocksdb::WriteBatch::default(), &opts)
.unwrap();