pub struct ServerState { /* private fields */ }Expand description
Cloneable shared state passed to all server transports.
Implementations§
Source§impl ServerState
impl ServerState
Sourcepub async fn build(config: ServerConfig) -> Result<Self, ServerError>
pub async fn build(config: ServerConfig) -> Result<Self, ServerError>
Build shared state from operator configuration.
§Errors
Returns ServerError if the store cannot connect or the engine cannot
be constructed.
Sourcepub async fn build_with_store<S>(
store: S,
runtime: RuntimeConfig,
) -> Result<Self, ServerError>where
S: EventStore + NamespaceStore,
pub async fn build_with_store<S>(
store: S,
runtime: RuntimeConfig,
) -> Result<Self, ServerError>where
S: EventStore + NamespaceStore,
Build shared state from an already-constructed store.
§Errors
Returns ServerError::EngineCall if the engine cannot be constructed.
Sourcepub fn from_parts(
namespace_resolver: NamespaceResolver,
runtime: RuntimeConfig,
) -> Self
pub fn from_parts( namespace_resolver: NamespaceResolver, runtime: RuntimeConfig, ) -> Self
Build shared state from explicit parts with a default worker registry.
Sourcepub fn from_parts_with_namespace_store(
namespace_resolver: NamespaceResolver,
runtime: RuntimeConfig,
namespace_store: Arc<dyn NamespaceStore>,
) -> Self
pub fn from_parts_with_namespace_store( namespace_resolver: NamespaceResolver, runtime: RuntimeConfig, namespace_store: Arc<dyn NamespaceStore>, ) -> Self
Build shared state from explicit parts with a caller-supplied durable namespace registry.
Identical to Self::from_parts except the namespace registry is the
supplied store rather than a fresh in-memory one, so a caller can seed the
durable set the control-plane read/create paths (GET/POST /namespaces) observe.
Sourcepub fn from_parts_with_registry(
namespace_resolver: NamespaceResolver,
runtime: RuntimeConfig,
worker_registry: ConnectedWorkerRegistry,
) -> Self
pub fn from_parts_with_registry( namespace_resolver: NamespaceResolver, runtime: RuntimeConfig, worker_registry: ConnectedWorkerRegistry, ) -> Self
Build shared state from explicit parts with a caller-supplied registry.
Sourcepub fn namespace_guard(&self) -> &NamespaceGuard
pub fn namespace_guard(&self) -> &NamespaceGuard
Borrow the namespace guard shared by all transports.
Sourcepub fn deploy_guard(&self) -> DeployGuard
pub fn deploy_guard(&self) -> DeployGuard
Build the deploy authorization guard over the shared resolver.
Sourcepub fn runtime_config(&self) -> &RuntimeConfig
pub fn runtime_config(&self) -> &RuntimeConfig
Borrow non-secret runtime settings needed by transports.
Sourcepub fn worker_registry(&self) -> &ConnectedWorkerRegistry
pub fn worker_registry(&self) -> &ConnectedWorkerRegistry
Borrow the connected-worker registry shared by worker transports and dispatch.
Sourcepub fn cluster_publisher(&self) -> &ClusterEventPublisher
pub fn cluster_publisher(&self) -> &ClusterEventPublisher
Borrow the WS3 cluster-event publisher shared by the cluster state-change sites (supervisor, worker registry) and the cluster subscription endpoint. Always present, on every boot.
Sourcepub fn transcript_publisher(&self) -> &ActivityEventPublisher
pub fn transcript_publisher(&self) -> &ActivityEventPublisher
Borrow the NOI-5b transcript sequencer shared by the worker->server
ingestion seam (which publishes a running activity’s ActivityEvents) and
the transcript subscription endpoint (which tails + resumes them). Always
present, on every boot.
Sourcepub fn attempt_owners(&self) -> &AttemptOwnerIndex
pub fn attempt_owners(&self) -> &AttemptOwnerIndex
Borrow the NOI-6 attempt -> owning-worker back-index. The agent-dispatch
path binds an owner when it dispatches an agent attempt and releases it on
completion, so the intervention router always resolves the CURRENT owner.
Sourcepub fn intervention_router(&self) -> InterventionRouter
pub fn intervention_router(&self) -> InterventionRouter
Build the NOI-6 intervention router over the connected-worker registry, the attempt-owner back-index, and the active intervention transport.
The transport is the liminal server-push
(LiminalInterventionTransport)
when the liminal-transport feature is compiled in — the production path
that pushes a routed command out on the owning worker’s connection — and a
null transport otherwise, which reports the target unreachable so every
command NACKs the attempt-scoped no-op rather than silently vanishing. The
router is cheap to build (it clones cloneable handles), so it is constructed
per request at the endpoint rather than stored.
Sourcepub fn cluster_self_node(&self) -> Option<&str>
pub fn cluster_self_node(&self) -> Option<&str>
This node’s configured cluster distribution name for the WS3 snapshot
self-identity, or None on a single-node boot (the snapshot then reports
the standalone self-label).
Sourcepub fn engine(&self) -> Result<Arc<Engine>, ServerError>
pub fn engine(&self) -> Result<Arc<Engine>, ServerError>
Clone the live engine handle the completion path records terminals through.
This is the SAME Arc<Engine> the gRPC completion callback is built over
(state.rs installs ServerOutboxDeliveryCallback::new(engine) on the
pending tracker when outbox.enabled), so the liminal completion path
re-enters worker results through the identical record_fan_out_completion
seam rather than inventing a second one.
§Errors
Returns ServerError when the namespace resolver has no engine handle
(a state built from parts without an engine).
Sourcepub fn pending_activities(&self) -> &PendingActivities
pub fn pending_activities(&self) -> &PendingActivities
Borrow the pending-activities tracker shared by the NIF bridge and worker stream handler.
Sourcepub fn heartbeat_tracker(&self) -> &HeartbeatTracker
pub fn heartbeat_tracker(&self) -> &HeartbeatTracker
Borrow the heartbeat/liveness tracker shared by dispatch and worker streams.
Sourcepub fn drain_state(&self) -> &DrainState
pub fn drain_state(&self) -> &DrainState
Borrow the drain gate shared by transports and worker dispatch.
Sourcepub fn metrics(&self) -> Option<&Metrics>
pub fn metrics(&self) -> Option<&Metrics>
Borrow the prometheus metrics handle when this state was built with a store.
Sourcepub fn health(&self) -> Option<&HealthState>
pub fn health(&self) -> Option<&HealthState>
Borrow health probe state when this state was built with a store.
Sourcepub fn activity_mock_registry(&self) -> Option<&ActivityMockRegistry>
pub fn activity_mock_registry(&self) -> Option<&ActivityMockRegistry>
Borrow the shared per-run activity-mock registry when the dev surface is
commissioned. Returns None on a server with the dev surface dark, so
the dev handlers refuse cleanly rather than mocking on a production
server.
Sourcepub fn outbox_store(&self) -> Option<Arc<dyn OutboxStore>>
pub fn outbox_store(&self) -> Option<Arc<dyn OutboxStore>>
Borrow the outbox store the dispatcher claims rows from, when the durable
(libSQL) backend is in use. This is the SAME leaf Arc<LibSqlStore> the
engine writes through, so the dispatcher shares its single
libsql::Connection rather than opening a second contending one. Returns
None for the in-memory backend, which has no outbox table.
Sourcepub fn namespace_store(&self) -> &Arc<dyn NamespaceStore>
pub fn namespace_store(&self) -> &Arc<dyn NamespaceStore>
Borrow the durable namespace registry shared by the control plane.
This is the SAME concrete leaf backend the engine writes events through
(haematite quorum-replicated, or libSQL / in-memory local-only),
captured as a NamespaceStore before the decorator chain wrapped it.
Always present on every boot, so the mint-on-register path (Phase 1 S5)
and GET /namespaces (S7) can reach a real registry regardless of
backend.
Sourcepub fn namespace_minter(&self) -> NamespaceMinter
pub fn namespace_minter(&self) -> NamespaceMinter
Build the shared minted-on-use hook over the durable namespace store and
the configured AutoCreate policy.
This is the SAME policy logic the worker-registration seam applies (S5);
the workflow-start safety net (S6) calls it after authorization so a
client that starts a workflow before any worker registers still gets a
durable namespace record. Cheap to build (clones an Arc + a Copy
policy), so transports construct it per request rather than holding it.
Sourcepub fn outbox_wake(&self) -> Arc<Notify>
pub fn outbox_wake(&self) -> Arc<Notify>
Clone the advisory outbox wake (LSUB-2) shared with the engine’s stage seam. The outbox dispatcher installs this handle so a committed fan-out row wakes its run loop in ~RTT rather than waiting for the next poll tick. The handle is always present; it is simply never pulsed when the outbox is not commissioned, so wiring it is free and behaviour is unchanged.
Sourcepub fn is_clustered(&self) -> bool
pub fn is_clustered(&self) -> bool
Whether this server is a node in a distributed haematite cluster.
true when boot constructed the distributed backend (a [store.cluster]
section was present) and is holding its inbound-write responder alive;
false for every single-node / non-haematite boot.
Sourcepub fn cluster_store(&self) -> Option<&Arc<HaematiteStore>>
pub fn cluster_store(&self) -> Option<&Arc<HaematiteStore>>
The concrete distributed haematite store the request-routing edge consults
for shard ownership (shard_for_workflow / owns_workflow_shard) and
unsteered-start remint. None for every single-node / non-clustered boot,
so the routing pre-step is a no-op and the default path is unchanged.
Sourcepub fn shard_directory(&self) -> Option<&Arc<StaticShardDirectory>>
pub fn shard_directory(&self) -> Option<&Arc<StaticShardDirectory>>
The request-routing shard directory (R-2) the edge consults to resolve a
non-owned shard’s owner. None for single-node / non-clustered boots, so
the edge falls back to the bare R-1 ownership check.
Sourcepub fn request_forwarder(&self) -> Option<&Arc<dyn RequestForwarder>>
pub fn request_forwarder(&self) -> Option<&Arc<dyn RequestForwarder>>
The R-3 request forwarder used to relay a non-local signal/query/cancel to
the shard owner. None for single-node / non-clustered boots.
Sourcepub fn spawn_heartbeat_sweeper(
&self,
shutdown: Receiver<bool>,
) -> JoinHandle<()>
pub fn spawn_heartbeat_sweeper( &self, shutdown: Receiver<bool>, ) -> JoinHandle<()>
Spawn the worker heartbeat expiry sweeper (#176): the production driver
of HeartbeatTracker::fail_expired_workers, failing every worker with
an in-flight task beyond the operator’s worker.heartbeat_window and
deregistering it with the provable
WorkerDeathReason::Timeout.
Always spawned on the server boot path — dead-worker detection is a
liveness correctness property, not an opt-in feature. The cadence is
derived from the heartbeat window
(sweep_interval: a quarter of the
window clamped to [1s, window], so the default 30s window sweeps every
7.5s); there is deliberately no separate config knob. The task exits
when shutdown flips to true, exactly like the transports; the
returned handle may be dropped to detach it (dropping a tokio
JoinHandle never cancels the task) and is returned so tests can await
clean shutdown.
Sourcepub fn spawn_cluster_supervisor(
&self,
config: SupervisorConfig,
shutdown: Receiver<bool>,
) -> Result<bool, ServerError>
pub fn spawn_cluster_supervisor( &self, config: SupervisorConfig, shutdown: Receiver<bool>, ) -> Result<bool, ServerError>
Spawn the SS-5b cluster supervisor: a background task that watches every
declared peer’s replication liveness and, on a confirmed peer death,
calls adopt_shards for that peer’s shards on THIS node’s live engine —
automatic failover with no manual trigger.
Does nothing (returns Ok(()) without spawning) unless this is a
distributed boot whose cluster config declared at least one peer with
owned_shards. A single-node / non-clustered server therefore never runs
a supervisor, so default behaviour is unchanged.
The spawned task drains on shutdown exactly like the transports.
§Errors
Returns ServerError when the engine handle cannot be resolved.
Sourcepub fn shutdown(&self) -> Result<(), ServerError>
pub fn shutdown(&self) -> Result<(), ServerError>
Shut down the embedded engine so in-flight durable appends can finish.
§Errors
Returns ServerError if the namespace resolver has no engine handle or the engine rejects
shutdown.
Trait Implementations§
Source§impl Clone for ServerState
impl Clone for ServerState
Source§fn clone(&self) -> ServerState
fn clone(&self) -> ServerState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ServerState
impl !UnwindSafe for ServerState
impl Freeze for ServerState
impl Send for ServerState
impl Sync for ServerState
impl Unpin for ServerState
impl UnsafeUnpin for ServerState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request