Skip to content

Commit 69fcfc5

Browse files
EddieHoustonphilippem
authored andcommitted
Simplify DB::open to use the shared block cache
Address review feedback: remove the Option<&Cache> parameter and the owned_cache lifetime workaround.
1 parent 2794a22 commit 69fcfc5

2 files changed

Lines changed: 6 additions & 19 deletions

File tree

src/new_index/db.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ pub enum DBFlush {
9090
}
9191

9292
impl DB {
93-
pub fn open(path: &Path, config: &Config, verify_compat: bool) -> DB {
94-
Self::open_with_cache(path, config, verify_compat, None)
95-
}
96-
97-
pub fn open_with_cache(path: &Path, config: &Config, verify_compat: bool, shared_cache: Option<&rocksdb::Cache>) -> DB {
93+
pub fn open(path: &Path, config: &Config, verify_compat: bool, shared_cache: &rocksdb::Cache) -> DB {
9894
debug!("opening DB at {:?}", path);
9995
let mut db_opts = rocksdb::Options::default();
10096
db_opts.create_if_missing(true);
@@ -152,16 +148,7 @@ impl DB {
152148

153149
// Configure block cache and table options
154150
let mut block_opts = rocksdb::BlockBasedOptions::default();
155-
let owned_cache: rocksdb::Cache;
156-
let cache = match shared_cache {
157-
Some(c) => c,
158-
None => {
159-
let cache_size_bytes = config.db_block_cache_mb * 1024 * 1024;
160-
owned_cache = rocksdb::Cache::new_lru_cache(cache_size_bytes);
161-
&owned_cache
162-
}
163-
};
164-
block_opts.set_block_cache(cache);
151+
block_opts.set_block_cache(shared_cache);
165152
// When --cache-index-filter-blocks is passed, store index and filter blocks
166153
// inside the block cache so their memory is bounded by --db-block-cache-mb.
167154
// Without this (the default), RocksDB keeps them on the heap where they may

src/new_index/schema.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ impl Store {
6868
// needs without being artificially capped at 1/3 of the total.
6969
let cache_size_bytes = config.db_block_cache_mb * 1024 * 1024;
7070
let shared_cache = rocksdb::Cache::new_lru_cache(cache_size_bytes);
71-
info!("shared LRU block cache: db_block_cache_mb='{}'", config.db_block_cache_mb);
71+
debug!("shared LRU block cache: db_block_cache_mb='{}'", config.db_block_cache_mb);
7272

73-
let txstore_db = DB::open_with_cache(&path.join("txstore"), config, verify_compat, Some(&shared_cache));
73+
let txstore_db = DB::open(&path.join("txstore"), config, verify_compat, &shared_cache);
7474
let added_blockhashes = load_blockhashes(&txstore_db, &BlockRow::done_filter());
7575
debug!("{} blocks were added", added_blockhashes.len());
7676

77-
let history_db = DB::open_with_cache(&path.join("history"), config, verify_compat, Some(&shared_cache));
77+
let history_db = DB::open(&path.join("history"), config, verify_compat, &shared_cache);
7878
let indexed_blockhashes = load_blockhashes(&history_db, &BlockRow::done_filter());
7979
debug!("{} blocks were indexed", indexed_blockhashes.len());
8080

81-
let cache_db = DB::open_with_cache(&path.join("cache"), config, verify_compat, Some(&shared_cache));
81+
let cache_db = DB::open(&path.join("cache"), config, verify_compat, &shared_cache);
8282

8383
let db_metrics = Arc::new(RocksDbMetrics::new(&metrics));
8484
txstore_db.start_stats_exporter(Arc::clone(&db_metrics), "txstore_db");

0 commit comments

Comments
 (0)