Skip to content

Commit

Permalink
fix rebase issues; with_extension
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 committed Feb 2, 2023
1 parent 0e12408 commit 3b2dc90
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
3 changes: 1 addition & 2 deletions runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ pub fn reserialize_bank_with_new_accounts_hash(
) -> bool {
let bank_post = snapshot_utils::get_bank_snapshots_dir(bank_snapshots_dir, slot);
let bank_post = bank_post.join(snapshot_utils::get_snapshot_file_name(slot));
let mut bank_pre = bank_post.clone();
bank_pre.set_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);
let bank_pre = bank_post.with_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);

let mut found = false;
{
Expand Down
5 changes: 2 additions & 3 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,10 @@ fn test_bank_serialize_style(
let temp_dir = TempDir::new().unwrap();
let slot_dir = temp_dir.path().join(slot.to_string());
let post_path = slot_dir.join(slot.to_string());
let mut pre_path = post_path.clone();
pre_path.set_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);
let pre_path = post_path.with_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);
std::fs::create_dir(&slot_dir).unwrap();
{
let mut f = std::fs::File::create(&pre_path).unwrap();
let mut f = std::fs::File::create(pre_path).unwrap();
f.write_all(&buf).unwrap();
}

Expand Down
25 changes: 6 additions & 19 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ impl BankSnapshotInfo {
// BankSnapshotPost file
let bank_snapshot_dir = get_bank_snapshots_dir(&bank_snapshots_dir, slot);
let bank_snapshot_post_path = bank_snapshot_dir.join(get_snapshot_file_name(slot));
let mut bank_snapshot_pre_path = bank_snapshot_post_path.clone();
bank_snapshot_pre_path.set_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);
let bank_snapshot_pre_path =
bank_snapshot_post_path.with_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);

if bank_snapshot_pre_path.is_file() {
return Some(BankSnapshotInfo {
Expand Down Expand Up @@ -991,8 +991,9 @@ pub fn add_bank_snapshot(
fs::create_dir_all(&bank_snapshot_dir)?;

// the bank snapshot is stored as bank_snapshots_dir/slot/slot.BANK_SNAPSHOT_PRE_FILENAME_EXTENSION
let mut bank_snapshot_path = bank_snapshot_dir.join(get_snapshot_file_name(slot));
bank_snapshot_path.set_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);
let bank_snapshot_path = bank_snapshot_dir
.join(get_snapshot_file_name(slot))
.with_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);

info!(
"Creating bank snapshot for slot {}, path: {}",
Expand Down Expand Up @@ -2318,30 +2319,16 @@ pub fn verify_snapshot_archive<P, Q, R>(
)
.unwrap();

// Bank snapshots may contain an accounts directory of hard linked append vecs,
// which must be removed in order for the directory comparison with the snapshot
// archive (below) to succeed.

let accounts_hardlinks_dir = snapshot_slot_dir.join("accounts_hardlinks");
if accounts_hardlinks_dir.is_dir() {
// This directory contain symlinks to all accounts snapshot directories.
// This directory contain symlinks to all <account_path>/snapshot/<slot> directories.
// They should all be removed.
for entry in fs::read_dir(&accounts_hardlinks_dir).unwrap() {
let dst_path = fs::read_link(entry.unwrap().path()).unwrap();
fs::remove_dir_all(dst_path).unwrap();
}
std::fs::remove_dir_all(accounts_hardlinks_dir).unwrap();
}

// Remove the new accounts/ to be consistent with the
// old archive structure.
let accounts_path = snapshot_slot_dir.join("accounts");
if accounts_path.is_dir() {
// Do not use the async move_and_async_delete_path because the assert below
// requires the job to be done.
// This is for test only, so the performance is not an issue.
std::fs::remove_dir_all(accounts_path).unwrap();
}
}

assert!(!dir_diff::is_different(&snapshots_to_verify, unpacked_snapshots).unwrap());
Expand Down

0 comments on commit 3b2dc90

Please sign in to comment.