2021-03-10 09:49:10 -08:00
|
|
|
use {
|
|
|
|
crate::{
|
2023-07-24 16:31:03 -07:00
|
|
|
serde_snapshot::SnapshotStreams,
|
2021-08-08 05:57:06 -07:00
|
|
|
snapshot_archive_info::{
|
|
|
|
FullSnapshotArchiveInfo, IncrementalSnapshotArchiveInfo, SnapshotArchiveInfoGetter,
|
|
|
|
},
|
2022-10-31 11:28:35 -07:00
|
|
|
snapshot_hash::SnapshotHash,
|
2023-07-24 16:31:03 -07:00
|
|
|
snapshot_package::SnapshotPackage,
|
2022-10-31 11:28:35 -07:00
|
|
|
snapshot_utils::snapshot_storage_rebuilder::{
|
|
|
|
RebuiltSnapshotStorage, SnapshotStorageRebuilder,
|
|
|
|
},
|
2020-06-17 08:27:03 -07:00
|
|
|
},
|
2021-03-10 09:49:10 -08:00
|
|
|
bzip2::bufread::BzDecoder,
|
2022-10-31 11:28:35 -07:00
|
|
|
crossbeam_channel::Sender,
|
2021-03-10 09:49:10 -08:00
|
|
|
flate2::read::GzDecoder,
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err,
|
2021-07-22 12:40:37 -07:00
|
|
|
lazy_static::lazy_static,
|
2021-03-10 09:49:10 -08:00
|
|
|
log::*,
|
2021-08-31 16:33:27 -07:00
|
|
|
rayon::prelude::*,
|
2021-03-10 09:49:10 -08:00
|
|
|
regex::Regex,
|
2023-08-09 13:03:36 -07:00
|
|
|
solana_accounts_db::{
|
|
|
|
account_storage::AccountStorageMap,
|
|
|
|
accounts_db::{
|
|
|
|
self, create_accounts_run_and_snapshot_dirs, AccountStorageEntry, AtomicAppendVecId,
|
|
|
|
},
|
|
|
|
accounts_file::AccountsFileError,
|
|
|
|
append_vec::AppendVec,
|
|
|
|
hardened_unpack::{
|
|
|
|
streaming_unpack_snapshot, unpack_snapshot, ParallelSelector, UnpackError,
|
|
|
|
UnpackedAppendVecMap,
|
|
|
|
},
|
|
|
|
shared_buffer_reader::{SharedBuffer, SharedBufferReader},
|
|
|
|
},
|
2022-08-29 11:17:27 -07:00
|
|
|
solana_measure::{measure, measure::Measure},
|
2023-07-24 16:31:03 -07:00
|
|
|
solana_sdk::{clock::Slot, hash::Hash},
|
2021-03-10 09:49:10 -08:00
|
|
|
std::{
|
2022-04-27 09:40:03 -07:00
|
|
|
cmp::Ordering,
|
|
|
|
collections::{HashMap, HashSet},
|
2021-03-10 09:49:10 -08:00
|
|
|
fmt,
|
2021-08-04 15:07:55 -07:00
|
|
|
io::{BufReader, BufWriter, Error as IoError, ErrorKind, Read, Seek, Write},
|
2023-03-30 08:16:36 -07:00
|
|
|
num::NonZeroUsize,
|
2021-03-10 09:49:10 -08:00
|
|
|
path::{Path, PathBuf},
|
2021-08-04 15:07:55 -07:00
|
|
|
process::ExitStatus,
|
2021-03-10 09:49:10 -08:00
|
|
|
str::FromStr,
|
2023-08-09 13:03:36 -07:00
|
|
|
sync::{atomic::AtomicU32, Arc, Mutex},
|
2022-10-31 11:28:35 -07:00
|
|
|
thread::{Builder, JoinHandle},
|
2021-02-04 07:00:33 -08:00
|
|
|
},
|
2021-08-04 15:07:55 -07:00
|
|
|
tar::{self, Archive},
|
2021-07-22 12:40:37 -07:00
|
|
|
tempfile::TempDir,
|
2021-03-10 09:49:10 -08:00
|
|
|
thiserror::Error,
|
2020-06-17 08:27:03 -07:00
|
|
|
};
|
2019-07-31 17:58:10 -07:00
|
|
|
|
2022-03-09 14:09:34 -08:00
|
|
|
mod archive_format;
|
2023-07-24 16:31:03 -07:00
|
|
|
pub mod snapshot_storage_rebuilder;
|
2022-03-09 14:09:34 -08:00
|
|
|
pub use archive_format::*;
|
|
|
|
|
2022-03-07 09:34:35 -08:00
|
|
|
pub const SNAPSHOT_STATUS_CACHE_FILENAME: &str = "status_cache";
|
2023-02-15 22:38:40 -08:00
|
|
|
pub const SNAPSHOT_VERSION_FILENAME: &str = "version";
|
|
|
|
pub const SNAPSHOT_STATE_COMPLETE_FILENAME: &str = "state_complete";
|
2023-03-17 15:22:10 -07:00
|
|
|
pub const SNAPSHOT_ACCOUNTS_HARDLINKS: &str = "accounts_hardlinks";
|
2022-03-14 12:03:59 -07:00
|
|
|
pub const SNAPSHOT_ARCHIVE_DOWNLOAD_DIR: &str = "remote";
|
2023-07-24 16:31:03 -07:00
|
|
|
pub const MAX_SNAPSHOT_DATA_FILE_SIZE: u64 = 32 * 1024 * 1024 * 1024; // 32 GiB
|
2021-12-17 10:27:54 -08:00
|
|
|
const MAX_SNAPSHOT_VERSION_FILE_SIZE: u64 = 8; // byte
|
2020-05-22 10:54:24 -07:00
|
|
|
const VERSION_STRING_V1_2_0: &str = "1.2.0";
|
2021-08-31 16:33:27 -07:00
|
|
|
pub const TMP_SNAPSHOT_ARCHIVE_PREFIX: &str = "tmp-snapshot-archive-";
|
2022-04-06 19:39:26 -07:00
|
|
|
pub const BANK_SNAPSHOT_PRE_FILENAME_EXTENSION: &str = "pre";
|
2023-03-30 08:16:36 -07:00
|
|
|
// The following unsafes are
|
|
|
|
// - Safe because the values are fixed, known non-zero constants
|
|
|
|
// - Necessary in order to have a plain NonZeroUsize as the constant, NonZeroUsize
|
|
|
|
// returns an Option<NonZeroUsize> and we can't .unwrap() at compile time
|
|
|
|
pub const DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN: NonZeroUsize =
|
|
|
|
unsafe { NonZeroUsize::new_unchecked(2) };
|
|
|
|
pub const DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN: NonZeroUsize =
|
|
|
|
unsafe { NonZeroUsize::new_unchecked(4) };
|
2022-05-31 09:06:41 -07:00
|
|
|
pub const FULL_SNAPSHOT_ARCHIVE_FILENAME_REGEX: &str = r"^snapshot-(?P<slot>[[:digit:]]+)-(?P<hash>[[:alnum:]]+)\.(?P<ext>tar|tar\.bz2|tar\.zst|tar\.gz|tar\.lz4)$";
|
|
|
|
pub const INCREMENTAL_SNAPSHOT_ARCHIVE_FILENAME_REGEX: &str = r"^incremental-snapshot-(?P<base>[[:digit:]]+)-(?P<slot>[[:digit:]]+)-(?P<hash>[[:alnum:]]+)\.(?P<ext>tar|tar\.bz2|tar\.zst|tar\.gz|tar\.lz4)$";
|
2021-07-01 10:20:56 -07:00
|
|
|
|
2023-01-19 11:25:30 -08:00
|
|
|
#[derive(Copy, Clone, Default, Eq, PartialEq, Debug)]
|
2020-05-22 10:54:24 -07:00
|
|
|
pub enum SnapshotVersion {
|
2023-01-19 11:25:30 -08:00
|
|
|
#[default]
|
2020-05-22 10:54:24 -07:00
|
|
|
V1_2_0,
|
|
|
|
}
|
|
|
|
|
2020-06-18 22:38:37 -07:00
|
|
|
impl fmt::Display for SnapshotVersion {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.write_str(From::from(*self))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-22 10:54:24 -07:00
|
|
|
impl From<SnapshotVersion> for &'static str {
|
|
|
|
fn from(snapshot_version: SnapshotVersion) -> &'static str {
|
|
|
|
match snapshot_version {
|
|
|
|
SnapshotVersion::V1_2_0 => VERSION_STRING_V1_2_0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for SnapshotVersion {
|
|
|
|
type Err = &'static str;
|
|
|
|
|
|
|
|
fn from_str(version_string: &str) -> std::result::Result<Self, Self::Err> {
|
2020-06-18 22:38:37 -07:00
|
|
|
// Remove leading 'v' or 'V' from slice
|
|
|
|
let version_string = if version_string
|
|
|
|
.get(..1)
|
|
|
|
.map_or(false, |s| s.eq_ignore_ascii_case("v"))
|
|
|
|
{
|
|
|
|
&version_string[1..]
|
|
|
|
} else {
|
|
|
|
version_string
|
|
|
|
};
|
2020-05-22 10:54:24 -07:00
|
|
|
match version_string {
|
|
|
|
VERSION_STRING_V1_2_0 => Ok(SnapshotVersion::V1_2_0),
|
|
|
|
_ => Err("unsupported snapshot version"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SnapshotVersion {
|
|
|
|
pub fn as_str(self) -> &'static str {
|
|
|
|
<&str as From<Self>>::from(self)
|
|
|
|
}
|
|
|
|
}
|
2020-02-26 20:10:31 -08:00
|
|
|
|
2022-04-06 19:39:26 -07:00
|
|
|
/// Information about a bank snapshot. Namely the slot of the bank, the path to the snapshot, and
|
|
|
|
/// the type of the snapshot.
|
2020-08-14 11:43:14 -07:00
|
|
|
#[derive(PartialEq, Eq, Debug)]
|
2021-07-22 12:40:37 -07:00
|
|
|
pub struct BankSnapshotInfo {
|
2022-04-06 19:39:26 -07:00
|
|
|
/// Slot of the bank
|
2019-11-02 00:38:30 -07:00
|
|
|
pub slot: Slot,
|
2022-04-06 19:39:26 -07:00
|
|
|
/// Type of the snapshot
|
|
|
|
pub snapshot_type: BankSnapshotType,
|
2023-02-01 16:51:32 -08:00
|
|
|
/// Path to the bank snapshot directory
|
|
|
|
pub snapshot_dir: PathBuf,
|
2023-02-24 11:50:29 -08:00
|
|
|
/// Snapshot version
|
|
|
|
pub snapshot_version: SnapshotVersion,
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialOrd for BankSnapshotInfo {
|
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
|
|
Some(self.cmp(other))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:57:15 -07:00
|
|
|
// Order BankSnapshotInfo by slot (ascending), which practically is sorting chronologically
|
2021-07-22 12:40:37 -07:00
|
|
|
impl Ord for BankSnapshotInfo {
|
|
|
|
fn cmp(&self, other: &Self) -> Ordering {
|
|
|
|
self.slot.cmp(&other.slot)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-01 16:51:32 -08:00
|
|
|
impl BankSnapshotInfo {
|
|
|
|
pub fn new_from_dir(
|
|
|
|
bank_snapshots_dir: impl AsRef<Path>,
|
|
|
|
slot: Slot,
|
2023-02-24 11:50:29 -08:00
|
|
|
) -> std::result::Result<BankSnapshotInfo, SnapshotNewFromDirError> {
|
2023-02-01 16:51:32 -08:00
|
|
|
// check this directory to see if there is a BankSnapshotPre and/or
|
|
|
|
// BankSnapshotPost file
|
2023-05-01 12:28:35 -07:00
|
|
|
let bank_snapshot_dir = get_bank_snapshot_dir(&bank_snapshots_dir, slot);
|
2023-02-01 16:51:32 -08:00
|
|
|
|
2023-02-24 11:50:29 -08:00
|
|
|
if !bank_snapshot_dir.is_dir() {
|
|
|
|
return Err(SnapshotNewFromDirError::InvalidBankSnapshotDir(
|
|
|
|
bank_snapshot_dir,
|
|
|
|
));
|
2023-02-01 16:51:32 -08:00
|
|
|
}
|
|
|
|
|
2023-04-28 15:44:59 -07:00
|
|
|
// Among the files checks, the completion flag file check should be done first to avoid the later
|
|
|
|
// I/O errors.
|
|
|
|
|
|
|
|
// There is a time window from the slot directory being created, and the content being completely
|
|
|
|
// filled. Check the completion to avoid using a highest found slot directory with missing content.
|
2023-05-12 10:19:07 -07:00
|
|
|
if !is_bank_snapshot_complete(&bank_snapshot_dir) {
|
2023-04-28 15:44:59 -07:00
|
|
|
return Err(SnapshotNewFromDirError::IncompleteDir(bank_snapshot_dir));
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:50:29 -08:00
|
|
|
let status_cache_file = bank_snapshot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
|
2023-04-28 15:44:59 -07:00
|
|
|
if !status_cache_file.is_file() {
|
2023-02-24 11:50:29 -08:00
|
|
|
return Err(SnapshotNewFromDirError::MissingStatusCacheFile(
|
|
|
|
status_cache_file,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
let version_path = bank_snapshot_dir.join(SNAPSHOT_VERSION_FILENAME);
|
|
|
|
let version_str = snapshot_version_from_file(&version_path).or(Err(
|
|
|
|
SnapshotNewFromDirError::MissingVersionFile(version_path),
|
|
|
|
))?;
|
|
|
|
let snapshot_version = SnapshotVersion::from_str(version_str.as_str())
|
|
|
|
.or(Err(SnapshotNewFromDirError::InvalidVersion))?;
|
|
|
|
|
|
|
|
let bank_snapshot_post_path = bank_snapshot_dir.join(get_snapshot_file_name(slot));
|
|
|
|
let bank_snapshot_pre_path =
|
|
|
|
bank_snapshot_post_path.with_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);
|
|
|
|
|
2023-06-26 08:53:25 -07:00
|
|
|
// NOTE: It is important that checking for "Pre" happens before "Post.
|
|
|
|
//
|
|
|
|
// Consider the scenario where AccountsHashVerifier is actively processing an
|
|
|
|
// AccountsPackage for a snapshot/slot; if AHV is in the middle of reserializing the
|
|
|
|
// bank snapshot file (writing the new "Post" file), and then the process dies,
|
|
|
|
// there will be an incomplete "Post" file on disk. We do not want only the existence of
|
|
|
|
// this "Post" file to be sufficient for deciding the snapshot type as "Post". More so,
|
|
|
|
// "Post" *requires* the *absence* of a "Pre" file.
|
2023-02-24 11:50:29 -08:00
|
|
|
let snapshot_type = if bank_snapshot_pre_path.is_file() {
|
|
|
|
BankSnapshotType::Pre
|
|
|
|
} else if bank_snapshot_post_path.is_file() {
|
|
|
|
BankSnapshotType::Post
|
|
|
|
} else {
|
|
|
|
return Err(SnapshotNewFromDirError::MissingSnapshotFile(
|
|
|
|
bank_snapshot_dir,
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(BankSnapshotInfo {
|
|
|
|
slot,
|
|
|
|
snapshot_type,
|
|
|
|
snapshot_dir: bank_snapshot_dir,
|
|
|
|
snapshot_version,
|
|
|
|
})
|
2023-02-01 16:51:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn snapshot_path(&self) -> PathBuf {
|
|
|
|
let mut bank_snapshot_path = self.snapshot_dir.join(get_snapshot_file_name(self.slot));
|
|
|
|
|
|
|
|
let ext = match self.snapshot_type {
|
|
|
|
BankSnapshotType::Pre => BANK_SNAPSHOT_PRE_FILENAME_EXTENSION,
|
|
|
|
BankSnapshotType::Post => "",
|
|
|
|
};
|
|
|
|
bank_snapshot_path.set_extension(ext);
|
|
|
|
|
|
|
|
bank_snapshot_path
|
|
|
|
}
|
|
|
|
}
|
2022-04-06 19:39:26 -07:00
|
|
|
/// Bank snapshots traditionally had their accounts hash calculated prior to serialization. Since
|
|
|
|
/// the hash calculation takes a long time, an optimization has been put in to offload the accounts
|
|
|
|
/// hash calculation. The bank serialization format has not changed, so we need another way to
|
|
|
|
/// identify if a bank snapshot contains the calculated accounts hash or not.
|
|
|
|
///
|
|
|
|
/// When a bank snapshot is first taken, it does not have the calculated accounts hash. It is said
|
|
|
|
/// that this bank snapshot is "pre" accounts hash. Later, when the accounts hash is calculated,
|
|
|
|
/// the bank snapshot is re-serialized, and is now "post" accounts hash.
|
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
|
|
|
pub enum BankSnapshotType {
|
|
|
|
/// This bank snapshot has *not* yet had its accounts hash calculated
|
|
|
|
Pre,
|
|
|
|
/// This bank snapshot *has* had its accounts hash calculated
|
|
|
|
Post,
|
|
|
|
}
|
|
|
|
|
2023-03-22 13:49:23 -07:00
|
|
|
/// When constructing a bank a snapshot, traditionally the snapshot was from a snapshot archive. Now,
|
|
|
|
/// the snapshot can be from a snapshot directory, or from a snapshot archive. This is the flag to
|
|
|
|
/// indicate which.
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
pub enum SnapshotFrom {
|
|
|
|
/// Build from the snapshot archive
|
|
|
|
Archive,
|
|
|
|
/// Build directly from the bank snapshot directory
|
|
|
|
Dir,
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Helper type when rebuilding from snapshots. Designed to handle when rebuilding from just a
|
|
|
|
/// full snapshot, or from both a full snapshot and an incremental snapshot.
|
|
|
|
#[derive(Debug)]
|
2023-07-24 16:31:03 -07:00
|
|
|
pub struct SnapshotRootPaths {
|
|
|
|
pub full_snapshot_root_file_path: PathBuf,
|
|
|
|
pub incremental_snapshot_root_file_path: Option<PathBuf>,
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Helper type to bundle up the results from `unarchive_snapshot()`
|
|
|
|
#[derive(Debug)]
|
2023-07-24 16:31:03 -07:00
|
|
|
pub struct UnarchivedSnapshot {
|
2021-10-05 22:24:48 -07:00
|
|
|
#[allow(dead_code)]
|
2021-07-22 12:40:37 -07:00
|
|
|
unpack_dir: TempDir,
|
2023-07-24 16:31:03 -07:00
|
|
|
pub storage: AccountStorageMap,
|
|
|
|
pub unpacked_snapshots_dir_and_version: UnpackedSnapshotsDirAndVersion,
|
|
|
|
pub measure_untar: Measure,
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Helper type for passing around the unpacked snapshots dir and the snapshot version together
|
|
|
|
#[derive(Debug)]
|
2023-07-24 16:31:03 -07:00
|
|
|
pub struct UnpackedSnapshotsDirAndVersion {
|
|
|
|
pub unpacked_snapshots_dir: PathBuf,
|
|
|
|
pub snapshot_version: SnapshotVersion,
|
2019-08-06 18:47:30 -07:00
|
|
|
}
|
|
|
|
|
2022-08-29 11:17:27 -07:00
|
|
|
/// Helper type for passing around account storage map and next append vec id
|
|
|
|
/// for reconstructing accounts from a snapshot
|
|
|
|
pub(crate) struct StorageAndNextAppendVecId {
|
|
|
|
pub storage: AccountStorageMap,
|
|
|
|
pub next_append_vec_id: AtomicAppendVecId,
|
|
|
|
}
|
|
|
|
|
2019-12-02 14:42:05 -08:00
|
|
|
#[derive(Error, Debug)]
|
2022-03-31 08:51:18 -07:00
|
|
|
#[allow(clippy::large_enum_variant)]
|
2019-10-18 18:16:06 -07:00
|
|
|
pub enum SnapshotError {
|
2020-09-25 11:33:43 -07:00
|
|
|
#[error("I/O error: {0}")]
|
2021-02-18 23:42:09 -08:00
|
|
|
Io(#[from] std::io::Error),
|
2023-05-22 14:09:09 -07:00
|
|
|
|
|
|
|
#[error("AccountsFile error: {0}")]
|
|
|
|
AccountsFileError(#[from] AccountsFileError),
|
2019-10-18 18:16:06 -07:00
|
|
|
|
2020-09-25 11:33:43 -07:00
|
|
|
#[error("serialization error: {0}")]
|
2020-06-17 01:56:29 -07:00
|
|
|
Serialize(#[from] bincode::Error),
|
2019-10-18 18:16:06 -07:00
|
|
|
|
2023-03-22 13:49:23 -07:00
|
|
|
#[error("crossbeam send error: {0}")]
|
|
|
|
CrossbeamSend(#[from] crossbeam_channel::SendError<PathBuf>),
|
|
|
|
|
2020-01-23 10:20:37 -08:00
|
|
|
#[error("archive generation failure {0}")]
|
|
|
|
ArchiveGenerationFailure(ExitStatus),
|
|
|
|
|
|
|
|
#[error("storage path symlink is invalid")]
|
|
|
|
StoragePathSymlinkInvalid,
|
2020-03-25 02:46:41 -07:00
|
|
|
|
2020-09-25 11:33:43 -07:00
|
|
|
#[error("Unpack error: {0}")]
|
2020-03-25 02:46:41 -07:00
|
|
|
UnpackError(#[from] UnpackError),
|
2020-09-28 16:04:46 -07:00
|
|
|
|
2021-07-20 23:55:24 -07:00
|
|
|
#[error("source({1}) - I/O error: {0}")]
|
|
|
|
IoWithSource(std::io::Error, &'static str),
|
2019-10-18 18:16:06 -07:00
|
|
|
|
2023-01-05 06:08:15 -08:00
|
|
|
#[error("source({1}) - I/O error: {0}, file: {2}")]
|
|
|
|
IoWithSourceAndFile(#[source] std::io::Error, &'static str, PathBuf),
|
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("could not get file name from path: {0}")]
|
2021-07-22 12:40:37 -07:00
|
|
|
PathToFileNameError(PathBuf),
|
2019-08-06 18:47:30 -07:00
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("could not get str from file name: {0}")]
|
2021-07-22 12:40:37 -07:00
|
|
|
FileNameToStrError(PathBuf),
|
|
|
|
|
|
|
|
#[error("could not parse snapshot archive's file name: {0}")]
|
|
|
|
ParseSnapshotArchiveFileNameError(String),
|
|
|
|
|
|
|
|
#[error("snapshots are incompatible: full snapshot slot ({0}) and incremental snapshot base slot ({1}) do not match")]
|
|
|
|
MismatchedBaseSlot(Slot, Slot),
|
2021-08-06 18:16:06 -07:00
|
|
|
|
|
|
|
#[error("no snapshot archives to load from")]
|
|
|
|
NoSnapshotArchives,
|
|
|
|
|
|
|
|
#[error("snapshot has mismatch: deserialized bank: {:?}, snapshot archive info: {:?}", .0, .1)]
|
2022-10-31 11:28:35 -07:00
|
|
|
MismatchedSlotHash((Slot, SnapshotHash), (Slot, SnapshotHash)),
|
2022-08-18 06:48:58 -07:00
|
|
|
|
|
|
|
#[error("snapshot slot deltas are invalid: {0}")]
|
|
|
|
VerifySlotDeltas(#[from] VerifySlotDeltasError),
|
2023-02-15 09:52:07 -08:00
|
|
|
|
2023-02-24 11:50:29 -08:00
|
|
|
#[error("bank_snapshot_info new_from_dir failed: {0}")]
|
|
|
|
NewFromDir(#[from] SnapshotNewFromDirError),
|
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("invalid snapshot dir path: {0}")]
|
2023-04-19 09:37:46 -07:00
|
|
|
InvalidSnapshotDirPath(PathBuf),
|
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("invalid AppendVec path: {0}")]
|
2023-02-15 09:52:07 -08:00
|
|
|
InvalidAppendVecPath(PathBuf),
|
2023-02-23 10:53:12 -08:00
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("invalid account path: {0}")]
|
2023-02-23 10:53:12 -08:00
|
|
|
InvalidAccountPath(PathBuf),
|
2023-02-24 11:50:29 -08:00
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("no valid snapshot dir found under {0}")]
|
2023-02-24 11:50:29 -08:00
|
|
|
NoSnapshotSlotDir(PathBuf),
|
2023-03-22 13:49:23 -07:00
|
|
|
|
|
|
|
#[error("snapshot dir account paths mismatching")]
|
|
|
|
AccountPathsMismatch,
|
2023-07-20 15:30:19 -07:00
|
|
|
|
|
|
|
#[error("failed to add bank snapshot for slot {1}: {0}")]
|
|
|
|
AddBankSnapshot(#[source] AddBankSnapshotError, Slot),
|
2020-08-14 11:43:14 -07:00
|
|
|
}
|
2023-03-22 13:49:23 -07:00
|
|
|
|
2023-02-24 11:50:29 -08:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum SnapshotNewFromDirError {
|
|
|
|
#[error("I/O error: {0}")]
|
|
|
|
Io(#[from] std::io::Error),
|
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("invalid bank snapshot directory {0}")]
|
2023-02-24 11:50:29 -08:00
|
|
|
InvalidBankSnapshotDir(PathBuf),
|
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("missing status cache file {0}")]
|
2023-02-24 11:50:29 -08:00
|
|
|
MissingStatusCacheFile(PathBuf),
|
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("missing version file {0}")]
|
2023-02-24 11:50:29 -08:00
|
|
|
MissingVersionFile(PathBuf),
|
|
|
|
|
|
|
|
#[error("invalid snapshot version")]
|
|
|
|
InvalidVersion,
|
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("snapshot directory incomplete {0}")]
|
2023-02-24 11:50:29 -08:00
|
|
|
IncompleteDir(PathBuf),
|
|
|
|
|
2023-07-24 09:02:55 -07:00
|
|
|
#[error("missing snapshot file {0}")]
|
2023-02-24 11:50:29 -08:00
|
|
|
MissingSnapshotFile(PathBuf),
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
pub type Result<T> = std::result::Result<T, SnapshotError>;
|
2020-08-14 11:43:14 -07:00
|
|
|
|
2022-08-18 06:48:58 -07:00
|
|
|
/// Errors that can happen in `verify_slot_deltas()`
|
|
|
|
#[derive(Error, Debug, PartialEq, Eq)]
|
|
|
|
pub enum VerifySlotDeltasError {
|
|
|
|
#[error("too many entries: {0} (max: {1})")]
|
|
|
|
TooManyEntries(usize, usize),
|
|
|
|
|
|
|
|
#[error("slot {0} is not a root")]
|
|
|
|
SlotIsNotRoot(Slot),
|
|
|
|
|
|
|
|
#[error("slot {0} is greater than bank slot {1}")]
|
|
|
|
SlotGreaterThanMaxRoot(Slot, Slot),
|
|
|
|
|
|
|
|
#[error("slot {0} has multiple entries")]
|
|
|
|
SlotHasMultipleEntries(Slot),
|
|
|
|
|
|
|
|
#[error("slot {0} was not found in slot history")]
|
|
|
|
SlotNotFoundInHistory(Slot),
|
|
|
|
|
|
|
|
#[error("slot {0} was in history but missing from slot deltas")]
|
|
|
|
SlotNotFoundInDeltas(Slot),
|
|
|
|
|
|
|
|
#[error("slot history is bad and cannot be used to verify slot deltas")]
|
|
|
|
BadSlotHistory,
|
|
|
|
}
|
|
|
|
|
2023-07-20 15:30:19 -07:00
|
|
|
/// Errors that can happen in `add_bank_snapshot()`
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum AddBankSnapshotError {
|
|
|
|
#[error("bank snapshot dir already exists: {0}")]
|
|
|
|
SnapshotDirAlreadyExists(PathBuf),
|
|
|
|
|
|
|
|
#[error("failed to create snapshot dir: {0}")]
|
|
|
|
CreateSnapshotDir(#[source] std::io::Error),
|
|
|
|
|
|
|
|
#[error("failed to hard link storages: {0}")]
|
|
|
|
HardLinkStorages(#[source] HardLinkStoragesToSnapshotError),
|
|
|
|
|
|
|
|
#[error("failed to serialize bank: {0}")]
|
|
|
|
SerializeBank(#[source] Box<SnapshotError>),
|
|
|
|
|
|
|
|
#[error("failed to serialize status cache: {0}")]
|
|
|
|
SerializeStatusCache(#[source] Box<SnapshotError>),
|
|
|
|
|
|
|
|
#[error("failed to write snapshot version file: {0}")]
|
|
|
|
WriteSnapshotVersionFile(#[source] std::io::Error),
|
|
|
|
|
|
|
|
#[error("failed to mark snapshot as 'complete': {0}")]
|
|
|
|
CreateStateCompleteFile(#[source] std::io::Error),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Errors that can happen in `hard_link_storages_to_snapshot()`
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum HardLinkStoragesToSnapshotError {
|
|
|
|
#[error("failed to create accounts hard links dir: {0}")]
|
|
|
|
CreateAccountsHardLinksDir(#[source] std::io::Error),
|
|
|
|
|
|
|
|
#[error("failed to flush storage: {0}")]
|
|
|
|
FlushStorage(#[source] AccountsFileError),
|
|
|
|
|
|
|
|
#[error("failed to get the snapshot's accounts hard link dir: {0}")]
|
|
|
|
GetSnapshotHardLinksDir(#[from] GetSnapshotAccountsHardLinkDirError),
|
|
|
|
|
|
|
|
#[error("failed to hard link storage: {0}")]
|
|
|
|
HardLinkStorage(#[source] std::io::Error),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Errors that can happen in `get_snapshot_accounts_hardlink_dir()`
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum GetSnapshotAccountsHardLinkDirError {
|
|
|
|
#[error("invalid account storage path: {0}")]
|
|
|
|
GetAccountPath(PathBuf),
|
|
|
|
|
|
|
|
#[error("failed to create the snapshot hard link dir: {0}")]
|
|
|
|
CreateSnapshotHardLinkDir(#[source] std::io::Error),
|
|
|
|
|
|
|
|
#[error("failed to symlink snapshot hard link dir {link} to {original}: {source}")]
|
|
|
|
SymlinkSnapshotHardLinkDir {
|
|
|
|
source: std::io::Error,
|
|
|
|
original: PathBuf,
|
|
|
|
link: PathBuf,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-06-09 10:04:25 -07:00
|
|
|
/// Creates directories if they do not exist, and canonicalizes the paths.
|
|
|
|
pub fn create_and_canonicalize_directories(directories: &[PathBuf]) -> Result<Vec<PathBuf>> {
|
|
|
|
directories
|
|
|
|
.iter()
|
|
|
|
.map(|path| {
|
2023-06-26 14:10:21 -07:00
|
|
|
fs_err::create_dir_all(path)?;
|
|
|
|
let path = fs_err::canonicalize(path)?;
|
|
|
|
Ok(path)
|
2023-06-09 10:04:25 -07:00
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2023-01-03 06:15:32 -08:00
|
|
|
/// Delete the files and subdirectories in a directory.
|
|
|
|
/// This is useful if the process does not have permission
|
|
|
|
/// to delete the top level directory it might be able to
|
|
|
|
/// delete the contents of that directory.
|
2023-08-09 13:03:36 -07:00
|
|
|
pub(crate) fn delete_contents_of_path(path: impl AsRef<Path>) {
|
|
|
|
accounts_db::delete_contents_of_path(path)
|
2023-01-03 06:15:32 -08:00
|
|
|
}
|
|
|
|
|
2023-05-23 15:33:09 -07:00
|
|
|
/// Moves and asynchronously deletes the contents of a directory to avoid blocking on it.
|
|
|
|
/// The directory is re-created after the move, and should now be empty.
|
|
|
|
pub fn move_and_async_delete_path_contents(path: impl AsRef<Path>) {
|
|
|
|
move_and_async_delete_path(&path);
|
|
|
|
// The following could fail if the rename failed.
|
|
|
|
// If that happens, the directory should be left as is.
|
|
|
|
// So we ignore errors here.
|
2023-06-27 10:08:47 -07:00
|
|
|
_ = std::fs::create_dir(path);
|
2023-05-23 15:33:09 -07:00
|
|
|
}
|
|
|
|
|
2023-01-03 06:15:32 -08:00
|
|
|
/// Delete directories/files asynchronously to avoid blocking on it.
|
2023-06-08 10:55:52 -07:00
|
|
|
/// First, in sync context, check if the original path exists, if it
|
|
|
|
/// does, rename the original path to *_to_be_deleted.
|
|
|
|
/// If there's an in-progress deleting thread for this path, return.
|
|
|
|
/// Then spawn a thread to delete the renamed path.
|
2023-04-27 19:45:59 -07:00
|
|
|
pub fn move_and_async_delete_path(path: impl AsRef<Path>) {
|
2023-06-08 10:55:52 -07:00
|
|
|
lazy_static! {
|
|
|
|
static ref IN_PROGRESS_DELETES: Mutex<HashSet<PathBuf>> = Mutex::new(HashSet::new());
|
|
|
|
};
|
2023-01-03 06:15:32 -08:00
|
|
|
|
2023-06-08 10:55:52 -07:00
|
|
|
// Grab the mutex so no new async delete threads can be spawned for this path.
|
|
|
|
let mut lock = IN_PROGRESS_DELETES.lock().unwrap();
|
2023-01-03 06:15:32 -08:00
|
|
|
|
2023-06-08 10:55:52 -07:00
|
|
|
// If the path does not exist, there's nothing to delete.
|
2023-01-03 06:15:32 -08:00
|
|
|
if !path.as_ref().exists() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-08 10:55:52 -07:00
|
|
|
// If the original path (`pathbuf` here) is already being deleted,
|
|
|
|
// then the path should not be moved and deleted again.
|
|
|
|
if lock.contains(path.as_ref()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut path_delete = path.as_ref().to_path_buf();
|
|
|
|
path_delete.set_file_name(format!(
|
|
|
|
"{}{}",
|
|
|
|
path_delete.file_name().unwrap().to_str().unwrap(),
|
|
|
|
"_to_be_deleted"
|
|
|
|
));
|
2023-06-27 10:08:47 -07:00
|
|
|
if let Err(err) = fs_err::rename(&path, &path_delete) {
|
|
|
|
warn!("Path renaming failed, falling back to rm_dir in sync mode: {err}");
|
2023-06-08 10:55:52 -07:00
|
|
|
// Although the delete here is synchronous, we want to prevent another thread
|
|
|
|
// from moving & deleting this directory via `move_and_async_delete_path`.
|
|
|
|
lock.insert(path.as_ref().to_path_buf());
|
|
|
|
drop(lock); // unlock before doing sync delete
|
|
|
|
|
|
|
|
delete_contents_of_path(&path);
|
|
|
|
IN_PROGRESS_DELETES.lock().unwrap().remove(path.as_ref());
|
2023-01-03 06:15:32 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-08 10:55:52 -07:00
|
|
|
lock.insert(path_delete.clone());
|
|
|
|
drop(lock);
|
2023-01-03 06:15:32 -08:00
|
|
|
Builder::new()
|
|
|
|
.name("solDeletePath".to_string())
|
|
|
|
.spawn(move || {
|
2023-06-07 13:31:16 -07:00
|
|
|
trace!("background deleting {}...", path_delete.display());
|
2023-06-26 14:10:21 -07:00
|
|
|
let (_, measure_delete) =
|
|
|
|
measure!(fs_err::remove_dir_all(&path_delete).expect("background delete"));
|
2023-06-07 13:31:16 -07:00
|
|
|
trace!(
|
|
|
|
"background deleting {}... Done, and{measure_delete}",
|
|
|
|
path_delete.display()
|
|
|
|
);
|
2023-06-08 10:55:52 -07:00
|
|
|
|
|
|
|
IN_PROGRESS_DELETES.lock().unwrap().remove(&path_delete);
|
2023-01-03 06:15:32 -08:00
|
|
|
})
|
2023-06-07 13:31:16 -07:00
|
|
|
.expect("spawn background delete thread");
|
2023-01-03 06:15:32 -08:00
|
|
|
}
|
|
|
|
|
2023-03-17 15:22:10 -07:00
|
|
|
/// The account snapshot directories under <account_path>/snapshot/<slot> contain account files hardlinked
|
|
|
|
/// from <account_path>/run taken at snapshot <slot> time. They are referenced by the symlinks from the
|
|
|
|
/// bank snapshot dir snapshot/<slot>/accounts_hardlinks/. We observed that sometimes the bank snapshot dir
|
|
|
|
/// could be deleted but the account snapshot directories were left behind, possibly by some manual operations
|
|
|
|
/// or some legacy code not using the symlinks to clean up the acccount snapshot hardlink directories.
|
|
|
|
/// This function cleans up any account snapshot directories that are no longer referenced by the bank
|
|
|
|
/// snapshot dirs, to ensure proper snapshot operations.
|
|
|
|
pub fn clean_orphaned_account_snapshot_dirs(
|
|
|
|
bank_snapshots_dir: impl AsRef<Path>,
|
|
|
|
account_snapshot_paths: &[PathBuf],
|
|
|
|
) -> Result<()> {
|
|
|
|
// Create the HashSet of the account snapshot hardlink directories referenced by the snapshot dirs.
|
|
|
|
// This is used to clean up any hardlinks that are no longer referenced by the snapshot dirs.
|
|
|
|
let mut account_snapshot_dirs_referenced = HashSet::new();
|
|
|
|
let snapshots = get_bank_snapshots(bank_snapshots_dir);
|
|
|
|
for snapshot in snapshots {
|
|
|
|
let account_hardlinks_dir = snapshot.snapshot_dir.join(SNAPSHOT_ACCOUNTS_HARDLINKS);
|
|
|
|
// loop through entries in the snapshot_hardlink_dir, read the symlinks, add the target to the HashSet
|
2023-06-26 10:14:27 -07:00
|
|
|
for entry in fs_err::read_dir(&account_hardlinks_dir)? {
|
2023-03-17 15:22:10 -07:00
|
|
|
let path = entry?.path();
|
2023-06-26 10:14:27 -07:00
|
|
|
let target = fs_err::read_link(&path)?;
|
2023-03-17 15:22:10 -07:00
|
|
|
account_snapshot_dirs_referenced.insert(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// loop through the account snapshot hardlink directories, if the directory is not in the account_snapshot_dirs_referenced set, delete it
|
|
|
|
for account_snapshot_path in account_snapshot_paths {
|
2023-06-26 10:14:27 -07:00
|
|
|
for entry in fs_err::read_dir(account_snapshot_path)? {
|
2023-03-17 15:22:10 -07:00
|
|
|
let path = entry?.path();
|
|
|
|
if !account_snapshot_dirs_referenced.contains(&path) {
|
|
|
|
info!(
|
|
|
|
"Removing orphaned account snapshot hardlink directory: {}",
|
|
|
|
path.display()
|
|
|
|
);
|
|
|
|
move_and_async_delete_path(&path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-05-09 11:08:12 -07:00
|
|
|
/// Purges incomplete bank snapshots
|
|
|
|
pub fn purge_incomplete_bank_snapshots(bank_snapshots_dir: impl AsRef<Path>) {
|
2023-06-27 10:08:47 -07:00
|
|
|
let Ok(read_dir_iter) = std::fs::read_dir(&bank_snapshots_dir) else {
|
2023-05-09 11:08:12 -07:00
|
|
|
// If we cannot read the bank snapshots dir, then there's nothing to do
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
let is_incomplete = |dir: &PathBuf| !is_bank_snapshot_complete(dir);
|
|
|
|
|
|
|
|
let incomplete_dirs: Vec<_> = read_dir_iter
|
|
|
|
.filter_map(|entry| entry.ok())
|
|
|
|
.map(|entry| entry.path())
|
|
|
|
.filter(|path| path.is_dir())
|
|
|
|
.filter(is_incomplete)
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
// attempt to purge all the incomplete directories; do not exit early
|
|
|
|
for incomplete_dir in incomplete_dirs {
|
|
|
|
let result = purge_bank_snapshot(&incomplete_dir);
|
|
|
|
match result {
|
|
|
|
Ok(_) => info!(
|
|
|
|
"Purged incomplete snapshot dir: {}",
|
|
|
|
incomplete_dir.display()
|
|
|
|
),
|
2023-06-27 10:08:47 -07:00
|
|
|
Err(err) => warn!("Failed to purge incomplete snapshot dir: {err}"),
|
2023-05-09 11:08:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Is the bank snapshot complete?
|
|
|
|
fn is_bank_snapshot_complete(bank_snapshot_dir: impl AsRef<Path>) -> bool {
|
|
|
|
let state_complete_path = bank_snapshot_dir
|
|
|
|
.as_ref()
|
|
|
|
.join(SNAPSHOT_STATE_COMPLETE_FILENAME);
|
|
|
|
state_complete_path.is_file()
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// If the validator halts in the middle of `archive_snapshot_package()`, the temporary staging
|
|
|
|
/// directory won't be cleaned up. Call this function to clean them up.
|
2021-08-21 13:41:03 -07:00
|
|
|
pub fn remove_tmp_snapshot_archives(snapshot_archives_dir: impl AsRef<Path>) {
|
2023-06-27 10:08:47 -07:00
|
|
|
if let Ok(entries) = std::fs::read_dir(snapshot_archives_dir) {
|
|
|
|
for entry in entries.flatten() {
|
2023-06-27 12:51:28 -07:00
|
|
|
if entry
|
2020-11-30 17:37:38 -08:00
|
|
|
.file_name()
|
2023-06-27 12:51:28 -07:00
|
|
|
.to_str()
|
|
|
|
.map(|file_name| file_name.starts_with(TMP_SNAPSHOT_ARCHIVE_PREFIX))
|
|
|
|
.unwrap_or(false)
|
|
|
|
{
|
2023-06-27 10:08:47 -07:00
|
|
|
let path = entry.path();
|
|
|
|
let result = if path.is_dir() {
|
|
|
|
fs_err::remove_dir_all(path)
|
2021-01-11 11:38:55 -08:00
|
|
|
} else {
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::remove_file(path)
|
|
|
|
};
|
|
|
|
if let Err(err) = result {
|
|
|
|
warn!("Failed to remove temporary snapshot archive: {err}");
|
2021-01-11 11:38:55 -08:00
|
|
|
}
|
2020-11-30 17:37:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 22:38:40 -08:00
|
|
|
/// Write the snapshot version as a file into the bank snapshot directory
|
|
|
|
pub fn write_snapshot_version_file(
|
|
|
|
version_file: impl AsRef<Path>,
|
|
|
|
version: SnapshotVersion,
|
2023-07-20 15:30:19 -07:00
|
|
|
) -> std::io::Result<()> {
|
2023-06-26 14:10:21 -07:00
|
|
|
fs_err::write(version_file, version.as_str().as_bytes())
|
2023-02-15 22:38:40 -08:00
|
|
|
}
|
|
|
|
|
2021-08-17 11:01:59 -07:00
|
|
|
/// Make a snapshot archive out of the snapshot package
|
2021-05-12 10:32:27 -07:00
|
|
|
pub fn archive_snapshot_package(
|
2021-08-13 14:08:09 -07:00
|
|
|
snapshot_package: &SnapshotPackage,
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir: impl AsRef<Path>,
|
|
|
|
incremental_snapshot_archives_dir: impl AsRef<Path>,
|
2023-03-30 08:16:36 -07:00
|
|
|
maximum_full_snapshot_archives_to_retain: NonZeroUsize,
|
|
|
|
maximum_incremental_snapshot_archives_to_retain: NonZeroUsize,
|
2021-05-12 10:32:27 -07:00
|
|
|
) -> Result<()> {
|
2020-01-23 10:20:37 -08:00
|
|
|
info!(
|
|
|
|
"Generating snapshot archive for slot {}",
|
2021-08-06 18:16:06 -07:00
|
|
|
snapshot_package.slot()
|
2020-01-23 10:20:37 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
let mut timer = Measure::start("snapshot_package-package_snapshots");
|
|
|
|
let tar_dir = snapshot_package
|
2021-08-06 18:16:06 -07:00
|
|
|
.path()
|
2020-01-23 10:20:37 -08:00
|
|
|
.parent()
|
|
|
|
.expect("Tar output path is invalid");
|
|
|
|
|
2023-06-26 14:10:21 -07:00
|
|
|
fs_err::create_dir_all(tar_dir)
|
|
|
|
.map_err(|err| SnapshotError::IoWithSource(err, "create archive path"))?;
|
2020-01-23 10:20:37 -08:00
|
|
|
|
|
|
|
// Create the staging directories
|
2021-08-31 16:33:27 -07:00
|
|
|
let staging_dir_prefix = TMP_SNAPSHOT_ARCHIVE_PREFIX;
|
2020-11-30 17:37:38 -08:00
|
|
|
let staging_dir = tempfile::Builder::new()
|
2021-01-11 10:21:15 -08:00
|
|
|
.prefix(&format!(
|
|
|
|
"{}{}-",
|
2021-08-17 11:01:59 -07:00
|
|
|
staging_dir_prefix,
|
2021-08-06 18:16:06 -07:00
|
|
|
snapshot_package.slot()
|
2021-01-11 10:21:15 -08:00
|
|
|
))
|
2021-07-20 23:55:24 -07:00
|
|
|
.tempdir_in(tar_dir)
|
|
|
|
.map_err(|e| SnapshotError::IoWithSource(e, "create archive tempdir"))?;
|
2020-11-30 17:37:38 -08:00
|
|
|
|
2021-03-10 09:49:10 -08:00
|
|
|
let staging_accounts_dir = staging_dir.path().join("accounts");
|
|
|
|
let staging_snapshots_dir = staging_dir.path().join("snapshots");
|
2023-02-15 22:38:40 -08:00
|
|
|
let staging_version_file = staging_dir.path().join(SNAPSHOT_VERSION_FILENAME);
|
2023-04-26 11:48:48 -07:00
|
|
|
|
|
|
|
// Create staging/accounts/
|
2023-06-26 14:10:21 -07:00
|
|
|
fs_err::create_dir_all(&staging_accounts_dir)
|
|
|
|
.map_err(|err| SnapshotError::IoWithSource(err, "create staging accounts path"))?;
|
2023-04-26 11:48:48 -07:00
|
|
|
|
|
|
|
let slot_str = snapshot_package.slot().to_string();
|
|
|
|
let staging_snapshot_dir = staging_snapshots_dir.join(&slot_str);
|
|
|
|
// Creates staging snapshots/<slot>/
|
2023-06-26 14:10:21 -07:00
|
|
|
fs_err::create_dir_all(&staging_snapshot_dir)
|
|
|
|
.map_err(|err| SnapshotError::IoWithSource(err, "create staging snapshots path"))?;
|
2020-01-23 10:20:37 -08:00
|
|
|
|
2023-05-01 11:24:59 -07:00
|
|
|
let src_snapshot_dir = &snapshot_package.bank_snapshot_dir;
|
2023-04-26 11:48:48 -07:00
|
|
|
// To be a source for symlinking and archiving, the path need to be an aboslute path
|
|
|
|
let src_snapshot_dir = src_snapshot_dir
|
|
|
|
.canonicalize()
|
|
|
|
.map_err(|_e| SnapshotError::InvalidSnapshotDirPath(src_snapshot_dir.clone()))?;
|
|
|
|
let staging_snapshot_file = staging_snapshot_dir.join(&slot_str);
|
|
|
|
let src_snapshot_file = src_snapshot_dir.join(slot_str);
|
|
|
|
symlink::symlink_file(src_snapshot_file, staging_snapshot_file)
|
|
|
|
.map_err(|e| SnapshotError::IoWithSource(e, "create snapshot symlink"))?;
|
|
|
|
|
|
|
|
// Following the existing archive format, the status cache is under snapshots/, not under <slot>/
|
|
|
|
// like in the snapshot dir.
|
|
|
|
let staging_status_cache = staging_snapshots_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
|
|
|
|
let src_status_cache = src_snapshot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
|
|
|
|
symlink::symlink_file(src_status_cache, staging_status_cache)
|
|
|
|
.map_err(|e| SnapshotError::IoWithSource(e, "create status cache symlink"))?;
|
2020-01-23 10:20:37 -08:00
|
|
|
|
|
|
|
// Add the AppendVecs into the compressible list
|
2023-01-11 12:05:15 -08:00
|
|
|
for storage in snapshot_package.snapshot_storages.iter() {
|
2020-01-23 10:20:37 -08:00
|
|
|
storage.flush()?;
|
|
|
|
let storage_path = storage.get_path();
|
2023-08-09 13:03:36 -07:00
|
|
|
let output_path = staging_accounts_dir.join(AppendVec::file_name(
|
2021-03-10 11:26:37 -08:00
|
|
|
storage.slot(),
|
|
|
|
storage.append_vec_id(),
|
|
|
|
));
|
2020-01-23 10:20:37 -08:00
|
|
|
|
|
|
|
// `storage_path` - The file path where the AppendVec itself is located
|
2021-01-02 18:08:15 -08:00
|
|
|
// `output_path` - The file path where the AppendVec will be placed in the staging directory.
|
2020-01-23 10:20:37 -08:00
|
|
|
let storage_path =
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::canonicalize(storage_path).expect("Could not get absolute path for accounts");
|
2021-07-20 23:55:24 -07:00
|
|
|
symlink::symlink_file(storage_path, &output_path)
|
|
|
|
.map_err(|e| SnapshotError::IoWithSource(e, "create storage symlink"))?;
|
2020-01-23 10:20:37 -08:00
|
|
|
if !output_path.is_file() {
|
|
|
|
return Err(SnapshotError::StoragePathSymlinkInvalid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-20 15:30:19 -07:00
|
|
|
write_snapshot_version_file(staging_version_file, snapshot_package.snapshot_version)
|
|
|
|
.map_err(|err| SnapshotError::IoWithSource(err, "write snapshot version file"))?;
|
2020-01-23 10:20:37 -08:00
|
|
|
|
|
|
|
// Tar the staging directory into the archive at `archive_path`
|
2021-01-11 11:38:55 -08:00
|
|
|
let archive_path = tar_dir.join(format!(
|
2021-05-27 10:00:27 -07:00
|
|
|
"{}{}.{}",
|
2021-08-17 11:01:59 -07:00
|
|
|
staging_dir_prefix,
|
2021-08-06 18:16:06 -07:00
|
|
|
snapshot_package.slot(),
|
2022-03-09 14:09:34 -08:00
|
|
|
snapshot_package.archive_format().extension(),
|
2021-01-11 11:38:55 -08:00
|
|
|
));
|
2020-09-06 17:25:49 -07:00
|
|
|
|
2021-08-04 15:07:55 -07:00
|
|
|
{
|
2023-06-26 10:14:27 -07:00
|
|
|
let mut archive_file = fs_err::File::create(&archive_path)?;
|
2021-08-04 15:07:55 -07:00
|
|
|
|
|
|
|
let do_archive_files = |encoder: &mut dyn Write| -> Result<()> {
|
|
|
|
let mut archive = tar::Builder::new(encoder);
|
2022-08-17 10:57:52 -07:00
|
|
|
// Serialize the version and snapshots files before accounts so we can quickly determine the version
|
|
|
|
// and other bank fields. This is necessary if we want to interleave unpacking with reconstruction
|
2023-02-15 22:38:40 -08:00
|
|
|
archive.append_path_with_name(
|
|
|
|
staging_dir.as_ref().join(SNAPSHOT_VERSION_FILENAME),
|
|
|
|
SNAPSHOT_VERSION_FILENAME,
|
|
|
|
)?;
|
2022-06-13 07:33:32 -07:00
|
|
|
for dir in ["snapshots", "accounts"] {
|
2021-08-04 15:07:55 -07:00
|
|
|
archive.append_dir_all(dir, staging_dir.as_ref().join(dir))?;
|
|
|
|
}
|
|
|
|
archive.into_inner()?;
|
|
|
|
Ok(())
|
|
|
|
};
|
2020-09-06 17:25:49 -07:00
|
|
|
|
2021-08-06 18:16:06 -07:00
|
|
|
match snapshot_package.archive_format() {
|
2021-08-04 15:07:55 -07:00
|
|
|
ArchiveFormat::TarBzip2 => {
|
|
|
|
let mut encoder =
|
|
|
|
bzip2::write::BzEncoder::new(archive_file, bzip2::Compression::best());
|
|
|
|
do_archive_files(&mut encoder)?;
|
|
|
|
encoder.finish()?;
|
|
|
|
}
|
|
|
|
ArchiveFormat::TarGzip => {
|
|
|
|
let mut encoder =
|
|
|
|
flate2::write::GzEncoder::new(archive_file, flate2::Compression::default());
|
|
|
|
do_archive_files(&mut encoder)?;
|
|
|
|
encoder.finish()?;
|
|
|
|
}
|
|
|
|
ArchiveFormat::TarZstd => {
|
|
|
|
let mut encoder = zstd::stream::Encoder::new(archive_file, 0)?;
|
|
|
|
do_archive_files(&mut encoder)?;
|
|
|
|
encoder.finish()?;
|
|
|
|
}
|
2022-05-16 10:44:15 -07:00
|
|
|
ArchiveFormat::TarLz4 => {
|
|
|
|
let mut encoder = lz4::EncoderBuilder::new().level(1).build(archive_file)?;
|
|
|
|
do_archive_files(&mut encoder)?;
|
|
|
|
let (_output, result) = encoder.finish();
|
|
|
|
result?
|
|
|
|
}
|
2021-08-04 15:07:55 -07:00
|
|
|
ArchiveFormat::Tar => {
|
|
|
|
do_archive_files(&mut archive_file)?;
|
|
|
|
}
|
|
|
|
};
|
2020-01-23 10:20:37 -08:00
|
|
|
}
|
|
|
|
|
2020-09-06 17:25:49 -07:00
|
|
|
// Atomically move the archive into position for other validators to find
|
2023-06-26 14:10:21 -07:00
|
|
|
let metadata = fs_err::metadata(&archive_path)
|
|
|
|
.map_err(|err| SnapshotError::IoWithSource(err, "archive path stat"))?;
|
|
|
|
fs_err::rename(&archive_path, snapshot_package.path())
|
|
|
|
.map_err(|err| SnapshotError::IoWithSource(err, "archive path rename"))?;
|
2020-01-23 10:20:37 -08:00
|
|
|
|
2021-09-04 05:37:29 -07:00
|
|
|
purge_old_snapshot_archives(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir,
|
|
|
|
incremental_snapshot_archives_dir,
|
2021-09-06 16:01:56 -07:00
|
|
|
maximum_full_snapshot_archives_to_retain,
|
|
|
|
maximum_incremental_snapshot_archives_to_retain,
|
2021-09-04 05:37:29 -07:00
|
|
|
);
|
2020-02-24 12:37:14 -08:00
|
|
|
|
2020-01-23 10:20:37 -08:00
|
|
|
timer.stop();
|
|
|
|
info!(
|
2020-02-26 20:28:53 -08:00
|
|
|
"Successfully created {:?}. slot: {}, elapsed ms: {}, size={}",
|
2021-08-06 18:16:06 -07:00
|
|
|
snapshot_package.path(),
|
|
|
|
snapshot_package.slot(),
|
2020-01-23 10:20:37 -08:00
|
|
|
timer.as_ms(),
|
|
|
|
metadata.len()
|
|
|
|
);
|
2022-03-26 10:29:13 -07:00
|
|
|
|
2020-01-23 10:20:37 -08:00
|
|
|
datapoint_info!(
|
2022-03-26 10:29:13 -07:00
|
|
|
"archive-snapshot-package",
|
2021-08-06 18:16:06 -07:00
|
|
|
("slot", snapshot_package.slot(), i64),
|
2022-05-16 10:44:15 -07:00
|
|
|
(
|
|
|
|
"archive_format",
|
|
|
|
snapshot_package.archive_format().to_string(),
|
|
|
|
String
|
|
|
|
),
|
2020-01-23 10:20:37 -08:00
|
|
|
("duration_ms", timer.as_ms(), i64),
|
2022-03-26 10:29:13 -07:00
|
|
|
(
|
2023-08-19 16:55:29 -07:00
|
|
|
if snapshot_package.snapshot_kind.is_full_snapshot() {
|
2022-03-26 10:29:13 -07:00
|
|
|
"full-snapshot-archive-size"
|
|
|
|
} else {
|
|
|
|
"incremental-snapshot-archive-size"
|
|
|
|
},
|
|
|
|
metadata.len(),
|
|
|
|
i64
|
|
|
|
),
|
2020-01-23 10:20:37 -08:00
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-04-06 19:39:26 -07:00
|
|
|
/// Get the bank snapshots in a directory
|
|
|
|
pub fn get_bank_snapshots(bank_snapshots_dir: impl AsRef<Path>) -> Vec<BankSnapshotInfo> {
|
|
|
|
let mut bank_snapshots = Vec::default();
|
2023-06-27 10:08:47 -07:00
|
|
|
match fs_err::read_dir(bank_snapshots_dir.as_ref()) {
|
2019-08-23 13:02:07 -07:00
|
|
|
Err(err) => {
|
2023-06-27 10:08:47 -07:00
|
|
|
info!("Unable to read bank snapshots directory: {err}");
|
2019-08-23 13:02:07 -07:00
|
|
|
}
|
2022-04-06 19:39:26 -07:00
|
|
|
Ok(paths) => paths
|
|
|
|
.filter_map(|entry| {
|
|
|
|
// check if this entry is a directory and only a Slot
|
|
|
|
// bank snapshots are bank_snapshots_dir/slot/slot(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION)
|
|
|
|
entry
|
|
|
|
.ok()
|
|
|
|
.filter(|entry| entry.path().is_dir())
|
|
|
|
.and_then(|entry| {
|
|
|
|
entry
|
|
|
|
.path()
|
|
|
|
.file_name()
|
|
|
|
.and_then(|file_name| file_name.to_str())
|
|
|
|
.and_then(|file_name| file_name.parse::<Slot>().ok())
|
|
|
|
})
|
|
|
|
})
|
2023-02-24 11:50:29 -08:00
|
|
|
.for_each(
|
|
|
|
|slot| match BankSnapshotInfo::new_from_dir(&bank_snapshots_dir, slot) {
|
2023-05-30 16:35:06 -07:00
|
|
|
Ok(snapshot_info) => bank_snapshots.push(snapshot_info),
|
2023-06-08 10:54:24 -07:00
|
|
|
// Other threads may be modifying bank snapshots in parallel; only return
|
|
|
|
// snapshots that are complete as deemed by BankSnapshotInfo::new_from_dir()
|
2023-06-06 12:07:45 -07:00
|
|
|
Err(err) => debug!("Unable to read bank snapshot for slot {slot}: {err}"),
|
2023-02-24 11:50:29 -08:00
|
|
|
},
|
|
|
|
),
|
2019-08-23 13:02:07 -07:00
|
|
|
}
|
2022-04-06 19:39:26 -07:00
|
|
|
bank_snapshots
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the bank snapshots in a directory
|
|
|
|
///
|
|
|
|
/// This function retains only the bank snapshots of type BankSnapshotType::Pre
|
|
|
|
pub fn get_bank_snapshots_pre(bank_snapshots_dir: impl AsRef<Path>) -> Vec<BankSnapshotInfo> {
|
|
|
|
let mut bank_snapshots = get_bank_snapshots(bank_snapshots_dir);
|
|
|
|
bank_snapshots.retain(|bank_snapshot| bank_snapshot.snapshot_type == BankSnapshotType::Pre);
|
|
|
|
bank_snapshots
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the bank snapshots in a directory
|
|
|
|
///
|
|
|
|
/// This function retains only the bank snapshots of type BankSnapshotType::Post
|
|
|
|
pub fn get_bank_snapshots_post(bank_snapshots_dir: impl AsRef<Path>) -> Vec<BankSnapshotInfo> {
|
|
|
|
let mut bank_snapshots = get_bank_snapshots(bank_snapshots_dir);
|
|
|
|
bank_snapshots.retain(|bank_snapshot| bank_snapshot.snapshot_type == BankSnapshotType::Post);
|
|
|
|
bank_snapshots
|
2019-07-31 17:58:10 -07:00
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Get the bank snapshot with the highest slot in a directory
|
2022-04-06 19:39:26 -07:00
|
|
|
///
|
|
|
|
/// This function gets the highest bank snapshot of type BankSnapshotType::Pre
|
|
|
|
pub fn get_highest_bank_snapshot_pre(
|
|
|
|
bank_snapshots_dir: impl AsRef<Path>,
|
|
|
|
) -> Option<BankSnapshotInfo> {
|
|
|
|
do_get_highest_bank_snapshot(get_bank_snapshots_pre(bank_snapshots_dir))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the bank snapshot with the highest slot in a directory
|
|
|
|
///
|
|
|
|
/// This function gets the highest bank snapshot of type BankSnapshotType::Post
|
|
|
|
pub fn get_highest_bank_snapshot_post(
|
|
|
|
bank_snapshots_dir: impl AsRef<Path>,
|
|
|
|
) -> Option<BankSnapshotInfo> {
|
|
|
|
do_get_highest_bank_snapshot(get_bank_snapshots_post(bank_snapshots_dir))
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:50:29 -08:00
|
|
|
/// Get the bank snapshot with the highest slot in a directory
|
|
|
|
///
|
|
|
|
/// This function gets the highest bank snapshot of any type
|
|
|
|
pub fn get_highest_bank_snapshot(bank_snapshots_dir: impl AsRef<Path>) -> Option<BankSnapshotInfo> {
|
|
|
|
do_get_highest_bank_snapshot(get_bank_snapshots(&bank_snapshots_dir))
|
|
|
|
}
|
|
|
|
|
2022-04-06 19:39:26 -07:00
|
|
|
fn do_get_highest_bank_snapshot(
|
|
|
|
mut bank_snapshots: Vec<BankSnapshotInfo>,
|
|
|
|
) -> Option<BankSnapshotInfo> {
|
|
|
|
bank_snapshots.sort_unstable();
|
2023-07-13 10:38:18 -07:00
|
|
|
bank_snapshots.into_iter().next_back()
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
2020-05-22 10:54:24 -07:00
|
|
|
pub fn serialize_snapshot_data_file<F>(data_file_path: &Path, serializer: F) -> Result<u64>
|
|
|
|
where
|
2023-06-27 10:08:47 -07:00
|
|
|
F: FnOnce(&mut BufWriter<std::fs::File>) -> Result<()>,
|
2020-05-22 10:54:24 -07:00
|
|
|
{
|
|
|
|
serialize_snapshot_data_file_capped::<F>(
|
|
|
|
data_file_path,
|
|
|
|
MAX_SNAPSHOT_DATA_FILE_SIZE,
|
|
|
|
serializer,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
pub fn deserialize_snapshot_data_file<T: Sized>(
|
|
|
|
data_file_path: &Path,
|
2023-06-27 10:08:47 -07:00
|
|
|
deserializer: impl FnOnce(&mut BufReader<std::fs::File>) -> Result<T>,
|
2021-07-22 12:40:37 -07:00
|
|
|
) -> Result<T> {
|
2023-06-27 10:08:47 -07:00
|
|
|
let wrapped_deserializer = move |streams: &mut SnapshotStreams<std::fs::File>| -> Result<T> {
|
2021-10-05 22:24:48 -07:00
|
|
|
deserializer(streams.full_snapshot_stream)
|
2021-07-22 12:40:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
let wrapped_data_file_path = SnapshotRootPaths {
|
|
|
|
full_snapshot_root_file_path: data_file_path.to_path_buf(),
|
|
|
|
incremental_snapshot_root_file_path: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
deserialize_snapshot_data_files_capped(
|
|
|
|
&wrapped_data_file_path,
|
|
|
|
MAX_SNAPSHOT_DATA_FILE_SIZE,
|
|
|
|
wrapped_deserializer,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-07-24 16:31:03 -07:00
|
|
|
pub fn deserialize_snapshot_data_files<T: Sized>(
|
2021-07-22 12:40:37 -07:00
|
|
|
snapshot_root_paths: &SnapshotRootPaths,
|
2023-06-27 10:08:47 -07:00
|
|
|
deserializer: impl FnOnce(&mut SnapshotStreams<std::fs::File>) -> Result<T>,
|
2021-07-22 12:40:37 -07:00
|
|
|
) -> Result<T> {
|
|
|
|
deserialize_snapshot_data_files_capped(
|
|
|
|
snapshot_root_paths,
|
2020-05-22 10:54:24 -07:00
|
|
|
MAX_SNAPSHOT_DATA_FILE_SIZE,
|
|
|
|
deserializer,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn serialize_snapshot_data_file_capped<F>(
|
2020-01-09 16:49:36 -08:00
|
|
|
data_file_path: &Path,
|
|
|
|
maximum_file_size: u64,
|
2020-05-22 10:54:24 -07:00
|
|
|
serializer: F,
|
2020-01-09 16:49:36 -08:00
|
|
|
) -> Result<u64>
|
|
|
|
where
|
2023-06-27 10:08:47 -07:00
|
|
|
F: FnOnce(&mut BufWriter<std::fs::File>) -> Result<()>,
|
2020-01-09 16:49:36 -08:00
|
|
|
{
|
2023-06-27 10:08:47 -07:00
|
|
|
let data_file = fs_err::File::create(data_file_path)?.into();
|
2020-01-09 16:49:36 -08:00
|
|
|
let mut data_file_stream = BufWriter::new(data_file);
|
|
|
|
serializer(&mut data_file_stream)?;
|
|
|
|
data_file_stream.flush()?;
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
let consumed_size = data_file_stream.stream_position()?;
|
2020-01-09 16:49:36 -08:00
|
|
|
if consumed_size > maximum_file_size {
|
|
|
|
let error_message = format!(
|
2022-12-06 06:30:06 -08:00
|
|
|
"too large snapshot data file to serialize: {data_file_path:?} has {consumed_size} bytes"
|
2020-01-09 16:49:36 -08:00
|
|
|
);
|
|
|
|
return Err(get_io_error(&error_message));
|
|
|
|
}
|
|
|
|
Ok(consumed_size)
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
fn deserialize_snapshot_data_files_capped<T: Sized>(
|
|
|
|
snapshot_root_paths: &SnapshotRootPaths,
|
2020-01-09 16:49:36 -08:00
|
|
|
maximum_file_size: u64,
|
2023-06-27 10:08:47 -07:00
|
|
|
deserializer: impl FnOnce(&mut SnapshotStreams<std::fs::File>) -> Result<T>,
|
2021-07-22 12:40:37 -07:00
|
|
|
) -> Result<T> {
|
|
|
|
let (full_snapshot_file_size, mut full_snapshot_data_file_stream) =
|
|
|
|
create_snapshot_data_file_stream(
|
|
|
|
&snapshot_root_paths.full_snapshot_root_file_path,
|
|
|
|
maximum_file_size,
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let (incremental_snapshot_file_size, mut incremental_snapshot_data_file_stream) =
|
|
|
|
if let Some(ref incremental_snapshot_root_file_path) =
|
|
|
|
snapshot_root_paths.incremental_snapshot_root_file_path
|
|
|
|
{
|
2023-07-28 12:21:22 -07:00
|
|
|
Some(create_snapshot_data_file_stream(
|
|
|
|
incremental_snapshot_root_file_path,
|
|
|
|
maximum_file_size,
|
|
|
|
)?)
|
2021-07-22 12:40:37 -07:00
|
|
|
} else {
|
2023-07-28 12:21:22 -07:00
|
|
|
None
|
|
|
|
}
|
|
|
|
.unzip();
|
2021-07-22 12:40:37 -07:00
|
|
|
|
|
|
|
let mut snapshot_streams = SnapshotStreams {
|
|
|
|
full_snapshot_stream: &mut full_snapshot_data_file_stream,
|
|
|
|
incremental_snapshot_stream: incremental_snapshot_data_file_stream.as_mut(),
|
|
|
|
};
|
|
|
|
let ret = deserializer(&mut snapshot_streams)?;
|
|
|
|
|
|
|
|
check_deserialize_file_consumed(
|
|
|
|
full_snapshot_file_size,
|
|
|
|
&snapshot_root_paths.full_snapshot_root_file_path,
|
|
|
|
&mut full_snapshot_data_file_stream,
|
|
|
|
)?;
|
|
|
|
|
|
|
|
if let Some(ref incremental_snapshot_root_file_path) =
|
|
|
|
snapshot_root_paths.incremental_snapshot_root_file_path
|
|
|
|
{
|
|
|
|
check_deserialize_file_consumed(
|
|
|
|
incremental_snapshot_file_size.unwrap(),
|
|
|
|
incremental_snapshot_root_file_path,
|
|
|
|
incremental_snapshot_data_file_stream.as_mut().unwrap(),
|
|
|
|
)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Before running the deserializer function, perform common operations on the snapshot archive
|
|
|
|
/// files, such as checking the file size and opening the file into a stream.
|
2023-04-28 07:46:57 -07:00
|
|
|
fn create_snapshot_data_file_stream(
|
|
|
|
snapshot_root_file_path: impl AsRef<Path>,
|
2021-07-22 12:40:37 -07:00
|
|
|
maximum_file_size: u64,
|
2023-06-27 10:08:47 -07:00
|
|
|
) -> Result<(u64, BufReader<std::fs::File>)> {
|
2023-06-26 10:14:27 -07:00
|
|
|
let snapshot_file_size = fs_err::metadata(&snapshot_root_file_path)?.len();
|
2020-01-09 16:49:36 -08:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
if snapshot_file_size > maximum_file_size {
|
2023-06-27 10:08:47 -07:00
|
|
|
let error_message = format!(
|
2021-07-22 12:40:37 -07:00
|
|
|
"too large snapshot data file to deserialize: {} has {} bytes (max size is {} bytes)",
|
2023-06-27 10:08:47 -07:00
|
|
|
snapshot_root_file_path.as_ref().display(),
|
|
|
|
snapshot_file_size,
|
|
|
|
maximum_file_size,
|
2020-01-09 16:49:36 -08:00
|
|
|
);
|
|
|
|
return Err(get_io_error(&error_message));
|
|
|
|
}
|
|
|
|
|
2023-06-27 10:08:47 -07:00
|
|
|
let snapshot_data_file = fs_err::File::open(snapshot_root_file_path.as_ref())?;
|
|
|
|
let snapshot_data_file_stream = BufReader::new(snapshot_data_file.into());
|
2020-01-09 16:49:36 -08:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
Ok((snapshot_file_size, snapshot_data_file_stream))
|
|
|
|
}
|
2020-01-09 16:49:36 -08:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// After running the deserializer function, perform common checks to ensure the snapshot archive
|
|
|
|
/// files were consumed correctly.
|
2023-04-28 07:46:57 -07:00
|
|
|
fn check_deserialize_file_consumed(
|
2021-07-22 12:40:37 -07:00
|
|
|
file_size: u64,
|
2023-04-28 07:46:57 -07:00
|
|
|
file_path: impl AsRef<Path>,
|
2023-06-27 10:08:47 -07:00
|
|
|
file_stream: &mut BufReader<std::fs::File>,
|
2023-04-28 07:46:57 -07:00
|
|
|
) -> Result<()> {
|
2021-07-22 12:40:37 -07:00
|
|
|
let consumed_size = file_stream.stream_position()?;
|
2020-01-09 16:49:36 -08:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
if consumed_size != file_size {
|
2023-06-27 10:08:47 -07:00
|
|
|
let error_message = format!(
|
2021-07-22 12:40:37 -07:00
|
|
|
"invalid snapshot data file: {} has {} bytes, however consumed {} bytes to deserialize",
|
2023-06-27 10:08:47 -07:00
|
|
|
file_path.as_ref().display(),
|
|
|
|
file_size,
|
|
|
|
consumed_size,
|
2020-01-09 16:49:36 -08:00
|
|
|
);
|
|
|
|
return Err(get_io_error(&error_message));
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
Ok(())
|
2020-01-09 16:49:36 -08:00
|
|
|
}
|
|
|
|
|
2023-03-17 15:22:10 -07:00
|
|
|
/// For all account_paths, create the run/ and snapshot/ sub directories.
|
|
|
|
/// If an account_path directory does not exist, create it.
|
|
|
|
/// It returns (account_run_paths, account_snapshot_paths) or error
|
|
|
|
pub fn create_all_accounts_run_and_snapshot_dirs(
|
|
|
|
account_paths: &[PathBuf],
|
|
|
|
) -> Result<(Vec<PathBuf>, Vec<PathBuf>)> {
|
2023-08-09 13:03:36 -07:00
|
|
|
accounts_db::create_all_accounts_run_and_snapshot_dirs(account_paths).map_err(|err| {
|
|
|
|
SnapshotError::IoWithSource(err, "Unable to create account run and snapshot directories")
|
|
|
|
})
|
2023-03-17 15:22:10 -07:00
|
|
|
}
|
|
|
|
|
2023-02-15 09:52:07 -08:00
|
|
|
/// Return account path from the appendvec path after checking its format.
|
|
|
|
fn get_account_path_from_appendvec_path(appendvec_path: &Path) -> Option<PathBuf> {
|
|
|
|
let run_path = appendvec_path.parent()?;
|
|
|
|
let run_file_name = run_path.file_name()?;
|
|
|
|
// All appendvec files should be under <account_path>/run/.
|
|
|
|
// When generating the bank snapshot directory, they are hardlinked to <account_path>/snapshot/<slot>/
|
|
|
|
if run_file_name != "run" {
|
|
|
|
error!(
|
|
|
|
"The account path {} does not have run/ as its immediate parent directory.",
|
|
|
|
run_path.display()
|
|
|
|
);
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let account_path = run_path.parent()?;
|
|
|
|
Some(account_path.to_path_buf())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// From an appendvec path, derive the snapshot hardlink path. If the corresponding snapshot hardlink
|
|
|
|
/// directory does not exist, create it.
|
|
|
|
fn get_snapshot_accounts_hardlink_dir(
|
|
|
|
appendvec_path: &Path,
|
|
|
|
bank_slot: Slot,
|
|
|
|
account_paths: &mut HashSet<PathBuf>,
|
|
|
|
hardlinks_dir: impl AsRef<Path>,
|
2023-07-20 15:30:19 -07:00
|
|
|
) -> std::result::Result<PathBuf, GetSnapshotAccountsHardLinkDirError> {
|
|
|
|
let account_path = get_account_path_from_appendvec_path(appendvec_path).ok_or_else(|| {
|
|
|
|
GetSnapshotAccountsHardLinkDirError::GetAccountPath(appendvec_path.to_path_buf())
|
|
|
|
})?;
|
2023-02-15 09:52:07 -08:00
|
|
|
|
|
|
|
let snapshot_hardlink_dir = account_path.join("snapshot").join(bank_slot.to_string());
|
|
|
|
|
|
|
|
// Use the hashset to track, to avoid checking the file system. Only set up the hardlink directory
|
|
|
|
// and the symlink to it at the first time of seeing the account_path.
|
|
|
|
if !account_paths.contains(&account_path) {
|
|
|
|
let idx = account_paths.len();
|
|
|
|
debug!(
|
|
|
|
"for appendvec_path {}, create hard-link path {}",
|
|
|
|
appendvec_path.display(),
|
|
|
|
snapshot_hardlink_dir.display()
|
|
|
|
);
|
2023-06-26 14:10:21 -07:00
|
|
|
fs_err::create_dir_all(&snapshot_hardlink_dir)
|
2023-07-20 15:30:19 -07:00
|
|
|
.map_err(GetSnapshotAccountsHardLinkDirError::CreateSnapshotHardLinkDir)?;
|
2023-02-15 09:52:07 -08:00
|
|
|
let symlink_path = hardlinks_dir.as_ref().join(format!("account_path_{idx}"));
|
2023-07-20 15:30:19 -07:00
|
|
|
symlink::symlink_dir(&snapshot_hardlink_dir, &symlink_path).map_err(|err| {
|
|
|
|
GetSnapshotAccountsHardLinkDirError::SymlinkSnapshotHardLinkDir {
|
|
|
|
source: err,
|
|
|
|
original: snapshot_hardlink_dir.clone(),
|
|
|
|
link: symlink_path,
|
|
|
|
}
|
2023-02-15 09:52:07 -08:00
|
|
|
})?;
|
|
|
|
account_paths.insert(account_path);
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(snapshot_hardlink_dir)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Hard-link the files from accounts/ to snapshot/<bank_slot>/accounts/
|
|
|
|
/// This keeps the appendvec files alive and with the bank snapshot. The slot and id
|
|
|
|
/// in the file names are also updated in case its file is a recycled one with inconsistent slot
|
|
|
|
/// and id.
|
2023-07-24 16:31:03 -07:00
|
|
|
pub fn hard_link_storages_to_snapshot(
|
2023-02-15 09:52:07 -08:00
|
|
|
bank_snapshot_dir: impl AsRef<Path>,
|
|
|
|
bank_slot: Slot,
|
|
|
|
snapshot_storages: &[Arc<AccountStorageEntry>],
|
2023-07-20 15:30:19 -07:00
|
|
|
) -> std::result::Result<(), HardLinkStoragesToSnapshotError> {
|
2023-05-05 09:36:21 -07:00
|
|
|
let accounts_hardlinks_dir = bank_snapshot_dir.as_ref().join(SNAPSHOT_ACCOUNTS_HARDLINKS);
|
2023-07-20 15:30:19 -07:00
|
|
|
fs_err::create_dir_all(&accounts_hardlinks_dir)
|
|
|
|
.map_err(HardLinkStoragesToSnapshotError::CreateAccountsHardLinksDir)?;
|
2023-02-15 09:52:07 -08:00
|
|
|
|
|
|
|
let mut account_paths: HashSet<PathBuf> = HashSet::new();
|
|
|
|
for storage in snapshot_storages {
|
2023-07-20 15:30:19 -07:00
|
|
|
storage
|
|
|
|
.flush()
|
|
|
|
.map_err(HardLinkStoragesToSnapshotError::FlushStorage)?;
|
2023-02-15 09:52:07 -08:00
|
|
|
let storage_path = storage.accounts.get_path();
|
|
|
|
let snapshot_hardlink_dir = get_snapshot_accounts_hardlink_dir(
|
|
|
|
&storage_path,
|
|
|
|
bank_slot,
|
|
|
|
&mut account_paths,
|
|
|
|
&accounts_hardlinks_dir,
|
|
|
|
)?;
|
|
|
|
// The appendvec could be recycled, so its filename may not be consistent to the slot and id.
|
|
|
|
// Use the storage slot and id to compose a consistent file name for the hard-link file.
|
|
|
|
let hardlink_filename = AppendVec::file_name(storage.slot(), storage.append_vec_id());
|
|
|
|
let hard_link_path = snapshot_hardlink_dir.join(hardlink_filename);
|
2023-07-20 15:30:19 -07:00
|
|
|
fs_err::hard_link(&storage_path, &hard_link_path)
|
|
|
|
.map_err(HardLinkStoragesToSnapshotError::HardLinkStorage)?;
|
2023-02-15 09:52:07 -08:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-01-18 07:10:56 -08:00
|
|
|
/// serializing needs Vec<Vec<Arc<AccountStorageEntry>>>, but data structure at runtime is Vec<Arc<AccountStorageEntry>>
|
2023-01-11 12:05:15 -08:00
|
|
|
/// translates to what we need
|
|
|
|
pub(crate) fn get_storages_to_serialize(
|
2023-01-18 07:10:56 -08:00
|
|
|
snapshot_storages: &[Arc<AccountStorageEntry>],
|
|
|
|
) -> Vec<Vec<Arc<AccountStorageEntry>>> {
|
2023-01-11 12:05:15 -08:00
|
|
|
snapshot_storages
|
|
|
|
.iter()
|
|
|
|
.map(|storage| vec![Arc::clone(storage)])
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
}
|
|
|
|
|
2021-06-14 15:46:49 -07:00
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct BankFromArchiveTimings {
|
|
|
|
pub rebuild_bank_from_snapshots_us: u64,
|
2021-07-22 12:40:37 -07:00
|
|
|
pub full_snapshot_untar_us: u64,
|
|
|
|
pub incremental_snapshot_untar_us: u64,
|
2021-06-14 15:46:49 -07:00
|
|
|
pub verify_snapshot_bank_us: u64,
|
|
|
|
}
|
|
|
|
|
2023-04-04 17:10:56 -07:00
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct BankFromDirTimings {
|
|
|
|
pub rebuild_bank_from_snapshot_us: u64,
|
|
|
|
pub build_storage_us: u64,
|
|
|
|
}
|
|
|
|
|
2022-05-17 07:32:18 -07:00
|
|
|
// From testing, 4 seems to be a sweet spot for ranges of 60M-360M accounts and 16-64 cores. This may need to be tuned later.
|
|
|
|
const PARALLEL_UNTAR_READERS_DEFAULT: usize = 4;
|
2021-06-29 16:26:15 -07:00
|
|
|
|
2023-07-24 16:31:03 -07:00
|
|
|
pub fn verify_and_unarchive_snapshots(
|
2021-08-21 13:41:03 -07:00
|
|
|
bank_snapshots_dir: impl AsRef<Path>,
|
2021-08-06 18:16:06 -07:00
|
|
|
full_snapshot_archive_info: &FullSnapshotArchiveInfo,
|
|
|
|
incremental_snapshot_archive_info: Option<&IncrementalSnapshotArchiveInfo>,
|
2022-07-06 15:30:30 -07:00
|
|
|
account_paths: &[PathBuf],
|
2022-08-29 11:17:27 -07:00
|
|
|
) -> Result<(UnarchivedSnapshot, Option<UnarchivedSnapshot>, AtomicU32)> {
|
2021-08-06 18:16:06 -07:00
|
|
|
check_are_snapshots_compatible(
|
|
|
|
full_snapshot_archive_info,
|
|
|
|
incremental_snapshot_archive_info,
|
|
|
|
)?;
|
|
|
|
|
2022-11-09 11:39:38 -08:00
|
|
|
let parallel_divisions = (num_cpus::get() / 4).clamp(1, PARALLEL_UNTAR_READERS_DEFAULT);
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2023-03-22 13:49:23 -07:00
|
|
|
let next_append_vec_id = Arc::new(AtomicAppendVecId::new(0));
|
2021-07-22 12:40:37 -07:00
|
|
|
let unarchived_full_snapshot = unarchive_snapshot(
|
2021-08-21 13:41:03 -07:00
|
|
|
&bank_snapshots_dir,
|
2021-08-31 16:33:27 -07:00
|
|
|
TMP_SNAPSHOT_ARCHIVE_PREFIX,
|
2021-08-06 18:16:06 -07:00
|
|
|
full_snapshot_archive_info.path(),
|
2021-07-22 12:40:37 -07:00
|
|
|
"snapshot untar",
|
2021-06-29 16:26:15 -07:00
|
|
|
account_paths,
|
2021-08-06 18:16:06 -07:00
|
|
|
full_snapshot_archive_info.archive_format(),
|
2021-07-22 12:40:37 -07:00
|
|
|
parallel_divisions,
|
2022-08-29 11:17:27 -07:00
|
|
|
next_append_vec_id.clone(),
|
2021-06-29 16:26:15 -07:00
|
|
|
)?;
|
2019-08-13 17:20:14 -07:00
|
|
|
|
2022-07-06 15:30:30 -07:00
|
|
|
let unarchived_incremental_snapshot =
|
2021-08-06 18:16:06 -07:00
|
|
|
if let Some(incremental_snapshot_archive_info) = incremental_snapshot_archive_info {
|
2021-07-22 12:40:37 -07:00
|
|
|
let unarchived_incremental_snapshot = unarchive_snapshot(
|
2021-08-21 13:41:03 -07:00
|
|
|
&bank_snapshots_dir,
|
2021-08-31 16:33:27 -07:00
|
|
|
TMP_SNAPSHOT_ARCHIVE_PREFIX,
|
2021-08-06 18:16:06 -07:00
|
|
|
incremental_snapshot_archive_info.path(),
|
2021-07-22 12:40:37 -07:00
|
|
|
"incremental snapshot untar",
|
|
|
|
account_paths,
|
2021-08-06 18:16:06 -07:00
|
|
|
incremental_snapshot_archive_info.archive_format(),
|
2021-07-22 12:40:37 -07:00
|
|
|
parallel_divisions,
|
2022-08-29 11:17:27 -07:00
|
|
|
next_append_vec_id.clone(),
|
2021-07-22 12:40:37 -07:00
|
|
|
)?;
|
|
|
|
Some(unarchived_incremental_snapshot)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2020-01-21 21:06:21 -08:00
|
|
|
|
2022-08-29 11:17:27 -07:00
|
|
|
Ok((
|
|
|
|
unarchived_full_snapshot,
|
|
|
|
unarchived_incremental_snapshot,
|
|
|
|
Arc::try_unwrap(next_append_vec_id).unwrap(),
|
|
|
|
))
|
2022-07-06 15:30:30 -07:00
|
|
|
}
|
|
|
|
|
2022-08-29 11:17:27 -07:00
|
|
|
/// Spawns a thread for unpacking a snapshot
|
|
|
|
fn spawn_unpack_snapshot_thread(
|
|
|
|
file_sender: Sender<PathBuf>,
|
|
|
|
account_paths: Arc<Vec<PathBuf>>,
|
|
|
|
ledger_dir: Arc<PathBuf>,
|
|
|
|
mut archive: Archive<SharedBufferReader>,
|
|
|
|
parallel_selector: Option<ParallelSelector>,
|
|
|
|
thread_index: usize,
|
|
|
|
) -> JoinHandle<()> {
|
|
|
|
Builder::new()
|
2022-09-26 12:51:31 -07:00
|
|
|
.name(format!("solUnpkSnpsht{thread_index:02}"))
|
2022-08-29 11:17:27 -07:00
|
|
|
.spawn(move || {
|
|
|
|
streaming_unpack_snapshot(
|
|
|
|
&mut archive,
|
|
|
|
ledger_dir.as_path(),
|
|
|
|
&account_paths,
|
|
|
|
parallel_selector,
|
|
|
|
&file_sender,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Streams unpacked files across channel
|
|
|
|
fn streaming_unarchive_snapshot(
|
|
|
|
file_sender: Sender<PathBuf>,
|
|
|
|
account_paths: Vec<PathBuf>,
|
|
|
|
ledger_dir: PathBuf,
|
|
|
|
snapshot_archive_path: PathBuf,
|
|
|
|
archive_format: ArchiveFormat,
|
|
|
|
num_threads: usize,
|
|
|
|
) -> Vec<JoinHandle<()>> {
|
|
|
|
let account_paths = Arc::new(account_paths);
|
|
|
|
let ledger_dir = Arc::new(ledger_dir);
|
|
|
|
let shared_buffer = untar_snapshot_create_shared_buffer(&snapshot_archive_path, archive_format);
|
|
|
|
|
2022-08-31 20:49:02 -07:00
|
|
|
// All shared buffer readers need to be created before the threads are spawned
|
|
|
|
#[allow(clippy::needless_collect)]
|
|
|
|
let archives: Vec<_> = (0..num_threads)
|
|
|
|
.map(|_| {
|
|
|
|
let reader = SharedBufferReader::new(&shared_buffer);
|
|
|
|
Archive::new(reader)
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
archives
|
|
|
|
.into_iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(thread_index, archive)| {
|
2022-08-29 11:17:27 -07:00
|
|
|
let parallel_selector = Some(ParallelSelector {
|
|
|
|
index: thread_index,
|
|
|
|
divisions: num_threads,
|
|
|
|
});
|
|
|
|
|
|
|
|
spawn_unpack_snapshot_thread(
|
|
|
|
file_sender.clone(),
|
|
|
|
account_paths.clone(),
|
|
|
|
ledger_dir.clone(),
|
|
|
|
archive,
|
|
|
|
parallel_selector,
|
|
|
|
thread_index,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:50:29 -08:00
|
|
|
/// BankSnapshotInfo::new_from_dir() requires a few meta files to accept a snapshot dir
|
|
|
|
/// as a valid one. A dir unpacked from an archive lacks these files. Fill them here to
|
|
|
|
/// allow new_from_dir() checks to pass. These checks are not needed for unpacked dirs,
|
|
|
|
/// but it is not clean to add another flag to new_from_dir() to skip them.
|
|
|
|
fn create_snapshot_meta_files_for_unarchived_snapshot(unpack_dir: impl AsRef<Path>) -> Result<()> {
|
|
|
|
let snapshots_dir = unpack_dir.as_ref().join("snapshots");
|
|
|
|
if !snapshots_dir.is_dir() {
|
|
|
|
return Err(SnapshotError::NoSnapshotSlotDir(snapshots_dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The unpacked dir has a single slot dir, which is the snapshot slot dir.
|
2023-06-27 10:08:47 -07:00
|
|
|
let slot_dir = std::fs::read_dir(&snapshots_dir)
|
2023-02-24 11:50:29 -08:00
|
|
|
.map_err(|_| SnapshotError::NoSnapshotSlotDir(snapshots_dir.clone()))?
|
|
|
|
.find(|entry| entry.as_ref().unwrap().path().is_dir())
|
|
|
|
.ok_or_else(|| SnapshotError::NoSnapshotSlotDir(snapshots_dir.clone()))?
|
|
|
|
.map_err(|_| SnapshotError::NoSnapshotSlotDir(snapshots_dir.clone()))?
|
|
|
|
.path();
|
|
|
|
|
|
|
|
let version_file = unpack_dir.as_ref().join(SNAPSHOT_VERSION_FILENAME);
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::hard_link(version_file, slot_dir.join(SNAPSHOT_VERSION_FILENAME))?;
|
2023-02-24 11:50:29 -08:00
|
|
|
|
|
|
|
let status_cache_file = snapshots_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::hard_link(
|
2023-02-24 11:50:29 -08:00
|
|
|
status_cache_file,
|
|
|
|
slot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME),
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let state_complete_file = slot_dir.join(SNAPSHOT_STATE_COMPLETE_FILENAME);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(state_complete_file)?;
|
2023-02-24 11:50:29 -08:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Perform the common tasks when unarchiving a snapshot. Handles creating the temporary
|
|
|
|
/// directories, untaring, reading the version file, and then returning those fields plus the
|
2022-08-29 11:17:27 -07:00
|
|
|
/// rebuilt storage
|
2023-04-28 07:46:57 -07:00
|
|
|
fn unarchive_snapshot(
|
|
|
|
bank_snapshots_dir: impl AsRef<Path>,
|
2021-07-22 12:40:37 -07:00
|
|
|
unpacked_snapshots_dir_prefix: &'static str,
|
2023-04-28 07:46:57 -07:00
|
|
|
snapshot_archive_path: impl AsRef<Path>,
|
2021-07-22 12:40:37 -07:00
|
|
|
measure_name: &'static str,
|
|
|
|
account_paths: &[PathBuf],
|
|
|
|
archive_format: ArchiveFormat,
|
|
|
|
parallel_divisions: usize,
|
2023-03-22 13:49:23 -07:00
|
|
|
next_append_vec_id: Arc<AtomicAppendVecId>,
|
2023-04-28 07:46:57 -07:00
|
|
|
) -> Result<UnarchivedSnapshot> {
|
2021-07-22 12:40:37 -07:00
|
|
|
let unpack_dir = tempfile::Builder::new()
|
|
|
|
.prefix(unpacked_snapshots_dir_prefix)
|
2021-08-21 13:41:03 -07:00
|
|
|
.tempdir_in(bank_snapshots_dir)?;
|
2021-07-22 12:40:37 -07:00
|
|
|
let unpacked_snapshots_dir = unpack_dir.path().join("snapshots");
|
|
|
|
|
2022-08-29 11:17:27 -07:00
|
|
|
let (file_sender, file_receiver) = crossbeam_channel::unbounded();
|
|
|
|
streaming_unarchive_snapshot(
|
|
|
|
file_sender,
|
|
|
|
account_paths.to_vec(),
|
|
|
|
unpack_dir.path().to_path_buf(),
|
|
|
|
snapshot_archive_path.as_ref().to_path_buf(),
|
2021-07-22 12:40:37 -07:00
|
|
|
archive_format,
|
|
|
|
parallel_divisions,
|
2022-08-29 11:17:27 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
let num_rebuilder_threads = num_cpus::get_physical()
|
|
|
|
.saturating_sub(parallel_divisions)
|
|
|
|
.max(1);
|
2022-09-22 09:44:25 -07:00
|
|
|
let (version_and_storages, measure_untar) = measure!(
|
2022-08-29 11:17:27 -07:00
|
|
|
SnapshotStorageRebuilder::rebuild_storage(
|
|
|
|
file_receiver,
|
|
|
|
num_rebuilder_threads,
|
2023-03-22 13:49:23 -07:00
|
|
|
next_append_vec_id,
|
|
|
|
SnapshotFrom::Archive,
|
2022-09-22 09:44:25 -07:00
|
|
|
)?,
|
2022-08-29 11:17:27 -07:00
|
|
|
measure_name
|
|
|
|
);
|
2021-07-22 12:40:37 -07:00
|
|
|
info!("{}", measure_untar);
|
|
|
|
|
2023-02-24 11:50:29 -08:00
|
|
|
create_snapshot_meta_files_for_unarchived_snapshot(&unpack_dir)?;
|
|
|
|
|
2022-09-22 09:44:25 -07:00
|
|
|
let RebuiltSnapshotStorage {
|
|
|
|
snapshot_version,
|
|
|
|
storage,
|
|
|
|
} = version_and_storages;
|
2021-07-22 12:40:37 -07:00
|
|
|
Ok(UnarchivedSnapshot {
|
|
|
|
unpack_dir,
|
2022-08-29 11:17:27 -07:00
|
|
|
storage,
|
2021-07-22 12:40:37 -07:00
|
|
|
unpacked_snapshots_dir_and_version: UnpackedSnapshotsDirAndVersion {
|
|
|
|
unpacked_snapshots_dir,
|
|
|
|
snapshot_version,
|
|
|
|
},
|
|
|
|
measure_untar,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-22 13:49:23 -07:00
|
|
|
/// Streams snapshot dir files across channel
|
|
|
|
/// Follow the flow of streaming_unarchive_snapshot(), but handle the from_dir case.
|
|
|
|
fn streaming_snapshot_dir_files(
|
|
|
|
file_sender: Sender<PathBuf>,
|
|
|
|
snapshot_file_path: impl Into<PathBuf>,
|
|
|
|
snapshot_version_path: impl Into<PathBuf>,
|
|
|
|
account_paths: &[PathBuf],
|
|
|
|
) -> Result<()> {
|
|
|
|
file_sender.send(snapshot_file_path.into())?;
|
|
|
|
file_sender.send(snapshot_version_path.into())?;
|
|
|
|
|
|
|
|
for account_path in account_paths {
|
2023-06-26 10:14:27 -07:00
|
|
|
for file in fs_err::read_dir(account_path)? {
|
2023-03-22 13:49:23 -07:00
|
|
|
file_sender.send(file?.path())?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Perform the common tasks when deserialize a snapshot. Handles reading snapshot file, reading the version file,
|
|
|
|
/// and then returning those fields plus the rebuilt storage
|
2023-07-24 16:31:03 -07:00
|
|
|
pub fn build_storage_from_snapshot_dir(
|
2023-03-22 13:49:23 -07:00
|
|
|
snapshot_info: &BankSnapshotInfo,
|
|
|
|
account_paths: &[PathBuf],
|
|
|
|
next_append_vec_id: Arc<AtomicAppendVecId>,
|
|
|
|
) -> Result<AccountStorageMap> {
|
|
|
|
let bank_snapshot_dir = &snapshot_info.snapshot_dir;
|
2023-05-05 09:36:21 -07:00
|
|
|
let accounts_hardlinks = bank_snapshot_dir.join(SNAPSHOT_ACCOUNTS_HARDLINKS);
|
2023-06-27 10:08:47 -07:00
|
|
|
let account_run_paths: HashSet<_> = HashSet::from_iter(account_paths);
|
2023-03-22 13:49:23 -07:00
|
|
|
|
2023-06-27 10:08:47 -07:00
|
|
|
for dir_entry in fs_err::read_dir(&accounts_hardlinks)? {
|
2023-03-27 19:55:10 -07:00
|
|
|
let symlink_path = dir_entry?.path();
|
2023-03-22 13:49:23 -07:00
|
|
|
// The symlink point to <account_path>/snapshot/<slot> which contain the account files hardlinks
|
|
|
|
// The corresponding run path should be <account_path>/run/
|
2023-06-27 10:08:47 -07:00
|
|
|
let account_snapshot_path = fs_err::read_link(&symlink_path)?;
|
|
|
|
let account_run_path = account_snapshot_path
|
2023-03-22 13:49:23 -07:00
|
|
|
.parent()
|
2023-06-27 10:08:47 -07:00
|
|
|
.ok_or_else(|| SnapshotError::InvalidAccountPath(account_snapshot_path.clone()))?
|
2023-03-22 13:49:23 -07:00
|
|
|
.parent()
|
2023-06-27 10:08:47 -07:00
|
|
|
.ok_or_else(|| SnapshotError::InvalidAccountPath(account_snapshot_path.clone()))?
|
2023-03-22 13:49:23 -07:00
|
|
|
.join("run");
|
2023-06-27 10:08:47 -07:00
|
|
|
if !account_run_paths.contains(&account_run_path) {
|
|
|
|
// The appendvec from the bank snapshot storage does not match any of the provided account_paths set.
|
2023-03-22 13:49:23 -07:00
|
|
|
// The accout paths have changed so the snapshot is no longer usable.
|
|
|
|
return Err(SnapshotError::AccountPathsMismatch);
|
|
|
|
}
|
|
|
|
// Generate hard-links to make the account files available in the main accounts/, and let the new appendvec
|
|
|
|
// paths be in accounts/
|
2023-06-27 10:08:47 -07:00
|
|
|
for file in fs_err::read_dir(&account_snapshot_path)? {
|
2023-03-27 19:55:10 -07:00
|
|
|
let file_path = file?.path();
|
2023-03-22 13:49:23 -07:00
|
|
|
let file_name = file_path
|
|
|
|
.file_name()
|
2023-03-27 19:55:10 -07:00
|
|
|
.ok_or_else(|| SnapshotError::InvalidAppendVecPath(file_path.to_path_buf()))?;
|
2023-06-27 10:08:47 -07:00
|
|
|
let dest_path = account_run_path.join(file_name);
|
|
|
|
fs_err::hard_link(&file_path, &dest_path)?;
|
2023-03-22 13:49:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 10:08:47 -07:00
|
|
|
let (file_sender, file_receiver) = crossbeam_channel::unbounded();
|
|
|
|
let snapshot_file_path = &snapshot_info.snapshot_path();
|
|
|
|
let snapshot_version_path = bank_snapshot_dir.join(SNAPSHOT_VERSION_FILENAME);
|
2023-03-22 13:49:23 -07:00
|
|
|
streaming_snapshot_dir_files(
|
|
|
|
file_sender,
|
|
|
|
snapshot_file_path,
|
|
|
|
snapshot_version_path,
|
|
|
|
account_paths,
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let num_rebuilder_threads = num_cpus::get_physical().saturating_sub(1).max(1);
|
|
|
|
let version_and_storages = SnapshotStorageRebuilder::rebuild_storage(
|
|
|
|
file_receiver,
|
|
|
|
num_rebuilder_threads,
|
|
|
|
next_append_vec_id,
|
|
|
|
SnapshotFrom::Dir,
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let RebuiltSnapshotStorage {
|
|
|
|
snapshot_version: _,
|
|
|
|
storage,
|
|
|
|
} = version_and_storages;
|
|
|
|
Ok(storage)
|
|
|
|
}
|
|
|
|
|
2021-12-17 10:27:54 -08:00
|
|
|
/// Reads the `snapshot_version` from a file. Before opening the file, its size
|
|
|
|
/// is compared to `MAX_SNAPSHOT_VERSION_FILE_SIZE`. If the size exceeds this
|
|
|
|
/// threshold, it is not opened and an error is returned.
|
|
|
|
fn snapshot_version_from_file(path: impl AsRef<Path>) -> Result<String> {
|
|
|
|
// Check file size.
|
2023-06-26 10:14:27 -07:00
|
|
|
let file_size = fs_err::metadata(&path)?.len();
|
2021-12-17 10:27:54 -08:00
|
|
|
if file_size > MAX_SNAPSHOT_VERSION_FILE_SIZE {
|
|
|
|
let error_message = format!(
|
|
|
|
"snapshot version file too large: {} has {} bytes (max size is {} bytes)",
|
|
|
|
path.as_ref().display(),
|
|
|
|
file_size,
|
|
|
|
MAX_SNAPSHOT_VERSION_FILE_SIZE,
|
|
|
|
);
|
|
|
|
return Err(get_io_error(&error_message));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read snapshot_version from file.
|
|
|
|
let mut snapshot_version = String::new();
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::open(path.as_ref()).and_then(|mut f| f.read_to_string(&mut snapshot_version))?;
|
2021-12-17 10:27:54 -08:00
|
|
|
Ok(snapshot_version.trim().to_string())
|
|
|
|
}
|
|
|
|
|
2021-08-06 18:16:06 -07:00
|
|
|
/// Check if an incremental snapshot is compatible with a full snapshot. This is done by checking
|
|
|
|
/// if the incremental snapshot's base slot is the same as the full snapshot's slot.
|
|
|
|
fn check_are_snapshots_compatible(
|
|
|
|
full_snapshot_archive_info: &FullSnapshotArchiveInfo,
|
|
|
|
incremental_snapshot_archive_info: Option<&IncrementalSnapshotArchiveInfo>,
|
|
|
|
) -> Result<()> {
|
|
|
|
if incremental_snapshot_archive_info.is_none() {
|
|
|
|
return Ok(());
|
|
|
|
}
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2021-08-06 18:16:06 -07:00
|
|
|
let incremental_snapshot_archive_info = incremental_snapshot_archive_info.unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2021-08-06 18:16:06 -07:00
|
|
|
(full_snapshot_archive_info.slot() == incremental_snapshot_archive_info.base_slot())
|
2022-08-22 18:01:03 -07:00
|
|
|
.then_some(())
|
2021-08-06 18:16:06 -07:00
|
|
|
.ok_or_else(|| {
|
|
|
|
SnapshotError::MismatchedBaseSlot(
|
|
|
|
full_snapshot_archive_info.slot(),
|
|
|
|
incremental_snapshot_archive_info.base_slot(),
|
|
|
|
)
|
|
|
|
})
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the `&str` from a `&Path`
|
2021-08-08 05:57:06 -07:00
|
|
|
pub fn path_to_file_name_str(path: &Path) -> Result<&str> {
|
2021-07-22 12:40:37 -07:00
|
|
|
path.file_name()
|
|
|
|
.ok_or_else(|| SnapshotError::PathToFileNameError(path.to_path_buf()))?
|
|
|
|
.to_str()
|
|
|
|
.ok_or_else(|| SnapshotError::FileNameToStrError(path.to_path_buf()))
|
|
|
|
}
|
|
|
|
|
2022-03-14 12:03:59 -07:00
|
|
|
pub fn build_snapshot_archives_remote_dir(snapshot_archives_dir: impl AsRef<Path>) -> PathBuf {
|
|
|
|
snapshot_archives_dir
|
|
|
|
.as_ref()
|
|
|
|
.join(SNAPSHOT_ARCHIVE_DOWNLOAD_DIR)
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Build the full snapshot archive path from its components: the snapshot archives directory, the
|
2021-07-01 10:20:56 -07:00
|
|
|
/// snapshot slot, the accounts hash, and the archive format.
|
2021-07-22 12:40:37 -07:00
|
|
|
pub fn build_full_snapshot_archive_path(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir: impl AsRef<Path>,
|
2021-07-01 10:20:56 -07:00
|
|
|
slot: Slot,
|
2022-10-31 11:28:35 -07:00
|
|
|
hash: &SnapshotHash,
|
2021-01-21 18:34:51 -08:00
|
|
|
archive_format: ArchiveFormat,
|
2020-02-24 12:37:14 -08:00
|
|
|
) -> PathBuf {
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir.as_ref().join(format!(
|
2021-05-27 10:00:27 -07:00
|
|
|
"snapshot-{}-{}.{}",
|
2021-07-01 10:20:56 -07:00
|
|
|
slot,
|
2022-10-31 11:28:35 -07:00
|
|
|
hash.0,
|
2022-03-09 14:09:34 -08:00
|
|
|
archive_format.extension(),
|
2020-02-24 12:37:14 -08:00
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Build the incremental snapshot archive path from its components: the snapshot archives
|
|
|
|
/// directory, the snapshot base slot, the snapshot slot, the accounts hash, and the archive
|
|
|
|
/// format.
|
|
|
|
pub fn build_incremental_snapshot_archive_path(
|
2022-05-10 13:37:41 -07:00
|
|
|
incremental_snapshot_archives_dir: impl AsRef<Path>,
|
2021-07-22 12:40:37 -07:00
|
|
|
base_slot: Slot,
|
|
|
|
slot: Slot,
|
2022-10-31 11:28:35 -07:00
|
|
|
hash: &SnapshotHash,
|
2021-07-22 12:40:37 -07:00
|
|
|
archive_format: ArchiveFormat,
|
|
|
|
) -> PathBuf {
|
2022-05-10 13:37:41 -07:00
|
|
|
incremental_snapshot_archives_dir.as_ref().join(format!(
|
2021-07-22 12:40:37 -07:00
|
|
|
"incremental-snapshot-{}-{}-{}.{}",
|
|
|
|
base_slot,
|
|
|
|
slot,
|
2022-10-31 11:28:35 -07:00
|
|
|
hash.0,
|
2022-03-09 14:09:34 -08:00
|
|
|
archive_format.extension(),
|
2021-07-22 12:40:37 -07:00
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Parse a full snapshot archive filename into its Slot, Hash, and Archive Format
|
2022-03-02 09:52:20 -08:00
|
|
|
pub(crate) fn parse_full_snapshot_archive_filename(
|
2021-07-22 12:40:37 -07:00
|
|
|
archive_filename: &str,
|
2022-10-31 11:28:35 -07:00
|
|
|
) -> Result<(Slot, SnapshotHash, ArchiveFormat)> {
|
2021-07-22 12:40:37 -07:00
|
|
|
lazy_static! {
|
|
|
|
static ref RE: Regex = Regex::new(FULL_SNAPSHOT_ARCHIVE_FILENAME_REGEX).unwrap();
|
|
|
|
}
|
2021-07-01 10:20:56 -07:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
let do_parse = || {
|
|
|
|
RE.captures(archive_filename).and_then(|captures| {
|
|
|
|
let slot = captures
|
|
|
|
.name("slot")
|
|
|
|
.map(|x| x.as_str().parse::<Slot>())?
|
|
|
|
.ok()?;
|
|
|
|
let hash = captures
|
|
|
|
.name("hash")
|
|
|
|
.map(|x| x.as_str().parse::<Hash>())?
|
|
|
|
.ok()?;
|
|
|
|
let archive_format = captures
|
|
|
|
.name("ext")
|
2022-03-09 14:09:34 -08:00
|
|
|
.map(|x| x.as_str().parse::<ArchiveFormat>())?
|
|
|
|
.ok()?;
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2022-10-31 11:28:35 -07:00
|
|
|
Some((slot, SnapshotHash(hash), archive_format))
|
2021-07-22 12:40:37 -07:00
|
|
|
})
|
|
|
|
};
|
2021-07-01 10:20:56 -07:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
do_parse().ok_or_else(|| {
|
|
|
|
SnapshotError::ParseSnapshotArchiveFileNameError(archive_filename.to_string())
|
2021-07-01 10:20:56 -07:00
|
|
|
})
|
2020-02-24 12:37:14 -08:00
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Parse an incremental snapshot archive filename into its base Slot, actual Slot, Hash, and Archive Format
|
2022-03-02 09:52:20 -08:00
|
|
|
pub(crate) fn parse_incremental_snapshot_archive_filename(
|
2021-07-22 12:40:37 -07:00
|
|
|
archive_filename: &str,
|
2022-10-31 11:28:35 -07:00
|
|
|
) -> Result<(Slot, Slot, SnapshotHash, ArchiveFormat)> {
|
2021-07-22 12:40:37 -07:00
|
|
|
lazy_static! {
|
|
|
|
static ref RE: Regex = Regex::new(INCREMENTAL_SNAPSHOT_ARCHIVE_FILENAME_REGEX).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
let do_parse = || {
|
|
|
|
RE.captures(archive_filename).and_then(|captures| {
|
|
|
|
let base_slot = captures
|
|
|
|
.name("base")
|
|
|
|
.map(|x| x.as_str().parse::<Slot>())?
|
|
|
|
.ok()?;
|
|
|
|
let slot = captures
|
|
|
|
.name("slot")
|
|
|
|
.map(|x| x.as_str().parse::<Slot>())?
|
|
|
|
.ok()?;
|
|
|
|
let hash = captures
|
|
|
|
.name("hash")
|
|
|
|
.map(|x| x.as_str().parse::<Hash>())?
|
|
|
|
.ok()?;
|
|
|
|
let archive_format = captures
|
|
|
|
.name("ext")
|
2022-03-09 14:09:34 -08:00
|
|
|
.map(|x| x.as_str().parse::<ArchiveFormat>())?
|
|
|
|
.ok()?;
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2022-10-31 11:28:35 -07:00
|
|
|
Some((base_slot, slot, SnapshotHash(hash), archive_format))
|
2021-07-22 12:40:37 -07:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
do_parse().ok_or_else(|| {
|
|
|
|
SnapshotError::ParseSnapshotArchiveFileNameError(archive_filename.to_string())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-14 12:03:59 -07:00
|
|
|
/// Walk down the snapshot archive to collect snapshot archive file info
|
|
|
|
fn get_snapshot_archives<T, F>(snapshot_archives_dir: &Path, cb: F) -> Vec<T>
|
|
|
|
where
|
|
|
|
F: Fn(PathBuf) -> Result<T>,
|
|
|
|
{
|
|
|
|
let walk_dir = |dir: &Path| -> Vec<T> {
|
2023-06-26 10:14:27 -07:00
|
|
|
let entry_iter = fs_err::read_dir(dir);
|
2022-03-14 12:03:59 -07:00
|
|
|
match entry_iter {
|
|
|
|
Err(err) => {
|
2023-06-27 10:08:47 -07:00
|
|
|
info!("Unable to read snapshot archives directory: {err}");
|
2022-03-14 12:03:59 -07:00
|
|
|
vec![]
|
|
|
|
}
|
|
|
|
Ok(entries) => entries
|
|
|
|
.filter_map(|entry| entry.map_or(None, |entry| cb(entry.path()).ok()))
|
|
|
|
.collect(),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut ret = walk_dir(snapshot_archives_dir);
|
2022-03-15 06:56:22 -07:00
|
|
|
let remote_dir = build_snapshot_archives_remote_dir(snapshot_archives_dir);
|
|
|
|
if remote_dir.exists() {
|
|
|
|
ret.append(&mut walk_dir(remote_dir.as_ref()));
|
|
|
|
}
|
2022-03-14 12:03:59 -07:00
|
|
|
ret
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get a list of the full snapshot archives from a directory
|
2022-05-10 13:37:41 -07:00
|
|
|
pub fn get_full_snapshot_archives(
|
|
|
|
full_snapshot_archives_dir: impl AsRef<Path>,
|
|
|
|
) -> Vec<FullSnapshotArchiveInfo> {
|
2022-03-14 12:03:59 -07:00
|
|
|
get_snapshot_archives(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir.as_ref(),
|
2022-03-14 12:03:59 -07:00
|
|
|
FullSnapshotArchiveInfo::new_from_path,
|
|
|
|
)
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
2022-03-14 12:03:59 -07:00
|
|
|
/// Get a list of the incremental snapshot archives from a directory
|
2022-05-10 13:37:41 -07:00
|
|
|
pub fn get_incremental_snapshot_archives(
|
|
|
|
incremental_snapshot_archives_dir: impl AsRef<Path>,
|
|
|
|
) -> Vec<IncrementalSnapshotArchiveInfo> {
|
2022-03-14 12:03:59 -07:00
|
|
|
get_snapshot_archives(
|
2022-05-10 13:37:41 -07:00
|
|
|
incremental_snapshot_archives_dir.as_ref(),
|
2022-03-14 12:03:59 -07:00
|
|
|
IncrementalSnapshotArchiveInfo::new_from_path,
|
|
|
|
)
|
2020-02-24 12:37:14 -08:00
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Get the highest slot of the full snapshot archives in a directory
|
2022-05-10 13:37:41 -07:00
|
|
|
pub fn get_highest_full_snapshot_archive_slot(
|
|
|
|
full_snapshot_archives_dir: impl AsRef<Path>,
|
|
|
|
) -> Option<Slot> {
|
|
|
|
get_highest_full_snapshot_archive_info(full_snapshot_archives_dir)
|
2021-08-06 18:16:06 -07:00
|
|
|
.map(|full_snapshot_archive_info| full_snapshot_archive_info.slot())
|
2021-07-01 10:20:56 -07:00
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Get the highest slot of the incremental snapshot archives in a directory, for a given full
|
|
|
|
/// snapshot slot
|
2022-05-10 13:37:41 -07:00
|
|
|
pub fn get_highest_incremental_snapshot_archive_slot(
|
|
|
|
incremental_snapshot_archives_dir: impl AsRef<Path>,
|
2021-07-22 12:40:37 -07:00
|
|
|
full_snapshot_slot: Slot,
|
|
|
|
) -> Option<Slot> {
|
2022-05-10 13:37:41 -07:00
|
|
|
get_highest_incremental_snapshot_archive_info(
|
|
|
|
incremental_snapshot_archives_dir,
|
|
|
|
full_snapshot_slot,
|
|
|
|
)
|
|
|
|
.map(|incremental_snapshot_archive_info| incremental_snapshot_archive_info.slot())
|
2021-07-01 10:20:56 -07:00
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Get the path (and metadata) for the full snapshot archive with the highest slot in a directory
|
2022-05-10 13:37:41 -07:00
|
|
|
pub fn get_highest_full_snapshot_archive_info(
|
|
|
|
full_snapshot_archives_dir: impl AsRef<Path>,
|
|
|
|
) -> Option<FullSnapshotArchiveInfo> {
|
|
|
|
let mut full_snapshot_archives = get_full_snapshot_archives(full_snapshot_archives_dir);
|
2021-07-22 12:40:37 -07:00
|
|
|
full_snapshot_archives.sort_unstable();
|
2023-07-13 10:38:18 -07:00
|
|
|
full_snapshot_archives.into_iter().next_back()
|
2021-07-01 10:20:56 -07:00
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// Get the path for the incremental snapshot archive with the highest slot, for a given full
|
|
|
|
/// snapshot slot, in a directory
|
2022-05-10 13:37:41 -07:00
|
|
|
pub fn get_highest_incremental_snapshot_archive_info(
|
|
|
|
incremental_snapshot_archives_dir: impl AsRef<Path>,
|
2021-07-22 12:40:37 -07:00
|
|
|
full_snapshot_slot: Slot,
|
2022-05-10 13:37:41 -07:00
|
|
|
) -> Option<IncrementalSnapshotArchiveInfo> {
|
2021-07-22 12:40:37 -07:00
|
|
|
// Since we want to filter down to only the incremental snapshot archives that have the same
|
|
|
|
// full snapshot slot as the value passed in, perform the filtering before sorting to avoid
|
|
|
|
// doing unnecessary work.
|
|
|
|
let mut incremental_snapshot_archives =
|
2022-05-10 13:37:41 -07:00
|
|
|
get_incremental_snapshot_archives(incremental_snapshot_archives_dir)
|
2021-07-22 12:40:37 -07:00
|
|
|
.into_iter()
|
|
|
|
.filter(|incremental_snapshot_archive_info| {
|
2021-08-06 18:16:06 -07:00
|
|
|
incremental_snapshot_archive_info.base_slot() == full_snapshot_slot
|
2021-07-22 12:40:37 -07:00
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
incremental_snapshot_archives.sort_unstable();
|
2023-07-13 10:38:18 -07:00
|
|
|
incremental_snapshot_archives.into_iter().next_back()
|
2019-08-13 17:20:14 -07:00
|
|
|
}
|
|
|
|
|
2022-05-10 13:37:41 -07:00
|
|
|
pub fn purge_old_snapshot_archives(
|
|
|
|
full_snapshot_archives_dir: impl AsRef<Path>,
|
|
|
|
incremental_snapshot_archives_dir: impl AsRef<Path>,
|
2023-03-30 08:16:36 -07:00
|
|
|
maximum_full_snapshot_archives_to_retain: NonZeroUsize,
|
|
|
|
maximum_incremental_snapshot_archives_to_retain: NonZeroUsize,
|
2022-05-10 13:37:41 -07:00
|
|
|
) {
|
2021-05-12 10:32:27 -07:00
|
|
|
info!(
|
2022-05-10 13:37:41 -07:00
|
|
|
"Purging old full snapshot archives in {}, retaining up to {} full snapshots",
|
|
|
|
full_snapshot_archives_dir.as_ref().display(),
|
|
|
|
maximum_full_snapshot_archives_to_retain
|
2021-05-12 10:32:27 -07:00
|
|
|
);
|
2022-04-27 09:40:03 -07:00
|
|
|
|
2022-05-10 13:37:41 -07:00
|
|
|
let mut full_snapshot_archives = get_full_snapshot_archives(&full_snapshot_archives_dir);
|
2022-04-27 09:40:03 -07:00
|
|
|
full_snapshot_archives.sort_unstable();
|
|
|
|
full_snapshot_archives.reverse();
|
|
|
|
|
2023-03-30 08:16:36 -07:00
|
|
|
let num_to_retain = full_snapshot_archives
|
|
|
|
.len()
|
|
|
|
.min(maximum_full_snapshot_archives_to_retain.get());
|
2022-03-11 13:01:48 -08:00
|
|
|
trace!(
|
2022-04-27 09:40:03 -07:00
|
|
|
"There are {} full snapshot archives, retaining {}",
|
|
|
|
full_snapshot_archives.len(),
|
|
|
|
num_to_retain,
|
2022-03-11 13:01:48 -08:00
|
|
|
);
|
|
|
|
|
2022-04-27 09:40:03 -07:00
|
|
|
let (full_snapshot_archives_to_retain, full_snapshot_archives_to_remove) =
|
|
|
|
if full_snapshot_archives.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(full_snapshot_archives.split_at(num_to_retain))
|
|
|
|
}
|
|
|
|
.unwrap_or_default();
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2022-04-27 09:40:03 -07:00
|
|
|
let retained_full_snapshot_slots = full_snapshot_archives_to_retain
|
|
|
|
.iter()
|
|
|
|
.map(|ai| ai.slot())
|
|
|
|
.collect::<HashSet<_>>();
|
|
|
|
|
|
|
|
fn remove_archives<T: SnapshotArchiveInfoGetter>(archives: &[T]) {
|
|
|
|
for path in archives.iter().map(|a| a.path()) {
|
|
|
|
trace!("Removing snapshot archive: {}", path.display());
|
2023-06-27 10:08:47 -07:00
|
|
|
let result = fs_err::remove_file(path);
|
|
|
|
if let Err(err) = result {
|
|
|
|
info!("Failed to remove snapshot archive: {err}",);
|
|
|
|
}
|
2022-04-27 09:40:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
remove_archives(full_snapshot_archives_to_remove);
|
|
|
|
|
2022-05-10 13:37:41 -07:00
|
|
|
info!(
|
|
|
|
"Purging old incremental snapshot archives in {}, retaining up to {} incremental snapshots",
|
|
|
|
incremental_snapshot_archives_dir.as_ref().display(),
|
|
|
|
maximum_incremental_snapshot_archives_to_retain
|
|
|
|
);
|
2022-04-27 09:40:03 -07:00
|
|
|
let mut incremental_snapshot_archives_by_base_slot = HashMap::<Slot, Vec<_>>::new();
|
2022-05-10 13:37:41 -07:00
|
|
|
for incremental_snapshot_archive in
|
|
|
|
get_incremental_snapshot_archives(&incremental_snapshot_archives_dir)
|
|
|
|
{
|
2022-04-27 09:40:03 -07:00
|
|
|
incremental_snapshot_archives_by_base_slot
|
|
|
|
.entry(incremental_snapshot_archive.base_slot())
|
|
|
|
.or_default()
|
|
|
|
.push(incremental_snapshot_archive)
|
|
|
|
}
|
2021-09-04 05:37:29 -07:00
|
|
|
|
2022-04-27 09:40:03 -07:00
|
|
|
let highest_full_snapshot_slot = retained_full_snapshot_slots.iter().max().copied();
|
|
|
|
for (base_slot, mut incremental_snapshot_archives) in incremental_snapshot_archives_by_base_slot
|
|
|
|
{
|
|
|
|
incremental_snapshot_archives.sort_unstable();
|
|
|
|
let num_to_retain = if Some(base_slot) == highest_full_snapshot_slot {
|
2023-03-30 08:16:36 -07:00
|
|
|
maximum_incremental_snapshot_archives_to_retain.get()
|
2022-04-27 09:40:03 -07:00
|
|
|
} else {
|
2022-09-22 15:23:03 -07:00
|
|
|
usize::from(retained_full_snapshot_slots.contains(&base_slot))
|
2022-04-27 09:40:03 -07:00
|
|
|
};
|
2022-03-11 13:01:48 -08:00
|
|
|
trace!(
|
2022-04-27 09:40:03 -07:00
|
|
|
"There are {} incremental snapshot archives for base slot {}, removing {} of them",
|
|
|
|
incremental_snapshot_archives.len(),
|
|
|
|
base_slot,
|
|
|
|
incremental_snapshot_archives
|
|
|
|
.len()
|
|
|
|
.saturating_sub(num_to_retain),
|
2022-03-11 13:01:48 -08:00
|
|
|
);
|
2021-09-04 05:37:29 -07:00
|
|
|
|
2022-04-27 09:40:03 -07:00
|
|
|
incremental_snapshot_archives.truncate(
|
|
|
|
incremental_snapshot_archives
|
|
|
|
.len()
|
|
|
|
.saturating_sub(num_to_retain),
|
|
|
|
);
|
|
|
|
remove_archives(&incremental_snapshot_archives);
|
|
|
|
}
|
2020-12-20 22:37:33 -08:00
|
|
|
}
|
|
|
|
|
2022-07-19 13:30:30 -07:00
|
|
|
fn unpack_snapshot_local(
|
|
|
|
shared_buffer: SharedBuffer,
|
2021-06-29 16:26:15 -07:00
|
|
|
ledger_dir: &Path,
|
|
|
|
account_paths: &[PathBuf],
|
2022-07-19 11:15:33 -07:00
|
|
|
parallel_divisions: usize,
|
2021-06-29 16:26:15 -07:00
|
|
|
) -> Result<UnpackedAppendVecMap> {
|
2022-07-19 11:15:33 -07:00
|
|
|
assert!(parallel_divisions > 0);
|
2021-07-08 11:44:47 -07:00
|
|
|
|
|
|
|
// allocate all readers before any readers start reading
|
2022-07-19 11:15:33 -07:00
|
|
|
let readers = (0..parallel_divisions)
|
2021-07-08 11:44:47 -07:00
|
|
|
.map(|_| SharedBufferReader::new(&shared_buffer))
|
2021-06-29 16:26:15 -07:00
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
2022-07-19 11:15:33 -07:00
|
|
|
// create 'parallel_divisions' # of parallel workers, each responsible for 1/parallel_divisions of all the files to extract.
|
2021-06-29 16:26:15 -07:00
|
|
|
let all_unpacked_append_vec_map = readers
|
|
|
|
.into_par_iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(index, reader)| {
|
|
|
|
let parallel_selector = Some(ParallelSelector {
|
|
|
|
index,
|
2022-07-19 11:15:33 -07:00
|
|
|
divisions: parallel_divisions,
|
2021-06-29 16:26:15 -07:00
|
|
|
});
|
|
|
|
let mut archive = Archive::new(reader);
|
|
|
|
unpack_snapshot(&mut archive, ledger_dir, account_paths, parallel_selector)
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
2022-05-16 06:49:17 -07:00
|
|
|
|
2021-06-29 16:26:15 -07:00
|
|
|
let mut unpacked_append_vec_map = UnpackedAppendVecMap::new();
|
|
|
|
for h in all_unpacked_append_vec_map {
|
|
|
|
unpacked_append_vec_map.extend(h?);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(unpacked_append_vec_map)
|
|
|
|
}
|
|
|
|
|
2022-07-19 13:30:30 -07:00
|
|
|
fn untar_snapshot_create_shared_buffer(
|
2022-05-16 06:49:17 -07:00
|
|
|
snapshot_tar: &Path,
|
2021-01-07 22:45:42 -08:00
|
|
|
archive_format: ArchiveFormat,
|
2022-07-19 16:15:41 -07:00
|
|
|
) -> SharedBuffer {
|
2023-06-27 10:08:47 -07:00
|
|
|
let open_file = || fs_err::File::open(snapshot_tar).unwrap();
|
2022-07-19 16:15:41 -07:00
|
|
|
match archive_format {
|
2022-07-19 13:30:30 -07:00
|
|
|
ArchiveFormat::TarBzip2 => SharedBuffer::new(BzDecoder::new(BufReader::new(open_file()))),
|
|
|
|
ArchiveFormat::TarGzip => SharedBuffer::new(GzDecoder::new(BufReader::new(open_file()))),
|
|
|
|
ArchiveFormat::TarZstd => SharedBuffer::new(
|
|
|
|
zstd::stream::read::Decoder::new(BufReader::new(open_file())).unwrap(),
|
|
|
|
),
|
|
|
|
ArchiveFormat::TarLz4 => {
|
|
|
|
SharedBuffer::new(lz4::Decoder::new(BufReader::new(open_file())).unwrap())
|
|
|
|
}
|
|
|
|
ArchiveFormat::Tar => SharedBuffer::new(BufReader::new(open_file())),
|
2022-07-19 16:15:41 -07:00
|
|
|
}
|
2019-08-13 17:20:14 -07:00
|
|
|
}
|
|
|
|
|
2023-04-28 07:46:57 -07:00
|
|
|
fn untar_snapshot_in(
|
|
|
|
snapshot_tar: impl AsRef<Path>,
|
2022-05-16 06:49:17 -07:00
|
|
|
unpack_dir: &Path,
|
|
|
|
account_paths: &[PathBuf],
|
|
|
|
archive_format: ArchiveFormat,
|
|
|
|
parallel_divisions: usize,
|
|
|
|
) -> Result<UnpackedAppendVecMap> {
|
2022-07-19 16:15:41 -07:00
|
|
|
let shared_buffer = untar_snapshot_create_shared_buffer(snapshot_tar.as_ref(), archive_format);
|
2022-07-19 13:30:30 -07:00
|
|
|
unpack_snapshot_local(shared_buffer, unpack_dir, account_paths, parallel_divisions)
|
2022-05-16 06:49:17 -07:00
|
|
|
}
|
|
|
|
|
2023-07-24 16:31:03 -07:00
|
|
|
pub fn verify_unpacked_snapshots_dir_and_version(
|
2021-07-22 12:40:37 -07:00
|
|
|
unpacked_snapshots_dir_and_version: &UnpackedSnapshotsDirAndVersion,
|
|
|
|
) -> Result<(SnapshotVersion, BankSnapshotInfo)> {
|
|
|
|
info!(
|
|
|
|
"snapshot version: {}",
|
|
|
|
&unpacked_snapshots_dir_and_version.snapshot_version
|
|
|
|
);
|
2020-01-21 21:06:21 -08:00
|
|
|
|
2022-09-22 09:44:25 -07:00
|
|
|
let snapshot_version = unpacked_snapshots_dir_and_version.snapshot_version;
|
2022-04-06 19:39:26 -07:00
|
|
|
let mut bank_snapshots =
|
|
|
|
get_bank_snapshots_post(&unpacked_snapshots_dir_and_version.unpacked_snapshots_dir);
|
|
|
|
if bank_snapshots.len() > 1 {
|
2019-09-25 13:42:19 -07:00
|
|
|
return Err(get_io_error("invalid snapshot format"));
|
|
|
|
}
|
2022-04-06 19:39:26 -07:00
|
|
|
let root_paths = bank_snapshots
|
2019-09-25 13:42:19 -07:00
|
|
|
.pop()
|
2019-08-05 22:53:19 -07:00
|
|
|
.ok_or_else(|| get_io_error("No snapshots found in snapshots directory"))?;
|
2021-07-22 12:40:37 -07:00
|
|
|
Ok((snapshot_version, root_paths))
|
2021-06-16 09:01:52 -07:00
|
|
|
}
|
2019-09-25 13:42:19 -07:00
|
|
|
|
2023-05-01 12:28:35 -07:00
|
|
|
/// Returns the file name of the bank snapshot for `slot`
|
|
|
|
pub fn get_snapshot_file_name(slot: Slot) -> String {
|
2019-07-31 17:58:10 -07:00
|
|
|
slot.to_string()
|
|
|
|
}
|
|
|
|
|
2023-05-01 12:28:35 -07:00
|
|
|
/// Constructs the path to the bank snapshot directory for `slot` within `bank_snapshots_dir`
|
|
|
|
pub fn get_bank_snapshot_dir(bank_snapshots_dir: impl AsRef<Path>, slot: Slot) -> PathBuf {
|
|
|
|
bank_snapshots_dir
|
|
|
|
.as_ref()
|
|
|
|
.join(get_snapshot_file_name(slot))
|
2019-07-31 17:58:10 -07:00
|
|
|
}
|
|
|
|
|
2019-10-18 18:16:06 -07:00
|
|
|
fn get_io_error(error: &str) -> SnapshotError {
|
2019-08-14 23:14:40 -07:00
|
|
|
warn!("Snapshot Error: {:?}", error);
|
2021-02-18 23:42:09 -08:00
|
|
|
SnapshotError::Io(IoError::new(ErrorKind::Other, error))
|
2019-07-31 17:58:10 -07:00
|
|
|
}
|
|
|
|
|
2022-04-06 19:55:44 -07:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
/// allow tests to specify what happened to the serialized format
|
|
|
|
pub enum VerifyBank {
|
|
|
|
/// the bank's serialized format is expected to be identical to what we are comparing against
|
|
|
|
Deterministic,
|
2023-04-24 18:52:50 -07:00
|
|
|
/// the serialized bank was 'reserialized' into a non-deterministic format
|
2022-04-06 19:55:44 -07:00
|
|
|
/// so, deserialize both files and compare deserialized results
|
2023-04-24 18:52:50 -07:00
|
|
|
NonDeterministic,
|
2022-04-06 19:55:44 -07:00
|
|
|
}
|
|
|
|
|
2023-04-28 07:46:57 -07:00
|
|
|
pub fn verify_snapshot_archive(
|
|
|
|
snapshot_archive: impl AsRef<Path>,
|
|
|
|
snapshots_to_verify: impl AsRef<Path>,
|
2021-01-07 22:45:42 -08:00
|
|
|
archive_format: ArchiveFormat,
|
2022-04-06 19:55:44 -07:00
|
|
|
verify_bank: VerifyBank,
|
2023-04-24 18:52:50 -07:00
|
|
|
slot: Slot,
|
2023-04-28 07:46:57 -07:00
|
|
|
) {
|
2019-10-19 12:09:45 -07:00
|
|
|
let temp_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let unpack_dir = temp_dir.path();
|
2023-04-24 18:52:50 -07:00
|
|
|
let unpack_account_dir = create_accounts_run_and_snapshot_dirs(unpack_dir).unwrap().0;
|
2021-03-10 09:49:10 -08:00
|
|
|
untar_snapshot_in(
|
|
|
|
snapshot_archive,
|
2021-06-18 06:34:46 -07:00
|
|
|
unpack_dir,
|
2023-04-24 18:52:50 -07:00
|
|
|
&[unpack_account_dir.clone()],
|
2021-03-10 09:49:10 -08:00
|
|
|
archive_format,
|
2021-06-29 16:26:15 -07:00
|
|
|
1,
|
2021-03-10 09:49:10 -08:00
|
|
|
)
|
|
|
|
.unwrap();
|
2019-10-19 12:09:45 -07:00
|
|
|
|
|
|
|
// Check snapshots are the same
|
2021-03-10 09:49:10 -08:00
|
|
|
let unpacked_snapshots = unpack_dir.join("snapshots");
|
2023-04-24 18:52:50 -07:00
|
|
|
|
|
|
|
// Since the unpack code collects all the appendvecs into one directory unpack_account_dir, we need to
|
|
|
|
// collect all the appendvecs in account_paths/<slot>/snapshot/ into one directory for later comparison.
|
|
|
|
let storages_to_verify = unpack_dir.join("storages_to_verify");
|
|
|
|
// Create the directory if it doesn't exist
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::create_dir_all(&storages_to_verify).unwrap();
|
2023-04-24 18:52:50 -07:00
|
|
|
|
|
|
|
let slot = slot.to_string();
|
|
|
|
let snapshot_slot_dir = snapshots_to_verify.as_ref().join(&slot);
|
|
|
|
|
|
|
|
if let VerifyBank::NonDeterministic = verify_bank {
|
2022-04-06 19:55:44 -07:00
|
|
|
// file contents may be different, but deserialized structs should be equal
|
|
|
|
let p1 = snapshots_to_verify.as_ref().join(&slot).join(&slot);
|
|
|
|
let p2 = unpacked_snapshots.join(&slot).join(&slot);
|
|
|
|
assert!(crate::serde_snapshot::compare_two_serialized_banks(&p1, &p2).unwrap());
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::remove_file(p1).unwrap();
|
|
|
|
fs_err::remove_file(p2).unwrap();
|
2023-04-24 18:52:50 -07:00
|
|
|
}
|
2023-02-01 16:51:32 -08:00
|
|
|
|
2023-04-24 18:52:50 -07:00
|
|
|
// The new the status_cache file is inside the slot directory together with the snapshot file.
|
|
|
|
// When unpacking an archive, the status_cache file from the archive is one-level up outside of
|
|
|
|
// the slot direcotry.
|
|
|
|
// The unpacked status_cache file need to be put back into the slot directory for the directory
|
|
|
|
// comparison to pass.
|
|
|
|
let existing_unpacked_status_cache_file =
|
|
|
|
unpacked_snapshots.join(SNAPSHOT_STATUS_CACHE_FILENAME);
|
|
|
|
let new_unpacked_status_cache_file = unpacked_snapshots
|
|
|
|
.join(&slot)
|
|
|
|
.join(SNAPSHOT_STATUS_CACHE_FILENAME);
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::rename(
|
2023-04-24 18:52:50 -07:00
|
|
|
existing_unpacked_status_cache_file,
|
|
|
|
new_unpacked_status_cache_file,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2023-02-15 09:52:07 -08:00
|
|
|
|
2023-05-05 09:36:21 -07:00
|
|
|
let accounts_hardlinks_dir = snapshot_slot_dir.join(SNAPSHOT_ACCOUNTS_HARDLINKS);
|
2023-04-24 18:52:50 -07:00
|
|
|
if accounts_hardlinks_dir.is_dir() {
|
|
|
|
// This directory contain symlinks to all <account_path>/snapshot/<slot> directories.
|
2023-06-26 10:14:27 -07:00
|
|
|
for entry in fs_err::read_dir(&accounts_hardlinks_dir).unwrap() {
|
|
|
|
let link_dst_path = fs_err::read_link(entry.unwrap().path()).unwrap();
|
2023-04-24 18:52:50 -07:00
|
|
|
// Copy all the files in dst_path into the storages_to_verify directory.
|
2023-06-26 10:14:27 -07:00
|
|
|
for entry in fs_err::read_dir(&link_dst_path).unwrap() {
|
2023-04-24 18:52:50 -07:00
|
|
|
let src_path = entry.unwrap().path();
|
|
|
|
let dst_path = storages_to_verify.join(src_path.file_name().unwrap());
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::copy(src_path, dst_path).unwrap();
|
2023-02-15 09:52:07 -08:00
|
|
|
}
|
|
|
|
}
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::remove_dir_all(accounts_hardlinks_dir).unwrap();
|
2023-04-24 18:52:50 -07:00
|
|
|
}
|
2023-02-15 22:38:40 -08:00
|
|
|
|
2023-04-24 18:52:50 -07:00
|
|
|
let version_path = snapshot_slot_dir.join(SNAPSHOT_VERSION_FILENAME);
|
|
|
|
if version_path.is_file() {
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::remove_file(version_path).unwrap();
|
2023-04-24 18:52:50 -07:00
|
|
|
}
|
2023-02-15 22:38:40 -08:00
|
|
|
|
2023-04-24 18:52:50 -07:00
|
|
|
let state_complete_path = snapshot_slot_dir.join(SNAPSHOT_STATE_COMPLETE_FILENAME);
|
|
|
|
if state_complete_path.is_file() {
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::remove_file(state_complete_path).unwrap();
|
2022-04-06 19:55:44 -07:00
|
|
|
}
|
|
|
|
|
2019-10-19 12:09:45 -07:00
|
|
|
assert!(!dir_diff::is_different(&snapshots_to_verify, unpacked_snapshots).unwrap());
|
|
|
|
|
2023-01-30 10:26:43 -08:00
|
|
|
// In the unarchiving case, there is an extra empty "accounts" directory. The account
|
|
|
|
// files in the archive accounts/ have been expanded to [account_paths].
|
|
|
|
// Remove the empty "accounts" directory for the directory comparison below.
|
|
|
|
// In some test cases the directory to compare do not come from unarchiving.
|
|
|
|
// Ignore the error when this directory does not exist.
|
2023-06-26 10:14:27 -07:00
|
|
|
_ = fs_err::remove_dir(unpack_account_dir.join("accounts"));
|
2019-10-19 12:09:45 -07:00
|
|
|
// Check the account entries are the same
|
2023-04-24 18:52:50 -07:00
|
|
|
assert!(!dir_diff::is_different(&storages_to_verify, unpack_account_dir).unwrap());
|
2019-07-31 17:58:10 -07:00
|
|
|
}
|
2020-01-09 16:49:36 -08:00
|
|
|
|
2023-05-05 11:01:08 -07:00
|
|
|
/// Purges bank snapshots, retaining the newest `num_bank_snapshots_to_retain`
|
2023-02-15 09:52:07 -08:00
|
|
|
pub fn purge_old_bank_snapshots(
|
|
|
|
bank_snapshots_dir: impl AsRef<Path>,
|
|
|
|
num_bank_snapshots_to_retain: usize,
|
2023-04-17 16:16:41 -07:00
|
|
|
filter_by_type: Option<BankSnapshotType>,
|
2023-02-15 09:52:07 -08:00
|
|
|
) {
|
2023-05-05 11:01:08 -07:00
|
|
|
let mut bank_snapshots = match filter_by_type {
|
2023-04-17 16:16:41 -07:00
|
|
|
Some(BankSnapshotType::Pre) => get_bank_snapshots_pre(&bank_snapshots_dir),
|
|
|
|
Some(BankSnapshotType::Post) => get_bank_snapshots_post(&bank_snapshots_dir),
|
|
|
|
None => get_bank_snapshots(&bank_snapshots_dir),
|
|
|
|
};
|
2023-05-05 11:01:08 -07:00
|
|
|
|
|
|
|
bank_snapshots.sort_unstable();
|
|
|
|
purge_bank_snapshots(
|
|
|
|
bank_snapshots
|
|
|
|
.iter()
|
|
|
|
.rev()
|
|
|
|
.skip(num_bank_snapshots_to_retain),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-23 10:18:05 -07:00
|
|
|
/// At startup, purge old (i.e. unusable) bank snapshots
|
|
|
|
///
|
|
|
|
/// Only a single bank snapshot could be needed at startup (when using fast boot), so
|
|
|
|
/// retain the highest bank snapshot "post", and purge the rest.
|
|
|
|
pub fn purge_old_bank_snapshots_at_startup(bank_snapshots_dir: impl AsRef<Path>) {
|
|
|
|
purge_old_bank_snapshots(&bank_snapshots_dir, 0, Some(BankSnapshotType::Pre));
|
|
|
|
purge_old_bank_snapshots(&bank_snapshots_dir, 1, Some(BankSnapshotType::Post));
|
|
|
|
|
|
|
|
let highest_bank_snapshot_post = get_highest_bank_snapshot_post(&bank_snapshots_dir);
|
|
|
|
if let Some(highest_bank_snapshot_post) = highest_bank_snapshot_post {
|
|
|
|
debug!(
|
|
|
|
"Retained bank snapshot for slot {}, and purged the rest.",
|
|
|
|
highest_bank_snapshot_post.slot
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 12:39:14 -07:00
|
|
|
/// Purges bank snapshots that are older than `slot`
|
|
|
|
pub fn purge_bank_snapshots_older_than_slot(bank_snapshots_dir: impl AsRef<Path>, slot: Slot) {
|
|
|
|
let mut bank_snapshots = get_bank_snapshots(&bank_snapshots_dir);
|
|
|
|
bank_snapshots.retain(|bank_snapshot| bank_snapshot.slot < slot);
|
|
|
|
purge_bank_snapshots(&bank_snapshots);
|
|
|
|
}
|
|
|
|
|
2023-05-05 11:01:08 -07:00
|
|
|
/// Purges all `bank_snapshots`
|
|
|
|
///
|
|
|
|
/// Does not exit early if there is an error while purging a bank snapshot.
|
|
|
|
fn purge_bank_snapshots<'a>(bank_snapshots: impl IntoIterator<Item = &'a BankSnapshotInfo>) {
|
|
|
|
for snapshot_dir in bank_snapshots.into_iter().map(|s| &s.snapshot_dir) {
|
|
|
|
if purge_bank_snapshot(snapshot_dir).is_err() {
|
|
|
|
warn!("Failed to purge bank snapshot: {}", snapshot_dir.display());
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
2023-05-04 16:19:26 -07:00
|
|
|
/// Remove the bank snapshot at this path
|
2023-07-24 16:31:03 -07:00
|
|
|
pub fn purge_bank_snapshot(bank_snapshot_dir: impl AsRef<Path>) -> Result<()> {
|
2023-05-04 16:19:26 -07:00
|
|
|
let accounts_hardlinks_dir = bank_snapshot_dir.as_ref().join(SNAPSHOT_ACCOUNTS_HARDLINKS);
|
|
|
|
if accounts_hardlinks_dir.is_dir() {
|
|
|
|
// This directory contain symlinks to all accounts snapshot directories.
|
|
|
|
// They should all be removed.
|
2023-06-26 10:14:27 -07:00
|
|
|
for accounts_hardlink_dir in fs_err::read_dir(accounts_hardlinks_dir)? {
|
|
|
|
let accounts_hardlink_dir = fs_err::read_link(accounts_hardlink_dir?.path())?;
|
2023-05-04 16:19:26 -07:00
|
|
|
move_and_async_delete_path(&accounts_hardlink_dir);
|
|
|
|
}
|
|
|
|
}
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::remove_dir_all(bank_snapshot_dir)?;
|
2023-05-04 16:19:26 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-09-07 16:26:35 -07:00
|
|
|
pub fn should_take_full_snapshot(
|
|
|
|
block_height: Slot,
|
|
|
|
full_snapshot_archive_interval_slots: Slot,
|
|
|
|
) -> bool {
|
|
|
|
block_height % full_snapshot_archive_interval_slots == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn should_take_incremental_snapshot(
|
|
|
|
block_height: Slot,
|
|
|
|
incremental_snapshot_archive_interval_slots: Slot,
|
|
|
|
last_full_snapshot_slot: Option<Slot>,
|
|
|
|
) -> bool {
|
|
|
|
block_height % incremental_snapshot_archive_interval_slots == 0
|
|
|
|
&& last_full_snapshot_slot.is_some()
|
|
|
|
}
|
|
|
|
|
2023-01-30 10:26:43 -08:00
|
|
|
pub fn create_tmp_accounts_dir_for_tests() -> (TempDir, PathBuf) {
|
|
|
|
let tmp_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let account_dir = create_accounts_run_and_snapshot_dirs(&tmp_dir).unwrap().0;
|
|
|
|
(tmp_dir, account_dir)
|
|
|
|
}
|
|
|
|
|
2020-01-09 16:49:36 -08:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
super::*,
|
|
|
|
assert_matches::assert_matches,
|
|
|
|
bincode::{deserialize_from, serialize_into},
|
2023-07-24 16:31:03 -07:00
|
|
|
std::{convert::TryFrom, mem::size_of},
|
2021-12-17 10:27:54 -08:00
|
|
|
tempfile::NamedTempFile,
|
2021-07-01 10:20:56 -07:00
|
|
|
};
|
2020-01-09 16:49:36 -08:00
|
|
|
#[test]
|
|
|
|
fn test_serialize_snapshot_data_file_under_limit() {
|
|
|
|
let temp_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let expected_consumed_size = size_of::<u32>() as u64;
|
2020-05-22 10:54:24 -07:00
|
|
|
let consumed_size = serialize_snapshot_data_file_capped(
|
2020-01-09 16:49:36 -08:00
|
|
|
&temp_dir.path().join("data-file"),
|
|
|
|
expected_consumed_size,
|
|
|
|
|stream| {
|
|
|
|
serialize_into(stream, &2323_u32)?;
|
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(consumed_size, expected_consumed_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_serialize_snapshot_data_file_over_limit() {
|
|
|
|
let temp_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let expected_consumed_size = size_of::<u32>() as u64;
|
2020-05-22 10:54:24 -07:00
|
|
|
let result = serialize_snapshot_data_file_capped(
|
2020-01-09 16:49:36 -08:00
|
|
|
&temp_dir.path().join("data-file"),
|
|
|
|
expected_consumed_size - 1,
|
|
|
|
|stream| {
|
|
|
|
serialize_into(stream, &2323_u32)?;
|
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
);
|
2021-02-18 23:42:09 -08:00
|
|
|
assert_matches!(result, Err(SnapshotError::Io(ref message)) if message.to_string().starts_with("too large snapshot data file to serialize"));
|
2020-01-09 16:49:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_deserialize_snapshot_data_file_under_limit() {
|
|
|
|
let expected_data = 2323_u32;
|
|
|
|
let expected_consumed_size = size_of::<u32>() as u64;
|
|
|
|
|
|
|
|
let temp_dir = tempfile::TempDir::new().unwrap();
|
2020-05-22 10:54:24 -07:00
|
|
|
serialize_snapshot_data_file_capped(
|
2020-01-09 16:49:36 -08:00
|
|
|
&temp_dir.path().join("data-file"),
|
|
|
|
expected_consumed_size,
|
|
|
|
|stream| {
|
|
|
|
serialize_into(stream, &expected_data)?;
|
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
let snapshot_root_paths = SnapshotRootPaths {
|
|
|
|
full_snapshot_root_file_path: temp_dir.path().join("data-file"),
|
|
|
|
incremental_snapshot_root_file_path: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
let actual_data = deserialize_snapshot_data_files_capped(
|
|
|
|
&snapshot_root_paths,
|
2020-01-09 16:49:36 -08:00
|
|
|
expected_consumed_size,
|
2021-07-22 12:40:37 -07:00
|
|
|
|stream| {
|
|
|
|
Ok(deserialize_from::<_, u32>(
|
|
|
|
&mut stream.full_snapshot_stream,
|
|
|
|
)?)
|
|
|
|
},
|
2020-01-09 16:49:36 -08:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(actual_data, expected_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_deserialize_snapshot_data_file_over_limit() {
|
|
|
|
let expected_data = 2323_u32;
|
|
|
|
let expected_consumed_size = size_of::<u32>() as u64;
|
|
|
|
|
|
|
|
let temp_dir = tempfile::TempDir::new().unwrap();
|
2020-05-22 10:54:24 -07:00
|
|
|
serialize_snapshot_data_file_capped(
|
2020-01-09 16:49:36 -08:00
|
|
|
&temp_dir.path().join("data-file"),
|
|
|
|
expected_consumed_size,
|
|
|
|
|stream| {
|
|
|
|
serialize_into(stream, &expected_data)?;
|
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
let snapshot_root_paths = SnapshotRootPaths {
|
|
|
|
full_snapshot_root_file_path: temp_dir.path().join("data-file"),
|
|
|
|
incremental_snapshot_root_file_path: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
let result = deserialize_snapshot_data_files_capped(
|
|
|
|
&snapshot_root_paths,
|
2020-01-09 16:49:36 -08:00
|
|
|
expected_consumed_size - 1,
|
2021-07-22 12:40:37 -07:00
|
|
|
|stream| {
|
|
|
|
Ok(deserialize_from::<_, u32>(
|
|
|
|
&mut stream.full_snapshot_stream,
|
|
|
|
)?)
|
|
|
|
},
|
2020-01-09 16:49:36 -08:00
|
|
|
);
|
2021-02-18 23:42:09 -08:00
|
|
|
assert_matches!(result, Err(SnapshotError::Io(ref message)) if message.to_string().starts_with("too large snapshot data file to deserialize"));
|
2020-01-09 16:49:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_deserialize_snapshot_data_file_extra_data() {
|
|
|
|
let expected_data = 2323_u32;
|
|
|
|
let expected_consumed_size = size_of::<u32>() as u64;
|
|
|
|
|
|
|
|
let temp_dir = tempfile::TempDir::new().unwrap();
|
2020-05-22 10:54:24 -07:00
|
|
|
serialize_snapshot_data_file_capped(
|
2020-01-09 16:49:36 -08:00
|
|
|
&temp_dir.path().join("data-file"),
|
|
|
|
expected_consumed_size * 2,
|
|
|
|
|stream| {
|
|
|
|
serialize_into(stream.by_ref(), &expected_data)?;
|
|
|
|
serialize_into(stream.by_ref(), &expected_data)?;
|
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
let snapshot_root_paths = SnapshotRootPaths {
|
|
|
|
full_snapshot_root_file_path: temp_dir.path().join("data-file"),
|
|
|
|
incremental_snapshot_root_file_path: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
let result = deserialize_snapshot_data_files_capped(
|
|
|
|
&snapshot_root_paths,
|
2020-01-09 16:49:36 -08:00
|
|
|
expected_consumed_size * 2,
|
2021-07-22 12:40:37 -07:00
|
|
|
|stream| {
|
|
|
|
Ok(deserialize_from::<_, u32>(
|
|
|
|
&mut stream.full_snapshot_stream,
|
|
|
|
)?)
|
|
|
|
},
|
2020-01-09 16:49:36 -08:00
|
|
|
);
|
2021-02-18 23:42:09 -08:00
|
|
|
assert_matches!(result, Err(SnapshotError::Io(ref message)) if message.to_string().starts_with("invalid snapshot data file"));
|
2020-01-09 16:49:36 -08:00
|
|
|
}
|
2020-02-24 12:37:14 -08:00
|
|
|
|
2021-12-17 10:27:54 -08:00
|
|
|
#[test]
|
|
|
|
fn test_snapshot_version_from_file_under_limit() {
|
2022-01-13 10:19:15 -08:00
|
|
|
let file_content = SnapshotVersion::default().as_str();
|
2021-12-17 10:27:54 -08:00
|
|
|
let mut file = NamedTempFile::new().unwrap();
|
|
|
|
file.write_all(file_content.as_bytes()).unwrap();
|
|
|
|
let version_from_file = snapshot_version_from_file(file.path()).unwrap();
|
|
|
|
assert_eq!(version_from_file, file_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_snapshot_version_from_file_over_limit() {
|
|
|
|
let over_limit_size = usize::try_from(MAX_SNAPSHOT_VERSION_FILE_SIZE + 1).unwrap();
|
|
|
|
let file_content = vec![7u8; over_limit_size];
|
|
|
|
let mut file = NamedTempFile::new().unwrap();
|
|
|
|
file.write_all(&file_content).unwrap();
|
|
|
|
assert_matches!(
|
|
|
|
snapshot_version_from_file(file.path()),
|
|
|
|
Err(SnapshotError::Io(ref message)) if message.to_string().starts_with("snapshot version file too large")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-24 12:37:14 -08:00
|
|
|
#[test]
|
2021-07-22 12:40:37 -07:00
|
|
|
fn test_parse_full_snapshot_archive_filename() {
|
2020-02-24 12:37:14 -08:00
|
|
|
assert_eq!(
|
2021-07-22 12:40:37 -07:00
|
|
|
parse_full_snapshot_archive_filename(&format!(
|
|
|
|
"snapshot-42-{}.tar.bz2",
|
|
|
|
Hash::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
2022-10-31 11:28:35 -07:00
|
|
|
(42, SnapshotHash(Hash::default()), ArchiveFormat::TarBzip2)
|
2020-02-24 12:37:14 -08:00
|
|
|
);
|
2020-04-03 13:13:49 -07:00
|
|
|
assert_eq!(
|
2021-07-22 12:40:37 -07:00
|
|
|
parse_full_snapshot_archive_filename(&format!(
|
|
|
|
"snapshot-43-{}.tar.zst",
|
|
|
|
Hash::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
2022-10-31 11:28:35 -07:00
|
|
|
(43, SnapshotHash(Hash::default()), ArchiveFormat::TarZstd)
|
2020-04-03 13:13:49 -07:00
|
|
|
);
|
2020-11-19 13:43:33 -08:00
|
|
|
assert_eq!(
|
2021-07-22 12:40:37 -07:00
|
|
|
parse_full_snapshot_archive_filename(&format!("snapshot-44-{}.tar", Hash::default()))
|
|
|
|
.unwrap(),
|
2022-10-31 11:28:35 -07:00
|
|
|
(44, SnapshotHash(Hash::default()), ArchiveFormat::Tar)
|
2020-11-19 13:43:33 -08:00
|
|
|
);
|
2022-05-31 09:06:41 -07:00
|
|
|
assert_eq!(
|
|
|
|
parse_full_snapshot_archive_filename(&format!(
|
|
|
|
"snapshot-45-{}.tar.lz4",
|
|
|
|
Hash::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
2022-10-31 11:28:35 -07:00
|
|
|
(45, SnapshotHash(Hash::default()), ArchiveFormat::TarLz4)
|
2022-05-31 09:06:41 -07:00
|
|
|
);
|
2020-04-03 13:13:49 -07:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
assert!(parse_full_snapshot_archive_filename("invalid").is_err());
|
|
|
|
assert!(
|
|
|
|
parse_full_snapshot_archive_filename("snapshot-bad!slot-bad!hash.bad!ext").is_err()
|
|
|
|
);
|
2021-05-27 10:00:27 -07:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
assert!(
|
|
|
|
parse_full_snapshot_archive_filename("snapshot-12345678-bad!hash.bad!ext").is_err()
|
|
|
|
);
|
|
|
|
assert!(parse_full_snapshot_archive_filename(&format!(
|
2021-07-01 10:20:56 -07:00
|
|
|
"snapshot-12345678-{}.bad!ext",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
2021-07-22 12:40:37 -07:00
|
|
|
.is_err());
|
|
|
|
assert!(parse_full_snapshot_archive_filename("snapshot-12345678-bad!hash.tar").is_err());
|
2021-05-27 10:00:27 -07:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
assert!(parse_full_snapshot_archive_filename(&format!(
|
2021-07-01 10:20:56 -07:00
|
|
|
"snapshot-bad!slot-{}.bad!ext",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
2021-07-22 12:40:37 -07:00
|
|
|
.is_err());
|
|
|
|
assert!(parse_full_snapshot_archive_filename(&format!(
|
2021-07-01 10:20:56 -07:00
|
|
|
"snapshot-12345678-{}.bad!ext",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
2021-07-22 12:40:37 -07:00
|
|
|
.is_err());
|
|
|
|
assert!(parse_full_snapshot_archive_filename(&format!(
|
2021-07-01 10:20:56 -07:00
|
|
|
"snapshot-bad!slot-{}.tar",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
2021-07-22 12:40:37 -07:00
|
|
|
.is_err());
|
2021-05-27 10:00:27 -07:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
assert!(parse_full_snapshot_archive_filename("snapshot-bad!slot-bad!hash.tar").is_err());
|
|
|
|
assert!(parse_full_snapshot_archive_filename("snapshot-12345678-bad!hash.tar").is_err());
|
|
|
|
assert!(parse_full_snapshot_archive_filename(&format!(
|
2021-07-01 10:20:56 -07:00
|
|
|
"snapshot-bad!slot-{}.tar",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
2021-07-22 12:40:37 -07:00
|
|
|
.is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse_incremental_snapshot_archive_filename() {
|
|
|
|
assert_eq!(
|
|
|
|
parse_incremental_snapshot_archive_filename(&format!(
|
|
|
|
"incremental-snapshot-42-123-{}.tar.bz2",
|
|
|
|
Hash::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
2022-10-31 11:28:35 -07:00
|
|
|
(
|
|
|
|
42,
|
|
|
|
123,
|
|
|
|
SnapshotHash(Hash::default()),
|
|
|
|
ArchiveFormat::TarBzip2
|
|
|
|
)
|
2021-07-22 12:40:37 -07:00
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
parse_incremental_snapshot_archive_filename(&format!(
|
|
|
|
"incremental-snapshot-43-234-{}.tar.zst",
|
|
|
|
Hash::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
2022-10-31 11:28:35 -07:00
|
|
|
(
|
|
|
|
43,
|
|
|
|
234,
|
|
|
|
SnapshotHash(Hash::default()),
|
|
|
|
ArchiveFormat::TarZstd
|
|
|
|
)
|
2021-07-22 12:40:37 -07:00
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
parse_incremental_snapshot_archive_filename(&format!(
|
|
|
|
"incremental-snapshot-44-345-{}.tar",
|
|
|
|
Hash::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
2022-10-31 11:28:35 -07:00
|
|
|
(44, 345, SnapshotHash(Hash::default()), ArchiveFormat::Tar)
|
2021-07-22 12:40:37 -07:00
|
|
|
);
|
2022-05-31 09:06:41 -07:00
|
|
|
assert_eq!(
|
|
|
|
parse_incremental_snapshot_archive_filename(&format!(
|
|
|
|
"incremental-snapshot-45-456-{}.tar.lz4",
|
|
|
|
Hash::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
2022-10-31 11:28:35 -07:00
|
|
|
(
|
|
|
|
45,
|
|
|
|
456,
|
|
|
|
SnapshotHash(Hash::default()),
|
|
|
|
ArchiveFormat::TarLz4
|
|
|
|
)
|
2022-05-31 09:06:41 -07:00
|
|
|
);
|
2021-07-22 12:40:37 -07:00
|
|
|
|
|
|
|
assert!(parse_incremental_snapshot_archive_filename("invalid").is_err());
|
|
|
|
assert!(parse_incremental_snapshot_archive_filename(&format!(
|
|
|
|
"snapshot-42-{}.tar",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
|
|
|
.is_err());
|
|
|
|
assert!(parse_incremental_snapshot_archive_filename(
|
|
|
|
"incremental-snapshot-bad!slot-bad!slot-bad!hash.bad!ext"
|
|
|
|
)
|
|
|
|
.is_err());
|
|
|
|
|
|
|
|
assert!(parse_incremental_snapshot_archive_filename(&format!(
|
|
|
|
"incremental-snapshot-bad!slot-56785678-{}.tar",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
|
|
|
.is_err());
|
|
|
|
|
|
|
|
assert!(parse_incremental_snapshot_archive_filename(&format!(
|
|
|
|
"incremental-snapshot-12345678-bad!slot-{}.tar",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
|
|
|
.is_err());
|
|
|
|
|
|
|
|
assert!(parse_incremental_snapshot_archive_filename(
|
|
|
|
"incremental-snapshot-12341234-56785678-bad!HASH.tar"
|
|
|
|
)
|
|
|
|
.is_err());
|
|
|
|
|
|
|
|
assert!(parse_incremental_snapshot_archive_filename(&format!(
|
|
|
|
"incremental-snapshot-12341234-56785678-{}.bad!ext",
|
|
|
|
Hash::new_unique()
|
|
|
|
))
|
|
|
|
.is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_check_are_snapshots_compatible() {
|
|
|
|
let slot1: Slot = 1234;
|
|
|
|
let slot2: Slot = 5678;
|
|
|
|
let slot3: Slot = 999_999;
|
|
|
|
|
2021-08-06 18:16:06 -07:00
|
|
|
let full_snapshot_archive_info = FullSnapshotArchiveInfo::new_from_path(PathBuf::from(
|
|
|
|
format!("/dir/snapshot-{}-{}.tar", slot1, Hash::new_unique()),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(check_are_snapshots_compatible(&full_snapshot_archive_info, None,).is_ok());
|
|
|
|
|
|
|
|
let incremental_snapshot_archive_info =
|
|
|
|
IncrementalSnapshotArchiveInfo::new_from_path(PathBuf::from(format!(
|
2021-07-22 12:40:37 -07:00
|
|
|
"/dir/incremental-snapshot-{}-{}-{}.tar",
|
|
|
|
slot1,
|
|
|
|
slot2,
|
|
|
|
Hash::new_unique()
|
2021-08-06 18:16:06 -07:00
|
|
|
)))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(check_are_snapshots_compatible(
|
|
|
|
&full_snapshot_archive_info,
|
|
|
|
Some(&incremental_snapshot_archive_info)
|
2021-07-22 12:40:37 -07:00
|
|
|
)
|
|
|
|
.is_ok());
|
|
|
|
|
2021-08-06 18:16:06 -07:00
|
|
|
let incremental_snapshot_archive_info =
|
|
|
|
IncrementalSnapshotArchiveInfo::new_from_path(PathBuf::from(format!(
|
2021-07-22 12:40:37 -07:00
|
|
|
"/dir/incremental-snapshot-{}-{}-{}.tar",
|
|
|
|
slot2,
|
|
|
|
slot3,
|
|
|
|
Hash::new_unique()
|
2021-08-06 18:16:06 -07:00
|
|
|
)))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(check_are_snapshots_compatible(
|
|
|
|
&full_snapshot_archive_info,
|
|
|
|
Some(&incremental_snapshot_archive_info)
|
2021-07-22 12:40:37 -07:00
|
|
|
)
|
|
|
|
.is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A test heler function that creates bank snapshot files
|
2021-08-21 13:41:03 -07:00
|
|
|
fn common_create_bank_snapshot_files(
|
|
|
|
bank_snapshots_dir: &Path,
|
|
|
|
min_slot: Slot,
|
|
|
|
max_slot: Slot,
|
|
|
|
) {
|
2021-07-22 12:40:37 -07:00
|
|
|
for slot in min_slot..max_slot {
|
2023-05-01 12:28:35 -07:00
|
|
|
let snapshot_dir = get_bank_snapshot_dir(bank_snapshots_dir, slot);
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::create_dir_all(&snapshot_dir).unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
|
|
|
|
let snapshot_filename = get_snapshot_file_name(slot);
|
|
|
|
let snapshot_path = snapshot_dir.join(snapshot_filename);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(snapshot_path).unwrap();
|
2023-02-24 11:50:29 -08:00
|
|
|
|
|
|
|
let status_cache_file = snapshot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(status_cache_file).unwrap();
|
2023-02-24 11:50:29 -08:00
|
|
|
|
|
|
|
let version_path = snapshot_dir.join(SNAPSHOT_VERSION_FILENAME);
|
|
|
|
write_snapshot_version_file(version_path, SnapshotVersion::default()).unwrap();
|
|
|
|
|
|
|
|
// Mark this directory complete so it can be used. Check this flag first before selecting for deserialization.
|
|
|
|
let state_complete_path = snapshot_dir.join(SNAPSHOT_STATE_COMPLETE_FILENAME);
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::File::create(state_complete_path).unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-04-06 19:39:26 -07:00
|
|
|
fn test_get_bank_snapshots() {
|
2021-07-22 12:40:37 -07:00
|
|
|
let temp_snapshots_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let min_slot = 10;
|
|
|
|
let max_slot = 20;
|
|
|
|
common_create_bank_snapshot_files(temp_snapshots_dir.path(), min_slot, max_slot);
|
|
|
|
|
2022-04-06 19:39:26 -07:00
|
|
|
let bank_snapshots = get_bank_snapshots(temp_snapshots_dir.path());
|
|
|
|
assert_eq!(bank_snapshots.len() as Slot, max_slot - min_slot);
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-04-06 19:39:26 -07:00
|
|
|
fn test_get_highest_bank_snapshot_post() {
|
2021-07-22 12:40:37 -07:00
|
|
|
let temp_snapshots_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let min_slot = 99;
|
|
|
|
let max_slot = 123;
|
|
|
|
common_create_bank_snapshot_files(temp_snapshots_dir.path(), min_slot, max_slot);
|
|
|
|
|
2022-04-06 19:39:26 -07:00
|
|
|
let highest_bank_snapshot = get_highest_bank_snapshot_post(temp_snapshots_dir.path());
|
|
|
|
assert!(highest_bank_snapshot.is_some());
|
|
|
|
assert_eq!(highest_bank_snapshot.unwrap().slot, max_slot - 1);
|
2021-05-27 10:00:27 -07:00
|
|
|
}
|
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
/// A test helper function that creates full and incremental snapshot archive files. Creates
|
|
|
|
/// full snapshot files in the range (`min_full_snapshot_slot`, `max_full_snapshot_slot`], and
|
|
|
|
/// incremental snapshot files in the range (`min_incremental_snapshot_slot`,
|
|
|
|
/// `max_incremental_snapshot_slot`]. Additionally, "bad" files are created for both full and
|
|
|
|
/// incremental snapshots to ensure the tests properly filter them out.
|
2021-07-01 10:20:56 -07:00
|
|
|
fn common_create_snapshot_archive_files(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir: &Path,
|
|
|
|
incremental_snapshot_archives_dir: &Path,
|
2021-07-22 12:40:37 -07:00
|
|
|
min_full_snapshot_slot: Slot,
|
|
|
|
max_full_snapshot_slot: Slot,
|
|
|
|
min_incremental_snapshot_slot: Slot,
|
|
|
|
max_incremental_snapshot_slot: Slot,
|
2021-07-01 10:20:56 -07:00
|
|
|
) {
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::create_dir_all(full_snapshot_archives_dir).unwrap();
|
|
|
|
fs_err::create_dir_all(incremental_snapshot_archives_dir).unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
for full_snapshot_slot in min_full_snapshot_slot..max_full_snapshot_slot {
|
|
|
|
for incremental_snapshot_slot in
|
|
|
|
min_incremental_snapshot_slot..max_incremental_snapshot_slot
|
|
|
|
{
|
|
|
|
let snapshot_filename = format!(
|
|
|
|
"incremental-snapshot-{}-{}-{}.tar",
|
|
|
|
full_snapshot_slot,
|
|
|
|
incremental_snapshot_slot,
|
|
|
|
Hash::default()
|
|
|
|
);
|
2022-05-10 13:37:41 -07:00
|
|
|
let snapshot_filepath = incremental_snapshot_archives_dir.join(snapshot_filename);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(snapshot_filepath).unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
let snapshot_filename =
|
|
|
|
format!("snapshot-{}-{}.tar", full_snapshot_slot, Hash::default());
|
2022-05-10 13:37:41 -07:00
|
|
|
let snapshot_filepath = full_snapshot_archives_dir.join(snapshot_filename);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(snapshot_filepath).unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
|
|
|
|
// Add in an incremental snapshot with a bad filename and high slot to ensure filename are filtered and sorted correctly
|
|
|
|
let bad_filename = format!(
|
|
|
|
"incremental-snapshot-{}-{}-bad!hash.tar",
|
|
|
|
full_snapshot_slot,
|
|
|
|
max_incremental_snapshot_slot + 1,
|
|
|
|
);
|
2022-05-10 13:37:41 -07:00
|
|
|
let bad_filepath = incremental_snapshot_archives_dir.join(bad_filename);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(bad_filepath).unwrap();
|
2021-05-27 10:00:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add in a snapshot with a bad filename and high slot to ensure filename are filtered and
|
|
|
|
// sorted correctly
|
2021-07-22 12:40:37 -07:00
|
|
|
let bad_filename = format!("snapshot-{}-bad!hash.tar", max_full_snapshot_slot + 1);
|
2022-05-10 13:37:41 -07:00
|
|
|
let bad_filepath = full_snapshot_archives_dir.join(bad_filename);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(bad_filepath).unwrap();
|
2021-07-01 10:20:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-22 12:40:37 -07:00
|
|
|
fn test_get_full_snapshot_archives() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2021-07-01 10:20:56 -07:00
|
|
|
let min_slot = 123;
|
|
|
|
let max_slot = 456;
|
2021-07-22 12:40:37 -07:00
|
|
|
common_create_snapshot_archive_files(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir.path(),
|
|
|
|
incremental_snapshot_archives_dir.path(),
|
2021-07-22 12:40:37 -07:00
|
|
|
min_slot,
|
|
|
|
max_slot,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
);
|
2021-05-27 10:00:27 -07:00
|
|
|
|
2022-05-10 13:37:41 -07:00
|
|
|
let snapshot_archives = get_full_snapshot_archives(full_snapshot_archives_dir);
|
2021-07-01 10:20:56 -07:00
|
|
|
assert_eq!(snapshot_archives.len() as Slot, max_slot - min_slot);
|
|
|
|
}
|
|
|
|
|
2022-03-14 12:03:59 -07:00
|
|
|
#[test]
|
|
|
|
fn test_get_full_snapshot_archives_remote() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2022-03-14 12:03:59 -07:00
|
|
|
let min_slot = 123;
|
|
|
|
let max_slot = 456;
|
|
|
|
common_create_snapshot_archive_files(
|
2023-05-05 09:36:32 -07:00
|
|
|
&full_snapshot_archives_dir
|
|
|
|
.path()
|
|
|
|
.join(SNAPSHOT_ARCHIVE_DOWNLOAD_DIR),
|
|
|
|
&incremental_snapshot_archives_dir
|
|
|
|
.path()
|
|
|
|
.join(SNAPSHOT_ARCHIVE_DOWNLOAD_DIR),
|
2022-03-14 12:03:59 -07:00
|
|
|
min_slot,
|
|
|
|
max_slot,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
|
2022-05-10 13:37:41 -07:00
|
|
|
let snapshot_archives = get_full_snapshot_archives(full_snapshot_archives_dir);
|
2022-03-14 12:03:59 -07:00
|
|
|
assert_eq!(snapshot_archives.len() as Slot, max_slot - min_slot);
|
|
|
|
assert!(snapshot_archives.iter().all(|info| info.is_remote()));
|
|
|
|
}
|
|
|
|
|
2021-07-01 10:20:56 -07:00
|
|
|
#[test]
|
2021-07-22 12:40:37 -07:00
|
|
|
fn test_get_incremental_snapshot_archives() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
let min_full_snapshot_slot = 12;
|
|
|
|
let max_full_snapshot_slot = 23;
|
|
|
|
let min_incremental_snapshot_slot = 34;
|
|
|
|
let max_incremental_snapshot_slot = 45;
|
|
|
|
common_create_snapshot_archive_files(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir.path(),
|
|
|
|
incremental_snapshot_archives_dir.path(),
|
2021-07-22 12:40:37 -07:00
|
|
|
min_full_snapshot_slot,
|
|
|
|
max_full_snapshot_slot,
|
|
|
|
min_incremental_snapshot_slot,
|
|
|
|
max_incremental_snapshot_slot,
|
|
|
|
);
|
2021-07-01 10:20:56 -07:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
let incremental_snapshot_archives =
|
2022-05-10 13:37:41 -07:00
|
|
|
get_incremental_snapshot_archives(incremental_snapshot_archives_dir);
|
2021-07-22 12:40:37 -07:00
|
|
|
assert_eq!(
|
|
|
|
incremental_snapshot_archives.len() as Slot,
|
|
|
|
(max_full_snapshot_slot - min_full_snapshot_slot)
|
|
|
|
* (max_incremental_snapshot_slot - min_incremental_snapshot_slot)
|
|
|
|
);
|
2021-07-01 10:20:56 -07:00
|
|
|
}
|
|
|
|
|
2022-03-14 12:03:59 -07:00
|
|
|
#[test]
|
|
|
|
fn test_get_incremental_snapshot_archives_remote() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2022-03-14 12:03:59 -07:00
|
|
|
let min_full_snapshot_slot = 12;
|
|
|
|
let max_full_snapshot_slot = 23;
|
|
|
|
let min_incremental_snapshot_slot = 34;
|
|
|
|
let max_incremental_snapshot_slot = 45;
|
|
|
|
common_create_snapshot_archive_files(
|
2023-05-05 09:36:32 -07:00
|
|
|
&full_snapshot_archives_dir
|
|
|
|
.path()
|
|
|
|
.join(SNAPSHOT_ARCHIVE_DOWNLOAD_DIR),
|
|
|
|
&incremental_snapshot_archives_dir
|
|
|
|
.path()
|
|
|
|
.join(SNAPSHOT_ARCHIVE_DOWNLOAD_DIR),
|
2022-03-14 12:03:59 -07:00
|
|
|
min_full_snapshot_slot,
|
|
|
|
max_full_snapshot_slot,
|
|
|
|
min_incremental_snapshot_slot,
|
|
|
|
max_incremental_snapshot_slot,
|
|
|
|
);
|
|
|
|
|
|
|
|
let incremental_snapshot_archives =
|
2022-05-10 13:37:41 -07:00
|
|
|
get_incremental_snapshot_archives(incremental_snapshot_archives_dir);
|
2022-03-14 12:03:59 -07:00
|
|
|
assert_eq!(
|
|
|
|
incremental_snapshot_archives.len() as Slot,
|
|
|
|
(max_full_snapshot_slot - min_full_snapshot_slot)
|
|
|
|
* (max_incremental_snapshot_slot - min_incremental_snapshot_slot)
|
|
|
|
);
|
|
|
|
assert!(incremental_snapshot_archives
|
|
|
|
.iter()
|
|
|
|
.all(|info| info.is_remote()));
|
|
|
|
}
|
|
|
|
|
2021-07-01 10:20:56 -07:00
|
|
|
#[test]
|
2021-07-22 12:40:37 -07:00
|
|
|
fn test_get_highest_full_snapshot_archive_slot() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2021-07-01 10:20:56 -07:00
|
|
|
let min_slot = 123;
|
|
|
|
let max_slot = 456;
|
2021-07-22 12:40:37 -07:00
|
|
|
common_create_snapshot_archive_files(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir.path(),
|
|
|
|
incremental_snapshot_archives_dir.path(),
|
2021-07-22 12:40:37 -07:00
|
|
|
min_slot,
|
|
|
|
max_slot,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
);
|
2021-07-01 10:20:56 -07:00
|
|
|
|
|
|
|
assert_eq!(
|
2022-05-10 13:37:41 -07:00
|
|
|
get_highest_full_snapshot_archive_slot(full_snapshot_archives_dir.path()),
|
2021-07-01 10:20:56 -07:00
|
|
|
Some(max_slot - 1)
|
|
|
|
);
|
2020-02-24 12:37:14 -08:00
|
|
|
}
|
2021-05-12 10:32:27 -07:00
|
|
|
|
2021-07-22 12:40:37 -07:00
|
|
|
#[test]
|
|
|
|
fn test_get_highest_incremental_snapshot_slot() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
let min_full_snapshot_slot = 12;
|
|
|
|
let max_full_snapshot_slot = 23;
|
|
|
|
let min_incremental_snapshot_slot = 34;
|
|
|
|
let max_incremental_snapshot_slot = 45;
|
|
|
|
common_create_snapshot_archive_files(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir.path(),
|
|
|
|
incremental_snapshot_archives_dir.path(),
|
2021-07-22 12:40:37 -07:00
|
|
|
min_full_snapshot_slot,
|
|
|
|
max_full_snapshot_slot,
|
|
|
|
min_incremental_snapshot_slot,
|
|
|
|
max_incremental_snapshot_slot,
|
|
|
|
);
|
|
|
|
|
|
|
|
for full_snapshot_slot in min_full_snapshot_slot..max_full_snapshot_slot {
|
|
|
|
assert_eq!(
|
|
|
|
get_highest_incremental_snapshot_archive_slot(
|
2022-05-10 13:37:41 -07:00
|
|
|
incremental_snapshot_archives_dir.path(),
|
2021-07-22 12:40:37 -07:00
|
|
|
full_snapshot_slot
|
|
|
|
),
|
|
|
|
Some(max_incremental_snapshot_slot - 1)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
get_highest_incremental_snapshot_archive_slot(
|
2022-05-10 13:37:41 -07:00
|
|
|
incremental_snapshot_archives_dir.path(),
|
2021-07-22 12:40:37 -07:00
|
|
|
max_full_snapshot_slot
|
|
|
|
),
|
|
|
|
None
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 10:32:27 -07:00
|
|
|
fn common_test_purge_old_snapshot_archives(
|
|
|
|
snapshot_names: &[&String],
|
2023-03-30 08:16:36 -07:00
|
|
|
maximum_full_snapshot_archives_to_retain: NonZeroUsize,
|
|
|
|
maximum_incremental_snapshot_archives_to_retain: NonZeroUsize,
|
2021-05-12 10:32:27 -07:00
|
|
|
expected_snapshots: &[&String],
|
|
|
|
) {
|
|
|
|
let temp_snap_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
|
|
|
|
for snap_name in snapshot_names {
|
2022-09-22 15:23:03 -07:00
|
|
|
let snap_path = temp_snap_dir.path().join(snap_name);
|
2023-06-27 10:08:47 -07:00
|
|
|
let mut _snap_file = fs_err::File::create(snap_path);
|
2021-05-12 10:32:27 -07:00
|
|
|
}
|
2021-09-04 05:37:29 -07:00
|
|
|
purge_old_snapshot_archives(
|
2022-05-10 13:37:41 -07:00
|
|
|
temp_snap_dir.path(),
|
2021-09-04 05:37:29 -07:00
|
|
|
temp_snap_dir.path(),
|
|
|
|
maximum_full_snapshot_archives_to_retain,
|
|
|
|
maximum_incremental_snapshot_archives_to_retain,
|
|
|
|
);
|
2021-05-12 10:32:27 -07:00
|
|
|
|
|
|
|
let mut retained_snaps = HashSet::new();
|
2023-06-26 10:14:27 -07:00
|
|
|
for entry in fs_err::read_dir(temp_snap_dir.path()).unwrap() {
|
2021-05-12 10:32:27 -07:00
|
|
|
let entry_path_buf = entry.unwrap().path();
|
|
|
|
let entry_path = entry_path_buf.as_path();
|
|
|
|
let snapshot_name = entry_path
|
|
|
|
.file_name()
|
|
|
|
.unwrap()
|
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
.to_string();
|
|
|
|
retained_snaps.insert(snapshot_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
for snap_name in expected_snapshots {
|
2022-02-20 07:06:23 -08:00
|
|
|
assert!(
|
|
|
|
retained_snaps.contains(snap_name.as_str()),
|
2022-12-06 06:30:06 -08:00
|
|
|
"{snap_name} not found"
|
2022-02-20 07:06:23 -08:00
|
|
|
);
|
2021-05-12 10:32:27 -07:00
|
|
|
}
|
2022-04-27 09:40:03 -07:00
|
|
|
assert_eq!(retained_snaps.len(), expected_snapshots.len());
|
2021-05-12 10:32:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-22 12:40:37 -07:00
|
|
|
fn test_purge_old_full_snapshot_archives() {
|
2021-05-12 10:32:27 -07:00
|
|
|
let snap1_name = format!("snapshot-1-{}.tar.zst", Hash::default());
|
|
|
|
let snap2_name = format!("snapshot-3-{}.tar.zst", Hash::default());
|
|
|
|
let snap3_name = format!("snapshot-50-{}.tar.zst", Hash::default());
|
|
|
|
let snapshot_names = vec![&snap1_name, &snap2_name, &snap3_name];
|
2022-02-20 07:06:23 -08:00
|
|
|
|
|
|
|
// expecting only the newest to be retained
|
|
|
|
let expected_snapshots = vec![&snap3_name];
|
2021-09-04 05:37:29 -07:00
|
|
|
common_test_purge_old_snapshot_archives(
|
|
|
|
&snapshot_names,
|
2023-03-30 08:16:36 -07:00
|
|
|
NonZeroUsize::new(1).unwrap(),
|
2021-09-04 05:37:29 -07:00
|
|
|
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
|
|
|
&expected_snapshots,
|
|
|
|
);
|
2021-05-12 10:32:27 -07:00
|
|
|
|
2022-03-05 18:46:46 -08:00
|
|
|
// retaining 2, expecting the 2 newest to be retained
|
2022-02-20 07:06:23 -08:00
|
|
|
let expected_snapshots = vec![&snap2_name, &snap3_name];
|
2021-09-04 05:37:29 -07:00
|
|
|
common_test_purge_old_snapshot_archives(
|
|
|
|
&snapshot_names,
|
2023-03-30 08:16:36 -07:00
|
|
|
NonZeroUsize::new(2).unwrap(),
|
2021-09-04 05:37:29 -07:00
|
|
|
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
|
|
|
&expected_snapshots,
|
|
|
|
);
|
2022-02-20 07:06:23 -08:00
|
|
|
|
|
|
|
// retaining 3, all three should be retained
|
|
|
|
let expected_snapshots = vec![&snap1_name, &snap2_name, &snap3_name];
|
|
|
|
common_test_purge_old_snapshot_archives(
|
|
|
|
&snapshot_names,
|
2023-03-30 08:16:36 -07:00
|
|
|
NonZeroUsize::new(3).unwrap(),
|
2022-02-20 07:06:23 -08:00
|
|
|
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
|
|
|
&expected_snapshots,
|
|
|
|
);
|
2021-05-12 10:32:27 -07:00
|
|
|
}
|
2021-07-01 10:20:56 -07:00
|
|
|
|
2021-08-04 14:42:42 -07:00
|
|
|
/// Mimic a running node's behavior w.r.t. purging old snapshot archives. Take snapshots in a
|
|
|
|
/// loop, and periodically purge old snapshot archives. After purging, check to make sure the
|
|
|
|
/// snapshot archives on disk are correct.
|
|
|
|
#[test]
|
|
|
|
fn test_purge_old_full_snapshot_archives_in_the_loop() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2023-03-30 08:16:36 -07:00
|
|
|
let maximum_snapshots_to_retain = NonZeroUsize::new(5).unwrap();
|
2021-08-04 14:42:42 -07:00
|
|
|
let starting_slot: Slot = 42;
|
|
|
|
|
|
|
|
for slot in (starting_slot..).take(100) {
|
|
|
|
let full_snapshot_archive_file_name =
|
|
|
|
format!("snapshot-{}-{}.tar", slot, Hash::default());
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archive_path = full_snapshot_archives_dir
|
2021-08-04 14:42:42 -07:00
|
|
|
.as_ref()
|
|
|
|
.join(full_snapshot_archive_file_name);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(full_snapshot_archive_path).unwrap();
|
2021-08-04 14:42:42 -07:00
|
|
|
|
|
|
|
// don't purge-and-check until enough snapshot archives have been created
|
2023-03-30 08:16:36 -07:00
|
|
|
if slot < starting_slot + maximum_snapshots_to_retain.get() as Slot {
|
2021-08-04 14:42:42 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// purge infrequently, so there will always be snapshot archives to purge
|
2023-03-30 08:16:36 -07:00
|
|
|
if slot % (maximum_snapshots_to_retain.get() as Slot * 2) != 0 {
|
2021-08-04 14:42:42 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-09-04 05:37:29 -07:00
|
|
|
purge_old_snapshot_archives(
|
2022-05-10 13:37:41 -07:00
|
|
|
&full_snapshot_archives_dir,
|
|
|
|
&incremental_snapshot_archives_dir,
|
2021-09-04 05:37:29 -07:00
|
|
|
maximum_snapshots_to_retain,
|
2023-03-30 08:16:36 -07:00
|
|
|
NonZeroUsize::new(usize::MAX).unwrap(),
|
2021-09-04 05:37:29 -07:00
|
|
|
);
|
2022-05-10 13:37:41 -07:00
|
|
|
let mut full_snapshot_archives =
|
|
|
|
get_full_snapshot_archives(&full_snapshot_archives_dir);
|
2021-08-04 14:42:42 -07:00
|
|
|
full_snapshot_archives.sort_unstable();
|
2023-03-30 08:16:36 -07:00
|
|
|
assert_eq!(
|
|
|
|
full_snapshot_archives.len(),
|
|
|
|
maximum_snapshots_to_retain.get()
|
|
|
|
);
|
2021-08-06 18:16:06 -07:00
|
|
|
assert_eq!(full_snapshot_archives.last().unwrap().slot(), slot);
|
2022-02-20 07:06:23 -08:00
|
|
|
for (i, full_snapshot_archive) in full_snapshot_archives.iter().rev().enumerate() {
|
2021-08-06 18:16:06 -07:00
|
|
|
assert_eq!(full_snapshot_archive.slot(), slot - i as Slot);
|
2021-08-04 14:42:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-01 10:20:56 -07:00
|
|
|
#[test]
|
2021-07-22 12:40:37 -07:00
|
|
|
fn test_purge_old_incremental_snapshot_archives() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2021-09-04 05:37:29 -07:00
|
|
|
let starting_slot = 100_000;
|
|
|
|
|
|
|
|
let maximum_incremental_snapshot_archives_to_retain =
|
|
|
|
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN;
|
|
|
|
let maximum_full_snapshot_archives_to_retain = DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN;
|
|
|
|
|
|
|
|
let incremental_snapshot_interval = 100;
|
|
|
|
let num_incremental_snapshots_per_full_snapshot =
|
2023-03-30 08:16:36 -07:00
|
|
|
maximum_incremental_snapshot_archives_to_retain.get() * 2;
|
2021-09-04 05:37:29 -07:00
|
|
|
let full_snapshot_interval =
|
|
|
|
incremental_snapshot_interval * num_incremental_snapshots_per_full_snapshot;
|
|
|
|
|
|
|
|
let mut snapshot_filenames = vec![];
|
|
|
|
(starting_slot..)
|
|
|
|
.step_by(full_snapshot_interval)
|
2023-03-30 08:16:36 -07:00
|
|
|
.take(
|
|
|
|
maximum_full_snapshot_archives_to_retain
|
|
|
|
.checked_mul(NonZeroUsize::new(2).unwrap())
|
|
|
|
.unwrap()
|
|
|
|
.get(),
|
|
|
|
)
|
2021-09-04 05:37:29 -07:00
|
|
|
.for_each(|full_snapshot_slot| {
|
|
|
|
let snapshot_filename =
|
|
|
|
format!("snapshot-{}-{}.tar", full_snapshot_slot, Hash::default());
|
2022-05-10 13:37:41 -07:00
|
|
|
let snapshot_path = full_snapshot_archives_dir.path().join(&snapshot_filename);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(snapshot_path).unwrap();
|
2021-09-04 05:37:29 -07:00
|
|
|
snapshot_filenames.push(snapshot_filename);
|
|
|
|
|
|
|
|
(full_snapshot_slot..)
|
|
|
|
.step_by(incremental_snapshot_interval)
|
|
|
|
.take(num_incremental_snapshots_per_full_snapshot)
|
|
|
|
.skip(1)
|
|
|
|
.for_each(|incremental_snapshot_slot| {
|
|
|
|
let snapshot_filename = format!(
|
|
|
|
"incremental-snapshot-{}-{}-{}.tar",
|
|
|
|
full_snapshot_slot,
|
|
|
|
incremental_snapshot_slot,
|
|
|
|
Hash::default()
|
|
|
|
);
|
2022-05-10 13:37:41 -07:00
|
|
|
let snapshot_path = incremental_snapshot_archives_dir
|
|
|
|
.path()
|
|
|
|
.join(&snapshot_filename);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(snapshot_path).unwrap();
|
2021-09-04 05:37:29 -07:00
|
|
|
snapshot_filenames.push(snapshot_filename);
|
|
|
|
});
|
|
|
|
});
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2021-09-04 05:37:29 -07:00
|
|
|
purge_old_snapshot_archives(
|
2022-05-10 13:37:41 -07:00
|
|
|
full_snapshot_archives_dir.path(),
|
|
|
|
incremental_snapshot_archives_dir.path(),
|
2021-09-04 05:37:29 -07:00
|
|
|
maximum_full_snapshot_archives_to_retain,
|
|
|
|
maximum_incremental_snapshot_archives_to_retain,
|
|
|
|
);
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2021-09-04 05:37:29 -07:00
|
|
|
// Ensure correct number of full snapshot archives are purged/retained
|
|
|
|
let mut remaining_full_snapshot_archives =
|
2022-05-10 13:37:41 -07:00
|
|
|
get_full_snapshot_archives(full_snapshot_archives_dir.path());
|
2021-09-04 05:37:29 -07:00
|
|
|
assert_eq!(
|
|
|
|
remaining_full_snapshot_archives.len(),
|
2023-03-30 08:16:36 -07:00
|
|
|
maximum_full_snapshot_archives_to_retain.get(),
|
2021-09-04 05:37:29 -07:00
|
|
|
);
|
|
|
|
remaining_full_snapshot_archives.sort_unstable();
|
2022-04-27 09:40:03 -07:00
|
|
|
let latest_full_snapshot_archive_slot =
|
|
|
|
remaining_full_snapshot_archives.last().unwrap().slot();
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2021-09-04 05:37:29 -07:00
|
|
|
// Ensure correct number of incremental snapshot archives are purged/retained
|
2023-03-29 06:55:05 -07:00
|
|
|
// For each additional full snapshot archive, one additional (the newest)
|
|
|
|
// incremental snapshot archive is retained. This is accounted for by the
|
|
|
|
// `+ maximum_full_snapshot_archives_to_retain.saturating_sub(1)`
|
2021-09-04 05:37:29 -07:00
|
|
|
let mut remaining_incremental_snapshot_archives =
|
2022-05-10 13:37:41 -07:00
|
|
|
get_incremental_snapshot_archives(incremental_snapshot_archives_dir.path());
|
2021-09-04 05:37:29 -07:00
|
|
|
assert_eq!(
|
|
|
|
remaining_incremental_snapshot_archives.len(),
|
|
|
|
maximum_incremental_snapshot_archives_to_retain
|
2023-03-30 08:16:36 -07:00
|
|
|
.get()
|
|
|
|
.saturating_add(
|
|
|
|
maximum_full_snapshot_archives_to_retain
|
|
|
|
.get()
|
|
|
|
.saturating_sub(1)
|
|
|
|
)
|
2021-09-04 05:37:29 -07:00
|
|
|
);
|
|
|
|
remaining_incremental_snapshot_archives.sort_unstable();
|
2022-04-27 09:40:03 -07:00
|
|
|
remaining_incremental_snapshot_archives.reverse();
|
|
|
|
|
|
|
|
// Ensure there exists one incremental snapshot all but the latest full snapshot
|
2023-03-30 08:16:36 -07:00
|
|
|
for i in (1..maximum_full_snapshot_archives_to_retain.get()).rev() {
|
2022-04-27 09:40:03 -07:00
|
|
|
let incremental_snapshot_archive =
|
|
|
|
remaining_incremental_snapshot_archives.pop().unwrap();
|
|
|
|
|
|
|
|
let expected_base_slot =
|
|
|
|
latest_full_snapshot_archive_slot - (i * full_snapshot_interval) as u64;
|
|
|
|
assert_eq!(incremental_snapshot_archive.base_slot(), expected_base_slot);
|
|
|
|
let expected_slot = expected_base_slot
|
|
|
|
+ (full_snapshot_interval - incremental_snapshot_interval) as u64;
|
|
|
|
assert_eq!(incremental_snapshot_archive.slot(), expected_slot);
|
|
|
|
}
|
2021-09-04 05:37:29 -07:00
|
|
|
|
|
|
|
// Ensure all remaining incremental snapshots are only for the latest full snapshot
|
|
|
|
for incremental_snapshot_archive in &remaining_incremental_snapshot_archives {
|
|
|
|
assert_eq!(
|
|
|
|
incremental_snapshot_archive.base_slot(),
|
|
|
|
latest_full_snapshot_archive_slot
|
|
|
|
);
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
2021-09-04 05:37:29 -07:00
|
|
|
|
|
|
|
// Ensure the remaining incremental snapshots are at the right slot
|
|
|
|
let expected_remaing_incremental_snapshot_archive_slots =
|
|
|
|
(latest_full_snapshot_archive_slot..)
|
|
|
|
.step_by(incremental_snapshot_interval)
|
|
|
|
.take(num_incremental_snapshots_per_full_snapshot)
|
|
|
|
.skip(
|
|
|
|
num_incremental_snapshots_per_full_snapshot
|
2023-03-30 08:16:36 -07:00
|
|
|
- maximum_incremental_snapshot_archives_to_retain.get(),
|
2021-09-04 05:37:29 -07:00
|
|
|
)
|
2022-04-27 09:40:03 -07:00
|
|
|
.collect::<HashSet<_>>();
|
2021-09-04 05:37:29 -07:00
|
|
|
|
|
|
|
let actual_remaining_incremental_snapshot_archive_slots =
|
|
|
|
remaining_incremental_snapshot_archives
|
|
|
|
.iter()
|
|
|
|
.map(|snapshot| snapshot.slot())
|
2022-04-27 09:40:03 -07:00
|
|
|
.collect::<HashSet<_>>();
|
2021-09-04 05:37:29 -07:00
|
|
|
assert_eq!(
|
|
|
|
actual_remaining_incremental_snapshot_archive_slots,
|
|
|
|
expected_remaing_incremental_snapshot_archive_slots
|
|
|
|
);
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_purge_all_incremental_snapshot_archives_when_no_full_snapshot_archives() {
|
2022-05-10 13:37:41 -07:00
|
|
|
let full_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
|
|
|
let incremental_snapshot_archives_dir = tempfile::TempDir::new().unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
|
2021-09-04 05:37:29 -07:00
|
|
|
for snapshot_filenames in [
|
2021-07-22 12:40:37 -07:00
|
|
|
format!("incremental-snapshot-100-120-{}.tar", Hash::default()),
|
|
|
|
format!("incremental-snapshot-100-140-{}.tar", Hash::default()),
|
|
|
|
format!("incremental-snapshot-100-160-{}.tar", Hash::default()),
|
|
|
|
format!("incremental-snapshot-100-180-{}.tar", Hash::default()),
|
|
|
|
format!("incremental-snapshot-200-220-{}.tar", Hash::default()),
|
|
|
|
format!("incremental-snapshot-200-240-{}.tar", Hash::default()),
|
|
|
|
format!("incremental-snapshot-200-260-{}.tar", Hash::default()),
|
|
|
|
format!("incremental-snapshot-200-280-{}.tar", Hash::default()),
|
|
|
|
] {
|
2022-05-10 13:37:41 -07:00
|
|
|
let snapshot_path = incremental_snapshot_archives_dir
|
|
|
|
.path()
|
2022-11-09 11:39:38 -08:00
|
|
|
.join(snapshot_filenames);
|
2023-06-27 10:08:47 -07:00
|
|
|
fs_err::File::create(snapshot_path).unwrap();
|
2021-07-22 12:40:37 -07:00
|
|
|
}
|
|
|
|
|
2022-05-10 13:37:41 -07:00
|
|
|
purge_old_snapshot_archives(
|
|
|
|
full_snapshot_archives_dir.path(),
|
|
|
|
incremental_snapshot_archives_dir.path(),
|
2023-03-30 08:16:36 -07:00
|
|
|
NonZeroUsize::new(usize::MAX).unwrap(),
|
|
|
|
NonZeroUsize::new(usize::MAX).unwrap(),
|
2022-05-10 13:37:41 -07:00
|
|
|
);
|
2021-07-22 12:40:37 -07:00
|
|
|
|
|
|
|
let remaining_incremental_snapshot_archives =
|
2022-05-10 13:37:41 -07:00
|
|
|
get_incremental_snapshot_archives(incremental_snapshot_archives_dir.path());
|
2021-07-22 12:40:37 -07:00
|
|
|
assert!(remaining_incremental_snapshot_archives.is_empty());
|
|
|
|
}
|
|
|
|
|
2023-02-15 09:52:07 -08:00
|
|
|
#[test]
|
|
|
|
fn test_get_snapshot_accounts_hardlink_dir() {
|
|
|
|
let slot: Slot = 1;
|
|
|
|
|
|
|
|
let mut account_paths_set: HashSet<PathBuf> = HashSet::new();
|
|
|
|
|
|
|
|
let bank_snapshots_dir_tmp = tempfile::TempDir::new().unwrap();
|
|
|
|
let bank_snapshot_dir = bank_snapshots_dir_tmp.path().join(slot.to_string());
|
2023-05-05 09:36:21 -07:00
|
|
|
let accounts_hardlinks_dir = bank_snapshot_dir.join(SNAPSHOT_ACCOUNTS_HARDLINKS);
|
2023-06-26 10:14:27 -07:00
|
|
|
fs_err::create_dir_all(&accounts_hardlinks_dir).unwrap();
|
2023-02-15 09:52:07 -08:00
|
|
|
|
|
|
|
let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests();
|
|
|
|
let appendvec_filename = format!("{slot}.0");
|
|
|
|
let appendvec_path = accounts_dir.join(appendvec_filename);
|
|
|
|
|
|
|
|
let ret = get_snapshot_accounts_hardlink_dir(
|
|
|
|
&appendvec_path,
|
|
|
|
slot,
|
|
|
|
&mut account_paths_set,
|
|
|
|
&accounts_hardlinks_dir,
|
|
|
|
);
|
|
|
|
assert!(ret.is_ok());
|
|
|
|
|
|
|
|
let wrong_appendvec_path = appendvec_path
|
|
|
|
.parent()
|
|
|
|
.unwrap()
|
|
|
|
.parent()
|
|
|
|
.unwrap()
|
|
|
|
.join(appendvec_path.file_name().unwrap());
|
|
|
|
let ret = get_snapshot_accounts_hardlink_dir(
|
|
|
|
&wrong_appendvec_path,
|
|
|
|
slot,
|
|
|
|
&mut account_paths_set,
|
|
|
|
accounts_hardlinks_dir,
|
|
|
|
);
|
|
|
|
|
2023-08-30 10:48:27 -07:00
|
|
|
assert_matches!(
|
2023-07-20 15:30:19 -07:00
|
|
|
ret,
|
|
|
|
Err(GetSnapshotAccountsHardLinkDirError::GetAccountPath(_))
|
2023-08-30 10:48:27 -07:00
|
|
|
);
|
2023-02-15 09:52:07 -08:00
|
|
|
}
|
2020-01-09 16:49:36 -08:00
|
|
|
}
|