pub struct CheckpointPruner { /* private fields */ }Expand description
Applies a RetentionPolicy to a collection of CheckpointRecords and
determines which records should be deleted.
§Usage
use ipfrs_tensorlogic::checkpoint_manager::{CheckpointRecord, CheckpointPruner, RetentionPolicy};
let records = vec![
CheckpointRecord { id: "cp_1".into(), cid: "Qm1".into(), round: 1,
created_at_ms: 0, size_bytes: 100, crc32: 0, is_pinned: false },
CheckpointRecord { id: "cp_2".into(), cid: "Qm2".into(), round: 2,
created_at_ms: 0, size_bytes: 100, crc32: 0, is_pinned: false },
];
let policy = RetentionPolicy { keep_last_n: 1, ..Default::default() };
let mut pruner = CheckpointPruner::new(records, policy);
let to_delete = pruner.prune();
assert_eq!(to_delete.len(), 1);
assert_eq!(to_delete[0].id, "cp_1");Implementations§
Source§impl CheckpointPruner
impl CheckpointPruner
Sourcepub fn new(records: Vec<CheckpointRecord>, policy: RetentionPolicy) -> Self
pub fn new(records: Vec<CheckpointRecord>, policy: RetentionPolicy) -> Self
Create a new pruner. Records are sorted by round ascending.
Sourcepub fn with_now_ms(self, now_ms: u64) -> Self
pub fn with_now_ms(self, now_ms: u64) -> Self
Override the “current time” used for age-based pruning decisions.
If not called, now_ms defaults to 0, which means every checkpoint
has an age ≥ 0 and the min_age_ms guard applies correctly.
Sourcepub fn prune(&mut self) -> Vec<CheckpointRecord>
pub fn prune(&mut self) -> Vec<CheckpointRecord>
Apply the retention policy and return the list of records to delete.
After the call the pruner’s internal record list contains only the surviving records; repeated calls therefore return an empty list.
Sourcepub fn surviving_count(&self) -> usize
pub fn surviving_count(&self) -> usize
Number of records currently held by the pruner (i.e. after any pruning).
Sourcepub fn total_bytes(&self) -> u64
pub fn total_bytes(&self) -> u64
Sum of size_bytes across all records currently held by the pruner.
Sourcepub fn pinned_count(&self) -> usize
pub fn pinned_count(&self) -> usize
Number of pinned records currently held by the pruner.
Sourcepub fn records(&self) -> &[CheckpointRecord]
pub fn records(&self) -> &[CheckpointRecord]
Read-only access to the surviving records.
Auto Trait Implementations§
impl Freeze for CheckpointPruner
impl RefUnwindSafe for CheckpointPruner
impl Send for CheckpointPruner
impl Sync for CheckpointPruner
impl Unpin for CheckpointPruner
impl UnsafeUnpin for CheckpointPruner
impl UnwindSafe for CheckpointPruner
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more