solana_runtime/
snapshot_config.rs

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