pub struct BlockDeduplicationTracker { /* private fields */ }Expand description
Tracks block deduplication across DAG nodes.
Maintains a mapping from CID to RefEntry, updated as blocks are
referenced or dereferenced. Useful for GC safety checks and for
reporting storage savings due to content-addressed deduplication.
Implementations§
Source§impl BlockDeduplicationTracker
impl BlockDeduplicationTracker
Sourcepub fn add_ref(&mut self, cid: &str, size_bytes: u64, now_secs: u64)
pub fn add_ref(&mut self, cid: &str, size_bytes: u64, now_secs: u64)
Records a reference to cid.
- If the block is already tracked, its
ref_countis incremented andlast_seen_secsis updated. - If the block is new, it is inserted with
ref_count = 1.
Sourcepub fn remove_ref(&mut self, cid: &str) -> bool
pub fn remove_ref(&mut self, cid: &str) -> bool
Removes one reference to cid.
- If
ref_count > 1, it is decremented. - If
ref_count == 1, the entry is removed entirely.
Returns true if the CID was found, false otherwise.
Sourcepub fn ref_count(&self, cid: &str) -> u32
pub fn ref_count(&self, cid: &str) -> u32
Returns the current reference count for cid, or 0 if not tracked.
Sourcepub fn is_safe_to_delete(&self, cid: &str) -> bool
pub fn is_safe_to_delete(&self, cid: &str) -> bool
Returns true if it is safe for GC to delete cid.
A block is safe to delete when it is not present in the tracker (no
live references) or its stored ref_count has somehow reached 0.
Returns all entries with ref_count > 1, sorted by savings_bytes descending.
Sourcepub fn unique_blocks(&self) -> Vec<&RefEntry>
pub fn unique_blocks(&self) -> Vec<&RefEntry>
Returns all entries with ref_count == 1.
Sourcepub fn stats(&self) -> DedupStats
pub fn stats(&self) -> DedupStats
Returns a snapshot of current deduplication statistics.
Sourcepub fn top_savings(&self, n: usize) -> Vec<&RefEntry>
pub fn top_savings(&self, n: usize) -> Vec<&RefEntry>
Returns the top n entries by savings_bytes descending.
Sourcepub fn prune_unreferenced(&mut self) -> usize
pub fn prune_unreferenced(&mut self) -> usize
Removes all entries whose ref_count is 0.
Returns the number of entries removed.
Trait Implementations§
Source§impl Debug for BlockDeduplicationTracker
impl Debug for BlockDeduplicationTracker
Source§impl Default for BlockDeduplicationTracker
impl Default for BlockDeduplicationTracker
Source§fn default() -> BlockDeduplicationTracker
fn default() -> BlockDeduplicationTracker
Auto Trait Implementations§
impl Freeze for BlockDeduplicationTracker
impl RefUnwindSafe for BlockDeduplicationTracker
impl Send for BlockDeduplicationTracker
impl Sync for BlockDeduplicationTracker
impl Unpin for BlockDeduplicationTracker
impl UnsafeUnpin for BlockDeduplicationTracker
impl UnwindSafe for BlockDeduplicationTracker
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