1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// This lint name differs across clippy versions; allow it without failing on
// toolchains that pre-date it (CI pins an older clippy than some local builds).
//! # theSix
//!
//! Policy-driven six-tier cache orchestration, built around an explicit
//! **high-performance availability (HPA) data-continuity contract**.
//!
//! ```text
//! Consumer
//! |
//! v
//! theSix continuity / policy plane
//! locality | availability | performance
//! consistency | durability | recovery
//! |
//! +-------------------+-------------------+
//! v v v
//! Performance Continuity Security
//! & locality & recovery CIA
//! +-------------------+-------------------+
//! v
//! Heterogeneous storage / cache / authority
//! ```
//!
//! Consumers depend on the *continuity contract*, not on a backend. L0-L6 are
//! replaceable infrastructure; the rung a value lands on is policy's decision,
//! and authority is configured rather than inferred from a tier number.
//!
//! # Guarantees
//!
//! | Property | Mechanism |
//! |---|---|
//! | Atomicity | Two-phase commit with a payload-free intent record. A crash leaves an intent, never a half-visible value. |
//! | Isolation | Single-flight population ownership; no control guard is ever held across an `.await`. |
//! | Durability honesty | `DurabilityClass` is `Volatile`, `Delegated` or `Verified`. Only a restart test may grant `Verified`. |
//! | Integrity | Every stored value carries a content digest; a damaged record is refused, not served. |
//! | Tenant isolation | The tenant is framed into the key, so a cross-tenant read finds nothing. |
//! | Capability honesty | A rung is reported as `Unbound` rather than silently replaced by another. |
//! | Bounded control plane | Every rung-scanning path is bounded by `LAST_CACHE_TIER`, so a fallback can never surface authority data. |
//!
//! # The control plane and the data plane
//!
//! [`Cachelito`] is the control-plane state registry: a pre-allocated sharded
//! slot map holding entry state, generation, population ownership and a commit
//! intent. It stores **no application payloads** — the intent record is a key
//! hash, a target rung, a generation and a kind, so a crash cannot leak a value
//! through it.
//!
//! [`CacheTier`] implementations are the data plane: they store and retrieve
//! values, and decide nothing. They are `async` because real backends are I/O.
//!
//! [`CacheManager`] sits between them, enforcing authentication, delegating tier
//! selection to a [`CachePolicy`], and coordinating through [`Cachelito`]. Every
//! control-plane call is synchronous and returns an owned snapshot, so
//! no shard guard can be held across an `.await` by construction.
//!
//! # Atomicity, concretely
//!
//! ```text
//! prepare(key, generation, rung) -> entry is Prepared; reads see a miss
//! write to the rung -> no payload anywhere in the control plane
//! commit(token) -> Ready, intent cleared, waiters notified
//! abort(token) -> restores the interrupted state
//! ```
//!
//! Recovery resolves an outstanding intent by kind: a [`IntentKind::Write`]
//! aborts, because the value is reproducible; an [`IntentKind::Move`] completes
//! forward, because aborting it would discard an already-committed value. Both
//! directions are idempotent.
//!
//! # Capability semantics
//!
//! Asking "which backend is this?" previously had no honest answer — the only
//! way to find out was to issue an operation and receive `TierUnavailable`, which
//! cannot distinguish *not compiled in*, *bound but down*, and *never
//! implemented*. See [`TierCapability`], [`CapabilityFlags`],
//! [`OperationalState`] and [`DurabilityClass`].
//!
//! Those are three axes rather than one enum because the properties are not
//! mutually exclusive: a rung can be persistent *and* shared *and* degraded at
//! the same moment.
//!
//! # Observability
//!
//! [`OperationRecord`] carries the eleven fields needed to reconstruct an
//! operation, with two deliberate omissions: no payload, and no key. A key is
//! identified by a non-reversible [`KeyIdentity`] — a digest plus a length —
//! because keys are as sensitive as the data they name.
//!
//! # Example
//!
//! ```no_run
//! use std::sync::Arc;
//! use thesix::{CacheContext, CacheManager, CacheTier, Cachelito, DefaultPolicy,
//! IdentityContext, L0Stub, L1Stub, L2Stub, L3Stub, L4Stub, L5Stub,
//! MemoryPool, TierRegistry};
//!
//! # async fn example() {
//! let tiers: Vec<Arc<dyn CacheTier<String>>> = vec![
//! Arc::new(L0Stub::<String>::new()),
//! Arc::new(L1Stub::<String>::new()),
//! Arc::new(L2Stub::<String>::new()),
//! Arc::new(L3Stub::<String>::new()),
//! Arc::new(L4Stub::<String>::new()),
//! Arc::new(L5Stub::<String>::new()),
//! ];
//! let pool = MemoryPool::<String>::new(1024).expect("pool");
//!
//! let manager: CacheManager<String, String, DefaultPolicy> =
//! CacheManager::new(DefaultPolicy, Cachelito::new(), TierRegistry::new(), tiers, pool);
//!
//! // Identity carries the tenant, and the tenant is part of the key: two tenants
//! // using the same application key never share an entry.
//! let ctx = CacheContext::new(IdentityContext::new(
//! "alice".to_string(),
//! vec!["reader".to_string()],
//! "tenant-1".to_string(),
//! ));
//!
//! // Application code never selects a tier.
//! let value = manager
//! .get_or_fetch(&"order-42".to_string(), &ctx, || async { Ok("payload".to_string()) })
//! .await;
//! # }
//! ```
//!
//! # Crate layout
//!
//! | Module | Purpose |
//! |--------|---------|
//! | [`manager`] | `CacheManager` — the public API and orchestration |
//! | [`control`] | `Cachelito` — control-plane state, generations, commit intents |
//! | [`policy`] | `CachePolicy`, operations, decisions, the ladder bound |
//! | [`capability`] | `TierCapability` and its three reporting axes |
//! | [`continuity`] | Continuity states, recovery direction and outcomes |
//! | [`integrity`] | Content digests, key fingerprints, slot placement |
//! | [`telemetry`] | `OperationRecord`, `TelemetrySink`, latency percentiles |
//! | [`tier`] | The `CacheTier` trait and the L0-L6 bindings |
//! | [`entry`] | `EntryState`, `Generation`, `CommitToken` |
//! | [`error`] | `CacheError` — the single error type |
//! | [`identity`] | `IdentityContext` and `CacheContext` |
//! | [`key`] | `Key`, `KeyRef`, tenant key framing |
//! | [`pool`] | `MemoryPool`, a fixed-capacity value allocator |
//! | [`fault`] | Deterministic, seedable fault injection (feature `faults`) |
//!
//! # Contract
//!
//! [`theSix.toml`](./theSix.toml) is the source of truth for the architecture and
//! is machine-checked: `cargo xtask contract` validates it, and `tests/contract`
//! asserts it agrees with this crate.
pub use ;
pub use ;
pub use Cachelito;
pub use ;
pub use ;
pub use CacheError;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use MemoryPool;
pub use ;
pub use FixedTierStub;
pub use ;
pub use ;
pub use L3RedisBackend;
pub use L4SledBackend;
pub use L5OxigraphBackend;
pub use ;