ledger-tool: Move AccountsDbConfig building to common helper function (#29975)
Several subcommands may wish to specify AccountsDb configuration options. The matching is currently duplicated in both "verify" and "create-snapshot" command, so move the config to a common helper. Note that each subcommand that wishes to use any argument will still need to add the argument to its' argument list under App::new().
This commit is contained in:
parent
1de87c00a7
commit
1e6e623da5
|
@ -1021,6 +1021,52 @@ fn hardforks_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<Slot>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build an `AccountsDbConfig` from subcommand arguments. All of the arguments
|
||||||
|
// matched by this functional are either optional or have a default value.
|
||||||
|
// Thus, a subcommand need not support all of the arguments that are matched
|
||||||
|
// by this function.
|
||||||
|
fn get_accounts_db_config(ledger_path: &Path, arg_matches: &ArgMatches<'_>) -> AccountsDbConfig {
|
||||||
|
let accounts_index_bins = value_t!(arg_matches, "accounts_index_bins", usize).ok();
|
||||||
|
let accounts_index_index_limit_mb =
|
||||||
|
if let Some(limit) = value_t!(arg_matches, "accounts_index_memory_limit_mb", usize).ok() {
|
||||||
|
IndexLimitMb::Limit(limit)
|
||||||
|
} else if arg_matches.is_present("disable_accounts_disk_index") {
|
||||||
|
IndexLimitMb::InMemOnly
|
||||||
|
} else {
|
||||||
|
IndexLimitMb::Unspecified
|
||||||
|
};
|
||||||
|
let accounts_index_drives: Vec<PathBuf> = if arg_matches.is_present("accounts_index_path") {
|
||||||
|
values_t_or_exit!(arg_matches, "accounts_index_path", String)
|
||||||
|
.into_iter()
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
vec![ledger_path.join("accounts_index.ledger-tool")]
|
||||||
|
};
|
||||||
|
let accounts_index_config = AccountsIndexConfig {
|
||||||
|
bins: accounts_index_bins,
|
||||||
|
index_limit_mb: accounts_index_index_limit_mb,
|
||||||
|
drives: Some(accounts_index_drives),
|
||||||
|
..AccountsIndexConfig::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let filler_accounts_config = FillerAccountsConfig {
|
||||||
|
count: value_t!(arg_matches, "accounts_filler_count", usize).unwrap_or(0),
|
||||||
|
size: value_t!(arg_matches, "accounts_filler_size", usize).unwrap_or(0),
|
||||||
|
};
|
||||||
|
|
||||||
|
AccountsDbConfig {
|
||||||
|
index: Some(accounts_index_config),
|
||||||
|
accounts_hash_cache_path: Some(ledger_path.join(AccountsDb::ACCOUNTS_HASH_CACHE_DIR)),
|
||||||
|
filler_accounts_config,
|
||||||
|
ancient_append_vec_offset: value_t!(arg_matches, "accounts_db_ancient_append_vecs", i64)
|
||||||
|
.ok(),
|
||||||
|
exhaustively_verify_refcounts: arg_matches.is_present("accounts_db_verify_refcounts"),
|
||||||
|
skip_initial_hash_calc: arg_matches.is_present("accounts_db_skip_initial_hash_calculation"),
|
||||||
|
..AccountsDbConfig::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn load_bank_forks(
|
fn load_bank_forks(
|
||||||
arg_matches: &ArgMatches,
|
arg_matches: &ArgMatches,
|
||||||
genesis_config: &GenesisConfig,
|
genesis_config: &GenesisConfig,
|
||||||
|
@ -2706,13 +2752,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
("verify", Some(arg_matches)) => {
|
("verify", Some(arg_matches)) => {
|
||||||
let mut accounts_index_config = AccountsIndexConfig::default();
|
|
||||||
if let Some(bins) = value_t!(arg_matches, "accounts_index_bins", usize).ok() {
|
|
||||||
accounts_index_config.bins = Some(bins);
|
|
||||||
}
|
|
||||||
|
|
||||||
let exit_signal = Arc::new(AtomicBool::new(false));
|
let exit_signal = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let no_os_memory_stats_reporting =
|
let no_os_memory_stats_reporting =
|
||||||
arg_matches.is_present("no_os_memory_stats_reporting");
|
arg_matches.is_present("no_os_memory_stats_reporting");
|
||||||
let system_monitor_service = SystemMonitorService::new(
|
let system_monitor_service = SystemMonitorService::new(
|
||||||
|
@ -2725,56 +2765,6 @@ fn main() {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
accounts_index_config.index_limit_mb = if let Some(limit) =
|
|
||||||
value_t!(arg_matches, "accounts_index_memory_limit_mb", usize).ok()
|
|
||||||
{
|
|
||||||
IndexLimitMb::Limit(limit)
|
|
||||||
} else if arg_matches.is_present("disable_accounts_disk_index") {
|
|
||||||
IndexLimitMb::InMemOnly
|
|
||||||
} else {
|
|
||||||
IndexLimitMb::Unspecified
|
|
||||||
};
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut accounts_index_paths: Vec<PathBuf> =
|
|
||||||
if arg_matches.is_present("accounts_index_path") {
|
|
||||||
values_t_or_exit!(arg_matches, "accounts_index_path", String)
|
|
||||||
.into_iter()
|
|
||||||
.map(PathBuf::from)
|
|
||||||
.collect()
|
|
||||||
} else {
|
|
||||||
vec![]
|
|
||||||
};
|
|
||||||
if accounts_index_paths.is_empty() {
|
|
||||||
accounts_index_paths = vec![ledger_path.join("accounts_index")];
|
|
||||||
}
|
|
||||||
accounts_index_config.drives = Some(accounts_index_paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
let filler_accounts_config = FillerAccountsConfig {
|
|
||||||
count: value_t_or_exit!(arg_matches, "accounts_filler_count", usize),
|
|
||||||
size: value_t_or_exit!(arg_matches, "accounts_filler_size", usize),
|
|
||||||
};
|
|
||||||
|
|
||||||
let accounts_db_config = Some(AccountsDbConfig {
|
|
||||||
index: Some(accounts_index_config),
|
|
||||||
accounts_hash_cache_path: Some(
|
|
||||||
ledger_path.join(AccountsDb::ACCOUNTS_HASH_CACHE_DIR),
|
|
||||||
),
|
|
||||||
filler_accounts_config,
|
|
||||||
ancient_append_vec_offset: value_t!(
|
|
||||||
arg_matches,
|
|
||||||
"accounts_db_ancient_append_vecs",
|
|
||||||
i64
|
|
||||||
)
|
|
||||||
.ok(),
|
|
||||||
exhaustively_verify_refcounts: arg_matches
|
|
||||||
.is_present("accounts_db_verify_refcounts"),
|
|
||||||
skip_initial_hash_calc: arg_matches
|
|
||||||
.is_present("accounts_db_skip_initial_hash_calculation"),
|
|
||||||
..AccountsDbConfig::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
let debug_keys = pubkeys_of(arg_matches, "debug_key")
|
let debug_keys = pubkeys_of(arg_matches, "debug_key")
|
||||||
.map(|pubkeys| Arc::new(pubkeys.into_iter().collect::<HashSet<_>>()));
|
.map(|pubkeys| Arc::new(pubkeys.into_iter().collect::<HashSet<_>>()));
|
||||||
|
|
||||||
|
@ -2793,7 +2783,7 @@ fn main() {
|
||||||
usize
|
usize
|
||||||
)
|
)
|
||||||
.ok(),
|
.ok(),
|
||||||
accounts_db_config,
|
accounts_db_config: Some(get_accounts_db_config(&ledger_path, arg_matches)),
|
||||||
verify_index: arg_matches.is_present("verify_accounts_index"),
|
verify_index: arg_matches.is_present("verify_accounts_index"),
|
||||||
allow_dead_slots: arg_matches.is_present("allow_dead_slots"),
|
allow_dead_slots: arg_matches.is_present("allow_dead_slots"),
|
||||||
accounts_db_test_hash_calculation: arg_matches
|
accounts_db_test_hash_calculation: arg_matches
|
||||||
|
@ -3026,18 +3016,6 @@ fn main() {
|
||||||
output_directory.display()
|
output_directory.display()
|
||||||
);
|
);
|
||||||
|
|
||||||
let accounts_db_config = Some(AccountsDbConfig {
|
|
||||||
ancient_append_vec_offset: value_t!(
|
|
||||||
arg_matches,
|
|
||||||
"accounts_db_ancient_append_vecs",
|
|
||||||
i64
|
|
||||||
)
|
|
||||||
.ok(),
|
|
||||||
skip_initial_hash_calc: arg_matches
|
|
||||||
.is_present("accounts_db_skip_initial_hash_calculation"),
|
|
||||||
..AccountsDbConfig::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
match load_bank_forks(
|
match load_bank_forks(
|
||||||
arg_matches,
|
arg_matches,
|
||||||
&genesis_config,
|
&genesis_config,
|
||||||
|
@ -3046,7 +3024,7 @@ fn main() {
|
||||||
new_hard_forks,
|
new_hard_forks,
|
||||||
halt_at_slot: Some(snapshot_slot),
|
halt_at_slot: Some(snapshot_slot),
|
||||||
poh_verify: false,
|
poh_verify: false,
|
||||||
accounts_db_config,
|
accounts_db_config: Some(get_accounts_db_config(&ledger_path, arg_matches)),
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
},
|
},
|
||||||
snapshot_archive_path,
|
snapshot_archive_path,
|
||||||
|
|
Loading…
Reference in New Issue