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
|
// Since AccountsBackgroundService isn't running, manually make a full snapshot archive
|
||||||
// at the right interval
|
// 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();
|
make_full_snapshot_archive(&bank, &snapshot_test_config.snapshot_config).unwrap();
|
||||||
}
|
}
|
||||||
// Similarly, make an incremental snapshot archive at the right interval, but only if
|
// Similarly, make an incremental snapshot archive at the right interval, but only if
|
||||||
|
@ -730,9 +731,11 @@ mod tests {
|
||||||
// taken at this slot.
|
// taken at this slot.
|
||||||
//
|
//
|
||||||
// Then, after making an incremental snapshot, restore the bank and verify it is correct
|
// Then, after making an incremental snapshot, restore the bank and verify it is correct
|
||||||
else if slot % INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS == 0
|
else if snapshot_utils::should_take_incremental_snapshot(
|
||||||
&& last_full_snapshot_slot.is_some()
|
slot,
|
||||||
&& slot != last_full_snapshot_slot.unwrap()
|
INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS,
|
||||||
|
last_full_snapshot_slot,
|
||||||
|
) && slot != last_full_snapshot_slot.unwrap()
|
||||||
{
|
{
|
||||||
make_incremental_snapshot_archive(
|
make_incremental_snapshot_archive(
|
||||||
&bank,
|
&bank,
|
||||||
|
|
|
@ -1188,7 +1188,10 @@ fn load_frozen_forks(
|
||||||
|
|
||||||
if let Some(snapshot_config) = snapshot_config {
|
if let Some(snapshot_config) = snapshot_config {
|
||||||
let block_height = new_root_bank.block_height();
|
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);
|
*last_full_snapshot_slot = Some(*root);
|
||||||
new_root_bank.clean_accounts(true, true, *last_full_snapshot_slot);
|
new_root_bank.clean_accounts(true, true, *last_full_snapshot_slot);
|
||||||
snapshot_utils::snapshot_bank(
|
snapshot_utils::snapshot_bank(
|
||||||
|
|
|
@ -172,19 +172,18 @@ impl SnapshotRequestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
let block_height = snapshot_root_bank.block_height();
|
let block_height = snapshot_root_bank.block_height();
|
||||||
let snapshot_type = if block_height
|
let snapshot_type = if snapshot_utils::should_take_full_snapshot(
|
||||||
% self.snapshot_config.full_snapshot_archive_interval_slots
|
block_height,
|
||||||
== 0
|
self.snapshot_config.full_snapshot_archive_interval_slots,
|
||||||
{
|
) {
|
||||||
*last_full_snapshot_slot = Some(snapshot_root_bank.slot());
|
*last_full_snapshot_slot = Some(snapshot_root_bank.slot());
|
||||||
Some(SnapshotType::FullSnapshot)
|
Some(SnapshotType::FullSnapshot)
|
||||||
} else if block_height
|
} else if snapshot_utils::should_take_incremental_snapshot(
|
||||||
% self
|
block_height,
|
||||||
.snapshot_config
|
self.snapshot_config
|
||||||
.incremental_snapshot_archive_interval_slots
|
.incremental_snapshot_archive_interval_slots,
|
||||||
== 0
|
*last_full_snapshot_slot,
|
||||||
&& last_full_snapshot_slot.is_some()
|
) {
|
||||||
{
|
|
||||||
Some(SnapshotType::IncrementalSnapshot(
|
Some(SnapshotType::IncrementalSnapshot(
|
||||||
last_full_snapshot_slot.unwrap(),
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in New Issue