pub struct AccessTracker { /* private fields */ }Expand description
Tracks access frequency and recency for storage tiering and eviction.
Implementations§
Source§impl AccessTracker
impl AccessTracker
Sourcepub fn new(config: TrackerConfig) -> Self
pub fn new(config: TrackerConfig) -> Self
Create a new tracker with the provided configuration.
Sourcepub fn record_access(&mut self, cid: &str, size: u64, now: u64)
pub fn record_access(&mut self, cid: &str, size: u64, now: u64)
Record one access to cid at logical time now (seconds).
If this is the first access for cid a new AccessRecord is
created. Otherwise the existing record is updated in-place and its
score is recomputed. After recording, capacity is enforced.
Sourcepub fn compute_score(&self, record: &AccessRecord, now: u64) -> f64
pub fn compute_score(&self, record: &AccessRecord, now: u64) -> f64
Compute the temperature score for record at logical time now.
Formula:
score = access_count / (1 + time_since_last_access * decay_factor)recency_weight from the config scales the final result so that
operators can tune how much recency matters relative to raw frequency.
Sourcepub fn update_score(&mut self, cid: &str, now: u64)
pub fn update_score(&mut self, cid: &str, now: u64)
Recompute and persist the score for the CID identified by cid.
This is useful when time has advanced without any new accesses.
Sourcepub fn is_hot(&self, cid: &str, now: u64) -> bool
pub fn is_hot(&self, cid: &str, now: u64) -> bool
Returns true when the CID’s current score exceeds hot_threshold.
Sourcepub fn is_cold(&self, cid: &str, now: u64) -> bool
pub fn is_cold(&self, cid: &str, now: u64) -> bool
Returns true when the CID’s current score is below cold_threshold.
Sourcepub fn hot_blocks(&self, now: u64) -> Vec<&AccessRecord>
pub fn hot_blocks(&self, now: u64) -> Vec<&AccessRecord>
All records currently scoring at or above hot_threshold.
Sourcepub fn cold_blocks(&self, now: u64) -> Vec<&AccessRecord>
pub fn cold_blocks(&self, now: u64) -> Vec<&AccessRecord>
All records currently scoring below cold_threshold.
Sourcepub fn evict_coldest(&mut self, now: u64) -> Option<AccessRecord>
pub fn evict_coldest(&mut self, now: u64) -> Option<AccessRecord>
Remove and return the single record with the lowest temperature score.
Returns None when the tracker is empty.
Sourcepub fn enforce_capacity(&mut self, now: u64) -> usize
pub fn enforce_capacity(&mut self, now: u64) -> usize
Evict records until records.len() <= max_records.
Returns the number of records evicted in this call.
Sourcepub fn get_record(&self, cid: &str) -> Option<&AccessRecord>
pub fn get_record(&self, cid: &str) -> Option<&AccessRecord>
Look up the record for cid, if present.
Sourcepub fn record_count(&self) -> usize
pub fn record_count(&self) -> usize
Number of records currently held.
Sourcepub fn stats(&self) -> &TrackerStats
pub fn stats(&self) -> &TrackerStats
Reference to the current aggregate statistics.
Sourcepub fn top_accessed(&self, n: usize) -> Vec<&AccessRecord>
pub fn top_accessed(&self, n: usize) -> Vec<&AccessRecord>
The n most-accessed records, sorted by access_count descending.
If n exceeds the number of records, all records are returned.
Auto Trait Implementations§
impl Freeze for AccessTracker
impl RefUnwindSafe for AccessTracker
impl Send for AccessTracker
impl Sync for AccessTracker
impl Unpin for AccessTracker
impl UnsafeUnpin for AccessTracker
impl UnwindSafe for AccessTracker
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