From 544c38341bf5af8a39ed604257ea57de2ade846a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 19 Mar 2024 09:26:46 -0700 Subject: [PATCH] add sync() to db abstraction for fsync(2). --- src/database/abstraction.rs | 1 + src/database/abstraction/rocksdb.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/database/abstraction.rs b/src/database/abstraction.rs index d620fa76..cdc308ee 100644 --- a/src/database/abstraction.rs +++ b/src/database/abstraction.rs @@ -18,6 +18,7 @@ pub(crate) trait KeyValueDatabaseEngine: Send + Sync { Self: Sized; fn open_tree(&self, name: &'static str) -> Result>; fn flush(&self) -> Result<()>; + fn sync(&self) -> Result<()> { Ok(()) } fn cleanup(&self) -> Result<()> { Ok(()) } fn memory_usage(&self) -> Result { Ok("Current database engine does not support memory usage reporting.".to_owned()) diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index c660bf90..f4c28ab8 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -170,12 +170,17 @@ impl KeyValueDatabaseEngine for Arc { } fn flush(&self) -> Result<()> { - debug!("Running flush_wal (no sync)"); rust_rocksdb::DBCommon::flush_wal(&self.rocks, false)?; Ok(()) } + fn sync(&self) -> Result<()> { + rust_rocksdb::DBCommon::flush_wal(&self.rocks, true)?; + + Ok(()) + } + fn memory_usage(&self) -> Result { let stats = rust_rocksdb::perf::get_memory_usage_stats(Some(&[&self.rocks]), Some(&[&self.cache]))?; Ok(format!(