Add CLI options and runtime support for selection of output snapshot version. (#10536)
This commit is contained in:
committed by
GitHub
parent
b172b3369e
commit
6d81eede93
@@ -16,6 +16,8 @@ use std::{
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
pub use crate::snapshot_utils::SnapshotVersion;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum CompressionType {
|
||||
Bzip2,
|
||||
@@ -36,6 +38,9 @@ pub struct SnapshotConfig {
|
||||
pub snapshot_path: PathBuf,
|
||||
|
||||
pub compression: CompressionType,
|
||||
|
||||
// Snapshot version to generate
|
||||
pub snapshot_version: SnapshotVersion,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -302,7 +307,12 @@ impl BankForks {
|
||||
|
||||
let storages: Vec<_> = bank.get_snapshot_storages();
|
||||
let mut add_snapshot_time = Measure::start("add-snapshot-ms");
|
||||
snapshot_utils::add_snapshot(&config.snapshot_path, &bank, &storages)?;
|
||||
snapshot_utils::add_snapshot(
|
||||
&config.snapshot_path,
|
||||
&bank,
|
||||
&storages,
|
||||
config.snapshot_version,
|
||||
)?;
|
||||
add_snapshot_time.stop();
|
||||
inc_new_counter_info!("add-snapshot-ms", add_snapshot_time.as_ms() as usize);
|
||||
|
||||
@@ -321,6 +331,7 @@ impl BankForks {
|
||||
&config.snapshot_package_output_path,
|
||||
storages,
|
||||
config.compression.clone(),
|
||||
config.snapshot_version,
|
||||
)?;
|
||||
|
||||
accounts_package_sender.send(package)?;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
use crate::bank_forks::CompressionType;
|
||||
use crate::snapshot_utils::SnapshotVersion;
|
||||
use crate::{accounts_db::SnapshotStorages, bank::BankSlotDelta};
|
||||
use solana_sdk::clock::Slot;
|
||||
use solana_sdk::hash::Hash;
|
||||
@@ -22,6 +23,7 @@ pub struct AccountsPackage {
|
||||
pub tar_output_file: PathBuf,
|
||||
pub hash: Hash,
|
||||
pub compression: CompressionType,
|
||||
pub snapshot_version: SnapshotVersion,
|
||||
}
|
||||
|
||||
impl AccountsPackage {
|
||||
@@ -34,6 +36,7 @@ impl AccountsPackage {
|
||||
tar_output_file: PathBuf,
|
||||
hash: Hash,
|
||||
compression: CompressionType,
|
||||
snapshot_version: SnapshotVersion,
|
||||
) -> Self {
|
||||
Self {
|
||||
root,
|
||||
@@ -44,6 +47,7 @@ impl AccountsPackage {
|
||||
tar_output_file,
|
||||
hash,
|
||||
compression,
|
||||
snapshot_version,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ pub const TAR_VERSION_FILE: &str = "version";
|
||||
const MAX_SNAPSHOT_DATA_FILE_SIZE: u64 = 32 * 1024 * 1024 * 1024; // 32 GiB
|
||||
const VERSION_STRING_V1_1_0: &str = "1.1.0";
|
||||
const VERSION_STRING_V1_2_0: &str = "1.2.0";
|
||||
const OUTPUT_SNAPSHOT_VERSION: SnapshotVersion = SnapshotVersion::V1_2_0;
|
||||
const DEFAULT_SNAPSHOT_VERSION: SnapshotVersion = SnapshotVersion::V1_2_0;
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
pub enum SnapshotVersion {
|
||||
@@ -45,6 +45,18 @@ pub enum SnapshotVersion {
|
||||
V1_2_0,
|
||||
}
|
||||
|
||||
impl Default for SnapshotVersion {
|
||||
fn default() -> Self {
|
||||
DEFAULT_SNAPSHOT_VERSION
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SnapshotVersion {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str(From::from(*self))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SnapshotVersion> for &'static str {
|
||||
fn from(snapshot_version: SnapshotVersion) -> &'static str {
|
||||
match snapshot_version {
|
||||
@@ -58,6 +70,15 @@ impl FromStr for SnapshotVersion {
|
||||
type Err = &'static str;
|
||||
|
||||
fn from_str(version_string: &str) -> std::result::Result<Self, Self::Err> {
|
||||
// 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
|
||||
};
|
||||
match version_string {
|
||||
VERSION_STRING_V1_1_0 => Ok(SnapshotVersion::V1_1_0),
|
||||
VERSION_STRING_V1_2_0 => Ok(SnapshotVersion::V1_2_0),
|
||||
@@ -134,6 +155,7 @@ pub fn package_snapshot<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||
snapshot_package_output_path: P,
|
||||
snapshot_storages: SnapshotStorages,
|
||||
compression: CompressionType,
|
||||
snapshot_version: SnapshotVersion,
|
||||
) -> Result<AccountsPackage> {
|
||||
// Hard link all the snapshots we need for this package
|
||||
let snapshot_hard_links_dir = tempfile::tempdir_in(snapshot_path)?;
|
||||
@@ -164,6 +186,7 @@ pub fn package_snapshot<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||
snapshot_package_output_file,
|
||||
bank.get_accounts_hash(),
|
||||
compression,
|
||||
snapshot_version,
|
||||
);
|
||||
|
||||
Ok(package)
|
||||
@@ -234,7 +257,7 @@ pub fn archive_snapshot_package(snapshot_package: &AccountsPackage) -> Result<()
|
||||
// Write version file
|
||||
{
|
||||
let mut f = std::fs::File::create(staging_version_file)?;
|
||||
f.write_all(OUTPUT_SNAPSHOT_VERSION.as_str().as_bytes())?;
|
||||
f.write_all(snapshot_package.snapshot_version.as_str().as_bytes())?;
|
||||
}
|
||||
|
||||
let (compression_option, file_ext) = get_compression_ext(&snapshot_package.compression);
|
||||
@@ -417,6 +440,7 @@ pub fn add_snapshot<P: AsRef<Path>>(
|
||||
snapshot_path: P,
|
||||
bank: &Bank,
|
||||
snapshot_storages: &[SnapshotStorage],
|
||||
snapshot_version: SnapshotVersion,
|
||||
) -> Result<SlotSnapshotPaths> {
|
||||
let slot = bank.slot();
|
||||
// snapshot_path/slot
|
||||
@@ -432,13 +456,12 @@ pub fn add_snapshot<P: AsRef<Path>>(
|
||||
|
||||
let mut bank_serialize = Measure::start("bank-serialize-ms");
|
||||
let bank_snapshot_serializer = move |stream: &mut BufWriter<File>| -> Result<()> {
|
||||
let serde_style = match snapshot_version {
|
||||
SnapshotVersion::V1_1_0 => SerdeStyle::OLDER,
|
||||
SnapshotVersion::V1_2_0 => SerdeStyle::NEWER,
|
||||
};
|
||||
serialize_into(stream.by_ref(), bank)?;
|
||||
bankrc_to_stream(
|
||||
SerdeStyle::NEWER,
|
||||
stream.by_ref(),
|
||||
&bank.rc,
|
||||
snapshot_storages,
|
||||
)?;
|
||||
bankrc_to_stream(serde_style, stream.by_ref(), &bank.rc, snapshot_storages)?;
|
||||
Ok(())
|
||||
};
|
||||
let consumed_size =
|
||||
|
Reference in New Issue
Block a user