1//! The plugin side of the Wire 2 cache.2//!3//! A codec knows one engine's slot format. It does not know a tier, a quota, a4//! TTL, or a directory: it asks the core for a descriptor and writes or reads5//! that descriptor. The SDK owns the request/reply plumbing, so a codec never6//! reads a frame.78use std::io;9use std::os::fd::OwnedFd;10use std::sync::Arc;11use std::time::Duration;1213mod chain;14mod descriptor;15mod driver;1617pubuse chain::{18AnchorSet, Chain, TABLE_LIMIT, TipTable, anchor_key, cache_key, canonical_parts, chain_keys,19 hash_into, key_after, lineage_key, part_kind_name, seed, template_seed,20 };21pubuse descriptor::{copy_in, copy_out, measure_write, verify_file};22pubuse driver::{CacheDriver, CacheSlot, PrefixOutcome, PrefixReply};2324use inf3r_proto::body;2526/// A restored cache file. The codec reads it and then releases the lease.27pubstructCacheFile {28pub key: [u8; 32],29pub lease_id: u64,30pub bytes: u64,31pub crc32c: u32,32pub token_count: u64,33pub tier: String,34pub file: OwnedFd,35 }3637/// A writable temp file. The codec writes it and then commits the lease.38pubstructCacheWrite {39pub lease_id: u64,40pub max_bytes: u64,41pub tier: String,42pub file: OwnedFd,43 }4445/// The fields of one reservation.46 #[derive(Clone, PartialEq, Eq, Debug)]47pubstructReserve {48pub key: [u8; 32],49pub lineage: Option<[u8; 32]>,50pub supersedes: Option<[u8; 32]>,51pub kind: body::CacheEntryKind,52pub est_bytes: u64,53pub prefill_ms: u32,54pub token_count: u64,55pub pin: bool,56 }5758/// What a flush saved.59 #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]60pubstructFlushReport {61pub saved: u32,62pub skipped: u32,63pub dirty_remaining: u32,64 }6566/// The core end of one cache session, as the codec sees it.67pubtraitCacheTransport: Send + Sync {68fnlookup(69 &self,70 keys: &[[u8; 32]],71 lineage: Option<[u8; 32]>,72 timeout: Duration,73 ) -> io::Result<Option<CacheFile>>;7475fnreserve(&self, request: Reserve, timeout: Duration) -> io::Result<Option<CacheWrite>>;7677fnrelease(&self, lease_id: u64, ok: bool, restore_ms: u32) -> io::Result<()>;7879fncommit(80 &self,81 lease_id: u64,82 ok: bool,83 bytes: u64,84 crc32c: u32,85 token_count: u64,86 save_ms: u32,87 ) -> io::Result<()>;88 }8990/// The engine-specific half. One per plugin process.91pubtraitCacheCodec: Send + Sync {92/// The static declaration that `catalogue` carries.93fnspec(&self) -> body::CacheSpec;9495/// The bundle half of the composite fingerprint, reported after `grant`.96fnfingerprint(&self) -> [u8; 32];9798/// Called once before the first job. The codec keeps this handle.99fnattach(&self, transport: Arc<dynCacheTransport>);100101/// Saves every dirty slot inside the budget. It may use the transport.102fnflush(&self, budget: Duration) -> FlushReport;103104/// Erases one VRAM slot. This is correctness, not cache policy.105fnerase(&self, slot: u32) -> io::Result<()>;106 }