diff --git a/crates/storage/provider/src/providers/rocksdb/provider.rs b/crates/storage/provider/src/providers/rocksdb/provider.rs index 142486697e..a673fa6291 100644 --- a/crates/storage/provider/src/providers/rocksdb/provider.rs +++ b/crates/storage/provider/src/providers/rocksdb/provider.rs @@ -427,7 +427,17 @@ impl fmt::Debug for RocksDBProviderInner { impl Drop for RocksDBProviderInner { fn drop(&mut self) { match self { - Self::ReadWrite { db, .. } => db.cancel_all_background_work(true), + Self::ReadWrite { db, .. } => { + // Flush all memtables if possible. If not, they will be rebuilt from the WAL on + // restart + if let Err(e) = db.flush_wal(true) { + tracing::warn!(target: "storage::rocksdb", ?e, "Failed to flush WAL on drop"); + } + if let Err(e) = db.flush() { + tracing::warn!(target: "storage::rocksdb", ?e, "Failed to flush memtables on drop"); + } + db.cancel_all_background_work(true); + } Self::ReadOnly { db, .. } => db.cancel_all_background_work(true), } }