| 1 | // Copyright 2026 Deno Land Inc. Apache-2.0 license. |
| 2 | |
| 3 | //! The vocabulary the core is written in: what it is told, what it |
| 4 | //! answers with, and the records it reads and writes. |
| 5 | //! |
| 6 | //! Everything here is data. `Event` is the only way in, `Effect` the only |
| 7 | //! way out, and the rest are the shapes those two carry. No decision is |
| 8 | //! made in this file — that is `State` in the crate root. |
| 9 | use super::*; |
| 10 | |
| 11 | pub type Ms = i64; |
| 12 | |
| 13 | pub type CellId = String; |
| 14 | pub type NodeId = String; |
| 15 | pub type RequestId = u64; |
| 16 | pub type WebSocketId = u64; |
| 17 | pub type OpId = u64; |
| 18 | pub type Epoch = u64; |
| 19 | |
| 20 | /// One runtime that this node can currently serve locally. |
| 21 | /// |
| 22 | /// Presence is a read-only projection of the decision core, not a second |
| 23 | /// inventory maintained by an adapter. Keeping the epoch beside the cell ID |
| 24 | /// lets management and inspection traffic identify the exact fenced runtime. |
| 25 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 26 | pub struct PresenceCell { |
| 27 | pub id: CellId, |
| 28 | pub epoch: Epoch, |
| 29 | } |
| 30 | |
| 31 | /// Cumulative lifecycle decisions exposed to management from the same state |
| 32 | /// machine that made them. These are advisory counters, but they are not a |
| 33 | /// second shell-owned model and replay to the same values for the same events. |
| 34 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] |
| 35 | pub struct ActivitySnapshot { |
| 36 | pub acquired: u64, |
| 37 | pub proxied: u64, |
| 38 | pub expired_owner_leases: u64, |
| 39 | pub restored: u64, |
| 40 | pub advanced_epochs: u64, |
| 41 | } |
| 42 | |
| 43 | /// Management-facing lifecycle state derived atomically from [`State`]. |
| 44 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 45 | pub struct PresenceSnapshot { |
| 46 | pub serving: bool, |
| 47 | pub cells: Vec<PresenceCell>, |
| 48 | pub activity: ActivitySnapshot, |
| 49 | pub lazy_lease_shadow: LeaseLifecycleShadowBatch, |
| 50 | } |
| 51 | |
| 52 | impl PresenceSnapshot { |
| 53 | pub fn owned_cells(&self) -> usize { |
| 54 | self.cells.len() |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 59 | pub struct Config { |
| 60 | /// Resident cells plus activation reservations may never exceed this. |
| 61 | pub max_resident: usize, |
| 62 | /// Complete nonresident routes which may be in flight at once. |
| 63 | /// |
| 64 | /// This is deliberately independent of the stateless Worker pool. A warm |
| 65 | /// request consumes no activation slot, while a cold request holds one |
| 66 | /// across ownership resolution, capacity waiting, restore, and publish. |
| 67 | pub max_activations: usize, |
| 68 | /// Evictions that may hold a durability proof in flight at once. |
| 69 | /// |
| 70 | /// A proof is a round trip to the bucket, so draining a node one cell at a |
| 71 | /// time takes the number of cells times that latency -- a node shedding |
| 72 | /// five hundred cells against a two hundred millisecond proof refuses |
| 73 | /// admission for a minute and a half while it walks down. Bounded |
| 74 | /// concurrency is what makes the walk down finish in a time anyone can |
| 75 | /// reason about. |
| 76 | pub max_evictions: usize, |
| 77 | /// Evictions in flight at once during a shutdown handoff. |
| 78 | /// |
| 79 | /// `max_evictions` is tuned for a background walk down beside live |
| 80 | /// traffic. A drain has no live traffic to protect and a stop grace to |
| 81 | /// beat, so it runs wider -- but still bounded, because a node handing |
| 82 | /// off thousands of cells at once is the same thundering herd against |
| 83 | /// the bucket that eviction bounding exists to prevent. |
| 84 | pub max_releases: usize, |
| 85 | /// Concurrent outbound WebSockets one cell may hold. |
| 86 | /// |
| 87 | /// Distinct from the node-wide pin budget, which counts *cells* held |
| 88 | /// resident: one socket is enough to pin a cell, so that budget says |
| 89 | /// nothing about how many a single cell may open. This bounds what one |
| 90 | /// application can consume on its own behalf. |
| 91 | pub max_outbound_websockets: usize, |
| 92 | /// What an evicted cell's ownership record should say. |
| 93 | /// |
| 94 | /// Releasing it lets any node take the cell next, which is what makes a |
| 95 | /// loaded node shed load rather than merely stop hosting it: keeping the |
| 96 | /// record means every later request for that cell still routes here, to a |
| 97 | /// node that already decided it has no room. Keeping it is right when the |
| 98 | /// local eviction snapshot is the point, because a same-node wake is a |
| 99 | /// rename instead of a restore. |
| 100 | pub ownership_on_evict: OwnershipOnEvict, |
| 101 | /// Production executors require a live self-node lease before serving. |
| 102 | /// Deterministic unit slices which do not exercise node authority can |
| 103 | /// disable this explicitly. |
| 104 | pub require_node_lease: bool, |
| 105 | /// Exact cross-node request protocol this process can authenticate and |
| 106 | /// understand. A live owner speaking another version is unavailable, not |
| 107 | /// stale: incompatibility never authorizes takeover. |
| 108 | pub peer_protocol: u16, |
| 109 | /// How long an activation effect may remain outstanding before the core |
| 110 | /// stops waiting for it. |
| 111 | /// |
| 112 | /// Without this a swallowed effect is invisible: no event ever arrives, no |
| 113 | /// timer is watching, and the request waits forever while every piece of |
| 114 | /// state remains perfectly consistent. celld shipped that and parked |
| 115 | /// requests past ninety seconds. `None` restores the old behaviour, which |
| 116 | /// only a test that wants to observe an indefinite wait should ask for. |
| 117 | pub operation_deadline_ms: Option<u64>, |
| 118 | /// How close an armed alarm may be before the cell stops being worth |
| 119 | /// evicting. Inside this window the wake would cost more than the |
| 120 | /// residency it saves, so the cell is held. |
| 121 | pub alarm_resident_ms: u64, |
| 122 | /// How long a cell may sit unused before the node gives it back, with no |
| 123 | /// pressure involved. `None` keeps every cell resident until something |
| 124 | /// needs the room. |
| 125 | pub idle_evict_ms: Option<u64>, |
| 126 | /// Ceilings and low watermarks for load shedding. |
| 127 | /// |
| 128 | /// `max_resident` is a hard cap on reservations; this is the softer, |
| 129 | /// resource-aware question of whether the node is overloaded at all. |
| 130 | /// Without it a node has only a cell count to reason about, so it meets |
| 131 | /// memory exhaustion by running into it rather than shedding. |
| 132 | pub pressure: pressure::PressureConfig, |
| 133 | } |
| 134 | |
| 135 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 136 | pub struct OwnerRecord { |
| 137 | /// `None` is a deliberately released, fenced record. Epochs never reset. |
| 138 | pub node: Option<NodeId>, |
| 139 | pub epoch: Epoch, |
| 140 | pub etag: String, |
| 141 | } |
| 142 | |
| 143 | /// The routing and authority fields read from `nodes/<node>.json`. |
| 144 | /// |
| 145 | /// The executor samples wall time and returns the verbatim record. The core, |
| 146 | /// not the storage adapter, decides whether it is live and routable. |
| 147 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 148 | pub struct NodeLeaseRecord { |
| 149 | pub node: NodeId, |
| 150 | pub addr: String, |
| 151 | pub expires_ms: u64, |
| 152 | pub peer_protocol: u16, |
| 153 | /// Per-process generation; production stores this in |
| 154 | /// `ownership_index_generation`. |
| 155 | pub generation: String, |
| 156 | /// Object version observed by the read. Empty only in synthetic events. |
| 157 | pub etag: String, |
| 158 | } |
| 159 | |
| 160 | /// One advisory fleet-capacity observation returned by the storage shell. |
| 161 | /// |
| 162 | /// Membership and expiry remain authoritative node-lease facts. Load is only |
| 163 | /// used to choose where an unowned cell should try to land; the chosen peer |
| 164 | /// must still atomically admit the handoff before it acquires ownership. |
| 165 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 166 | pub struct CapacityPeer { |
| 167 | pub node: NodeId, |
| 168 | pub addr: String, |
| 169 | pub expires_ms: u64, |
| 170 | pub peer_protocol: u16, |
| 171 | pub sampled_ms: u64, |
| 172 | pub resident_cells: usize, |
| 173 | pub host_websockets: usize, |
| 174 | pub rss_bytes: u64, |
| 175 | pub pressured: bool, |
| 176 | } |
| 177 | |
| 178 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 179 | pub struct NodeLeaseSpec { |
| 180 | pub addr: String, |
| 181 | pub peer_protocol: u16, |
| 182 | pub generation: String, |
| 183 | /// The generation named by a clean local reload certificate. An initial |
| 184 | /// lease CAS can resume local cells only when it replaces this exact, |
| 185 | /// still-live generation. |
| 186 | pub resume_generation: Option<String>, |
| 187 | pub ttl_ms: u64, |
| 188 | pub mode: NodeLeaseMode, |
| 189 | pub linger_ms: u64, |
| 190 | } |
| 191 | |
| 192 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] |
| 193 | pub enum NodeLeaseMode { |
| 194 | #[default] |
| 195 | Continuous, |
| 196 | Shadow, |
| 197 | Lazy, |
| 198 | } |
| 199 | |
| 200 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 201 | pub enum NodeLeaseAuthorityAction { |
| 202 | Hold, |
| 203 | Renew, |
| 204 | } |
| 205 | |
| 206 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 207 | pub struct LeaseLifecycleShadowSnapshot { |
| 208 | pub mode: NodeLeaseMode, |
| 209 | pub active_cells: usize, |
| 210 | pub serving_cells: usize, |
| 211 | pub idle_ms: u64, |
| 212 | pub linger_ms: u64, |
| 213 | pub lease_active: bool, |
| 214 | pub elapsed_since_ok_ms: u64, |
| 215 | pub elapsed_since_renew_ms: u64, |
| 216 | pub ttl_ms: u64, |
| 217 | pub shadow_release_reported: bool, |
| 218 | } |
| 219 | |
| 220 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 221 | pub struct LeaseLifecycleShadowExpected { |
| 222 | pub shadow_release: bool, |
| 223 | pub authority_action: NodeLeaseAuthorityAction, |
| 224 | } |
| 225 | |
| 226 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 227 | pub struct LeaseLifecycleShadowDecision { |
| 228 | pub sequence: u64, |
| 229 | pub observed_at_ms: u64, |
| 230 | pub snapshot: LeaseLifecycleShadowSnapshot, |
| 231 | pub expected: LeaseLifecycleShadowExpected, |
| 232 | } |
| 233 | |
| 234 | #[derive(Clone, Debug, Default, PartialEq, Eq)] |
| 235 | pub struct LeaseLifecycleShadowBatch { |
| 236 | pub dropped: u64, |
| 237 | pub decisions: Vec<LeaseLifecycleShadowDecision>, |
| 238 | } |
| 239 | |
| 240 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 241 | pub enum CasGuard { |
| 242 | Absent, |
| 243 | Match(String), |
| 244 | } |
| 245 | |
| 246 | /// See [`Config::ownership_on_evict`]. |
| 247 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] |
| 248 | pub enum OwnershipOnEvict { |
| 249 | /// Publish the cell as unowned so any node may take it next. |
| 250 | #[default] |
| 251 | Release, |
| 252 | /// Keep the record, so a same-node wake can reuse the local snapshot. |
| 253 | Sticky, |
| 254 | } |
| 255 | |
| 256 | /// Why the node is halting. The shell writes this down: a process that |
| 257 | /// self-fences and exits without saying why leaves an operator with an exit |
| 258 | /// code and nothing else. |
| 259 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 260 | pub enum HaltReason { |
| 261 | /// The node lease was not renewed inside its TTL, so this node can no |
| 262 | /// longer prove it owns anything it is serving. |
| 263 | NodeLeaseExpired, |
| 264 | } |
| 265 | |
| 266 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 267 | pub enum CasOutcome { |
| 268 | Applied, |
| 269 | Rejected, |
| 270 | } |
| 271 | |
| 272 | /// Observable result of a successful restore effect. A non-fresh activation |
| 273 | /// may still discover that no local or replicated database exists; the |
| 274 | /// adapter reports what happened instead of making the core infer I/O truth. |
| 275 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 276 | pub struct RestoreOutcome { |
| 277 | pub restored: bool, |
| 278 | /// The alarm the restored database already had armed. |
| 279 | /// |
| 280 | /// A cell carries its alarm in its own SQLite, so a cell that arrives |
| 281 | /// here from another node — or wakes cold — has one the isolate has not |
| 282 | /// re-armed yet. Nothing else tells this node about it: the observer |
| 283 | /// fires when a *running* isolate calls `setAlarm`, which is exactly the |
| 284 | /// case this is not. Without it the mirror reads "no alarm" and every |
| 285 | /// residency decision that consults it is wrong in the direction of |
| 286 | /// shedding a cell that is about to fire. |
| 287 | pub alarm: Option<RestoredAlarm>, |
| 288 | } |
| 289 | |
| 290 | /// See [`RestoreOutcome::alarm`]. |
| 291 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 292 | pub struct RestoredAlarm { |
| 293 | pub at_ms: i64, |
| 294 | /// Whether a durable wake entry already covers it. Read from the same |
| 295 | /// flusher the observer consults, not assumed: claiming coverage this |
| 296 | /// node cannot prove is how an alarm gets lost across an eviction. |
| 297 | pub covered: bool, |
| 298 | } |
| 299 | |
| 300 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 301 | pub enum LeaseCasOutcome { |
| 302 | Applied { etag: String }, |
| 303 | Rejected, |
| 304 | } |
| 305 | |
| 306 | /// Deterministic timers are versioned effects, not implicit clock reads. A |
| 307 | /// stale firing from a replaced lease generation is harmless. |
| 308 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 309 | pub enum Timer { |
| 310 | NodeLeaseRenew { |
| 311 | generation: u64, |
| 312 | }, |
| 313 | NodeLeaseFence { |
| 314 | generation: u64, |
| 315 | }, |
| 316 | CellAlarm { |
| 317 | cell: CellId, |
| 318 | generation: u64, |
| 319 | }, |
| 320 | /// Fires if `op` is still outstanding. Identified by operation rather than |
| 321 | /// by cell, so a completion that lands first simply leaves a stale timer |
| 322 | /// that finds nothing to expire. |
| 323 | OperationDeadline { |
| 324 | op: OpId, |
| 325 | }, |
| 326 | } |
| 327 | |
| 328 | /// Whether a failed operation definitely did not commit or may have committed |
| 329 | /// before its caller lost the response. |
| 330 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 331 | pub enum Failure { |
| 332 | Definite, |
| 333 | Ambiguous, |
| 334 | } |
| 335 | |
| 336 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 337 | pub enum WebSocketKind { |
| 338 | Hibernatable, |
| 339 | Regular, |
| 340 | /// A transport the cell opened itself with `new WebSocket(url)`. It pins |
| 341 | /// its cell exactly as a regular one does -- a live transport cannot move |
| 342 | /// with ownership -- but unlike an inbound client socket it is created by |
| 343 | /// application code at a rate the application chooses, so how much of the |
| 344 | /// node it may hold is budgeted. |
| 345 | Outbound, |
| 346 | } |
| 347 | |
| 348 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 349 | pub enum Event { |
| 350 | StartNodeLease { |
| 351 | now_ms: u64, |
| 352 | spec: NodeLeaseSpec, |
| 353 | }, |
| 354 | SelfNodeLeaseRead { |
| 355 | op: OpId, |
| 356 | now_ms: u64, |
| 357 | now_mono_ms: u64, |
| 358 | result: Result<Option<NodeLeaseRecord>, Failure>, |
| 359 | }, |
| 360 | NodeLeaseCasCompleted { |
| 361 | op: OpId, |
| 362 | now_mono_ms: u64, |
| 363 | result: Result<LeaseCasOutcome, Failure>, |
| 364 | }, |
| 365 | /// The executor scanned the local paths after an exact node-generation |
| 366 | /// handoff. These cells retain their existing ownership epochs, so the |
| 367 | /// core can materialize them without reading or changing each owner. |
| 368 | LocalCellsRead { |
| 369 | result: Result<Vec<LocalCell>, Failure>, |
| 370 | }, |
| 371 | TimerFired { |
| 372 | timer: Timer, |
| 373 | now_ms: u64, |
| 374 | now_mono_ms: u64, |
| 375 | }, |
| 376 | Request { |
| 377 | request: RequestId, |
| 378 | cell: CellId, |
| 379 | }, |
| 380 | /// Production form of [`Event::Request`] with the sampled clocks needed |
| 381 | /// to acquire an idle lazy node lease. Untimed model slices retain the |
| 382 | /// compact variant above and use the state's last observed clocks. |
| 383 | RequestAt { |
| 384 | request: RequestId, |
| 385 | cell: CellId, |
| 386 | now_ms: u64, |
| 387 | now_mono_ms: u64, |
| 388 | }, |
| 389 | /// A peer selected this node as a possible landing place for an unowned |
| 390 | /// cell. Unlike ordinary ingress, this request must refuse immediately if |
| 391 | /// its advertised capacity has gone stale; waiting here would strand the |
| 392 | /// forwarding node instead of letting it traverse another candidate. |
| 393 | CapacityRequestAt { |
| 394 | request: RequestId, |
| 395 | cell: CellId, |
| 396 | now_ms: u64, |
| 397 | now_mono_ms: u64, |
| 398 | }, |
| 399 | /// Reserve an idle resident isolate for a top-level Worker request. The |
| 400 | /// shell falls back to the stateless pool when no resident is available; |
| 401 | /// choosing and pinning a resident is lifecycle policy and therefore |
| 402 | /// belongs in the replayable core. |
| 403 | WorkerRequest { |
| 404 | request: RequestId, |
| 405 | }, |
| 406 | /// Stop cold activation work for a planned same-node replacement while |
| 407 | /// leaving published runtimes and ownership intact. Late shell completions |
| 408 | /// are stale, so a long restore cannot consume the complete shutdown grace |
| 409 | /// and disable the certified local-reload path for every resident cell. |
| 410 | BeginPreserve, |
| 411 | Cancel { |
| 412 | request: RequestId, |
| 413 | }, |
| 414 | ActivityFinished { |
| 415 | request: RequestId, |
| 416 | }, |
| 417 | /// A request that ran locally advanced its cell's committed WAL to |
| 418 | /// `position`. Its response is withheld — the output gate — until that |
| 419 | /// position is replicated, so celld never acknowledges a write it could |
| 420 | /// still lose. Read-only requests emit [`Event::ActivityFinished`] instead |
| 421 | /// and pay no durability latency. The epoch is not carried: the core reads |
| 422 | /// it from the pinned cell's resident phase, which cannot change while the |
| 423 | /// request holds it. |
| 424 | Wrote { |
| 425 | request: RequestId, |
| 426 | position: u64, |
| 427 | }, |
| 428 | /// The shell finished proving a gated write durable. `Ok(position)` reports |
| 429 | /// the committed-write position the replica has *actually* proved durable; |
| 430 | /// the core acknowledges only when it covers the gated write's position, so |
| 431 | /// a replicator that proves less than it was asked to cannot force an early |
| 432 | /// ack. `Err` failed the proof outright. |
| 433 | DurableReached { |
| 434 | op: OpId, |
| 435 | result: Result<u64, Failure>, |
| 436 | }, |
| 437 | WebSocketOpened { |
| 438 | cell: CellId, |
| 439 | websocket: WebSocketId, |
| 440 | kind: WebSocketKind, |
| 441 | }, |
| 442 | WebSocketClosed { |
| 443 | cell: CellId, |
| 444 | websocket: WebSocketId, |
| 445 | }, |
| 446 | AlarmObserved { |
| 447 | cell: CellId, |
| 448 | at_ms: Option<i64>, |
| 449 | covered: bool, |
| 450 | now_ms: u64, |
| 451 | now_mono_ms: u64, |
| 452 | }, |
| 453 | AlarmFinished { |
| 454 | op: OpId, |
| 455 | now_ms: u64, |
| 456 | now_mono_ms: u64, |
| 457 | result: Result<(Option<i64>, bool), Failure>, |
| 458 | }, |
| 459 | WakeHint { |
| 460 | cell: CellId, |
| 461 | }, |
| 462 | WakeHintAt { |
| 463 | cell: CellId, |
| 464 | now_ms: u64, |
| 465 | now_mono_ms: u64, |
| 466 | }, |
| 467 | OwnerRead { |
| 468 | op: OpId, |
| 469 | /// Wall-clock observation made when the ownership read completed. It |
| 470 | /// bounds reuse of a shared owner-node lease without letting the core |
| 471 | /// read a clock itself. |
| 472 | now_ms: u64, |
| 473 | result: Result<Option<OwnerRecord>, Failure>, |
| 474 | }, |
| 475 | NodeLeaseRead { |
| 476 | op: OpId, |
| 477 | now_ms: u64, |
| 478 | result: Result<Option<NodeLeaseRecord>, Failure>, |
| 479 | }, |
| 480 | CapacityPeersRead { |
| 481 | op: OpId, |
| 482 | now_ms: u64, |
| 483 | result: Result<Vec<CapacityPeer>, Failure>, |
| 484 | }, |
| 485 | OwnerCasCompleted { |
| 486 | op: OpId, |
| 487 | result: Result<CasOutcome, Failure>, |
| 488 | }, |
| 489 | OwnerReleased { |
| 490 | op: OpId, |
| 491 | result: Result<CasOutcome, Failure>, |
| 492 | }, |
| 493 | RestoreCompleted { |
| 494 | op: OpId, |
| 495 | result: Result<RestoreOutcome, Failure>, |
| 496 | }, |
| 497 | RuntimeStarted { |
| 498 | op: OpId, |
| 499 | result: Result<(), Failure>, |
| 500 | }, |
| 501 | Published { |
| 502 | op: OpId, |
| 503 | result: Result<(), Failure>, |
| 504 | }, |
| 505 | DurabilityChecked { |
| 506 | op: OpId, |
| 507 | result: Result<(), Failure>, |
| 508 | }, |
| 509 | RuntimeStopped { |
| 510 | op: OpId, |
| 511 | }, |
| 512 | /// Policy input for this first slice. Later eviction selection emits this |
| 513 | /// from the same core rather than an external caller choosing a victim. |
| 514 | Evict { |
| 515 | cell: CellId, |
| 516 | }, |
| 517 | /// A periodic resource sample from the edge. |
| 518 | /// |
| 519 | /// The core never reads a clock or a proc file; the shell measures and |
| 520 | /// hands the numbers over, and every decision that follows -- whether the |
| 521 | /// node is overloaded, whether the latch stays hot, how far to shed -- |
| 522 | /// happens here where a schedule can replay it. |
| 523 | LoadSampled { |
| 524 | load: pressure::Load, |
| 525 | now_mono_ms: u64, |
| 526 | }, |
| 527 | /// Retire an exact cached remote route after a dispatch failure which is |
| 528 | /// known not to have executed the request. Newer route generations are |
| 529 | /// unaffected by delayed failure reports. |
| 530 | InvalidateRemote { |
| 531 | cell: CellId, |
| 532 | node: NodeId, |
| 533 | epoch: Epoch, |
| 534 | }, |
| 535 | NodeFenced, |
| 536 | /// The node is shutting down: hand every resident cell to a peer by |
| 537 | /// releasing its owner record, so a takeover is immediate rather than |
| 538 | /// waiting out the node lease. Unlike an on-demand evict this always |
| 539 | /// releases, whatever `ownership_on_evict` is set to. Releases run at |
| 540 | /// most `max_releases` at a time, and the pump takes the next resident |
| 541 | /// as each one completes -- a cell that is active when the drain begins |
| 542 | /// is picked up once its activity finishes. |
| 543 | ReleaseAll, |
| 544 | } |
| 545 | |
| 546 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 547 | pub enum Route { |
| 548 | Local, |
| 549 | Remote { |
| 550 | node: NodeId, |
| 551 | addr: String, |
| 552 | epoch: Epoch, |
| 553 | peer_protocol: u16, |
| 554 | }, |
| 555 | } |
| 556 | |
| 557 | /// Exact resident isolate reserved for a top-level Worker request. |
| 558 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 559 | pub struct WorkerRoute { |
| 560 | pub cell: CellId, |
| 561 | pub epoch: Epoch, |
| 562 | /// A pending durability proof made stale by selecting this still-routable |
| 563 | /// resident. The executor uses the ID only to release its effect waiter; |
| 564 | /// a late completion is ignored by the core's phase check. |
| 565 | pub retired_durability: Option<OpId>, |
| 566 | } |
| 567 | |
| 568 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 569 | pub enum RequestError { |
| 570 | NodeUnavailable, |
| 571 | ResolveFailed, |
| 572 | AcquireFailed, |
| 573 | RestoreFailed, |
| 574 | RuntimeFailed, |
| 575 | PublishFailed, |
| 576 | NodeFenced, |
| 577 | PeerIncompatible, |
| 578 | CapacityExhausted, |
| 579 | /// A local write ran but its durability could not be proven, so the |
| 580 | /// response must fail rather than falsely acknowledge the write. |
| 581 | DurabilityUnproven, |
| 582 | } |
| 583 | |
| 584 | /// Work performed outside the core. Every asynchronous effect is versioned; |
| 585 | /// completion events with an obsolete `op` are ignored. |
| 586 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 587 | pub enum Effect { |
| 588 | ScheduleTimer { |
| 589 | timer: Timer, |
| 590 | at_mono_ms: u64, |
| 591 | }, |
| 592 | ReadSelfNodeLease { |
| 593 | op: OpId, |
| 594 | }, |
| 595 | CasNodeLease { |
| 596 | op: OpId, |
| 597 | guard: CasGuard, |
| 598 | record: NodeLeaseRecord, |
| 599 | /// The prior record's peer-visible expiry for a renewal. The shell |
| 600 | /// uses it to report how much authority remained when the attempt |
| 601 | /// completed. An initial acquisition has no prior authority. |
| 602 | authority_expires_ms: Option<u64>, |
| 603 | }, |
| 604 | /// Read the local cell inventory. This is emitted only after the initial |
| 605 | /// node lease CAS replaced the exact certified predecessor generation. |
| 606 | ReadLocalCells, |
| 607 | /// Shadow mode proposed the lazy release but deliberately retained |
| 608 | /// authority. The shell only records this decision; it performs no I/O. |
| 609 | ObserveNodeLeaseShadowRelease { |
| 610 | sequence: u64, |
| 611 | }, |
| 612 | /// Lazy mode stopped renewing its idle node lease. The bucket object is |
| 613 | /// intentionally left to expire; this effect is observability only. |
| 614 | ObserveNodeLeaseReleased, |
| 615 | ReadOwner { |
| 616 | op: OpId, |
| 617 | cell: CellId, |
| 618 | }, |
| 619 | ReadNodeLease { |
| 620 | op: OpId, |
| 621 | cell: CellId, |
| 622 | owner: NodeId, |
| 623 | }, |
| 624 | /// Enumerate recent node leases and return their advisory load records. |
| 625 | /// Listing and bounded parallel reads are adapter mechanics; selection, |
| 626 | /// reservations, and exclusions are deterministic core policy. |
| 627 | ReadCapacityPeers { |
| 628 | op: OpId, |
| 629 | cell: CellId, |
| 630 | }, |
| 631 | CasOwner { |
| 632 | op: OpId, |
| 633 | cell: CellId, |
| 634 | guard: CasGuard, |
| 635 | epoch: Epoch, |
| 636 | takeover: bool, |
| 637 | }, |
| 638 | /// Bring the bucket's wake entry for this cell into line with its alarm. |
| 639 | /// |
| 640 | /// Emitted wherever the alarm settles, which is the only place that |
| 641 | /// knows. An arm needs an entry; a consumed alarm needs its entry gone, |
| 642 | /// or every later due scan finds a hint for an alarm that already fired |
| 643 | /// and wakes a cell with nothing to do. `next_alarm_ms` is -1 when no |
| 644 | /// alarm remains. |
| 645 | ReconcileWakeEntry { |
| 646 | cell: CellId, |
| 647 | next_alarm_ms: i64, |
| 648 | }, |
| 649 | /// Publish an evicted cell as unowned, keeping its epoch, so the next |
| 650 | /// node to want it can take it without waiting for this one to notice. |
| 651 | ReleaseOwner { |
| 652 | op: OpId, |
| 653 | cell: CellId, |
| 654 | epoch: Epoch, |
| 655 | }, |
| 656 | Restore { |
| 657 | op: OpId, |
| 658 | cell: CellId, |
| 659 | spec: RestoreSpec, |
| 660 | }, |
| 661 | StartRuntime { |
| 662 | op: OpId, |
| 663 | cell: CellId, |
| 664 | epoch: Epoch, |
| 665 | }, |
| 666 | Publish { |
| 667 | op: OpId, |
| 668 | cell: CellId, |
| 669 | epoch: Epoch, |
| 670 | }, |
| 671 | /// Prove that every commit made before this effect is recoverable from |
| 672 | /// replica authority. Voluntary eviction cannot begin until this succeeds. |
| 673 | EnsureDurable { |
| 674 | op: OpId, |
| 675 | cell: CellId, |
| 676 | epoch: Epoch, |
| 677 | }, |
| 678 | /// The output gate: prove the cell's committed `position` is replicated so |
| 679 | /// a withheld local write response can be released. Unlike |
| 680 | /// [`Effect::EnsureDurable`] this is per-request and changes no cell phase, |
| 681 | /// so the cell keeps serving co-resident requests while one response waits. |
| 682 | AwaitDurable { |
| 683 | op: OpId, |
| 684 | cell: CellId, |
| 685 | epoch: Epoch, |
| 686 | position: u64, |
| 687 | }, |
| 688 | StopRuntime { |
| 689 | op: OpId, |
| 690 | cell: CellId, |
| 691 | epoch: Epoch, |
| 692 | cause: StopCause, |
| 693 | }, |
| 694 | FireAlarm { |
| 695 | op: OpId, |
| 696 | cell: CellId, |
| 697 | epoch: Epoch, |
| 698 | scheduled_ms: i64, |
| 699 | }, |
| 700 | Complete { |
| 701 | request: RequestId, |
| 702 | result: Result<Route, RequestError>, |
| 703 | }, |
| 704 | /// Release a withheld local write response now that its durability is |
| 705 | /// decided: `Ok` acknowledges the write, `Err` fails it. Emitted only for a |
| 706 | /// request the shell held open via [`Event::Wrote`]. |
| 707 | ReleaseResponse { |
| 708 | request: RequestId, |
| 709 | result: Result<(), RequestError>, |
| 710 | }, |
| 711 | /// Complete the synchronous resident-selection decision. `None` means |
| 712 | /// the executor must use the ordinary stateless Worker pool. |
| 713 | CompleteWorker { |
| 714 | request: RequestId, |
| 715 | route: Option<WorkerRoute>, |
| 716 | }, |
| 717 | /// Refuse a transport the node cannot afford to hold. The shell closes it; |
| 718 | /// the cell carries on without it. |
| 719 | CloseWebSocket { |
| 720 | cell: CellId, |
| 721 | websocket: WebSocketId, |
| 722 | }, |
| 723 | Halt { |
| 724 | code: i32, |
| 725 | reason: HaltReason, |
| 726 | }, |
| 727 | } |
| 728 | |
| 729 | /// One database encoded by the local cell path. |
| 730 | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] |
| 731 | pub struct LocalCell { |
| 732 | pub id: CellId, |
| 733 | pub epoch: Epoch, |
| 734 | } |
| 735 | |
| 736 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 737 | pub enum StopCause { |
| 738 | Cleanup, |
| 739 | /// `rebalance` means this eviction hands the cell to the fleet: its |
| 740 | /// ownership record is released and the local replica is not worth |
| 741 | /// keeping. An idle eviction is the opposite on both counts -- it |
| 742 | /// keeps the record so the next activation here renames the file into |
| 743 | /// place instead of paying a full remote restore. |
| 744 | Evict { |
| 745 | rebalance: bool, |
| 746 | }, |
| 747 | Fence, |
| 748 | /// A durability proof came back negative, so this runtime's memory and its |
| 749 | /// local database may hold writes the bucket does not. celld has just told |
| 750 | /// the caller those writes failed; continuing to serve them is the |
| 751 | /// divergence, not the failure. Stop, keep no local snapshot, and let the |
| 752 | /// next activation restore from the bucket. |
| 753 | Reset, |
| 754 | } |