metrale_telemetry/prefix_cache/
tier_evict.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-26: [`TierEvict`]: what an SSM spill-tier eviction did with its
4//! victim.
5//!
6//! Owner: telemetry.
7//! Invariants: none beyond the types.
8
9/// 2026-09-26: Outcome of
10/// [`crate::prefix_cache::PrefixCache::evict_snapshot_to_tier`].
11///
12/// The depth gate (`min_tokens`, which the model engine derives from
13/// `METRALE_SSM_SPILL_MIN_TOKENS`) is applied when the victim is chosen, so a
14/// shallow victim's entry is removed rather than left findable with no stored
15/// bytes. Either arm returns the victim's slot for the caller to free.
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum TierEvict {
18    /// 2026-09-26: The entry is marked spilled and stays findable; the caller
19    /// moves the bytes to the tier.
20    Spill {
21        /// 2026-09-26: The victim's snapshot slot: spill from it, then free it.
22        slot: usize,
23        /// 2026-09-26: Tier key: the entry's prefix hash.
24        key: u64,
25        /// 2026-09-26: Victim depth in tokens.
26        depth: usize,
27    },
28    /// 2026-09-26: Shallower than `min_tokens`: the entry was removed, and
29    /// `tier_spills` was not incremented.
30    Drop {
31        /// 2026-09-26: The victim's snapshot slot, for the caller to free.
32        slot: usize,
33        /// 2026-09-26: Victim depth in tokens.
34        depth: usize,
35    },
36}
37
38impl TierEvict {
39    /// 2026-09-26: The victim's slot, whichever arm was taken.
40    pub fn slot(&self) -> usize {
41        match *self {
42            TierEvict::Spill { slot, .. } | TierEvict::Drop { slot, .. } => slot,
43        }
44    }
45}