From 0ddb28b57be5655418b1404e76edca1deacdd4b9 Mon Sep 17 00:00:00 2001 From: Xiang Zhu Date: Tue, 21 Feb 2023 15:36:03 -0800 Subject: [PATCH 1/5] Fix the hardlink failure --- runtime/src/snapshot_utils.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 0d7ac2ea79c591..2834c78ae4a8d5 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -1014,6 +1014,22 @@ pub fn add_bank_snapshot( // directory. Then, when adding new snapshots, the newer incomplete snapshot directory could // be found. If so, it should be removed. remove_bank_snapshot(slot, &bank_snapshots_dir)?; + } else { + // Even the snapshot directory is not found, still ensure the account snapshot directory + // is also clean. hardlink failure could happen if an old files exist when generating a + // new snapshot. + let account_paths = &bank.accounts().accounts_db.paths; + for account_path in account_paths { + let account_snapshot_path = account_path + .parent() + .unwrap() + .join("snapshot") + .join(bank.slot().to_string()); + if account_snapshot_path.is_dir() { + // remove the account snapshot directory + fs::remove_dir_all(&account_snapshot_path)?; + } + } } fs::create_dir_all(&bank_snapshot_dir)?; From eadada36ede9455739f8edf1d25e81cfa712624e Mon Sep 17 00:00:00 2001 From: Xiang Zhu Date: Tue, 21 Feb 2023 16:03:43 -0800 Subject: [PATCH 2/5] minor comment cleanup --- runtime/src/snapshot_utils.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 2834c78ae4a8d5..56e097d1d7536b 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -1016,8 +1016,7 @@ pub fn add_bank_snapshot( remove_bank_snapshot(slot, &bank_snapshots_dir)?; } else { // Even the snapshot directory is not found, still ensure the account snapshot directory - // is also clean. hardlink failure could happen if an old files exist when generating a - // new snapshot. + // is also clean. hardlink failure will happen if an old file exists. let account_paths = &bank.accounts().accounts_db.paths; for account_path in account_paths { let account_snapshot_path = account_path From 7442a64ac1c136dddd75be020f5d97293aaa4fd3 Mon Sep 17 00:00:00 2001 From: Xiang Zhu Date: Wed, 22 Feb 2023 08:20:42 -0800 Subject: [PATCH 3/5] use ? and slot_str --- runtime/src/snapshot_utils.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 56e097d1d7536b..ca1cae9ac4cfa0 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -1018,12 +1018,13 @@ pub fn add_bank_snapshot( // Even the snapshot directory is not found, still ensure the account snapshot directory // is also clean. hardlink failure will happen if an old file exists. let account_paths = &bank.accounts().accounts_db.paths; + let slot_str = slot.to_string(); for account_path in account_paths { let account_snapshot_path = account_path .parent() - .unwrap() + .ok_or(SnapshotError::InvalidAppendVecPath(account_path.clone()))? .join("snapshot") - .join(bank.slot().to_string()); + .join(slot_str.clone()); if account_snapshot_path.is_dir() { // remove the account snapshot directory fs::remove_dir_all(&account_snapshot_path)?; From 667e75ee9e02ed9d3180af38d375b05489ab5e54 Mon Sep 17 00:00:00 2001 From: Xiang Zhu Date: Wed, 22 Feb 2023 12:56:26 -0800 Subject: [PATCH 4/5] &slot_str --- runtime/src/snapshot_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index ca1cae9ac4cfa0..2b200eef2c4654 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -1024,7 +1024,7 @@ pub fn add_bank_snapshot( .parent() .ok_or(SnapshotError::InvalidAppendVecPath(account_path.clone()))? .join("snapshot") - .join(slot_str.clone()); + .join(&slot_str); if account_snapshot_path.is_dir() { // remove the account snapshot directory fs::remove_dir_all(&account_snapshot_path)?; From c3b5bf9bedacf9ad7887136a83570b56c74a1e35 Mon Sep 17 00:00:00 2001 From: Xiang Zhu Date: Wed, 22 Feb 2023 15:18:46 -0800 Subject: [PATCH 5/5] Add InvalidAccountPath --- runtime/src/snapshot_utils.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 2b200eef2c4654..ae084f3e99e3d4 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -296,6 +296,9 @@ pub enum SnapshotError { #[error("invalid AppendVec path: {}", .0.display())] InvalidAppendVecPath(PathBuf), + + #[error("invalid account path: {}", .0.display())] + InvalidAccountPath(PathBuf), } pub type Result = std::result::Result; @@ -1022,7 +1025,7 @@ pub fn add_bank_snapshot( for account_path in account_paths { let account_snapshot_path = account_path .parent() - .ok_or(SnapshotError::InvalidAppendVecPath(account_path.clone()))? + .ok_or(SnapshotError::InvalidAccountPath(account_path.clone()))? .join("snapshot") .join(&slot_str); if account_snapshot_path.is_dir() {