mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 09:54:09 +01:00
Flush DB after the last index update
This commit is contained in:
parent
1d5d75c2ac
commit
0a3df920cf
@ -22,6 +22,7 @@ impl ReadStore for FakeStore {
|
||||
|
||||
impl WriteStore for FakeStore {
|
||||
fn write(&self, _rows: Vec<Row>) {}
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
|
@ -344,12 +344,14 @@ impl<'a> BufferedWriter<'a> {
|
||||
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.flush();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
11
src/store.rs
11
src/store.rs
@ -20,6 +20,7 @@ pub trait ReadStore: Sync {
|
||||
|
||||
pub trait WriteStore: Sync {
|
||||
fn write(&self, rows: Vec<Row>);
|
||||
fn flush(&self);
|
||||
}
|
||||
|
||||
pub struct DBStore {
|
||||
@ -95,7 +96,15 @@ impl WriteStore for DBStore {
|
||||
batch.put(row.key.as_slice(), row.value.as_slice()).unwrap();
|
||||
}
|
||||
let mut opts = rocksdb::WriteOptions::new();
|
||||
opts.set_sync(true);
|
||||
opts.set_sync(false);
|
||||
self.db.write_opt(batch, &opts).unwrap();
|
||||
}
|
||||
|
||||
fn flush(&self) {
|
||||
let mut opts = rocksdb::WriteOptions::new();
|
||||
opts.set_sync(true);
|
||||
self.db
|
||||
.write_opt(rocksdb::WriteBatch::default(), &opts)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user