solana_runtime/
snapshot_config.rs

1use {
2    crate::snapshot_utils::{self, ArchiveFormat, SnapshotInterval, SnapshotVersion, ZstdConfig},
3    std::{num::NonZeroUsize, path::PathBuf},
4};
5
6/// Snapshot configuration and runtime information
7#[derive(Clone, Debug)]
8pub struct SnapshotConfig {
9    /// Specifies the ways thats snapshots are allowed to be used
10    pub usage: SnapshotUsage,
11
12    /// Generate a new full snapshot archive every this many slots
13    pub full_snapshot_archive_interval: SnapshotInterval,
14
15    /// Generate a new incremental snapshot archive every this many slots
16    pub incremental_snapshot_archive_interval: SnapshotInterval,
17
18    /// Path to the directory where full snapshot archives are stored
19    pub full_snapshot_archives_dir: PathBuf,
20
21    /// Path to the directory where incremental snapshot archives are stored
22    pub incremental_snapshot_archives_dir: PathBuf,
23
24    /// Path to the directory where bank snapshots are stored
25    pub bank_snapshots_dir: PathBuf,
26
27    /// The archive format to use for snapshots
28    pub archive_format: ArchiveFormat,
29
30    /// Snapshot version to generate
31    pub snapshot_version: SnapshotVersion,
32
33    /// Maximum number of full snapshot archives to retain
34    pub maximum_full_snapshot_archives_to_retain: NonZeroUsize,
35
36    /// Maximum number of incremental snapshot archives to retain
37    /// NOTE: Incremental snapshots will only be kept for the latest full snapshot
38    pub maximum_incremental_snapshot_archives_to_retain: NonZeroUsize,
39
40    // Thread niceness adjustment for snapshot packager service
41    pub packager_thread_niceness_adj: i8,
42}
43
44impl Default for SnapshotConfig {
45    fn default() -> Self {
46        Self {
47            usage: SnapshotUsage::LoadAndGenerate,
48            full_snapshot_archive_interval: SnapshotInterval::Slots(
49                snapshot_utils::DEFAULT_FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS,
50            ),
51            incremental_snapshot_archive_interval: SnapshotInterval::Slots(
52                snapshot_utils::DEFAULT_INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS,
53            ),
54            full_snapshot_archives_dir: PathBuf::default(),
55            incremental_snapshot_archives_dir: PathBuf::default(),
56            bank_snapshots_dir: PathBuf::default(),
57            archive_format: ArchiveFormat::TarZstd {
58                config: ZstdConfig::default(),
59            },
60            snapshot_version: SnapshotVersion::default(),
61            maximum_full_snapshot_archives_to_retain:
62                snapshot_utils::DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
63            maximum_incremental_snapshot_archives_to_retain:
64                snapshot_utils::DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
65            packager_thread_niceness_adj: 0,
66        }
67    }
68}
69
70impl SnapshotConfig {
71    /// A new snapshot config used for only loading at startup
72    pub fn new_load_only() -> Self {
73        Self {
74            usage: SnapshotUsage::LoadOnly,
75            full_snapshot_archive_interval: SnapshotInterval::Disabled,
76            incremental_snapshot_archive_interval: SnapshotInterval::Disabled,
77            ..Self::default()
78        }
79    }
80
81    /// A new snapshot config used to disable snapshot generation and loading at
82    /// startup
83    pub fn new_disabled() -> Self {
84        Self {
85            usage: SnapshotUsage::Disabled,
86            full_snapshot_archive_interval: SnapshotInterval::Disabled,
87            incremental_snapshot_archive_interval: SnapshotInterval::Disabled,
88            ..Self::default()
89        }
90    }
91
92    /// Should snapshots be generated?
93    pub fn should_generate_snapshots(&self) -> bool {
94        self.usage == SnapshotUsage::LoadAndGenerate
95    }
96
97    /// Should snapshots be loaded?
98    pub fn should_load_snapshots(&self) -> bool {
99        self.usage == SnapshotUsage::LoadAndGenerate || self.usage == SnapshotUsage::LoadOnly
100    }
101}
102
103/// Specify the ways that snapshots are allowed to be used
104#[derive(Debug, Clone, Eq, PartialEq)]
105pub enum SnapshotUsage {
106    /// Snapshots are never generated or loaded at startup,
107    /// instead start from genesis.
108    Disabled,
109    /// Snapshots are only used at startup, to load the accounts and bank
110    LoadOnly,
111    /// Snapshots are used everywhere; both at startup (i.e. load) and steady-state (i.e.
112    /// generate).  This enables taking snapshots.
113    LoadAndGenerate,
114}