(cherry picked from commit 7fe870ba48
)
Co-authored-by: sakridge <sakridge@gmail.com>
This commit is contained in:
@ -34,6 +34,7 @@ use solana_ledger::{
|
|||||||
leader_schedule::FixedSchedule,
|
leader_schedule::FixedSchedule,
|
||||||
leader_schedule_cache::LeaderScheduleCache,
|
leader_schedule_cache::LeaderScheduleCache,
|
||||||
};
|
};
|
||||||
|
use solana_measure::measure::Measure;
|
||||||
use solana_metrics::datapoint_info;
|
use solana_metrics::datapoint_info;
|
||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
@ -202,9 +203,13 @@ impl Validator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info!("Cleaning accounts paths..");
|
||||||
|
let mut start = Measure::start("clean_accounts_paths");
|
||||||
for accounts_path in &config.account_paths {
|
for accounts_path in &config.account_paths {
|
||||||
cleanup_accounts_path(accounts_path);
|
cleanup_accounts_path(accounts_path);
|
||||||
}
|
}
|
||||||
|
start.stop();
|
||||||
|
info!("done. {}", start);
|
||||||
|
|
||||||
info!("creating bank...");
|
info!("creating bank...");
|
||||||
let mut validator_exit = ValidatorExit::default();
|
let mut validator_exit = ValidatorExit::default();
|
||||||
@ -990,30 +995,13 @@ fn get_stake_percent_in_gossip(bank: &Bank, cluster_info: &ClusterInfo, log: boo
|
|||||||
online_stake * 100 / total_activated_stake
|
online_stake * 100 / total_activated_stake
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup_accounts_dir_entry(path: std::fs::DirEntry, accounts_file_regex: ®ex::Regex) {
|
|
||||||
if let Ok(file_type) = path.file_type() {
|
|
||||||
if file_type.is_file() {
|
|
||||||
if let Ok(file_name) = path.file_name().into_string() {
|
|
||||||
if accounts_file_regex.is_match(&file_name) {
|
|
||||||
if let Err(e) = std::fs::remove_file(path.path()) {
|
|
||||||
info!("Couldn't delete file: {:?} error: {:?}", path, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup anything that looks like an accounts append-vec
|
// Cleanup anything that looks like an accounts append-vec
|
||||||
fn cleanup_accounts_path(account_path: &std::path::Path) {
|
fn cleanup_accounts_path(account_path: &std::path::Path) {
|
||||||
use regex::Regex;
|
if std::fs::remove_dir_all(account_path).is_err() {
|
||||||
let accounts_file_regex = Regex::new(r"(\d+).(\d+)").unwrap();
|
warn!(
|
||||||
if let Ok(dir_entries) = std::fs::read_dir(&account_path) {
|
"encountered error removing accounts path: {:?}",
|
||||||
for entry in dir_entries {
|
account_path
|
||||||
if let Ok(path) = entry {
|
);
|
||||||
cleanup_accounts_dir_entry(path, &accounts_file_regex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1195,20 +1183,4 @@ mod tests {
|
|||||||
rpc_override_health_check
|
rpc_override_health_check
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn accounts_clean() {
|
|
||||||
use std::fs::File;
|
|
||||||
let temp_dir = tempfile::tempdir_in("farf").unwrap();
|
|
||||||
let temp_path = temp_dir.path();
|
|
||||||
{
|
|
||||||
let _file1 = File::create(temp_path.join("foo.txt")).unwrap();
|
|
||||||
let _file2 = File::create(temp_path.join("123.2222")).unwrap();
|
|
||||||
}
|
|
||||||
std::fs::create_dir(temp_path.join("12.088")).unwrap();
|
|
||||||
cleanup_accounts_path(temp_dir.path());
|
|
||||||
assert!(File::open(temp_path.join("foo.txt")).is_ok());
|
|
||||||
assert!(File::open(temp_path.join("123.2222")).is_err());
|
|
||||||
assert!(std::fs::read_dir(temp_path.join("12.088")).is_ok());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user