Skip to content

Commit 003d492

Browse files
authored
Merge branch 'new-index' into startup-logging
2 parents 7517756 + 69fcfc5 commit 003d492

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ impl Config {
242242
).arg(
243243
Arg::with_name("db_block_cache_mb")
244244
.long("db-block-cache-mb")
245-
.help("RocksDB block cache size in MB per database. Bounds index/filter block memory; use 4096+ for initial sync to avoid table-reader heap growth.")
245+
.help("RocksDB block cache size in MB (shared across all databases). Bounds index/filter block memory; use 4096+ for initial sync to avoid table-reader heap growth.")
246246
.takes_value(true)
247-
.default_value("8")
247+
.default_value("24")
248248
).arg(
249249
Arg::with_name("db_parallelism")
250250
.long("db-parallelism")

src/new_index/db.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ pub enum DBFlush {
9090
}
9191

9292
impl DB {
93-
pub fn open(path: &Path, config: &Config, verify_compat: bool) -> DB {
93+
pub fn open(path: &Path, config: &Config, verify_compat: bool, shared_cache: &rocksdb::Cache) -> DB {
9494
info!("opening DB at {:?}", path);
95+
9596
let mut db_opts = rocksdb::Options::default();
9697
db_opts.create_if_missing(true);
9798
db_opts.set_max_open_files(100_000); // TODO: make sure to `ulimit -n` this process correctly
@@ -148,8 +149,7 @@ impl DB {
148149

149150
// Configure block cache and table options
150151
let mut block_opts = rocksdb::BlockBasedOptions::default();
151-
let cache_size_bytes = config.db_block_cache_mb * 1024 * 1024;
152-
block_opts.set_block_cache(&rocksdb::Cache::new_lru_cache(cache_size_bytes));
152+
block_opts.set_block_cache(shared_cache);
153153
// When --cache-index-filter-blocks is passed, store index and filter blocks
154154
// inside the block cache so their memory is bounded by --db-block-cache-mb.
155155
// Without this (the default), RocksDB keeps them on the heap where they may

src/new_index/schema.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,24 @@ impl Store {
6161
pub fn open(config: &Config, metrics: &Metrics, verify_compat: bool) -> Self {
6262
let path = config.db_path.join("newindex");
6363

64-
let txstore_db = DB::open(&path.join("txstore"), config, verify_compat);
64+
// Create a single shared LRU cache for all three DBs. The total size is
65+
// --db-block-cache-mb (not multiplied by 3). RocksDB's LRU cache is
66+
// thread-safe, so all DBs share one eviction pool. This lets the
67+
// txstore (which holds the bulk of the data) claim as much cache as it
68+
// needs without being artificially capped at 1/3 of the total.
69+
let cache_size_bytes = config.db_block_cache_mb * 1024 * 1024;
70+
let shared_cache = rocksdb::Cache::new_lru_cache(cache_size_bytes);
71+
debug!("shared LRU block cache: db_block_cache_mb='{}'", config.db_block_cache_mb);
72+
73+
let txstore_db = DB::open(&path.join("txstore"), config, verify_compat, &shared_cache);
6574
let added_blockhashes = load_blockhashes(&txstore_db, &BlockRow::done_filter());
6675
info!("{} blocks were added", added_blockhashes.len());
6776

68-
let history_db = DB::open(&path.join("history"), config, verify_compat);
77+
let history_db = DB::open(&path.join("history"), config, verify_compat, &shared_cache);
6978
let indexed_blockhashes = load_blockhashes(&history_db, &BlockRow::done_filter());
7079
info!("{} blocks were indexed", indexed_blockhashes.len());
7180

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

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

0 commit comments

Comments
 (0)