pub struct HistoryCacheStats {
pub len: AtomicUsize,
pub evicted: AtomicU64,
pub max_sn: AtomicI64,
pub min_sn: AtomicI64,
}Expand description
Atomically updated snapshot statistics of a HistoryCache.
Note: the actual BTreeMap storage of the cache
still needs &mut self to mutate (concurrent read/write
BTreeMap mutation does not exist in std), but statistics values
(length, max/min SN, eviction counter) are carried in parallel in an
Arc<HistoryCacheStats>. Monitoring threads, SEDP tick
loops and telemetry can thus poll lock-free, without taking the
writer/reader lock.
Consistency guarantee: every mutating method of the cache updates the
atomics after the BTreeMap mutation, with Release ordering.
Readers use Acquire ordering — they see a consistent
state of the last completed cache operation, never a
half-updated state of the individual atomics.
What is not guaranteed: cross-field consistency. If a
reader reads len and then max_sn, further inserts can have
happened between the loads. That is acceptable for
monitoring; for hard wire paths (heartbeat build) the
writer lock is still taken.
Fields§
§len: AtomicUsizeNumber of changes in the cache (corresponds to BTreeMap::len).
evicted: AtomicU64Number of samples discarded by KeepLast eviction since start.
max_sn: AtomicI64Highest SN in the cache, or [STATS_SENTINEL_NO_SN] if empty.
min_sn: AtomicI64Lowest SN in the cache, or [STATS_SENTINEL_NO_SN] if empty.
Implementations§
Source§impl HistoryCacheStats
impl HistoryCacheStats
Sourcepub fn snapshot(&self) -> HistoryCacheSnapshot
pub fn snapshot(&self) -> HistoryCacheSnapshot
Snapshot of the four atomics as a plain-old-data struct. Loaded with
Acquire ordering — synchronized with the
Release store in HistoryCache::insert /
HistoryCache::remove_up_to.