Skip to content

Commit 343906c

Browse files
authored
[typed store] add backoff to safe_drop_db (#21787)
## Description Mitigates the race between the destructor and metric threads. Reason: `rocksdb::DB::Destroy` returns an error immediately if any other reference is still alive --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK:
1 parent 38ba8f3 commit 343906c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/typed-store/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2021"
99
publish = false
1010

1111
[dependencies]
12+
backoff.workspace = true
1213
bcs.workspace = true
1314
bincode.workspace = true
1415
collectable.workspace = true

crates/typed-store/src/rocks/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{
2222
traits::{Map, TableSummary},
2323
};
2424
use crate::{DbIterator, TypedStoreError};
25+
use backoff::backoff::Backoff;
2526
use prometheus::{Histogram, HistogramTimer};
2627
use rocksdb::properties::num_files_at_level;
2728
use rocksdb::{checkpoint::Checkpoint, DBPinnableSlice, LiveFile};
@@ -1768,7 +1769,19 @@ pub fn open_cf_opts_secondary<P: AsRef<Path>>(
17681769
}
17691770

17701771
pub fn safe_drop_db(path: PathBuf) -> Result<(), rocksdb::Error> {
1771-
rocksdb::DB::destroy(&rocksdb::Options::default(), path)
1772+
let mut backoff = backoff::ExponentialBackoff {
1773+
max_elapsed_time: Some(Duration::from_secs(30)),
1774+
..Default::default()
1775+
};
1776+
loop {
1777+
match rocksdb::DB::destroy(&rocksdb::Options::default(), path.clone()) {
1778+
Ok(()) => return Ok(()),
1779+
Err(err) => match backoff.next_backoff() {
1780+
Some(duration) => std::thread::sleep(duration),
1781+
None => return Err(err),
1782+
},
1783+
}
1784+
}
17721785
}
17731786

17741787
fn populate_missing_cfs(

0 commit comments

Comments
 (0)