IndexLimitMb option adds 'Unspecified' state (#24249)

This commit is contained in:
Jeff Washington (jwash)
2022-04-12 09:38:09 -05:00
committed by GitHub
parent 605036c117
commit 1bc49d219d
5 changed files with 47 additions and 19 deletions

View File

@ -50,7 +50,7 @@ pub const ACCOUNTS_INDEX_CONFIG_FOR_TESTING: AccountsIndexConfig = AccountsIndex
bins: Some(BINS_FOR_TESTING),
flush_threads: Some(FLUSH_THREADS_TESTING),
drives: None,
index_limit_mb: None,
index_limit_mb: IndexLimitMb::Unspecified,
ages_to_stay_in_cache: None,
scan_results_limit_bytes: None,
started_from_validator: false,
@ -59,7 +59,7 @@ pub const ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS: AccountsIndexConfig = AccountsIn
bins: Some(BINS_FOR_BENCHMARKS),
flush_threads: Some(FLUSH_THREADS_TESTING),
drives: None,
index_limit_mb: None,
index_limit_mb: IndexLimitMb::Unspecified,
ages_to_stay_in_cache: None,
scan_results_limit_bytes: None,
started_from_validator: false,
@ -157,12 +157,29 @@ pub struct AccountSecondaryIndexesIncludeExclude {
pub keys: HashSet<Pubkey>,
}
/// specification of how much memory in-mem portion of account index can use
#[derive(Debug, Clone)]
pub enum IndexLimitMb {
/// nothing explicit specified, so default
Unspecified,
/// limit was specified, use disk index for rest
Limit(usize),
/// in-mem-only was specified, no disk index
InMemOnly,
}
impl Default for IndexLimitMb {
fn default() -> Self {
Self::Unspecified
}
}
#[derive(Debug, Default, Clone)]
pub struct AccountsIndexConfig {
pub bins: Option<usize>,
pub flush_threads: Option<usize>,
pub drives: Option<Vec<PathBuf>>,
pub index_limit_mb: Option<usize>,
pub index_limit_mb: IndexLimitMb,
pub ages_to_stay_in_cache: Option<Age>,
pub scan_results_limit_bytes: Option<usize>,
/// true if the accounts index is being created as a result of being started as a validator (as opposed to test, etc.)

View File

@ -1,6 +1,6 @@
use {
crate::{
accounts_index::{AccountsIndexConfig, IndexValue},
accounts_index::{AccountsIndexConfig, IndexLimitMb, IndexValue},
bucket_map_holder_stats::BucketMapHolderStats,
in_mem_accounts_index::{InMemAccountsIndex, SlotT},
waitable_condvar::WaitableCondvar,
@ -153,7 +153,13 @@ impl<T: IndexValue> BucketMapHolder<T> {
let mut bucket_config = BucketMapConfig::new(bins);
bucket_config.drives = config.as_ref().and_then(|config| config.drives.clone());
let mut mem_budget_mb = config.as_ref().and_then(|config| config.index_limit_mb);
let mut mem_budget_mb = config.as_ref().and_then(|config| {
if let IndexLimitMb::Limit(mb) = config.index_limit_mb {
Some(mb)
} else {
None
}
});
let bucket_map_tests_allowed = mem_budget_mb.is_none()
&& !config
.as_ref()
@ -391,7 +397,7 @@ pub mod tests {
fn test_disk_index_enabled() {
let bins = 1;
let config = AccountsIndexConfig {
index_limit_mb: Some(0),
index_limit_mb: IndexLimitMb::Limit(0),
..AccountsIndexConfig::default()
};
let test = BucketMapHolder::<u64>::new(bins, &Some(config), 1);

View File

@ -1263,7 +1263,7 @@ impl Drop for FlushGuard<'_> {
mod tests {
use {
super::*,
crate::accounts_index::{AccountsIndexConfig, BINS_FOR_TESTING},
crate::accounts_index::{AccountsIndexConfig, IndexLimitMb, BINS_FOR_TESTING},
itertools::Itertools,
};
@ -1281,7 +1281,7 @@ mod tests {
let holder = Arc::new(BucketMapHolder::new(
BINS_FOR_TESTING,
&Some(AccountsIndexConfig {
index_limit_mb: Some(1),
index_limit_mb: IndexLimitMb::Limit(1),
..AccountsIndexConfig::default()
}),
1,