Skip to content

Commit 8192046

Browse files
starknet_patricia_storage: spawn a task or not based on config
1 parent 93549f6 commit 8192046

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

crates/apollo_deployments/resources/app_configs/committer_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"committer_config.storage_config.inner_storage_config.enable_statistics": true,
1111
"committer_config.storage_config.inner_storage_config.max_background_jobs": 8,
1212
"committer_config.storage_config.inner_storage_config.use_mmap_reads": false,
13-
"committer_config.storage_config.inner_storage_config.spawn_blocking_reads": false,
13+
"committer_config.storage_config.inner_storage_config.spawn_blocking_reads": true,
1414
"committer_config.storage_config.inner_storage_config.max_subcompactions": 8,
1515
"committer_config.storage_config.inner_storage_config.max_write_buffers": 4,
1616
"committer_config.storage_config.inner_storage_config.num_threads": 8,

crates/apollo_deployments/resources/app_configs/replacer_committer_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"committer_config.storage_config.inner_storage_config.cache_size": 8589934592,
1010
"committer_config.storage_config.inner_storage_config.enable_statistics": true,
1111
"committer_config.storage_config.inner_storage_config.max_background_jobs": 8,
12-
"committer_config.storage_config.inner_storage_config.spawn_blocking_reads": false,
12+
"committer_config.storage_config.inner_storage_config.spawn_blocking_reads": true,
1313
"committer_config.storage_config.inner_storage_config.max_subcompactions": 8,
1414
"committer_config.storage_config.inner_storage_config.max_write_buffers": 4,
1515
"committer_config.storage_config.inner_storage_config.num_threads": 8,

crates/apollo_node/resources/config_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@
572572
"committer_config.storage_config.inner_storage_config.spawn_blocking_reads": {
573573
"description": "Whether to spawn blocking tasks for read operations",
574574
"privacy": "Public",
575-
"value": false
575+
"value": true
576576
},
577577
"committer_config.storage_config.inner_storage_config.write_buffer_size": {
578578
"description": "Amount of data to build up in memory before writing to disk",

crates/starknet_patricia_storage/src/rocksdb_storage.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl RocksDbOptions {
119119
pub struct RocksDbStorage {
120120
db: Arc<DB>,
121121
options: Arc<RocksDbOptions>,
122-
_config: RocksDbStorageConfig,
122+
config: RocksDbStorageConfig,
123123
}
124124

125125
/// Configuration for RocksDB storage.
@@ -170,7 +170,7 @@ impl Default for RocksDbStorageConfig {
170170
bloom_filter_bits: BLOOM_FILTER_NUM_BITS,
171171
enable_statistics: true,
172172
use_mmap_reads: false,
173-
spawn_blocking_reads: false,
173+
spawn_blocking_reads: true,
174174
}
175175
}
176176
}
@@ -260,7 +260,7 @@ impl RocksDbStorage {
260260
pub fn new(path: &Path, config: RocksDbStorageConfig) -> PatriciaStorageResult<Self> {
261261
let options = RocksDbOptions::from_config(&config);
262262
let db = Arc::new(DB::open(&options.db_options, path)?);
263-
Ok(Self { db, options: Arc::new(options), _config: config })
263+
Ok(Self { db, options: Arc::new(options), config })
264264
}
265265
}
266266

@@ -289,28 +289,40 @@ impl Storage for RocksDbStorage {
289289
type Config = RocksDbStorageConfig;
290290

291291
async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
292-
// TODO(Nimrod): Config should indicate whether to spawn a task or not.
293-
let db = self.db.clone();
294-
let key = key.clone();
295-
Ok(spawn_blocking(move || db.get(&key.0).map(|opt| opt.map(DbValue))).await??)
292+
if self.config.spawn_blocking_reads {
293+
let db = self.db.clone();
294+
let key = key.clone();
295+
Ok(spawn_blocking(move || db.get(&key.0).map(|opt| opt.map(DbValue))).await??)
296+
} else {
297+
Ok(self.db.get(&key.0).map(|opt| opt.map(DbValue))?)
298+
}
296299
}
297300

298301
async fn set(&mut self, key: DbKey, value: DbValue) -> PatriciaStorageResult<()> {
299302
Ok(self.db.put_opt(&key.0, &value.0, &self.options.write_options)?)
300303
}
301304

302305
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
303-
// TODO(Nimrod): Config should indicate whether to spawn a task or not.
304-
let db = self.db.clone();
305-
let keys: Vec<Vec<u8>> = keys.iter().map(|k| k.0.clone()).collect();
306-
spawn_blocking(move || {
307-
let raw_keys = keys.iter().map(|k| k.as_slice());
308-
db.multi_get(raw_keys)
306+
if self.config.spawn_blocking_reads {
307+
let db = self.db.clone();
308+
let keys: Vec<Vec<u8>> = keys.iter().map(|k| k.0.clone()).collect();
309+
Ok(spawn_blocking(move || {
310+
let raw_keys = keys.iter().map(|k| k.as_slice());
311+
db.multi_get(raw_keys)
312+
.into_iter()
313+
.map(|r| r.map(|opt| opt.map(DbValue)).map_err(|e| e.into()))
314+
.collect::<Result<Vec<_>, PatriciaStorageError>>()
315+
})
316+
.await??)
317+
} else {
318+
let raw_keys = keys.iter().map(|k| k.0.as_slice());
319+
Ok(self
320+
.db
321+
.multi_get(raw_keys)
309322
.into_iter()
310323
.map(|r| r.map(|opt| opt.map(DbValue)).map_err(|e| e.into()))
311-
.collect::<Result<Vec<_>, PatriciaStorageError>>()
312-
})
313-
.await?
324+
.collect::<Result<Vec<_>, PatriciaStorageError>>()?)
325+
}
314326
}
315327

316328
async fn mset(&mut self, key_to_value: DbHashMap) -> PatriciaStorageResult<()> {

0 commit comments

Comments
 (0)