-
Notifications
You must be signed in to change notification settings - Fork 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
create and canonicalize account_paths #32037
create and canonicalize account_paths #32037
Conversation
validator/src/main.rs
Outdated
let account_paths: Vec<PathBuf> = account_paths | ||
.into_iter() | ||
.map(|account_path| { | ||
match std::fs::create_dir_all(&account_path) |
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.
Creation happens before canonicalization; this is intentional.
std::fs::canonicalize will fail if the path does not exist. So we have 4 cases:
- user passes a path which does not exist -> we create it, canonicalization just makes it absolute.
- user passes a path which does exist -> "creating" does nothing, canonicalization just makes it absolute.
- user passes a broken symlink -> canonicalization fails, validator crashes
- user passes a good symlink -> create does nothing, canonicalization gives us the followed link
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.
To be clear I just re-implemented the logic which was removed in the previous PR
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.
should have commented after I create the function. Same comments applied to the create_and_canonicalize_directories
fn
@@ -422,6 +422,21 @@ pub enum VerifySlotDeltasError { | |||
BadSlotHistory, | |||
} | |||
|
|||
/// Creates directories if they do not exist, and canonicalizes the paths. | |||
pub fn create_and_canonicalize_directories(directories: &[PathBuf]) -> Result<Vec<PathBuf>> { |
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.
wasn't super happy about this returning a SnapshotError
, since it's only somewhat related to snapshots. Somewhat of a hack because I want to keep info about which path caused the error which afaik isn't easy to do w/ IoError
@@ -1413,20 +1420,10 @@ pub fn main() { | |||
validator_config.account_snapshot_paths = account_snapshot_paths; | |||
|
|||
validator_config.account_shrink_paths = account_shrink_paths.map(|paths| { | |||
paths |
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.
we were doing the same thing in 2 places, just moved it to a function so we can also use this in ledger-tool when I get to checking that out.
Leaving ledger-tool as a separate task/PR - this PR just tries to get us back to the state we had wrt canonicalization pre-#30645 |
Codecov Report
@@ Coverage Diff @@
## master #32037 +/- ##
=======================================
Coverage 81.8% 81.9%
=======================================
Files 763 763
Lines 207671 207682 +11
=======================================
+ Hits 170073 170113 +40
+ Misses 37598 37569 -29 |
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.
@@ -963,8 +964,7 @@ pub fn main() { | |||
.map(BlockstoreRecoveryMode::from); | |||
|
|||
// Canonicalize ledger path to avoid issues with symlink creation | |||
let _ = fs::create_dir_all(&ledger_path); |
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.
Interesting that we would ignore errors here...
Seems correct to not ignore those errors in the new code.
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.
History: #7877
Probably just the simplest/quickest way to get it created & not have an unwrap?
🤔 maybe some concerns about permissions? It's possible we have a ledger_dir
w/ permissions to write inside the dir, but not permissions to write in the parent dir. To me it was not obvious what the result of create_dir_all
would be just from reading the docs (it's Ok
if ledger_path
exists).
Agree it seems better to not ignore the errors.
Co-authored-by: Brooks <brooks@prumo.org>
.pop() | ||
.unwrap(); |
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.
fn returns a Vec, so we gotta pop it out.
We created slice above and already checked the Result
is Ok
, unwrap
is safe.
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.
note's like this are better as code comments (in the future)
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.
lgtm
This one needs to be backported to v1.16, yes? |
}); | ||
let ledger_path = create_and_canonicalize_directories(&[ledger_path]) | ||
.unwrap_or_else(|err| { | ||
eprintln!("Unable to access ledger path: {err}"); |
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.
Thinking about making the logs easy to grep, it would be nice if the message contains Error
. Since this is an eprintln!()
instead of an error!()
, what do you think about prepending Error
to the existing for:
"Error: unable to access ledger path: {err}"
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.
As for my last comment about including Error
, we have a mix of these in the validator/src/main.rs
; I'd say things are good to go as-is and maybe I'll do a cleanup to make all instances of eprintln!()
and exit()
specifically include the word Error
Added 1.16 label, now waiting on CI to merge. |
Co-authored-by: Brooks <brooks@prumo.org> (cherry picked from commit 4a566ec)
Problem
We stopped canonicalizing validator
account_paths
in #30645.This causes issues if users specify
account_paths
which are symlinks, when we start to clean our account directories. The directory that the cleanup process deletes & recreates should be at the followed path, not the location of the link.Summary of Changes
canonicalize the
account_paths
like we've always done.Fixes #