Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions ledger-tool/src/ledger_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,19 @@ pub fn load_and_process_ledger(
};

let (snapshot_request_sender, snapshot_request_receiver) = crossbeam_channel::unbounded();
let snapshot_controller = Arc::new(SnapshotController::new(
snapshot_request_sender,
SnapshotConfig::new_load_only(),
bank_forks.read().unwrap().root(),
));
let snapshot_controller = if arg_matches.is_present("snapshot_slot") {
Arc::new(SnapshotController::new(
snapshot_request_sender,
SnapshotConfig::new_generate_snapshots_externally(),
bank_forks.read().unwrap().root(),
))
} else {
Arc::new(SnapshotController::new(
snapshot_request_sender,
SnapshotConfig::new_load_only(),
bank_forks.read().unwrap().root(),
))
};
let pending_snapshot_packages = Arc::new(Mutex::new(PendingSnapshotPackages::default()));
let snapshot_request_handler = SnapshotRequestHandler {
snapshot_controller: snapshot_controller.clone(),
Expand Down
9 changes: 9 additions & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,15 @@ fn main() {
exit(1);
});

// If we are creating an incremental snapshot, it must be based on a full snapshot
if is_incremental {
assert!(bank
.accounts()
.accounts_db
.latest_full_snapshot_slot()
.is_some());
}

// Snapshot creation will implicitly perform AccountsDb
// flush and clean operations. These operations cannot be
// run concurrently, so ensure ABS is stopped to avoid that
Expand Down
71 changes: 71 additions & 0 deletions snapshots/src/snapshot_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ impl SnapshotConfig {
}
}

/// A new snapshot config used for loading at startup and generating
/// snapshots during runtime. Snapshot generation intervals are disabled
/// to indicate that snapshots will be generated externally.
pub fn new_generate_snapshots_externally() -> Self {
Self {
usage: SnapshotUsage::LoadAndGenerate,
full_snapshot_archive_interval: SnapshotInterval::Disabled,
incremental_snapshot_archive_interval: SnapshotInterval::Disabled,
..Self::default()
}
}

/// A new snapshot config used to disable snapshot generation and loading at
/// startup
pub fn new_disabled() -> Self {
Expand Down Expand Up @@ -123,3 +135,62 @@ pub enum SnapshotUsage {
/// generate). This enables taking snapshots.
LoadAndGenerate,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_new_load_only() {
let cfg = SnapshotConfig::new_load_only();

assert!(!cfg.should_generate_snapshots());
assert!(cfg.should_load_snapshots());

assert!(matches!(
cfg.full_snapshot_archive_interval,
SnapshotInterval::Disabled
));
assert!(matches!(
cfg.incremental_snapshot_archive_interval,
SnapshotInterval::Disabled
));
}

#[test]
fn test_new_disabled() {
let cfg = SnapshotConfig::new_disabled();

assert!(!cfg.should_generate_snapshots());
assert!(!cfg.should_load_snapshots());

assert!(matches!(
cfg.full_snapshot_archive_interval,
SnapshotInterval::Disabled
));
assert!(matches!(
cfg.incremental_snapshot_archive_interval,
SnapshotInterval::Disabled
));
}

#[test]
fn test_new_generate_snapshots_externally() {
let cfg = SnapshotConfig::new_generate_snapshots_externally();

// Even though intervals are disabled (snapshots handled externally),
// usage indicates load+generate semantics.
assert_eq!(cfg.usage, SnapshotUsage::LoadAndGenerate);
assert!(cfg.should_generate_snapshots());
assert!(cfg.should_load_snapshots());

assert!(matches!(
cfg.full_snapshot_archive_interval,
SnapshotInterval::Disabled
));
assert!(matches!(
cfg.incremental_snapshot_archive_interval,
SnapshotInterval::Disabled
));
}
}
Loading