Skip to content
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

Merged
merged 6 commits into from
Jun 9, 2023

Conversation

apfitzge
Copy link
Contributor

@apfitzge apfitzge commented Jun 8, 2023

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 #

let account_paths: Vec<PathBuf> = account_paths
.into_iter()
.map(|account_path| {
match std::fs::create_dir_all(&account_path)
Copy link
Contributor Author

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:

  1. user passes a path which does not exist -> we create it, canonicalization just makes it absolute.
  2. user passes a path which does exist -> "creating" does nothing, canonicalization just makes it absolute.
  3. user passes a broken symlink -> canonicalization fails, validator crashes
  4. user passes a good symlink -> create does nothing, canonicalization gives us the followed link

Copy link
Contributor Author

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

Copy link
Contributor Author

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>> {
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@apfitzge
Copy link
Contributor Author

apfitzge commented Jun 8, 2023

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
Copy link

codecov bot commented Jun 9, 2023

Codecov Report

Merging #32037 (286a1ad) into master (8596e00) will increase coverage by 0.0%.
The diff coverage is 0.0%.

@@           Coverage Diff           @@
##           master   #32037   +/-   ##
=======================================
  Coverage    81.8%    81.9%           
=======================================
  Files         763      763           
  Lines      207671   207682   +11     
=======================================
+ Hits       170073   170113   +40     
+ Misses      37598    37569   -29     

t-nelson
t-nelson previously approved these changes Jun 9, 2023
Copy link
Contributor

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

validator/src/main.rs Outdated Show resolved Hide resolved
validator/src/main.rs Outdated Show resolved Hide resolved
validator/src/main.rs Outdated Show resolved Hide resolved
Co-authored-by: Brooks <brooks@prumo.org>
Comment on lines +972 to +973
.pop()
.unwrap();
Copy link
Contributor Author

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.

Copy link
Contributor

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)

@apfitzge apfitzge requested a review from brooksprumo June 9, 2023 15:38
Copy link
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@brooksprumo
Copy link
Contributor

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}");
Copy link
Contributor

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}"

Copy link
Contributor

@steviez steviez left a 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

@apfitzge apfitzge added the v1.16 PRs that should be backported to v1.16 label Jun 9, 2023
@apfitzge
Copy link
Contributor Author

apfitzge commented Jun 9, 2023

This one needs to be backported to v1.16, yes?

Added 1.16 label, now waiting on CI to merge.

@apfitzge apfitzge merged commit 4a566ec into solana-labs:master Jun 9, 2023
4 checks passed
@apfitzge apfitzge deleted the gotta_canonicalize_em_all branch June 9, 2023 17:04
mergify bot pushed a commit that referenced this pull request Jun 9, 2023
Co-authored-by: Brooks <brooks@prumo.org>
(cherry picked from commit 4a566ec)
mergify bot added a commit that referenced this pull request Jun 9, 2023
…2048)

create and canonicalize account_paths (#32037)

Co-authored-by: Brooks <brooks@prumo.org>
(cherry picked from commit 4a566ec)

Co-authored-by: Andrew Fitzgerald <apfitzge@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.16 PRs that should be backported to v1.16
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants