add additional flushes

This commit is contained in:
Jonathan de Jong 2022-02-08 10:58:38 +01:00
parent 632ef87337
commit 0e0a025c37
5 changed files with 21 additions and 1 deletions

View file

@ -13,6 +13,8 @@ pub trait Database {
fn names<'a>(&'a self) -> Vec<Vec<u8>>; fn names<'a>(&'a self) -> Vec<Vec<u8>>;
fn segment<'a>(&'a mut self, name: Vec<u8>) -> Option<Box<dyn Segment + 'a>>; // change return type to Result fn segment<'a>(&'a mut self, name: Vec<u8>) -> Option<Box<dyn Segment + 'a>>; // change return type to Result
fn flush(&mut self);
} }
pub trait Segment { pub trait Segment {
@ -54,8 +56,10 @@ pub fn copy_database(
} }
drop(dst_seg); drop(dst_seg);
drop(src_seg_iter); drop(src_seg_iter);
drop(src_seg);
dst.flush();
} }
Ok(()) Ok(())

View file

@ -64,6 +64,10 @@ impl Database for HeedDB {
.map(|(k, _)| k) .map(|(k, _)| k)
.collect_vec() .collect_vec()
} }
fn flush(&mut self) {
// NOOP
}
} }
pub struct HeedSegment { pub struct HeedSegment {
env: heed::Env, env: heed::Env,

View file

@ -80,6 +80,10 @@ impl Database for RocksDB {
.map(|v| v.as_bytes().to_vec()) .map(|v| v.as_bytes().to_vec())
.collect() .collect()
} }
fn flush(&mut self) {
self.rocks.flush().unwrap()
}
} }
impl Drop for RocksDB { impl Drop for RocksDB {

View file

@ -33,6 +33,10 @@ impl Database for SledDB {
.ok() .ok()
.map(|t| -> Box<dyn Segment> { Box::new(t) }) .map(|t| -> Box<dyn Segment> { Box::new(t) })
} }
fn flush(&mut self) {
self.0.flush().unwrap();
}
} }
impl Segment for Tree { impl Segment for Tree {

View file

@ -64,6 +64,10 @@ impl Database for SqliteDB {
name: string, name: string,
})) }))
} }
fn flush(&mut self) {
// NOOP
}
} }
pub struct SqliteSegment<'a> { pub struct SqliteSegment<'a> {