Add fn to check when to take snapshots (#19682)
This commit is contained in:
parent
85571c93a4
commit
4a5f83d3a7
|
@ -722,7 +722,8 @@ mod tests {
|
|||
|
||||
// Since AccountsBackgroundService isn't running, manually make a full snapshot archive
|
||||
// at the right interval
|
||||
if slot % FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS == 0 {
|
||||
if snapshot_utils::should_take_full_snapshot(slot, FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS)
|
||||
{
|
||||
make_full_snapshot_archive(&bank, &snapshot_test_config.snapshot_config).unwrap();
|
||||
}
|
||||
// Similarly, make an incremental snapshot archive at the right interval, but only if
|
||||
|
@ -730,9 +731,11 @@ mod tests {
|
|||
// taken at this slot.
|
||||
//
|
||||
// Then, after making an incremental snapshot, restore the bank and verify it is correct
|
||||
else if slot % INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS == 0
|
||||
&& last_full_snapshot_slot.is_some()
|
||||
&& slot != last_full_snapshot_slot.unwrap()
|
||||
else if snapshot_utils::should_take_incremental_snapshot(
|
||||
slot,
|
||||
INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS,
|
||||
last_full_snapshot_slot,
|
||||
) && slot != last_full_snapshot_slot.unwrap()
|
||||
{
|
||||
make_incremental_snapshot_archive(
|
||||
&bank,
|
||||
|
|
|
@ -1188,7 +1188,10 @@ fn load_frozen_forks(
|
|||
|
||||
if let Some(snapshot_config) = snapshot_config {
|
||||
let block_height = new_root_bank.block_height();
|
||||
if block_height % snapshot_config.full_snapshot_archive_interval_slots == 0 {
|
||||
if snapshot_utils::should_take_full_snapshot(
|
||||
block_height,
|
||||
snapshot_config.full_snapshot_archive_interval_slots,
|
||||
) {
|
||||
*last_full_snapshot_slot = Some(*root);
|
||||
new_root_bank.clean_accounts(true, true, *last_full_snapshot_slot);
|
||||
snapshot_utils::snapshot_bank(
|
||||
|
|
|
@ -172,19 +172,18 @@ impl SnapshotRequestHandler {
|
|||
}
|
||||
|
||||
let block_height = snapshot_root_bank.block_height();
|
||||
let snapshot_type = if block_height
|
||||
% self.snapshot_config.full_snapshot_archive_interval_slots
|
||||
== 0
|
||||
{
|
||||
let snapshot_type = if snapshot_utils::should_take_full_snapshot(
|
||||
block_height,
|
||||
self.snapshot_config.full_snapshot_archive_interval_slots,
|
||||
) {
|
||||
*last_full_snapshot_slot = Some(snapshot_root_bank.slot());
|
||||
Some(SnapshotType::FullSnapshot)
|
||||
} else if block_height
|
||||
% self
|
||||
.snapshot_config
|
||||
.incremental_snapshot_archive_interval_slots
|
||||
== 0
|
||||
&& last_full_snapshot_slot.is_some()
|
||||
{
|
||||
} else if snapshot_utils::should_take_incremental_snapshot(
|
||||
block_height,
|
||||
self.snapshot_config
|
||||
.incremental_snapshot_archive_interval_slots,
|
||||
*last_full_snapshot_slot,
|
||||
) {
|
||||
Some(SnapshotType::IncrementalSnapshot(
|
||||
last_full_snapshot_slot.unwrap(),
|
||||
))
|
||||
|
|
|
@ -1795,6 +1795,22 @@ pub fn package_and_archive_incremental_snapshot(
|
|||
))
|
||||
}
|
||||
|
||||
pub fn should_take_full_snapshot(
|
||||
block_height: Slot,
|
||||
full_snapshot_archive_interval_slots: Slot,
|
||||
) -> bool {
|
||||
block_height % full_snapshot_archive_interval_slots == 0
|
||||
}
|
||||
|
||||
pub fn should_take_incremental_snapshot(
|
||||
block_height: Slot,
|
||||
incremental_snapshot_archive_interval_slots: Slot,
|
||||
last_full_snapshot_slot: Option<Slot>,
|
||||
) -> bool {
|
||||
block_height % incremental_snapshot_archive_interval_slots == 0
|
||||
&& last_full_snapshot_slot.is_some()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in New Issue