diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index db7fd97e027b11..f7b9b8453ea779 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -66,7 +66,6 @@ use { mod archive_format; mod snapshot_storage_rebuilder; -use crate::accounts_db::AppendVecId; pub use archive_format::*; #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -1972,21 +1971,6 @@ pub(crate) fn parse_incremental_snapshot_archive_filename( }) } -pub(crate) fn parse_appendvec_filename(filename: &str) -> Option<(Slot, AppendVecId)> { - lazy_static! { - static ref STORAGE_FILE_REGEX: Regex = - Regex::new(r"^(?P[0-9]+)\.(?P[0-9]+)$").unwrap(); - }; - - STORAGE_FILE_REGEX.captures(filename).map(|cap| { - let slot_str = cap.name("slot").map(|m| m.as_str()); - let id_str = cap.name("id").map(|m| m.as_str()); - let slot: Slot = slot_str.unwrap().parse::().unwrap(); - let id: AppendVecId = id_str.unwrap().parse::().unwrap(); - (slot, id) - }) -} - pub(crate) fn parse_snapshot_filename(filename: &str) -> Option<(Slot, BankSnapshotType)> { lazy_static! { static ref SNAPSHOT_FILE_REGEX: Regex = diff --git a/runtime/src/snapshot_utils/snapshot_storage_rebuilder.rs b/runtime/src/snapshot_utils/snapshot_storage_rebuilder.rs index 3d183842615a64..1d3d21e4bf0cd1 100644 --- a/runtime/src/snapshot_utils/snapshot_storage_rebuilder.rs +++ b/runtime/src/snapshot_utils/snapshot_storage_rebuilder.rs @@ -2,8 +2,7 @@ use { super::{ - get_io_error, parse_appendvec_filename, snapshot_version_from_file, SnapshotError, - SnapshotFrom, SnapshotVersion, + get_io_error, snapshot_version_from_file, SnapshotError, SnapshotFrom, SnapshotVersion, }, crate::{ accounts_db::{AccountStorageEntry, AccountStorageMap, AppendVecId, AtomicAppendVecId}, @@ -263,14 +262,12 @@ impl SnapshotStorageRebuilder { let filename = path.file_name().unwrap().to_str().unwrap().to_owned(); if let Some(SnapshotFileKind::Storage) = get_snapshot_file_kind(&filename) { if self.snapshot_from == Some(SnapshotFrom::File) { - if let Some(appendvec_entry) = parse_appendvec_filename(&filename) { - let (_slot, appendvec_id) = appendvec_entry; - let next_appendvec_id = appendvec_id + 1; - // Always set to the maximum to avoid id conflict. - let _ = &self - .next_append_vec_id - .fetch_max(next_appendvec_id, Ordering::Relaxed); - } + let (_slot, appendvec_id) = get_slot_and_append_vec_id(&filename); + let next_appendvec_id = appendvec_id + 1; + // Always set to the maximum to avoid id conflict. + let _ = &self + .next_append_vec_id + .fetch_max(next_appendvec_id as u32, Ordering::Relaxed); } let (slot, slot_complete) = self.insert_slot_storage_file(path, filename); if slot_complete { @@ -420,12 +417,21 @@ pub fn get_snapshot_file_kind(filename: &str) -> Option { /// Get the slot and append vec id from the filename pub(crate) fn get_slot_and_append_vec_id(filename: &str) -> (Slot, usize) { - let mut split = filename.split('.'); - let slot = split.next().unwrap().parse().unwrap(); - let append_vec_id = split.next().unwrap().parse().unwrap(); - assert!(split.next().is_none()); + lazy_static! { + static ref STORAGE_FILE_REGEX: Regex = + Regex::new(r"^(?P[0-9]+)\.(?P[0-9]+)$").unwrap(); + }; - (slot, append_vec_id) + STORAGE_FILE_REGEX + .captures(filename) + .map(|cap| { + let slot_str = cap.name("slot").map(|m| m.as_str()); + let id_str = cap.name("id").map(|m| m.as_str()); + let slot: Slot = slot_str.unwrap().parse::().unwrap(); + let id = id_str.unwrap().parse::().unwrap() as usize; + (slot, id) + }) + .unwrap() } #[cfg(test)]