fix(rocksdb): flush memtables before dropping (#21234)

This commit is contained in:
joshieDo
2026-01-21 02:19:36 +00:00
committed by GitHub
parent 660964a0f5
commit 238433e146

View File

@@ -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),
}
}