Skip to content

Commit

Permalink
remove parse_appendvec_filename
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 committed Dec 13, 2022
1 parent a2c179f commit 0329e89
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
16 changes: 0 additions & 16 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<slot>[0-9]+)\.(?P<id>[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::<u64>().unwrap();
let id: AppendVecId = id_str.unwrap().parse::<u32>().unwrap();
(slot, id)
})
}

pub(crate) fn parse_snapshot_filename(filename: &str) -> Option<(Slot, BankSnapshotType)> {
lazy_static! {
static ref SNAPSHOT_FILE_REGEX: Regex =
Expand Down
36 changes: 21 additions & 15 deletions runtime/src/snapshot_utils/snapshot_storage_rebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -420,12 +417,21 @@ pub fn get_snapshot_file_kind(filename: &str) -> Option<SnapshotFileKind> {

/// 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<slot>[0-9]+)\.(?P<id>[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::<u64>().unwrap();
let id = id_str.unwrap().parse::<u32>().unwrap() as usize;
(slot, id)
})
.unwrap()
}

#[cfg(test)]
Expand Down

0 comments on commit 0329e89

Please sign in to comment.