Skip to content

Commit d4c2530

Browse files
committed
chore(rocks_db): move ShallowTempDir to benches crate
1 parent 6ef1d58 commit d4c2530

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

benches/benches/vm_set/blockchain.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ use fuel_core::{
2020
GenesisDatabase,
2121
},
2222
service::Config,
23-
state::{
24-
historical_rocksdb::HistoricalRocksDB,
25-
rocks_db::ShallowTempDir,
26-
},
23+
state::historical_rocksdb::HistoricalRocksDB,
2724
};
2825
use fuel_core_benches::*;
2926
use fuel_core_storage::{
@@ -67,12 +64,12 @@ use rand::{
6764
pub struct BenchDb {
6865
db: GenesisDatabase,
6966
/// Used for RAII cleanup. Contents of this directory are deleted on drop.
70-
_tmp_dir: ShallowTempDir,
67+
_tmp_dir: utils::ShallowTempDir,
7168
}
7269

7370
impl BenchDb {
7471
fn new(contract_id: &ContractId) -> anyhow::Result<Self> {
75-
let tmp_dir = ShallowTempDir::new();
72+
let tmp_dir = utils::ShallowTempDir::new();
7673

7774
let db = HistoricalRocksDB::<OnChain>::default_open(
7875
tmp_dir.path(),

benches/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use std::{
3838

3939
pub mod default_gas_costs;
4040
pub mod import;
41+
pub mod utils;
4142

4243
pub use fuel_core_storage::vm_storage::VmStorage;
4344
pub use rand::Rng;

benches/src/utils.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use rand::RngCore;
2+
use std::{
3+
env,
4+
path::PathBuf,
5+
};
6+
7+
/// Reimplementation of `tempdir::TempDir` that allows creating a new
8+
/// instance without actually creating a new directory on the filesystem.
9+
/// This is needed since rocksdb requires empty directory for checkpoints.
10+
pub struct ShallowTempDir {
11+
path: PathBuf,
12+
}
13+
14+
impl Default for ShallowTempDir {
15+
fn default() -> Self {
16+
Self::new()
17+
}
18+
}
19+
20+
impl ShallowTempDir {
21+
/// Creates a random directory.
22+
pub fn new() -> Self {
23+
let mut rng = rand::thread_rng();
24+
let mut path = env::temp_dir();
25+
path.push(format!("fuel-core-shallow-{}", rng.next_u64()));
26+
Self { path }
27+
}
28+
29+
/// Returns the path of the directory.
30+
pub fn path(&self) -> &PathBuf {
31+
&self.path
32+
}
33+
}
34+
35+
impl Drop for ShallowTempDir {
36+
fn drop(&mut self) {
37+
// Ignore errors
38+
let _ = std::fs::remove_dir_all(&self.path);
39+
}
40+
}

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use fuel_core_storage::{
3535
Result as StorageResult,
3636
};
3737
use itertools::Itertools;
38-
use rand::RngCore;
3938
use rocksdb::{
4039
BlockBasedOptions,
4140
BoundColumnFamily,
@@ -55,7 +54,6 @@ use rocksdb::{
5554
use std::{
5655
cmp,
5756
collections::BTreeMap,
58-
env,
5957
fmt,
6058
fmt::Formatter,
6159
iter,
@@ -69,41 +67,6 @@ use tempfile::TempDir;
6967

7068
type DB = DBWithThreadMode<MultiThreaded>;
7169

72-
/// Reimplementation of `tempdir::TempDir` that allows creating a new
73-
/// instance without actually creating a new directory on the filesystem.
74-
/// This is needed since rocksdb requires empty directory for checkpoints.
75-
pub struct ShallowTempDir {
76-
path: PathBuf,
77-
}
78-
79-
impl Default for ShallowTempDir {
80-
fn default() -> Self {
81-
Self::new()
82-
}
83-
}
84-
85-
impl ShallowTempDir {
86-
/// Creates a random directory.
87-
pub fn new() -> Self {
88-
let mut rng = rand::thread_rng();
89-
let mut path = env::temp_dir();
90-
path.push(format!("fuel-core-shallow-{}", rng.next_u64()));
91-
Self { path }
92-
}
93-
94-
/// Returns the path of the directory.
95-
pub fn path(&self) -> &PathBuf {
96-
&self.path
97-
}
98-
}
99-
100-
impl Drop for ShallowTempDir {
101-
fn drop(&mut self) {
102-
// Ignore errors
103-
let _ = std::fs::remove_dir_all(&self.path);
104-
}
105-
}
106-
10770
type DropFn = Box<dyn FnOnce() + Send + Sync>;
10871
#[derive(Default)]
10972
struct DropResources {

0 commit comments

Comments
 (0)