Skip to content

Commit

Permalink
store: cancel background RocksDB tasks before closing the database (#…
Browse files Browse the repository at this point in the history
…4429)

Per RocksDB FAQ:

> Q: Is it safe to close RocksDB while another thread is issuing read,
>    write or manual compaction requests?
> A: No.  The users of RocksDB need to make sure all functions have
>    finished before they close RocksDB.  You can speed up the waiting
>    by calling CancelAllBackgroundWork().

Better be safe than sorry so add the call before the rocksdb::DB object
is dropped.

Fixes: #3266
  • Loading branch information
mina86 authored Jul 9, 2021
1 parent 96d1050 commit 14c547c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions core/store/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use std::marker::PhantomPinned;
use std::sync::RwLock;

use borsh::{BorshDeserialize, BorshSerialize};
#[cfg(feature = "single_thread_rocksdb")]
use rocksdb::Env;
use rocksdb::{
BlockBasedOptions, Cache, ColumnFamily, ColumnFamilyDescriptor, Direction, IteratorMode,
Options, ReadOptions, WriteBatch, DB,
BlockBasedOptions, Cache, ColumnFamily, ColumnFamilyDescriptor, Direction,
Env, IteratorMode, Options, ReadOptions, WriteBatch, DB,
};
use strum::EnumIter;
use tracing::warn;
Expand Down Expand Up @@ -751,13 +749,15 @@ impl PreWriteCheckErr {
}
}

#[cfg(feature = "single_thread_rocksdb")]
impl Drop for RocksDB {
fn drop(&mut self) {
// RocksDB with only one thread stuck on wait some condition var
// Turn on additional threads to proceed
let mut env = Env::default().unwrap();
env.set_background_threads(4);
if cfg!(feature = "single_thread_rocksdb") {
// RocksDB with only one thread stuck on wait some condition var
// Turn on additional threads to proceed
let mut env = Env::default().unwrap();
env.set_background_threads(4);
}
self.db.cancel_all_background_work(true);
}
}

Expand Down

0 comments on commit 14c547c

Please sign in to comment.