From 238433e146d82c432a9096d8bbd7c8c9f8d11fed Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Wed, 21 Jan 2026 02:19:36 +0000 Subject: [PATCH] fix(rocksdb): flush memtables before dropping (#21234) --- .../provider/src/providers/rocksdb/provider.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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), } }