Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validator cli: Clarifies snapshot intervals #2128

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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),
Comment on lines +1668 to +1670
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this big match, note that there's a prepended ! on the no_incremental_snapshots. So the logic is based around yes incremental snapshots, thus avoiding double negatives.

) {
(_, 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()
},
);
Comment on lines +1730 to +1742
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always log the snapshot values now.


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()
},
Comment on lines -1725 to -1737
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And since we're always logging the snapshot values, no need to print them here again.

\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