-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Account files remove #26910
Merged
xiangzhu70
merged 9 commits into
solana-labs:master
from
xiangzhu70:account_files_remove
Aug 20, 2022
Merged
Account files remove #26910
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dd0cb8b
Create a new function cleanup_accounts_paths, a trivial change
xiangzhu70 fa7dc67
Remove account files asynchronously
xiangzhu70 a8449e8
Update and simplify the implementation after the validator test runs.
xiangzhu70 93a6705
Fixes after testing on the dev device
xiangzhu70 724768b
Discard tokio. Use thread instead
xiangzhu70 bc605ff
Fix comments format
xiangzhu70 cc14f5b
Fix config type to pass the github test
jeffwashington c632860
Fix failed tests. Handle the case of non-existing path
jeffwashington 72e4e9b
Final cleanup, addressing the review comments
jeffwashington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -456,14 +456,7 @@ impl Validator { | |
info!("Cleaning accounts paths.."); | ||
*start_progress.write().unwrap() = ValidatorStartProgress::CleaningAccounts; | ||
let mut start = Measure::start("clean_accounts_paths"); | ||
for accounts_path in &config.account_paths { | ||
cleanup_accounts_path(accounts_path); | ||
} | ||
if let Some(ref shrink_paths) = config.account_shrink_paths { | ||
for accounts_path in shrink_paths { | ||
cleanup_accounts_path(accounts_path); | ||
} | ||
} | ||
cleanup_accounts_paths(config); | ||
start.stop(); | ||
info!("done. {}", start); | ||
|
||
|
@@ -2061,13 +2054,56 @@ fn get_stake_percent_in_gossip(bank: &Bank, cluster_info: &ClusterInfo, log: boo | |
online_stake_percentage as u64 | ||
} | ||
|
||
// Cleanup anything that looks like an accounts append-vec | ||
fn cleanup_accounts_path(account_path: &std::path::Path) { | ||
if let Err(e) = std::fs::remove_dir_all(account_path) { | ||
warn!( | ||
"encountered error removing accounts path: {:?}: {}", | ||
account_path, e | ||
/// Delete directories/files asynchronously to avoid blocking on it. | ||
/// Fist, in sync context, rename the original path to *_deleted, | ||
/// then spawn a thread to delete the renamed path. | ||
/// If the process is killed and the deleting process is not done, | ||
/// the leftover path will be deleted in the next process life, so | ||
/// there is no file space leaking. | ||
fn move_and_async_delete_path(path: impl AsRef<Path> + Copy) { | ||
let mut path_delete = PathBuf::new(); | ||
path_delete.push(path); | ||
path_delete.set_file_name(format!( | ||
"{}{}", | ||
path_delete.file_name().unwrap().to_str().unwrap(), | ||
"_to_be_deleted" | ||
)); | ||
|
||
if path_delete.exists() { | ||
debug!("{} exists, delete it first.", path_delete.display()); | ||
std::fs::remove_dir_all(&path_delete).unwrap(); | ||
} | ||
|
||
if !path.as_ref().exists() { | ||
info!( | ||
"move_and_async_delete_path: path {} does not exist", | ||
path.as_ref().display() | ||
); | ||
return; | ||
} | ||
|
||
std::fs::rename(&path, &path_delete).unwrap(); | ||
|
||
Builder::new() | ||
.name("delete_path".to_string()) | ||
.spawn(move || { | ||
std::fs::remove_dir_all(&path_delete).unwrap(); | ||
info!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think get rid of this info. It is always true that this will be done in bg now. |
||
"Cleaning path {} done asynchronously in a spawned thread", | ||
path_delete.display() | ||
); | ||
}) | ||
.unwrap(); | ||
} | ||
|
||
fn cleanup_accounts_paths(config: &ValidatorConfig) { | ||
for accounts_path in &config.account_paths { | ||
move_and_async_delete_path(accounts_path); | ||
} | ||
if let Some(ref shrink_paths) = config.account_shrink_paths { | ||
for accounts_path in shrink_paths { | ||
move_and_async_delete_path(accounts_path); | ||
} | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think get rid of this. only useful for your debugging. nobody keeps debug logs turned on.