Move SnapshotArchiveInfo and friends into its own module (#19114)
This commit is contained in:
@ -34,6 +34,7 @@ pub mod rent_collector;
|
||||
pub mod secondary_index;
|
||||
pub mod serde_snapshot;
|
||||
mod shared_buffer_reader;
|
||||
pub mod snapshot_archive_info;
|
||||
pub mod snapshot_config;
|
||||
pub mod snapshot_package;
|
||||
pub mod snapshot_runtime_info;
|
||||
|
149
runtime/src/snapshot_archive_info.rs
Normal file
149
runtime/src/snapshot_archive_info.rs
Normal file
@ -0,0 +1,149 @@
|
||||
//! Information about snapshot archives
|
||||
|
||||
use crate::snapshot_utils::{self, ArchiveFormat, Result};
|
||||
use solana_sdk::{clock::Slot, hash::Hash};
|
||||
use std::{cmp::Ordering, path::PathBuf};
|
||||
|
||||
/// Trait to query the snapshot archive information
|
||||
pub trait SnapshotArchiveInfoGetter {
|
||||
fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo;
|
||||
|
||||
fn path(&self) -> &PathBuf {
|
||||
&self.snapshot_archive_info().path
|
||||
}
|
||||
|
||||
fn slot(&self) -> Slot {
|
||||
self.snapshot_archive_info().slot
|
||||
}
|
||||
|
||||
fn hash(&self) -> &Hash {
|
||||
&self.snapshot_archive_info().hash
|
||||
}
|
||||
|
||||
fn archive_format(&self) -> ArchiveFormat {
|
||||
self.snapshot_archive_info().archive_format
|
||||
}
|
||||
}
|
||||
|
||||
/// Common information about a snapshot archive
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct SnapshotArchiveInfo {
|
||||
/// Path to the snapshot archive file
|
||||
pub path: PathBuf,
|
||||
|
||||
/// Slot that the snapshot was made
|
||||
pub slot: Slot,
|
||||
|
||||
/// Hash of the accounts at this slot
|
||||
pub hash: Hash,
|
||||
|
||||
/// Archive format for the snapshot file
|
||||
pub archive_format: ArchiveFormat,
|
||||
}
|
||||
|
||||
/// Information about a full snapshot archive: its path, slot, hash, and archive format
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct FullSnapshotArchiveInfo(SnapshotArchiveInfo);
|
||||
|
||||
impl FullSnapshotArchiveInfo {
|
||||
/// Parse the path to a full snapshot archive and return a new `FullSnapshotArchiveInfo`
|
||||
pub fn new_from_path(path: PathBuf) -> Result<Self> {
|
||||
let filename = snapshot_utils::path_to_file_name_str(path.as_path())?;
|
||||
let (slot, hash, archive_format) =
|
||||
snapshot_utils::parse_full_snapshot_archive_filename(filename)?;
|
||||
|
||||
Ok(Self::new(SnapshotArchiveInfo {
|
||||
path,
|
||||
slot,
|
||||
hash,
|
||||
archive_format,
|
||||
}))
|
||||
}
|
||||
|
||||
pub(crate) fn new(snapshot_archive_info: SnapshotArchiveInfo) -> Self {
|
||||
Self(snapshot_archive_info)
|
||||
}
|
||||
}
|
||||
|
||||
impl SnapshotArchiveInfoGetter for FullSnapshotArchiveInfo {
|
||||
fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for FullSnapshotArchiveInfo {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
// Order `FullSnapshotArchiveInfo` by slot (ascending), which practially is sorting chronologically
|
||||
impl Ord for FullSnapshotArchiveInfo {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.slot().cmp(&other.slot())
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about an incremental snapshot archive: its path, slot, base slot, hash, and archive format
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct IncrementalSnapshotArchiveInfo {
|
||||
/// The slot that the incremental snapshot was based from. This is the same as the full
|
||||
/// snapshot slot used when making the incremental snapshot.
|
||||
base_slot: Slot,
|
||||
|
||||
/// Use the `SnapshotArchiveInfo` struct for the common fields: path, slot, hash, and
|
||||
/// archive_format, but as they pertain to the incremental snapshot.
|
||||
inner: SnapshotArchiveInfo,
|
||||
}
|
||||
|
||||
impl IncrementalSnapshotArchiveInfo {
|
||||
/// Parse the path to an incremental snapshot archive and return a new `IncrementalSnapshotArchiveInfo`
|
||||
pub fn new_from_path(path: PathBuf) -> Result<Self> {
|
||||
let filename = snapshot_utils::path_to_file_name_str(path.as_path())?;
|
||||
let (base_slot, slot, hash, archive_format) =
|
||||
snapshot_utils::parse_incremental_snapshot_archive_filename(filename)?;
|
||||
|
||||
Ok(Self::new(
|
||||
base_slot,
|
||||
SnapshotArchiveInfo {
|
||||
path,
|
||||
slot,
|
||||
hash,
|
||||
archive_format,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) fn new(base_slot: Slot, snapshot_archive_info: SnapshotArchiveInfo) -> Self {
|
||||
Self {
|
||||
base_slot,
|
||||
inner: snapshot_archive_info,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn base_slot(&self) -> Slot {
|
||||
self.base_slot
|
||||
}
|
||||
}
|
||||
|
||||
impl SnapshotArchiveInfoGetter for IncrementalSnapshotArchiveInfo {
|
||||
fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for IncrementalSnapshotArchiveInfo {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
// Order `IncrementalSnapshotArchiveInfo` by base slot (ascending), then slot (ascending), which
|
||||
// practially is sorting chronologically
|
||||
impl Ord for IncrementalSnapshotArchiveInfo {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.base_slot()
|
||||
.cmp(&other.base_slot())
|
||||
.then(self.slot().cmp(&other.slot()))
|
||||
}
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
use crate::snapshot_utils::{
|
||||
ArchiveFormat, BankSnapshotInfo, Result, SnapshotArchiveInfo, SnapshotArchiveInfoGetter,
|
||||
SnapshotVersion, TMP_FULL_SNAPSHOT_PREFIX, TMP_INCREMENTAL_SNAPSHOT_PREFIX,
|
||||
};
|
||||
use crate::{
|
||||
accounts_db::SnapshotStorages,
|
||||
bank::{Bank, BankSlotDelta},
|
||||
};
|
||||
use crate::{
|
||||
snapshot_archive_info::{SnapshotArchiveInfo, SnapshotArchiveInfoGetter},
|
||||
snapshot_utils::{
|
||||
ArchiveFormat, BankSnapshotInfo, Result, SnapshotVersion, TMP_FULL_SNAPSHOT_PREFIX,
|
||||
TMP_INCREMENTAL_SNAPSHOT_PREFIX,
|
||||
},
|
||||
};
|
||||
use log::*;
|
||||
use solana_sdk::clock::Slot;
|
||||
use solana_sdk::genesis_config::ClusterType;
|
||||
|
@ -9,6 +9,9 @@ use {
|
||||
SnapshotStreams,
|
||||
},
|
||||
shared_buffer_reader::{SharedBuffer, SharedBufferReader},
|
||||
snapshot_archive_info::{
|
||||
FullSnapshotArchiveInfo, IncrementalSnapshotArchiveInfo, SnapshotArchiveInfoGetter,
|
||||
},
|
||||
snapshot_package::{
|
||||
AccountsPackage, AccountsPackagePre, AccountsPackageSendError, AccountsPackageSender,
|
||||
},
|
||||
@ -39,149 +42,6 @@ use {
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
/// Trait to query the snapshot archive information
|
||||
pub trait SnapshotArchiveInfoGetter {
|
||||
fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo;
|
||||
|
||||
fn path(&self) -> &PathBuf {
|
||||
&self.snapshot_archive_info().path
|
||||
}
|
||||
|
||||
fn slot(&self) -> Slot {
|
||||
self.snapshot_archive_info().slot
|
||||
}
|
||||
|
||||
fn hash(&self) -> &Hash {
|
||||
&self.snapshot_archive_info().hash
|
||||
}
|
||||
|
||||
fn archive_format(&self) -> ArchiveFormat {
|
||||
self.snapshot_archive_info().archive_format
|
||||
}
|
||||
}
|
||||
|
||||
/// Common information about a snapshot archive
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct SnapshotArchiveInfo {
|
||||
/// Path to the snapshot archive file
|
||||
pub path: PathBuf,
|
||||
|
||||
/// Slot that the snapshot was made
|
||||
pub slot: Slot,
|
||||
|
||||
/// Hash of the accounts at this slot
|
||||
pub hash: Hash,
|
||||
|
||||
/// Archive format for the snapshot file
|
||||
pub archive_format: ArchiveFormat,
|
||||
}
|
||||
|
||||
/// Information about a full snapshot archive: its path, slot, hash, and archive format
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct FullSnapshotArchiveInfo(SnapshotArchiveInfo);
|
||||
|
||||
impl FullSnapshotArchiveInfo {
|
||||
/// Parse the path to a full snapshot archive and return a new `FullSnapshotArchiveInfo`
|
||||
pub fn new_from_path(path: PathBuf) -> Result<Self> {
|
||||
let filename = path_to_file_name_str(path.as_path())?;
|
||||
let (slot, hash, archive_format) = parse_full_snapshot_archive_filename(filename)?;
|
||||
|
||||
Ok(Self::new(SnapshotArchiveInfo {
|
||||
path,
|
||||
slot,
|
||||
hash,
|
||||
archive_format,
|
||||
}))
|
||||
}
|
||||
|
||||
fn new(snapshot_archive_info: SnapshotArchiveInfo) -> Self {
|
||||
Self(snapshot_archive_info)
|
||||
}
|
||||
}
|
||||
|
||||
impl SnapshotArchiveInfoGetter for FullSnapshotArchiveInfo {
|
||||
fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for FullSnapshotArchiveInfo {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
// Order `FullSnapshotArchiveInfo` by slot (ascending), which practially is sorting chronologically
|
||||
impl Ord for FullSnapshotArchiveInfo {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.slot().cmp(&other.slot())
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about an incremental snapshot archive: its path, slot, base slot, hash, and archive format
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct IncrementalSnapshotArchiveInfo {
|
||||
/// The slot that the incremental snapshot was based from. This is the same as the full
|
||||
/// snapshot slot used when making the incremental snapshot.
|
||||
base_slot: Slot,
|
||||
|
||||
/// Use the `SnapshotArchiveInfo` struct for the common fields: path, slot, hash, and
|
||||
/// archive_format, but as they pertain to the incremental snapshot.
|
||||
inner: SnapshotArchiveInfo,
|
||||
}
|
||||
|
||||
impl IncrementalSnapshotArchiveInfo {
|
||||
/// Parse the path to an incremental snapshot archive and return a new `IncrementalSnapshotArchiveInfo`
|
||||
pub fn new_from_path(path: PathBuf) -> Result<Self> {
|
||||
let filename = path_to_file_name_str(path.as_path())?;
|
||||
let (base_slot, slot, hash, archive_format) =
|
||||
parse_incremental_snapshot_archive_filename(filename)?;
|
||||
|
||||
Ok(Self::new(
|
||||
base_slot,
|
||||
SnapshotArchiveInfo {
|
||||
path,
|
||||
slot,
|
||||
hash,
|
||||
archive_format,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
fn new(base_slot: Slot, snapshot_archive_info: SnapshotArchiveInfo) -> Self {
|
||||
Self {
|
||||
base_slot,
|
||||
inner: snapshot_archive_info,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn base_slot(&self) -> Slot {
|
||||
self.base_slot
|
||||
}
|
||||
}
|
||||
|
||||
impl SnapshotArchiveInfoGetter for IncrementalSnapshotArchiveInfo {
|
||||
fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for IncrementalSnapshotArchiveInfo {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
// Order `IncrementalSnapshotArchiveInfo` by base slot (ascending), then slot (ascending), which
|
||||
// practially is sorting chronologically
|
||||
impl Ord for IncrementalSnapshotArchiveInfo {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.base_slot()
|
||||
.cmp(&other.base_slot())
|
||||
.then(self.slot().cmp(&other.slot()))
|
||||
}
|
||||
}
|
||||
|
||||
pub const SNAPSHOT_STATUS_CACHE_FILE_NAME: &str = "status_cache";
|
||||
|
||||
pub const MAX_BANK_SNAPSHOTS: usize = 8; // Save some snapshots but not too many
|
||||
@ -1119,7 +979,7 @@ fn check_are_snapshots_compatible(
|
||||
}
|
||||
|
||||
/// Get the `&str` from a `&Path`
|
||||
fn path_to_file_name_str(path: &Path) -> Result<&str> {
|
||||
pub fn path_to_file_name_str(path: &Path) -> Result<&str> {
|
||||
path.file_name()
|
||||
.ok_or_else(|| SnapshotError::PathToFileNameError(path.to_path_buf()))?
|
||||
.to_str()
|
||||
@ -1172,7 +1032,7 @@ fn archive_format_from_str(archive_format: &str) -> Option<ArchiveFormat> {
|
||||
}
|
||||
|
||||
/// Parse a full snapshot archive filename into its Slot, Hash, and Archive Format
|
||||
fn parse_full_snapshot_archive_filename(
|
||||
pub fn parse_full_snapshot_archive_filename(
|
||||
archive_filename: &str,
|
||||
) -> Result<(Slot, Hash, ArchiveFormat)> {
|
||||
lazy_static! {
|
||||
@ -1203,7 +1063,7 @@ fn parse_full_snapshot_archive_filename(
|
||||
}
|
||||
|
||||
/// Parse an incremental snapshot archive filename into its base Slot, actual Slot, Hash, and Archive Format
|
||||
fn parse_incremental_snapshot_archive_filename(
|
||||
pub fn parse_incremental_snapshot_archive_filename(
|
||||
archive_filename: &str,
|
||||
) -> Result<(Slot, Slot, Hash, ArchiveFormat)> {
|
||||
lazy_static! {
|
||||
|
Reference in New Issue
Block a user