@@ -470,6 +470,7 @@ pub(crate) struct ShrinkCollect<'a, T: ShrinkCollectRefs<'a>> {
470
470
pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
471
471
index: Some(ACCOUNTS_INDEX_CONFIG_FOR_TESTING),
472
472
base_working_path: None,
473
+ accounts_hash_cache_path: None,
473
474
filler_accounts_config: FillerAccountsConfig::const_default(),
474
475
write_cache_limit_bytes: None,
475
476
ancient_append_vec_offset: None,
@@ -481,6 +482,7 @@ pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
481
482
pub const ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS: AccountsDbConfig = AccountsDbConfig {
482
483
index: Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS),
483
484
base_working_path: None,
485
+ accounts_hash_cache_path: None,
484
486
filler_accounts_config: FillerAccountsConfig::const_default(),
485
487
write_cache_limit_bytes: None,
486
488
ancient_append_vec_offset: None,
@@ -541,6 +543,7 @@ pub struct AccountsDbConfig {
541
543
pub index: Option<AccountsIndexConfig>,
542
544
/// Base directory for various necessary files
543
545
pub base_working_path: Option<PathBuf>,
546
+ pub accounts_hash_cache_path: Option<PathBuf>,
544
547
pub filler_accounts_config: FillerAccountsConfig,
545
548
pub write_cache_limit_bytes: Option<u64>,
546
549
/// if None, ancient append vecs are set to ANCIENT_APPEND_VEC_DEFAULT_OFFSET
@@ -1480,16 +1483,14 @@ pub struct AccountsDb {
1480
1483
1481
1484
/// Base directory for various necessary files
1482
1485
base_working_path: PathBuf,
1483
- /// Directories for account hash calculations, within base_working_path
1486
+ // used by tests - held until we are dropped
1487
+ #[allow(dead_code)]
1488
+ base_working_temp_dir: Option<TempDir>,
1489
+
1484
1490
full_accounts_hash_cache_path: PathBuf,
1485
1491
incremental_accounts_hash_cache_path: PathBuf,
1486
1492
transient_accounts_hash_cache_path: PathBuf,
1487
1493
1488
- // used by tests
1489
- // holds this until we are dropped
1490
- #[allow(dead_code)]
1491
- temp_accounts_hash_cache_path: Option<TempDir>,
1492
-
1493
1494
pub shrink_paths: RwLock<Option<Vec<PathBuf>>>,
1494
1495
1495
1496
/// Directory of paths this accounts_db needs to hold/remove
@@ -2425,46 +2426,35 @@ pub struct PubkeyHashAccount {
2425
2426
}
2426
2427
2427
2428
impl AccountsDb {
2428
- pub const ACCOUNTS_HASH_CACHE_DIR : &'static str = "accounts_hash_cache";
2429
+ pub const DEFAULT_ACCOUNTS_HASH_CACHE_DIR : &'static str = "accounts_hash_cache";
2429
2430
2430
2431
pub fn default_for_tests() -> Self {
2431
- Self::default_with_accounts_index(AccountInfoAccountsIndex::default_for_tests(), None)
2432
+ Self::default_with_accounts_index(AccountInfoAccountsIndex::default_for_tests(), None, None )
2432
2433
}
2433
2434
2434
2435
fn default_with_accounts_index(
2435
2436
accounts_index: AccountInfoAccountsIndex,
2436
2437
base_working_path: Option<PathBuf>,
2438
+ accounts_hash_cache_path: Option<PathBuf>,
2437
2439
) -> Self {
2438
2440
let num_threads = get_thread_count();
2439
2441
// 400M bytes
2440
2442
const MAX_READ_ONLY_CACHE_DATA_SIZE: usize = 400_000_000;
2441
2443
// read only cache does not update lru on read of an entry unless it has been at least this many ms since the last lru update
2442
2444
const READ_ONLY_CACHE_MS_TO_SKIP_LRU_UPDATE: u32 = 100;
2443
2445
2444
- let (base_working_path, accounts_hash_cache_path, temp_accounts_hash_cache_path) =
2445
- match base_working_path {
2446
- Some(base_working_path) => {
2447
- let accounts_hash_cache_path =
2448
- base_working_path.join(Self::ACCOUNTS_HASH_CACHE_DIR);
2449
- (base_working_path, accounts_hash_cache_path, None)
2450
- }
2451
- None => {
2452
- let temp_accounts_hash_cache_path = Some(TempDir::new().unwrap());
2453
- let base_working_path = temp_accounts_hash_cache_path
2454
- .as_ref()
2455
- .unwrap()
2456
- .path()
2457
- .to_path_buf();
2458
- let accounts_hash_cache_path =
2459
- base_working_path.join(Self::ACCOUNTS_HASH_CACHE_DIR);
2460
- (
2461
- base_working_path,
2462
- accounts_hash_cache_path,
2463
- temp_accounts_hash_cache_path,
2464
- )
2465
- }
2446
+ let (base_working_path, base_working_temp_dir) =
2447
+ if let Some(base_working_path) = base_working_path {
2448
+ (base_working_path, None)
2449
+ } else {
2450
+ let base_working_temp_dir = TempDir::new().unwrap();
2451
+ let base_working_path = base_working_temp_dir.path().to_path_buf();
2452
+ (base_working_path, Some(base_working_temp_dir))
2466
2453
};
2467
2454
2455
+ let accounts_hash_cache_path = accounts_hash_cache_path
2456
+ .unwrap_or_else(|| base_working_path.join(Self::DEFAULT_ACCOUNTS_HASH_CACHE_DIR));
2457
+
2468
2458
let mut bank_hash_stats = HashMap::new();
2469
2459
bank_hash_stats.insert(0, BankHashStats::default());
2470
2460
@@ -2496,10 +2486,10 @@ impl AccountsDb {
2496
2486
write_version: AtomicU64::new(0),
2497
2487
paths: vec![],
2498
2488
base_working_path,
2489
+ base_working_temp_dir,
2499
2490
full_accounts_hash_cache_path: accounts_hash_cache_path.join("full"),
2500
2491
incremental_accounts_hash_cache_path: accounts_hash_cache_path.join("incremental"),
2501
2492
transient_accounts_hash_cache_path: accounts_hash_cache_path.join("transient"),
2502
- temp_accounts_hash_cache_path,
2503
2493
shrink_paths: RwLock::new(None),
2504
2494
temp_paths: None,
2505
2495
file_size: DEFAULT_FILE_SIZE,
@@ -2580,7 +2570,9 @@ impl AccountsDb {
2580
2570
let base_working_path = accounts_db_config
2581
2571
.as_ref()
2582
2572
.and_then(|x| x.base_working_path.clone());
2583
-
2573
+ let accounts_hash_cache_path = accounts_db_config
2574
+ .as_ref()
2575
+ .and_then(|config| config.accounts_hash_cache_path.clone());
2584
2576
let filler_accounts_config = accounts_db_config
2585
2577
.as_ref()
2586
2578
.map(|config| config.filler_accounts_config)
@@ -2635,7 +2627,11 @@ impl AccountsDb {
2635
2627
.and_then(|x| x.write_cache_limit_bytes),
2636
2628
partitioned_epoch_rewards_config,
2637
2629
exhaustively_verify_refcounts,
2638
- ..Self::default_with_accounts_index(accounts_index, base_working_path)
2630
+ ..Self::default_with_accounts_index(
2631
+ accounts_index,
2632
+ base_working_path,
2633
+ accounts_hash_cache_path,
2634
+ )
2639
2635
};
2640
2636
if paths_is_empty {
2641
2637
// Create a temporary set of accounts directories, used primarily
0 commit comments