add write buffer corking using rocksdb manual_wal_flush.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
3969b667ba
commit
3f60365cc6
4 changed files with 98 additions and 6 deletions
|
@ -20,6 +20,9 @@ pub(crate) trait KeyValueDatabaseEngine: Send + Sync {
|
|||
fn flush(&self) -> Result<()>;
|
||||
#[allow(dead_code)]
|
||||
fn sync(&self) -> Result<()> { Ok(()) }
|
||||
fn cork(&self) -> Result<()> { Ok(()) }
|
||||
fn uncork(&self) -> Result<()> { Ok(()) }
|
||||
fn corked(&self) -> bool { false }
|
||||
fn cleanup(&self) -> Result<()> { Ok(()) }
|
||||
fn memory_usage(&self) -> Result<String> {
|
||||
Ok("Current database engine does not support memory usage reporting.".to_owned())
|
||||
|
@ -89,3 +92,32 @@ pub(crate) trait KvTree: Send + Sync {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Cork {
|
||||
db: Arc<dyn KeyValueDatabaseEngine>,
|
||||
flush: bool,
|
||||
sync: bool,
|
||||
}
|
||||
|
||||
impl Cork {
|
||||
pub(crate) fn new(db: &Arc<dyn KeyValueDatabaseEngine>, flush: bool, sync: bool) -> Self {
|
||||
db.cork().unwrap();
|
||||
Cork {
|
||||
db: db.clone(),
|
||||
flush,
|
||||
sync,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Cork {
|
||||
fn drop(&mut self) {
|
||||
self.db.uncork().ok();
|
||||
if self.flush {
|
||||
self.db.flush().ok();
|
||||
}
|
||||
if self.sync {
|
||||
self.db.sync().ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue