Skip to content

Commit c69d054

Browse files
netromexgreenxrymnc
authored
fix: Only cancel background work if primary RocksDB instance is dropped (#2918)
This effectively reverts https://github.com/FuelLabs/fuel-core/pull/2730/files which causes a lot of "Shutdown in progress: stalled writes" errors when multiple rocksdb instances are being dropped in a running node. --------- Co-authored-by: green <xgreenx9999@gmail.com> Co-authored-by: Aaryamann Challani <43716372+rymnc@users.noreply.github.com>
1 parent 1680dd1 commit c69d054

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

.changes/fixed/2918.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Only cancel background work if primary RocksDB instance is dropped

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fuel-vm-private = { version = "0.60.0", package = "fuel-vm", default-features =
104104

105105
# Common dependencies
106106
anyhow = "1.0"
107-
async-graphql = { version = "7.0.11", features = [
107+
async-graphql = { version = "7.0.15", features = [
108108
"graphiql",
109109
"tracing",
110110
], default-features = false }

crates/fuel-core/src/state/rocks_db.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use super::rocks_db_key_iterator::{
1212
ExtractItem,
1313
RocksDBKeyIterator,
1414
};
15+
use core::ops::Deref;
1516
use fuel_core_metrics::core_metrics::DatabaseMetrics;
1617
use fuel_core_storage::{
1718
iter::{
@@ -72,6 +73,23 @@ use std::{
7273
};
7374
use tempfile::TempDir;
7475

76+
#[derive(Debug)]
77+
struct PrimaryInstance(DBWithThreadMode<MultiThreaded>);
78+
79+
impl Deref for PrimaryInstance {
80+
type Target = DBWithThreadMode<MultiThreaded>;
81+
82+
fn deref(&self) -> &Self::Target {
83+
&self.0
84+
}
85+
}
86+
87+
impl Drop for PrimaryInstance {
88+
fn drop(&mut self) {
89+
self.cancel_all_background_work(true);
90+
}
91+
}
92+
7593
type DB = DBWithThreadMode<MultiThreaded>;
7694

7795
type DropFn = Box<dyn FnOnce() + Send + Sync>;
@@ -135,7 +153,7 @@ impl DatabaseConfig {
135153

136154
pub struct RocksDb<Description> {
137155
read_options: ReadOptions,
138-
db: Arc<DB>,
156+
db: Arc<PrimaryInstance>,
139157
block_opts: Arc<BlockBasedOptions>,
140158
create_family: Option<Arc<Mutex<BTreeMap<String, Options>>>>,
141159
snapshot: Option<rocksdb::SnapshotWithThreadMode<'static, DB>>,
@@ -150,7 +168,6 @@ impl<Description> Drop for RocksDb<Description> {
150168
// Drop the snapshot before the db.
151169
// Dropping the snapshot after the db will cause a sigsegv.
152170
self.snapshot = None;
153-
self.db.cancel_all_background_work(true);
154171
}
155172
}
156173

@@ -402,7 +419,7 @@ where
402419
}
403420
ColumnsPolicy::Lazy => Some(Arc::new(Mutex::new(cf_descriptors_to_create))),
404421
};
405-
let db = Arc::new(db);
422+
let db = Arc::new(PrimaryInstance(db));
406423

407424
let rocks_db = RocksDb {
408425
read_options: Self::generate_read_options(&None),

0 commit comments

Comments
 (0)