AcctIdx: env var "SOLANA_TEST_ACCOUNTS_INDEX_MEMORY_LIMIT_MB" (#23194)
* AcctIdx: env var "SOLANA_TEST_ACCOUNTS_INDEX_MEMORY_LIMIT_MB" * ignore env var when starting as validator * Update runtime/src/bucket_map_holder.rs Co-authored-by: Trent Nelson <trent.a.b.nelson@gmail.com> Co-authored-by: Trent Nelson <trent.a.b.nelson@gmail.com>
This commit is contained in:
parent
ac70070e5b
commit
7ebf398ed7
|
@ -52,6 +52,7 @@ pub const ACCOUNTS_INDEX_CONFIG_FOR_TESTING: AccountsIndexConfig = AccountsIndex
|
|||
index_limit_mb: None,
|
||||
ages_to_stay_in_cache: None,
|
||||
scan_results_limit_bytes: None,
|
||||
started_from_validator: false,
|
||||
};
|
||||
pub const ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS: AccountsIndexConfig = AccountsIndexConfig {
|
||||
bins: Some(BINS_FOR_BENCHMARKS),
|
||||
|
@ -60,6 +61,7 @@ pub const ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS: AccountsIndexConfig = AccountsIn
|
|||
index_limit_mb: None,
|
||||
ages_to_stay_in_cache: None,
|
||||
scan_results_limit_bytes: None,
|
||||
started_from_validator: false,
|
||||
};
|
||||
pub type ScanResult<T> = Result<T, ScanError>;
|
||||
pub type SlotList<T> = Vec<(Slot, T)>;
|
||||
|
@ -162,6 +164,8 @@ pub struct AccountsIndexConfig {
|
|||
pub index_limit_mb: Option<usize>,
|
||||
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.)
|
||||
pub started_from_validator: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
|
@ -858,13 +862,7 @@ pub struct AccountsIndex<T: IndexValue> {
|
|||
|
||||
impl<T: IndexValue> AccountsIndex<T> {
|
||||
pub fn default_for_tests() -> Self {
|
||||
let mut config = ACCOUNTS_INDEX_CONFIG_FOR_TESTING;
|
||||
if let Ok(limit) = std::env::var("SOLANA_TEST_ACCOUNTS_INDEX_MEMORY_LIMIT_MB") {
|
||||
// allocate with disk buckets
|
||||
config.index_limit_mb = Some(limit.parse::<usize>().unwrap());
|
||||
}
|
||||
|
||||
Self::new(Some(config))
|
||||
Self::new(Some(ACCOUNTS_INDEX_CONFIG_FOR_TESTING))
|
||||
}
|
||||
|
||||
pub fn new(config: Option<AccountsIndexConfig>) -> Self {
|
||||
|
|
|
@ -153,7 +153,20 @@ 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 mem_budget_mb = config.as_ref().and_then(|config| config.index_limit_mb);
|
||||
let mut mem_budget_mb = config.as_ref().and_then(|config| config.index_limit_mb);
|
||||
let bucket_map_tests_allowed = mem_budget_mb.is_none()
|
||||
&& !config
|
||||
.as_ref()
|
||||
.map(|config| config.started_from_validator)
|
||||
.unwrap_or_default();
|
||||
if bucket_map_tests_allowed {
|
||||
if let Ok(limit) = std::env::var("SOLANA_TEST_ACCOUNTS_INDEX_MEMORY_LIMIT_MB") {
|
||||
// allocate with disk buckets if mem budget was not set, we were NOT started from validator, and env var was set
|
||||
// we do not want the env var to have an effect when running the validator (only tests, benches, etc.)
|
||||
mem_budget_mb = Some(limit.parse::<usize>().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
// only allocate if mem_budget_mb is Some
|
||||
let disk = mem_budget_mb.map(|_| BucketMap::new(bucket_config));
|
||||
Self {
|
||||
|
|
|
@ -2117,7 +2117,10 @@ pub fn main() {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let mut accounts_index_config = AccountsIndexConfig::default();
|
||||
let mut accounts_index_config = AccountsIndexConfig {
|
||||
started_from_validator: true, // this is the only place this is set
|
||||
..AccountsIndexConfig::default()
|
||||
};
|
||||
if let Some(bins) = value_t!(matches, "accounts_index_bins", usize).ok() {
|
||||
accounts_index_config.bins = Some(bins);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue