pub struct LocalBackend { /* private fields */ }Expand description
The always-compiled durable backend that journals to a dedicated durable.db.
Construct it from a zeph_db::DbPool (or open one with LocalBackend::open), then attach an
optional PayloadCipher and HMAC key with the builder methods. Call LocalBackend::init
once before use to apply the schema migrations.
§Examples
use zeph_durable::LocalBackend;
// 1 MiB payload ceiling, matching the spec default.
let backend = LocalBackend::open("durable.db", 1_048_576).await?;
backend.init().await?;Implementations§
Source§impl LocalBackend
impl LocalBackend
Sourcepub fn new(pool: DbPool, max_payload_bytes: u64) -> Self
pub fn new(pool: DbPool, max_payload_bytes: u64) -> Self
Wrap an existing zeph_db::DbPool as a local backend with the given payload ceiling.
Call LocalBackend::init before any journal operation to apply the schema. Attach a
cipher and HMAC key with with_cipher and
with_hmac_key.
Sourcepub async fn open(
path: &str,
max_payload_bytes: u64,
) -> Result<Self, DurableError>
pub async fn open( path: &str, max_payload_bytes: u64, ) -> Result<Self, DurableError>
Open (or create) a backend on a dedicated durable.db file (or :memory:).
Connecting also applies the schema migrations, so a freshly opened backend is ready to use;
init may still be called and is idempotent.
§Errors
Returns DurableError::Storage if the pool cannot be opened or migrations fail.
Sourcepub fn with_cipher(self, cipher: Arc<dyn PayloadCipher>) -> Self
pub fn with_cipher(self, cipher: Arc<dyn PayloadCipher>) -> Self
Inject the AEAD payload cipher used to seal and open payload-bearing entries.
Sourcepub fn with_hmac_key(self, key: [u8; 32]) -> Self
pub fn with_hmac_key(self, key: [u8; 32]) -> Self
Configure the keyed-BLAKE3 HMAC key stamped over control entries on shared-database deployments.
Sourcepub fn pool(&self) -> &DbPool
pub fn pool(&self) -> &DbPool
Borrow the underlying pool (for tests and adapters that need direct access).
Sourcepub async fn init(&self) -> Result<(), DurableError>
pub async fn init(&self) -> Result<(), DurableError>
Apply the durable schema migrations to the backing pool.
Idempotent: safe to call repeatedly. The schema is owned by zeph-db, not this crate.
§Errors
Returns DurableError::Storage if a migration fails.
Sourcepub async fn list_executions(
&self,
status: Option<&str>,
kind: Option<&str>,
limit: i64,
) -> Result<Vec<ExecutionSummary>, DurableError>
pub async fn list_executions( &self, status: Option<&str>, kind: Option<&str>, limit: i64, ) -> Result<Vec<ExecutionSummary>, DurableError>
List execution summaries for operability surfaces (the zeph durable CLI and TUI).
Returns at most limit executions, newest first, optionally filtered by status and kind
(each is matched against the raw column tag; None disables that filter). Only execution-level
metadata is read — never payload bytes or resolver tokens (INV-5). The per-execution step
count is the number of journal entries recorded for it.
Span: durable.backend.list.
§Errors
Returns DurableError::Storage if the query fails, or DurableError::Decode if a stored
id or status cannot be reconstructed (schema corruption — the status column is
CHECK-constrained, so this is a fail-closed guard rather than a routine path).
Sourcepub async fn read_execution_redacted(
&self,
id: ExecutionId,
) -> Result<Vec<RedactedEntry>, DurableError>
pub async fn read_execution_redacted( &self, id: ExecutionId, ) -> Result<Vec<RedactedEntry>, DurableError>
Read one execution’s journal entries as redaction-safe metadata, without decrypting payloads.
Unlike read_execution, this never touches the cipher, so it works
against a journal whose AEAD key is unavailable and never exposes plaintext (INV-5). It backs
the default (redacted) zeph durable show/inspect output. Entries are returned in append
order.
Span: durable.backend.read_redacted.
§Errors
Returns DurableError::Storage if the query fails.
Sourcepub async fn count_prunable(
&self,
policy: &RetentionPolicy,
) -> Result<u64, DurableError>
pub async fn count_prunable( &self, policy: &RetentionPolicy, ) -> Result<u64, DurableError>
Count terminal executions a prune sweep would delete under policy.
Read-only: backs zeph durable prune --dry-run. It applies the same TTL cutoffs as the
delete path, so the count is exactly what a real sweep would remove now.
§Errors
Returns DurableError::Storage if the query fails.
Sourcepub async fn open_execution(
&self,
id: ExecutionId,
kind: ExecutionKind,
) -> Result<bool, DurableError>
pub async fn open_execution( &self, id: ExecutionId, kind: ExecutionKind, ) -> Result<bool, DurableError>
Ensure a durable_executions row exists for id, returning whether this is a resume.
Inserts a fresh running row for a new execution (returning false) or detects an existing
row for a resumed one (returning true). The journal’s foreign key requires this row before
any entry is appended, so callers open the execution first.
Span: durable.backend.open.
§Errors
Returns DurableError::Storage if the lookup or insert fails.
Trait Implementations§
Source§impl Debug for LocalBackend
impl Debug for LocalBackend
Source§impl ExecutionBackend for LocalBackend
impl ExecutionBackend for LocalBackend
Source§fn capabilities(&self) -> BackendCapabilities
fn capabilities(&self) -> BackendCapabilities
Source§async fn lookup_committed_result(
&self,
id: ExecutionId,
idem_key: IdempotencyKey,
) -> Result<Option<JournalEntry>, DurableError>
async fn lookup_committed_result( &self, id: ExecutionId, idem_key: IdempotencyKey, ) -> Result<Option<JournalEntry>, DurableError>
Source§impl Journal for LocalBackend
impl Journal for LocalBackend
Source§async fn append(&self, entry: JournalEntry) -> Result<JournalSeq, DurableError>
async fn append(&self, entry: JournalEntry) -> Result<JournalSeq, DurableError>
Source§async fn read_execution(
&self,
id: ExecutionId,
) -> Result<Vec<JournalEntry>, DurableError>
async fn read_execution( &self, id: ExecutionId, ) -> Result<Vec<JournalEntry>, DurableError>
Source§async fn read_execution_range(
&self,
id: ExecutionId,
from_step_id: u32,
limit: usize,
) -> Result<Vec<JournalEntry>, DurableError>
async fn read_execution_range( &self, id: ExecutionId, from_step_id: u32, limit: usize, ) -> Result<Vec<JournalEntry>, DurableError>
Source§async fn finalize(
&self,
id: ExecutionId,
status: ExecutionStatus,
) -> Result<(), DurableError>
async fn finalize( &self, id: ExecutionId, status: ExecutionStatus, ) -> Result<(), DurableError>
Source§async fn prune(&self, policy: &RetentionPolicy) -> Result<u64, DurableError>
async fn prune(&self, policy: &RetentionPolicy) -> Result<u64, DurableError>
policy and return the number of rows deleted. Read moreAuto Trait Implementations§
impl !Freeze for LocalBackend
impl !RefUnwindSafe for LocalBackend
impl !UnwindSafe for LocalBackend
impl Send for LocalBackend
impl Sync for LocalBackend
impl Unpin for LocalBackend
impl UnsafeUnpin for LocalBackend
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more