pub struct StorageAccessLogger {
pub entries: VecDeque<AccessEntry>,
pub max_entries: usize,
pub stats: AccessStats,
pub next_id: u64,
}Expand description
Bounded, structured audit log for storage operations.
Maintains a FIFO ring of AccessEntry records up to max_entries in
length. When the ring is full, the oldest entry is evicted before the new
one is appended. All mutations also update the running AccessStats.
Fields§
§entries: VecDeque<AccessEntry>The ring of logged entries.
max_entries: usizeMaximum number of entries retained before oldest entries are dropped.
stats: AccessStatsCumulative statistics over the lifetime of this logger (cleared with Self::clear).
next_id: u64Monotonic counter for the next AccessEntry::entry_id.
Implementations§
Source§impl StorageAccessLogger
impl StorageAccessLogger
Sourcepub fn new(max_entries: usize) -> Self
pub fn new(max_entries: usize) -> Self
Create a new logger with the given capacity.
max_entries sets the maximum number of entries held in memory.
When this limit is reached the oldest entry is dropped on each new
Self::log call. The default value used by higher-level helpers is
5000.
Sourcepub fn log(
&mut self,
cid: String,
op: AccessOp,
size_bytes: Option<u64>,
latency_us: u64,
success: bool,
timestamp_secs: u64,
caller_tag: String,
)
pub fn log( &mut self, cid: String, op: AccessOp, size_bytes: Option<u64>, latency_us: u64, success: bool, timestamp_secs: u64, caller_tag: String, )
Record a storage operation.
§Parameters
cid– Content identifier for the block involved.op– The operation type.size_bytes– Bytes written (meaningful for Put/BatchPut; passNoneotherwise).latency_us– Operation latency in microseconds.success– Whether the operation completed without error.timestamp_secs– Unix timestamp (seconds).caller_tag– String label for the calling component.
Sourcepub fn recent(&self, n: usize) -> Vec<&AccessEntry>
pub fn recent(&self, n: usize) -> Vec<&AccessEntry>
Return references to the last n entries in chronological order.
If n exceeds the number of stored entries, all entries are returned.
Sourcepub fn entries_for_cid(&self, cid: &str) -> Vec<&AccessEntry>
pub fn entries_for_cid(&self, cid: &str) -> Vec<&AccessEntry>
Return all entries whose AccessEntry::cid matches cid.
Sourcepub fn entries_for_caller(&self, caller: &str) -> Vec<&AccessEntry>
pub fn entries_for_caller(&self, caller: &str) -> Vec<&AccessEntry>
Return all entries whose AccessEntry::caller_tag matches caller.
Sourcepub fn detect_pattern(&self) -> AccessPattern
pub fn detect_pattern(&self) -> AccessPattern
Analyse the last 10 entries to detect an AccessPattern.
Detection priority:
- Repeated — if any single CID appears 3 or more times.
- Random — fallback (Sequential detection is deferred).
Sourcepub fn stats(&self) -> &AccessStats
pub fn stats(&self) -> &AccessStats
Return a reference to the current AccessStats.
Auto Trait Implementations§
impl Freeze for StorageAccessLogger
impl RefUnwindSafe for StorageAccessLogger
impl Send for StorageAccessLogger
impl Sync for StorageAccessLogger
impl Unpin for StorageAccessLogger
impl UnsafeUnpin for StorageAccessLogger
impl UnwindSafe for StorageAccessLogger
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