Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit d1b8499

Browse files
authored
Support a custom path for the accounts hash cache (#33115)
1 parent 255029f commit d1b8499

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

accounts-db/src/accounts_db.rs

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ pub(crate) struct ShrinkCollect<'a, T: ShrinkCollectRefs<'a>> {
470470
pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
471471
index: Some(ACCOUNTS_INDEX_CONFIG_FOR_TESTING),
472472
base_working_path: None,
473+
accounts_hash_cache_path: None,
473474
filler_accounts_config: FillerAccountsConfig::const_default(),
474475
write_cache_limit_bytes: None,
475476
ancient_append_vec_offset: None,
@@ -481,6 +482,7 @@ pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
481482
pub const ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS: AccountsDbConfig = AccountsDbConfig {
482483
index: Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS),
483484
base_working_path: None,
485+
accounts_hash_cache_path: None,
484486
filler_accounts_config: FillerAccountsConfig::const_default(),
485487
write_cache_limit_bytes: None,
486488
ancient_append_vec_offset: None,
@@ -541,6 +543,7 @@ pub struct AccountsDbConfig {
541543
pub index: Option<AccountsIndexConfig>,
542544
/// Base directory for various necessary files
543545
pub base_working_path: Option<PathBuf>,
546+
pub accounts_hash_cache_path: Option<PathBuf>,
544547
pub filler_accounts_config: FillerAccountsConfig,
545548
pub write_cache_limit_bytes: Option<u64>,
546549
/// if None, ancient append vecs are set to ANCIENT_APPEND_VEC_DEFAULT_OFFSET
@@ -1480,16 +1483,14 @@ pub struct AccountsDb {
14801483

14811484
/// Base directory for various necessary files
14821485
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+
14841490
full_accounts_hash_cache_path: PathBuf,
14851491
incremental_accounts_hash_cache_path: PathBuf,
14861492
transient_accounts_hash_cache_path: PathBuf,
14871493

1488-
// used by tests
1489-
// holds this until we are dropped
1490-
#[allow(dead_code)]
1491-
temp_accounts_hash_cache_path: Option<TempDir>,
1492-
14931494
pub shrink_paths: RwLock<Option<Vec<PathBuf>>>,
14941495

14951496
/// Directory of paths this accounts_db needs to hold/remove
@@ -2425,46 +2426,35 @@ pub struct PubkeyHashAccount {
24252426
}
24262427

24272428
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";
24292430

24302431
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)
24322433
}
24332434

24342435
fn default_with_accounts_index(
24352436
accounts_index: AccountInfoAccountsIndex,
24362437
base_working_path: Option<PathBuf>,
2438+
accounts_hash_cache_path: Option<PathBuf>,
24372439
) -> Self {
24382440
let num_threads = get_thread_count();
24392441
// 400M bytes
24402442
const MAX_READ_ONLY_CACHE_DATA_SIZE: usize = 400_000_000;
24412443
// 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
24422444
const READ_ONLY_CACHE_MS_TO_SKIP_LRU_UPDATE: u32 = 100;
24432445

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))
24662453
};
24672454

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+
24682458
let mut bank_hash_stats = HashMap::new();
24692459
bank_hash_stats.insert(0, BankHashStats::default());
24702460

@@ -2496,10 +2486,10 @@ impl AccountsDb {
24962486
write_version: AtomicU64::new(0),
24972487
paths: vec![],
24982488
base_working_path,
2489+
base_working_temp_dir,
24992490
full_accounts_hash_cache_path: accounts_hash_cache_path.join("full"),
25002491
incremental_accounts_hash_cache_path: accounts_hash_cache_path.join("incremental"),
25012492
transient_accounts_hash_cache_path: accounts_hash_cache_path.join("transient"),
2502-
temp_accounts_hash_cache_path,
25032493
shrink_paths: RwLock::new(None),
25042494
temp_paths: None,
25052495
file_size: DEFAULT_FILE_SIZE,
@@ -2580,7 +2570,9 @@ impl AccountsDb {
25802570
let base_working_path = accounts_db_config
25812571
.as_ref()
25822572
.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());
25842576
let filler_accounts_config = accounts_db_config
25852577
.as_ref()
25862578
.map(|config| config.filler_accounts_config)
@@ -2635,7 +2627,11 @@ impl AccountsDb {
26352627
.and_then(|x| x.write_cache_limit_bytes),
26362628
partitioned_epoch_rewards_config,
26372629
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+
)
26392635
};
26402636
if paths_is_empty {
26412637
// Create a temporary set of accounts directories, used primarily

0 commit comments

Comments
 (0)