Skip to content

Commit

Permalink
validator cli: Clarifies snapshot intervals (solana-labs#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Jul 16, 2024
1 parent 147c97d commit 4c7996c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 45 deletions.
24 changes: 13 additions & 11 deletions validator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,30 +499,32 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.long("no-incremental-snapshots")
.takes_value(false)
.help("Disable incremental snapshots")
.long_help(
"Disable incremental snapshots by setting this flag. When enabled, \
--snapshot-interval-slots will set the incremental snapshot interval. To set \
the full snapshot interval, use --full-snapshot-interval-slots.",
),
)
.arg(
Arg::with_name("incremental_snapshot_interval_slots")
.long("incremental-snapshot-interval-slots")
.alias("snapshot-interval-slots")
Arg::with_name("snapshot_interval_slots")
.long("snapshot-interval-slots")
.alias("incremental-snapshot-interval-slots")
.value_name("NUMBER")
.takes_value(true)
.default_value(&default_args.incremental_snapshot_archive_interval_slots)
.help("Number of slots between generating snapshots, 0 to disable snapshots"),
.help("Number of slots between generating snapshots")
.long_help(
"Number of slots between generating snapshots. \
If incremental snapshots are enabled, this sets the incremental snapshot interval. \
If incremental snapshots are disabled, this sets the full snapshot interval. \
Setting this to 0 disables all snapshots.",
),
)
.arg(
Arg::with_name("full_snapshot_interval_slots")
.long("full-snapshot-interval-slots")
.value_name("NUMBER")
.takes_value(true)
.default_value(&default_args.full_snapshot_archive_interval_slots)
.help(
.help("Number of slots between generating full snapshots")
.long_help(
"Number of slots between generating full snapshots. Must be a multiple of the \
incremental snapshot interval.",
incremental snapshot interval. Only used when incremental snapshots are enabled.",
),
)
.arg(
Expand Down
84 changes: 50 additions & 34 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,27 +1665,42 @@ pub fn main() {
})
});

let incremental_snapshot_interval_slots =
value_t_or_exit!(matches, "incremental_snapshot_interval_slots", u64);
let (full_snapshot_archive_interval_slots, incremental_snapshot_archive_interval_slots) =
if incremental_snapshot_interval_slots > 0 {
if !matches.is_present("no_incremental_snapshots") {
(
value_t_or_exit!(matches, "full_snapshot_interval_slots", u64),
incremental_snapshot_interval_slots,
)
} else {
(
incremental_snapshot_interval_slots,
DISABLED_SNAPSHOT_ARCHIVE_INTERVAL,
)
}
} else {
let (full_snapshot_archive_interval_slots, incremental_snapshot_archive_interval_slots) = match (
!matches.is_present("no_incremental_snapshots"),
value_t_or_exit!(matches, "snapshot_interval_slots", u64),
) {
(_, 0) => {
// snapshots are disabled
(
DISABLED_SNAPSHOT_ARCHIVE_INTERVAL,
DISABLED_SNAPSHOT_ARCHIVE_INTERVAL,
)
};
}
(true, incremental_snapshot_interval_slots) => {
// incremental snapshots are enabled
// use --snapshot-interval-slots for the incremental snapshot interval
(
value_t_or_exit!(matches, "full_snapshot_interval_slots", u64),
incremental_snapshot_interval_slots,
)
}
(false, full_snapshot_interval_slots) => {
// incremental snapshots are *disabled*
// use --snapshot-interval-slots for the *full* snapshot interval
// also warn if --full-snapshot-interval-slots was specified
if matches.occurrences_of("full_snapshot_interval_slots") > 0 {
warn!(
"Incremental snapshots are disabled, yet --full-snapshot-interval-slots was specified! \
Note that --full-snapshot-interval-slots is *ignored* when incremental snapshots are disabled. \
Use --snapshot-interval-slots instead.",
);
}
(
full_snapshot_interval_slots,
DISABLED_SNAPSHOT_ARCHIVE_INTERVAL,
)
}
};

validator_config.snapshot_config = SnapshotConfig {
usage: if full_snapshot_archive_interval_slots == DISABLED_SNAPSHOT_ARCHIVE_INTERVAL {
Expand All @@ -1712,29 +1727,30 @@ pub fn main() {
incremental_snapshot_archive_interval_slots,
);

info!(
"Snapshot configuration: full snapshot interval: {} slots, incremental snapshot interval: {} slots",
if full_snapshot_archive_interval_slots == DISABLED_SNAPSHOT_ARCHIVE_INTERVAL {
"disabled".to_string()
} else {
full_snapshot_archive_interval_slots.to_string()
},
if incremental_snapshot_archive_interval_slots == DISABLED_SNAPSHOT_ARCHIVE_INTERVAL {
"disabled".to_string()
} else {
incremental_snapshot_archive_interval_slots.to_string()
},
);

if !is_snapshot_config_valid(
&validator_config.snapshot_config,
validator_config.accounts_hash_interval_slots,
) {
eprintln!(
"Invalid snapshot configuration provided: snapshot intervals are incompatible. \
\n\t- full snapshot interval MUST be a multiple of incremental snapshot interval (if \
enabled)\
\n\t- full snapshot interval MUST be larger than incremental snapshot \
interval (if enabled)\
\nSnapshot configuration values:\
\n\tfull snapshot interval: {}\
\n\tincremental snapshot interval: {}",
if full_snapshot_archive_interval_slots == DISABLED_SNAPSHOT_ARCHIVE_INTERVAL {
"disabled".to_string()
} else {
full_snapshot_archive_interval_slots.to_string()
},
if incremental_snapshot_archive_interval_slots == DISABLED_SNAPSHOT_ARCHIVE_INTERVAL {
"disabled".to_string()
} else {
incremental_snapshot_archive_interval_slots.to_string()
},
\n\t- full snapshot interval MUST be a multiple of incremental snapshot interval \
(if enabled) \
\n\t- full snapshot interval MUST be larger than incremental snapshot interval \
(if enabled)",
);
exit(1);
}
Expand Down

0 comments on commit 4c7996c

Please sign in to comment.