pub struct Engine { /* private fields */ }Expand description
Public handle for the protocol-neutral Elastik engine.
Engine is cloneable and owns the startup writer lock for the data root.
Dropping the last clone releases the lock.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn builder() -> EngineBuilder
pub fn builder() -> EngineBuilder
Returns a fresh EngineBuilder populated with crate defaults.
Sourcepub fn verify_token(&self, token: &[u8]) -> AccessTier
pub fn verify_token(&self, token: &[u8]) -> AccessTier
Maps raw token bytes to an AccessTier.
Constant-time comparison against configured tokens. Returns
AccessTier::Anon for empty, unrecognized, or invalid token bytes;
returns the highest matching tier otherwise.
Sourcepub fn allows_read(&self, tier: AccessTier) -> bool
pub fn allows_read(&self, tier: AccessTier) -> bool
Returns whether tier satisfies the engine’s configured read gate.
Adapters use this for non-world read-only surfaces that still need to
mirror /proc/* read policy, such as protocol-local metrics.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Starts orderly shutdown.
Sets the engine-owned shutdown signal so subscribers
(crate::EngineSubscription recv loops, adapter graceful-shutdown
futures) can drain in-flight work. Repeated calls are no-ops; only
the first call flips the signal.
Source§impl Engine
impl Engine
Sourcepub fn list_worlds(
&self,
tier: AccessTier,
) -> Result<Vec<ValidatedWorldPath>, EngineError>
pub fn list_worlds( &self, tier: AccessTier, ) -> Result<Vec<ValidatedWorldPath>, EngineError>
Lists every canonical world (durable + in-memory) in sorted order.
§Errors
EngineError::Authiftieris belowRead.EngineError::TransientStorage/EngineError::Storage/EngineError::InsufficientStoragefor storage failures.
Sourcepub fn list_worlds_with_prefix(
&self,
prefix: &str,
tier: AccessTier,
) -> Result<Vec<ValidatedWorldPath>, EngineError>
pub fn list_worlds_with_prefix( &self, prefix: &str, tier: AccessTier, ) -> Result<Vec<ValidatedWorldPath>, EngineError>
Lists canonical worlds with the supplied canonical prefix.
This is intended for adapters that need a bounded namespace view (for example retained replay) without materializing the full proc-worlds set first. It applies the read gate directly and intentionally bypasses proc-path authorization; do not expose it directly as a network endpoint.
§Errors
Same authorization and storage failures as Engine::list_worlds.
Sourcepub fn list_worlds_with_prefix_bounded(
&self,
prefix: &str,
tier: AccessTier,
max: usize,
) -> Result<Option<Vec<ValidatedWorldPath>>, EngineError>
pub fn list_worlds_with_prefix_bounded( &self, prefix: &str, tier: AccessTier, max: usize, ) -> Result<Option<Vec<ValidatedWorldPath>>, EngineError>
Lists canonical worlds with the supplied canonical prefix, returning
Ok(None) if more than max distinct worlds match.
This is intended for adapter-internal bounded scans. It uses the same
read-tier gate as Engine::list_worlds_with_prefix.
Sourcepub fn du(&self, tier: AccessTier) -> Result<Vec<WorldUsage>, EngineError>
pub fn du(&self, tier: AccessTier) -> Result<Vec<WorldUsage>, EngineError>
Returns per-world body byte size, du-style.
§Errors
See Engine::list_worlds for the storage-failure variants. Same
Read-tier requirement.
Sourcepub fn df(&self, tier: AccessTier) -> Result<DfSnapshot, EngineError>
pub fn df(&self, tier: AccessTier) -> Result<DfSnapshot, EngineError>
Returns aggregate storage + memory usage, df-style.
§Errors
EngineError::Authiftieris belowRead.
Sourcepub fn pool(&self, tier: AccessTier) -> Result<PoolSnapshot, EngineError>
pub fn pool(&self, tier: AccessTier) -> Result<PoolSnapshot, EngineError>
Returns the read-cache + ledger-writer counter snapshot.
§Errors
EngineError::Authiftieris belowRead.
Sourcepub fn verify_audit(
&self,
world: &ValidatedWorldPath,
tier: AccessTier,
) -> Result<AuditVerify, EngineError>
pub fn verify_audit( &self, world: &ValidatedWorldPath, tier: AccessTier, ) -> Result<AuditVerify, EngineError>
Verifies a single world’s HMAC audit chain.
Returns AuditVerify::Valid / AuditVerify::Broken /
AuditVerify::NotApplicable (the latter for in-memory worlds with
no chain).
§Errors
EngineError::Authiftieris belowRead.EngineError::NotFoundifworlddoes not exist.EngineError::TransientStorage/EngineError::Storage/EngineError::InsufficientStoragefor storage failures during verification.
Source§impl Engine
impl Engine
Sourcepub fn read(
&self,
world: &ValidatedWorldPath,
tier: AccessTier,
) -> Result<Option<ReadResult>, EngineError>
pub fn read( &self, world: &ValidatedWorldPath, tier: AccessTier, ) -> Result<Option<ReadResult>, EngineError>
Reads a world’s full representation.
§Returns
Ok(Some(ReadResult))if the world exists.Ok(None)if the world does not exist (callers that want 404 semantics handle this).
§Errors
EngineError::Authiftieris belowRead.EngineError::TransientStoragefor SQLiteBUSY/LOCKED.EngineError::InsufficientStoragefor full-disk failures.EngineError::Storagefor other storage errors.
Sourcepub async fn replace(
&self,
world: &ValidatedWorldPath,
representation: Representation,
preconditions: Preconditions,
tier: AccessTier,
) -> Result<WriteResult, EngineError>
pub async fn replace( &self, world: &ValidatedWorldPath, representation: Representation, preconditions: Preconditions, tier: AccessTier, ) -> Result<WriteResult, EngineError>
Replaces a world with the provided representation.
Creates the world if it does not exist; otherwise overwrites the body, content type, and headers, then advances the audit chain.
§Errors
EngineError::Authiftieris below the namespace’s write requirement (Writeforhome/,Approvefor system namespaces).EngineError::PayloadTooLargeif the body exceeds the per-world cap.EngineError::PreconditionFailedifpreconditionsreject the write.EngineError::QuotaExceededfor durable-storage quota failures.EngineError::TransientStorage/EngineError::InsufficientStorage/EngineError::Storagefor storage-layer failures.
Sourcepub async fn append(
&self,
world: &ValidatedWorldPath,
body: Bytes,
preconditions: Preconditions,
tier: AccessTier,
) -> Result<WriteResult, EngineError>
pub async fn append( &self, world: &ValidatedWorldPath, body: Bytes, preconditions: Preconditions, tier: AccessTier, ) -> Result<WriteResult, EngineError>
Appends bytes to a world’s body and advances the audit chain.
Same auth requirements and error variants as Engine::replace.
The world’s content type and metadata headers are unchanged.
§Errors
Same as Engine::replace.
Sourcepub async fn delete(
&self,
world: &ValidatedWorldPath,
preconditions: Preconditions,
tier: AccessTier,
) -> Result<(), EngineError>
pub async fn delete( &self, world: &ValidatedWorldPath, preconditions: Preconditions, tier: AccessTier, ) -> Result<(), EngineError>
Deletes a world with default, empty audit metadata.
Convenience wrapper around the delete transition that records empty
content-type and headers in the audit intent. Adapters that need to
preserve the deleted representation’s metadata in the audit log
should call Engine::delete_traced with a populated
crate::DeleteMetadata.
§Errors
EngineError::Authiftieris belowApprove.EngineError::AppendOnlyfor append-only worlds (e.g.var/log/deletes).EngineError::PreconditionFailed/EngineError::NotFound.EngineError::TransientStorage/EngineError::InsufficientStorage/EngineError::Storagefor storage-layer failures.
Sourcepub fn subscribe(
&self,
pattern: &SubscribePattern,
tier: AccessTier,
since: Option<u64>,
) -> Result<EngineSubscription, EngineError>
pub fn subscribe( &self, pattern: &SubscribePattern, tier: AccessTier, since: Option<u64>, ) -> Result<EngineSubscription, EngineError>
Subscribes to change events matching pattern.
If since is Some(id), the subscription replays every event with
id > since from the in-memory ring before switching to the live
stream. Replay is bounded by the configured listen_replay_max; if
since is older than the ring’s floor, the first recv call yields
a crate::SubscriptionRecvError::Lagged error.
The returned EngineSubscription holds a subscription slot until
dropped; drop it promptly when finished so other subscribers can
join.
§Errors
EngineError::Authiftieris belowRead.EngineError::SubscriptionLimitif the slot pool is full.EngineError::ShuttingDownifEngine::shutdownhas been called.
Source§impl Engine
impl Engine
Sourcepub async fn replace_traced<H: EngineWriteTraceHooks + ?Sized>(
&self,
world: &ValidatedWorldPath,
representation: Representation,
preconditions: Preconditions,
tier: AccessTier,
hooks: &H,
) -> Result<WriteResult, EngineError>
pub async fn replace_traced<H: EngineWriteTraceHooks + ?Sized>( &self, world: &ValidatedWorldPath, representation: Representation, preconditions: Preconditions, tier: AccessTier, hooks: &H, ) -> Result<WriteResult, EngineError>
Same as crate::Engine::replace but invokes hooks on each
protocol phase.
Adapters use this to drive structured trace output or per-operation metrics without paying the hook cost in non-traced call sites.
§Errors
Same as crate::Engine::replace.
Sourcepub async fn append_traced<H: EngineWriteTraceHooks + ?Sized>(
&self,
world: &ValidatedWorldPath,
body: Bytes,
preconditions: Preconditions,
tier: AccessTier,
hooks: &H,
) -> Result<WriteResult, EngineError>
pub async fn append_traced<H: EngineWriteTraceHooks + ?Sized>( &self, world: &ValidatedWorldPath, body: Bytes, preconditions: Preconditions, tier: AccessTier, hooks: &H, ) -> Result<WriteResult, EngineError>
Same as crate::Engine::append but invokes hooks on each
protocol phase.
§Errors
Same as crate::Engine::append.
Sourcepub async fn delete_traced<H: EngineDeleteTraceHooks + ?Sized>(
&self,
world: &ValidatedWorldPath,
metadata: DeleteMetadata,
preconditions: Preconditions,
tier: AccessTier,
hooks: &H,
) -> Result<(), EngineError>
pub async fn delete_traced<H: EngineDeleteTraceHooks + ?Sized>( &self, world: &ValidatedWorldPath, metadata: DeleteMetadata, preconditions: Preconditions, tier: AccessTier, hooks: &H, ) -> Result<(), EngineError>
Same as crate::Engine::delete but invokes hooks on each
protocol phase and records the supplied DeleteMetadata in the
audit intent.
Adapters that want to surface the deleted representation’s content
type and headers in operator audit views should use this method
instead of crate::Engine::delete (which records empty metadata).
§Errors
Same as crate::Engine::delete, plus the hook-side
audit_intent_failed callback fires before the
EngineError::Storage / EngineError::TransientStorage /
EngineError::InsufficientStorage / EngineError::InternalInvariant
result is returned when the audit-intent write itself fails.