Add SnapshotUsage to SnapshotConfig (#27508)

This commit is contained in:
Brooks Prumo 2022-09-02 08:56:23 -04:00 committed by GitHub
parent 4071dc3cac
commit 6684c62280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 6 deletions

View File

@ -276,7 +276,9 @@ impl AccountsHashVerifier {
) {
if accounts_package.snapshot_type.is_none()
|| pending_snapshot_package.is_none()
|| snapshot_config.is_none()
|| !snapshot_config
.map(|snapshot_config| snapshot_config.should_generate_snapshots())
.unwrap_or(false)
{
return;
};

View File

@ -946,12 +946,10 @@ fn load_bank_forks(
}
Some(SnapshotConfig {
full_snapshot_archive_interval_slots: Slot::MAX,
incremental_snapshot_archive_interval_slots: Slot::MAX,
full_snapshot_archives_dir,
incremental_snapshot_archives_dir,
bank_snapshots_dir,
..SnapshotConfig::default()
..SnapshotConfig::new_load_only()
})
};

View File

@ -745,7 +745,7 @@ impl LocalCluster {
incremental_snapshot_archive_interval_slots: Slot::MAX,
full_snapshot_archives_dir: DUMMY_SNAPSHOT_CONFIG_PATH_MARKER.into(),
bank_snapshots_dir: DUMMY_SNAPSHOT_CONFIG_PATH_MARKER.into(),
..SnapshotConfig::default()
..SnapshotConfig::new_load_only()
}
}
}

View File

@ -457,6 +457,7 @@ impl SnapshotValidatorConfig {
) -> SnapshotValidatorConfig {
assert!(accounts_hash_interval_slots > 0);
assert!(full_snapshot_archive_interval_slots > 0);
assert!(full_snapshot_archive_interval_slots != Slot::MAX);
assert!(full_snapshot_archive_interval_slots % accounts_hash_interval_slots == 0);
if incremental_snapshot_archive_interval_slots != Slot::MAX {
assert!(incremental_snapshot_archive_interval_slots > 0);

View File

@ -7,6 +7,9 @@ use {
/// Snapshot configuration and runtime information
#[derive(Clone, Debug)]
pub struct SnapshotConfig {
/// Specifies the ways thats snapshots are allowed to be used
pub usage: SnapshotUsage,
/// Generate a new full snapshot archive every this many slots
pub full_snapshot_archive_interval_slots: Slot,
@ -45,6 +48,7 @@ pub struct SnapshotConfig {
impl Default for SnapshotConfig {
fn default() -> Self {
Self {
usage: SnapshotUsage::LoadAndGenerate,
full_snapshot_archive_interval_slots:
snapshot_utils::DEFAULT_FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS,
incremental_snapshot_archive_interval_slots:
@ -63,3 +67,30 @@ impl Default for SnapshotConfig {
}
}
}
impl SnapshotConfig {
/// A new snapshot config used for only loading at startup
#[must_use]
pub fn new_load_only() -> Self {
Self {
usage: SnapshotUsage::LoadOnly,
..Self::default()
}
}
/// Should snapshots be generated?
#[must_use]
pub fn should_generate_snapshots(&self) -> bool {
self.usage == SnapshotUsage::LoadAndGenerate
}
}
/// Specify the ways that snapshots are allowed to be used
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum SnapshotUsage {
/// Snapshots are only used at startup, to load the accounts and bank
LoadOnly,
/// Snapshots are used everywhere; both at startup (i.e. load) and steady-state (i.e.
/// generate). This enables taking snapshots.
LoadAndGenerate,
}

View File

@ -50,7 +50,7 @@ use {
},
hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
runtime_config::RuntimeConfig,
snapshot_config::SnapshotConfig,
snapshot_config::{SnapshotConfig, SnapshotUsage},
snapshot_utils::{
self, ArchiveFormat, SnapshotVersion, DEFAULT_ARCHIVE_COMPRESSION,
DEFAULT_FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS,
@ -2929,6 +2929,11 @@ pub fn main() {
};
validator_config.snapshot_config = Some(SnapshotConfig {
usage: if full_snapshot_archive_interval_slots == Slot::MAX {
SnapshotUsage::LoadOnly
} else {
SnapshotUsage::LoadAndGenerate
},
full_snapshot_archive_interval_slots,
incremental_snapshot_archive_interval_slots,
bank_snapshots_dir,