Diffinery

homeflare/celldpublic

celld/crates/logic/types.rs
757 lines · 25.7 KBRaw History
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.
9use super::*;
10
11pub type Ms = i64;
12
13pub type CellId = String;
14pub type NodeId = String;
15pub type RequestId = u64;
16pub type WebSocketId = u64;
17pub type OpId = u64;
18pub 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)]
26pub 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)]
35pub 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)]
45pub struct PresenceSnapshot {
46 pub serving: bool,
47 pub cells: Vec<PresenceCell>,
48 pub activity: ActivitySnapshot,
49 pub lazy_lease_shadow: LeaseLifecycleShadowBatch,
50}
51
52impl PresenceSnapshot {
53 pub fn owned_cells(&self) -> usize {
54 self.cells.len()
55 }
56}
57
58#[derive(Clone, Copy, Debug, PartialEq, Eq)]
59pub 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)]
136pub 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)]
148pub 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)]
166pub 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 /// The memory this peer's cells hold, which is what it decides its own
176 /// pressure on. `None` from a peer that predates the field.
177 pub in_use_bytes: Option<u64>,
178 pub pressured: bool,
179}
180
181#[derive(Clone, Debug, PartialEq, Eq)]
182pub struct NodeLeaseSpec {
183 pub addr: String,
184 pub peer_protocol: u16,
185 pub generation: String,
186 /// The generation named by a clean local reload certificate. An initial
187 /// lease CAS can resume local cells only when it replaces this exact,
188 /// still-live generation.
189 pub resume_generation: Option<String>,
190 pub ttl_ms: u64,
191 pub mode: NodeLeaseMode,
192 pub linger_ms: u64,
193}
194
195#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
196pub enum NodeLeaseMode {
197 #[default]
198 Continuous,
199 Shadow,
200 Lazy,
201}
202
203#[derive(Clone, Copy, Debug, PartialEq, Eq)]
204pub enum NodeLeaseAuthorityAction {
205 Hold,
206 Renew,
207}
208
209#[derive(Clone, Debug, PartialEq, Eq)]
210pub struct LeaseLifecycleShadowSnapshot {
211 pub mode: NodeLeaseMode,
212 pub active_cells: usize,
213 pub serving_cells: usize,
214 pub idle_ms: u64,
215 pub linger_ms: u64,
216 pub lease_active: bool,
217 pub elapsed_since_ok_ms: u64,
218 pub elapsed_since_renew_ms: u64,
219 pub ttl_ms: u64,
220 pub shadow_release_reported: bool,
221}
222
223#[derive(Clone, Copy, Debug, PartialEq, Eq)]
224pub struct LeaseLifecycleShadowExpected {
225 pub shadow_release: bool,
226 pub authority_action: NodeLeaseAuthorityAction,
227}
228
229#[derive(Clone, Debug, PartialEq, Eq)]
230pub struct LeaseLifecycleShadowDecision {
231 pub sequence: u64,
232 pub observed_at_ms: u64,
233 pub snapshot: LeaseLifecycleShadowSnapshot,
234 pub expected: LeaseLifecycleShadowExpected,
235}
236
237#[derive(Clone, Debug, Default, PartialEq, Eq)]
238pub struct LeaseLifecycleShadowBatch {
239 pub dropped: u64,
240 pub decisions: Vec<LeaseLifecycleShadowDecision>,
241}
242
243#[derive(Clone, Debug, PartialEq, Eq)]
244pub enum CasGuard {
245 Absent,
246 Match(String),
247}
248
249/// See [`Config::ownership_on_evict`].
250#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
251pub enum OwnershipOnEvict {
252 /// Publish the cell as unowned so any node may take it next.
253 #[default]
254 Release,
255 /// Keep the record, so a same-node wake can reuse the local snapshot.
256 Sticky,
257}
258
259/// Why the node is halting. The shell writes this down: a process that
260/// self-fences and exits without saying why leaves an operator with an exit
261/// code and nothing else.
262#[derive(Clone, Copy, Debug, PartialEq, Eq)]
263pub enum HaltReason {
264 /// The node lease was not renewed inside its TTL, so this node can no
265 /// longer prove it owns anything it is serving.
266 NodeLeaseExpired,
267}
268
269#[derive(Clone, Copy, Debug, PartialEq, Eq)]
270pub enum CasOutcome {
271 Applied,
272 Rejected,
273}
274
275/// Observable result of a successful restore effect. A non-fresh activation
276/// may still discover that no local or replicated database exists; the
277/// adapter reports what happened instead of making the core infer I/O truth.
278#[derive(Clone, Copy, Debug, PartialEq, Eq)]
279pub struct RestoreOutcome {
280 pub restored: bool,
281 /// The alarm the restored database already had armed.
282 ///
283 /// A cell carries its alarm in its own SQLite, so a cell that arrives
284 /// here from another node — or wakes cold — has one the isolate has not
285 /// re-armed yet. Nothing else tells this node about it: the observer
286 /// fires when a *running* isolate calls `setAlarm`, which is exactly the
287 /// case this is not. Without it the mirror reads "no alarm" and every
288 /// residency decision that consults it is wrong in the direction of
289 /// shedding a cell that is about to fire.
290 pub alarm: Option<RestoredAlarm>,
291}
292
293/// See [`RestoreOutcome::alarm`].
294#[derive(Clone, Copy, Debug, PartialEq, Eq)]
295pub struct RestoredAlarm {
296 pub at_ms: i64,
297 /// Whether a durable wake entry already covers it. Read from the same
298 /// flusher the observer consults, not assumed: claiming coverage this
299 /// node cannot prove is how an alarm gets lost across an eviction.
300 pub covered: bool,
301}
302
303#[derive(Clone, Debug, PartialEq, Eq)]
304pub enum LeaseCasOutcome {
305 Applied { etag: String },
306 Rejected,
307}
308
309/// Deterministic timers are versioned effects, not implicit clock reads. A
310/// stale firing from a replaced lease generation is harmless.
311#[derive(Clone, Debug, PartialEq, Eq)]
312pub enum Timer {
313 NodeLeaseRenew {
314 generation: u64,
315 },
316 NodeLeaseFence {
317 generation: u64,
318 },
319 CellAlarm {
320 cell: CellId,
321 generation: u64,
322 },
323 /// Fires if `op` is still outstanding. Identified by operation rather than
324 /// by cell, so a completion that lands first simply leaves a stale timer
325 /// that finds nothing to expire.
326 OperationDeadline {
327 op: OpId,
328 },
329}
330
331/// Whether a failed operation definitely did not commit or may have committed
332/// before its caller lost the response.
333#[derive(Clone, Copy, Debug, PartialEq, Eq)]
334pub enum Failure {
335 Definite,
336 Ambiguous,
337}
338
339#[derive(Clone, Copy, Debug, PartialEq, Eq)]
340pub enum WebSocketKind {
341 Hibernatable,
342 Regular,
343 /// A transport the cell opened itself with `new WebSocket(url)`. It pins
344 /// its cell exactly as a regular one does -- a live transport cannot move
345 /// with ownership -- but unlike an inbound client socket it is created by
346 /// application code at a rate the application chooses, so how much of the
347 /// node it may hold is budgeted.
348 Outbound,
349}
350
351#[derive(Clone, Debug, PartialEq, Eq)]
352pub enum Event {
353 StartNodeLease {
354 now_ms: u64,
355 spec: NodeLeaseSpec,
356 },
357 SelfNodeLeaseRead {
358 op: OpId,
359 now_ms: u64,
360 now_mono_ms: u64,
361 result: Result<Option<NodeLeaseRecord>, Failure>,
362 },
363 NodeLeaseCasCompleted {
364 op: OpId,
365 now_mono_ms: u64,
366 result: Result<LeaseCasOutcome, Failure>,
367 },
368 /// The executor scanned the local paths after an exact node-generation
369 /// handoff. These cells retain their existing ownership epochs, so the
370 /// core can materialize them without reading or changing each owner.
371 LocalCellsRead {
372 result: Result<Vec<LocalCell>, Failure>,
373 },
374 TimerFired {
375 timer: Timer,
376 now_ms: u64,
377 now_mono_ms: u64,
378 },
379 Request {
380 request: RequestId,
381 cell: CellId,
382 },
383 /// Production form of [`Event::Request`] with the sampled clocks needed
384 /// to acquire an idle lazy node lease. Untimed model slices retain the
385 /// compact variant above and use the state's last observed clocks.
386 RequestAt {
387 request: RequestId,
388 cell: CellId,
389 now_ms: u64,
390 now_mono_ms: u64,
391 },
392 /// A peer selected this node as a possible landing place for an unowned
393 /// cell. Unlike ordinary ingress, this request must refuse immediately if
394 /// its advertised capacity has gone stale; waiting here would strand the
395 /// forwarding node instead of letting it traverse another candidate.
396 CapacityRequestAt {
397 request: RequestId,
398 cell: CellId,
399 now_ms: u64,
400 now_mono_ms: u64,
401 },
402 /// Reserve an idle resident isolate for a top-level Worker request. The
403 /// shell falls back to the stateless pool when no resident is available;
404 /// choosing and pinning a resident is lifecycle policy and therefore
405 /// belongs in the replayable core.
406 WorkerRequest {
407 request: RequestId,
408 },
409 /// Stop cold activation work for a planned same-node replacement while
410 /// leaving published runtimes and ownership intact. Late shell completions
411 /// are stale, so a long restore cannot consume the complete shutdown grace
412 /// and disable the certified local-reload path for every resident cell.
413 BeginPreserve,
414 Cancel {
415 request: RequestId,
416 },
417 ActivityFinished {
418 request: RequestId,
419 },
420 /// A request that ran locally advanced its cell's committed WAL to
421 /// `position`. Its response is withheld — the output gate — until that
422 /// position is replicated, so celld never acknowledges a write it could
423 /// still lose. Read-only requests emit [`Event::ActivityFinished`] instead
424 /// and pay no durability latency. The epoch is not carried: the core reads
425 /// it from the pinned cell's resident phase, which cannot change while the
426 /// request holds it.
427 Wrote {
428 request: RequestId,
429 position: u64,
430 },
431 /// The shell finished proving a gated write durable. `Ok(position)` reports
432 /// the committed-write position the replica has *actually* proved durable;
433 /// the core acknowledges only when it covers the gated write's position, so
434 /// a replicator that proves less than it was asked to cannot force an early
435 /// ack. `Err` failed the proof outright.
436 DurableReached {
437 op: OpId,
438 result: Result<u64, Failure>,
439 },
440 WebSocketOpened {
441 cell: CellId,
442 websocket: WebSocketId,
443 kind: WebSocketKind,
444 },
445 WebSocketClosed {
446 cell: CellId,
447 websocket: WebSocketId,
448 },
449 AlarmObserved {
450 cell: CellId,
451 at_ms: Option<i64>,
452 covered: bool,
453 now_ms: u64,
454 now_mono_ms: u64,
455 },
456 AlarmFinished {
457 op: OpId,
458 now_ms: u64,
459 now_mono_ms: u64,
460 result: Result<(Option<i64>, bool), Failure>,
461 },
462 WakeHint {
463 cell: CellId,
464 },
465 WakeHintAt {
466 cell: CellId,
467 now_ms: u64,
468 now_mono_ms: u64,
469 },
470 OwnerRead {
471 op: OpId,
472 /// Wall-clock observation made when the ownership read completed. It
473 /// bounds reuse of a shared owner-node lease without letting the core
474 /// read a clock itself.
475 now_ms: u64,
476 result: Result<Option<OwnerRecord>, Failure>,
477 },
478 NodeLeaseRead {
479 op: OpId,
480 now_ms: u64,
481 result: Result<Option<NodeLeaseRecord>, Failure>,
482 },
483 CapacityPeersRead {
484 op: OpId,
485 now_ms: u64,
486 result: Result<Vec<CapacityPeer>, Failure>,
487 },
488 OwnerCasCompleted {
489 op: OpId,
490 result: Result<CasOutcome, Failure>,
491 },
492 OwnerReleased {
493 op: OpId,
494 result: Result<CasOutcome, Failure>,
495 },
496 RestoreCompleted {
497 op: OpId,
498 result: Result<RestoreOutcome, Failure>,
499 },
500 RuntimeStarted {
501 op: OpId,
502 result: Result<(), Failure>,
503 },
504 Published {
505 op: OpId,
506 result: Result<(), Failure>,
507 },
508 DurabilityChecked {
509 op: OpId,
510 result: Result<(), Failure>,
511 },
512 RuntimeStopped {
513 op: OpId,
514 },
515 /// Policy input for this first slice. Later eviction selection emits this
516 /// from the same core rather than an external caller choosing a victim.
517 Evict {
518 cell: CellId,
519 },
520 /// A periodic resource sample from the edge.
521 ///
522 /// The core never reads a clock or a proc file; the shell measures and
523 /// hands the numbers over, and every decision that follows -- whether the
524 /// node is overloaded, whether the latch stays hot, how far to shed --
525 /// happens here where a schedule can replay it.
526 LoadSampled {
527 load: pressure::Load,
528 now_mono_ms: u64,
529 },
530 /// Retire an exact cached remote route after a dispatch failure which is
531 /// known not to have executed the request. Newer route generations are
532 /// unaffected by delayed failure reports.
533 InvalidateRemote {
534 cell: CellId,
535 node: NodeId,
536 epoch: Epoch,
537 },
538 NodeFenced,
539 /// The node is shutting down: hand every resident cell to a peer by
540 /// releasing its owner record, so a takeover is immediate rather than
541 /// waiting out the node lease. Unlike an on-demand evict this always
542 /// releases, whatever `ownership_on_evict` is set to. Releases run at
543 /// most `max_releases` at a time, and the pump takes the next resident
544 /// as each one completes -- a cell that is active when the drain begins
545 /// is picked up once its activity finishes.
546 ReleaseAll,
547}
548
549#[derive(Clone, Debug, PartialEq, Eq)]
550pub enum Route {
551 Local,
552 Remote {
553 node: NodeId,
554 addr: String,
555 epoch: Epoch,
556 peer_protocol: u16,
557 },
558}
559
560/// Exact resident isolate reserved for a top-level Worker request.
561#[derive(Clone, Debug, PartialEq, Eq)]
562pub struct WorkerRoute {
563 pub cell: CellId,
564 pub epoch: Epoch,
565 /// A pending durability proof made stale by selecting this still-routable
566 /// resident. The executor uses the ID only to release its effect waiter;
567 /// a late completion is ignored by the core's phase check.
568 pub retired_durability: Option<OpId>,
569}
570
571#[derive(Clone, Copy, Debug, PartialEq, Eq)]
572pub enum RequestError {
573 NodeUnavailable,
574 ResolveFailed,
575 AcquireFailed,
576 RestoreFailed,
577 RuntimeFailed,
578 PublishFailed,
579 NodeFenced,
580 PeerIncompatible,
581 CapacityExhausted,
582 /// A local write ran but its durability could not be proven, so the
583 /// response must fail rather than falsely acknowledge the write.
584 DurabilityUnproven,
585}
586
587/// Work performed outside the core. Every asynchronous effect is versioned;
588/// completion events with an obsolete `op` are ignored.
589#[derive(Clone, Debug, PartialEq, Eq)]
590pub enum Effect {
591 ScheduleTimer {
592 timer: Timer,
593 at_mono_ms: u64,
594 },
595 ReadSelfNodeLease {
596 op: OpId,
597 },
598 CasNodeLease {
599 op: OpId,
600 guard: CasGuard,
601 record: NodeLeaseRecord,
602 /// The prior record's peer-visible expiry for a renewal. The shell
603 /// uses it to report how much authority remained when the attempt
604 /// completed. An initial acquisition has no prior authority.
605 authority_expires_ms: Option<u64>,
606 },
607 /// Read the local cell inventory. This is emitted only after the initial
608 /// node lease CAS replaced the exact certified predecessor generation.
609 ReadLocalCells,
610 /// Shadow mode proposed the lazy release but deliberately retained
611 /// authority. The shell only records this decision; it performs no I/O.
612 ObserveNodeLeaseShadowRelease {
613 sequence: u64,
614 },
615 /// Lazy mode stopped renewing its idle node lease. The bucket object is
616 /// intentionally left to expire; this effect is observability only.
617 ObserveNodeLeaseReleased,
618 ReadOwner {
619 op: OpId,
620 cell: CellId,
621 },
622 ReadNodeLease {
623 op: OpId,
624 cell: CellId,
625 owner: NodeId,
626 },
627 /// Enumerate recent node leases and return their advisory load records.
628 /// Listing and bounded parallel reads are adapter mechanics; selection,
629 /// reservations, and exclusions are deterministic core policy.
630 ReadCapacityPeers {
631 op: OpId,
632 cell: CellId,
633 },
634 CasOwner {
635 op: OpId,
636 cell: CellId,
637 guard: CasGuard,
638 epoch: Epoch,
639 takeover: bool,
640 },
641 /// Bring the bucket's wake entry for this cell into line with its alarm.
642 ///
643 /// Emitted wherever the alarm settles, which is the only place that
644 /// knows. An arm needs an entry; a consumed alarm needs its entry gone,
645 /// or every later due scan finds a hint for an alarm that already fired
646 /// and wakes a cell with nothing to do. `next_alarm_ms` is -1 when no
647 /// alarm remains.
648 ReconcileWakeEntry {
649 cell: CellId,
650 next_alarm_ms: i64,
651 },
652 /// Publish an evicted cell as unowned, keeping its epoch, so the next
653 /// node to want it can take it without waiting for this one to notice.
654 ReleaseOwner {
655 op: OpId,
656 cell: CellId,
657 epoch: Epoch,
658 },
659 Restore {
660 op: OpId,
661 cell: CellId,
662 spec: RestoreSpec,
663 },
664 StartRuntime {
665 op: OpId,
666 cell: CellId,
667 epoch: Epoch,
668 },
669 Publish {
670 op: OpId,
671 cell: CellId,
672 epoch: Epoch,
673 },
674 /// Prove that every commit made before this effect is recoverable from
675 /// replica authority. Voluntary eviction cannot begin until this succeeds.
676 EnsureDurable {
677 op: OpId,
678 cell: CellId,
679 epoch: Epoch,
680 },
681 /// The output gate: prove the cell's committed `position` is replicated so
682 /// a withheld local write response can be released. Unlike
683 /// [`Effect::EnsureDurable`] this is per-request and changes no cell phase,
684 /// so the cell keeps serving co-resident requests while one response waits.
685 AwaitDurable {
686 op: OpId,
687 cell: CellId,
688 epoch: Epoch,
689 position: u64,
690 },
691 StopRuntime {
692 op: OpId,
693 cell: CellId,
694 epoch: Epoch,
695 cause: StopCause,
696 },
697 FireAlarm {
698 op: OpId,
699 cell: CellId,
700 epoch: Epoch,
701 scheduled_ms: i64,
702 },
703 Complete {
704 request: RequestId,
705 result: Result<Route, RequestError>,
706 },
707 /// Release a withheld local write response now that its durability is
708 /// decided: `Ok` acknowledges the write, `Err` fails it. Emitted only for a
709 /// request the shell held open via [`Event::Wrote`].
710 ReleaseResponse {
711 request: RequestId,
712 result: Result<(), RequestError>,
713 },
714 /// Complete the synchronous resident-selection decision. `None` means
715 /// the executor must use the ordinary stateless Worker pool.
716 CompleteWorker {
717 request: RequestId,
718 route: Option<WorkerRoute>,
719 },
720 /// Refuse a transport the node cannot afford to hold. The shell closes it;
721 /// the cell carries on without it.
722 CloseWebSocket {
723 cell: CellId,
724 websocket: WebSocketId,
725 },
726 Halt {
727 code: i32,
728 reason: HaltReason,
729 },
730}
731
732/// One database encoded by the local cell path.
733#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
734pub struct LocalCell {
735 pub id: CellId,
736 pub epoch: Epoch,
737}
738
739#[derive(Clone, Copy, Debug, PartialEq, Eq)]
740pub enum StopCause {
741 Cleanup,
742 /// `rebalance` means this eviction hands the cell to the fleet: its
743 /// ownership record is released and the local replica is not worth
744 /// keeping. An idle eviction is the opposite on both counts -- it
745 /// keeps the record so the next activation here renames the file into
746 /// place instead of paying a full remote restore.
747 Evict {
748 rebalance: bool,
749 },
750 Fence,
751 /// A durability proof came back negative, so this runtime's memory and its
752 /// local database may hold writes the bucket does not. celld has just told
753 /// the caller those writes failed; continuing to serve them is the
754 /// divergence, not the failure. Stop, keep no local snapshot, and let the
755 /// next activation restore from the bucket.
756 Reset,
757}