Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions runtime/src/snapshot_utils/snapshot_storage_rebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use {
iter::{IntoParallelIterator, ParallelIterator},
ThreadPool, ThreadPoolBuilder,
},
regex::Regex,
solana_sdk::clock::Slot,
std::{
collections::HashMap,
Expand Down Expand Up @@ -348,32 +349,20 @@ enum SnapshotFileKind {

/// Determines `SnapshotFileKind` for `filename` if any
fn get_snapshot_file_kind(filename: &str) -> Option<SnapshotFileKind> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is something like this what you had in mind @brooksprumo?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes! Looks good to me. Thanks for doing this.

if filename == "version" {
return Some(SnapshotFileKind::Version);
}

let mut periods = 0;
let mut saw_numbers = false;
for x in filename.chars() {
if !x.is_ascii_digit() {
if x == '.' {
if periods > 0 || !saw_numbers {
return None;
}
saw_numbers = false;
periods += 1;
} else {
return None;
}
} else {
saw_numbers = true;
}
}

match (periods, saw_numbers) {
(0, true) => Some(SnapshotFileKind::BankFields),
(1, true) => Some(SnapshotFileKind::Storage),
(_, _) => None,
lazy_static! {
static ref VERSION_FILE_REGEX: Regex = Regex::new(r"^version$").unwrap();
static ref BANK_FIELDS_FILE_REGEX: Regex = Regex::new(r"^[0-9]+$").unwrap();
static ref STORAGE_FILE_REGEX: Regex = Regex::new(r"^[0-9]+\.[0-9]+$").unwrap();
};

if VERSION_FILE_REGEX.is_match(filename) {
Some(SnapshotFileKind::Version)
} else if BANK_FIELDS_FILE_REGEX.is_match(filename) {
Some(SnapshotFileKind::BankFields)
} else if STORAGE_FILE_REGEX.is_match(filename) {
Some(SnapshotFileKind::Storage)
} else {
None
}
}

Expand Down