State storage
On this page
State that outlives one call, or crosses worker processes.
trait FunctionStorage
Section titled “trait FunctionStorage”pub trait FunctionStorage: Send + Sync { // --- key/value (overwrite), keyed by (scope, key) ---
fn kv_get(&self, scope: &[u8], key: &[u8]) -> Option<Vec<u8>>; fn kv_put(&self, scope: &[u8], key: &[u8], value: &[u8]); fn kv_del(&self, scope: &[u8], key: &[u8]);
// --- append-only log, keyed by (scope, ns, key) ---
fn append(&self, scope: &[u8], ns: &[u8], key: &[u8], value: Vec<u8>) -> i64; fn scan( &self, scope: &[u8], ns: &[u8], key: &[u8], after_id: i64, limit: usize, ) -> Vec<(i64, Vec<u8>)>;
// --- FIFO work queue per scope ---
fn queue_push(&self, scope: &[u8], items: &[Vec<u8>]); fn queue_pop(&self, scope: &[u8]) -> Option<Vec<u8>>;
// --- lifecycle ---
fn clear(&self, scope: &[u8]);
fn gc(&self, ttl: Duration) { let _ = ttl; }}Description
Backend contract for cross-process worker state. Keys are opaque byte
strings; scope is the execution id (or a transaction id). Implementations
must be safe to share across threads and processes.
constant DEFAULT_ORPHAN_TTL_SECS
Section titled “constant DEFAULT_ORPHAN_TTL_SECS”pub const DEFAULT_ORPHAN_TTL_SECS: u64 = 24 * 60 * 60;Description
Default age after which idle state is treated as a crashed-worker orphan.
Overridable via VGI_BUFFERING_STORE_TTL_SECS.
struct FsStorage
Section titled “struct FsStorage”pub struct FsStorage { base: PathBuf,}Description
Cross-process append-log + kv + queue store backed by the filesystem.
type_alias SharedStorage
Section titled “type_alias SharedStorage”pub type SharedStorage = Arc<dyn FunctionStorage>;Description
A shared, thread-safe handle to the worker’s storage backend.
function default_storage
Section titled “function default_storage”pub fn default_storage() -> Arc<dyn FunctionStorage>Description
Construct the worker’s storage backend from VGI_WORKER_SHARED_STORAGE
(memory | fs | sqlite | http). Unset selects sqlite when compiled
in, else fs. Runs an orphan GC pass on construction.
function orphan_ttl
Section titled “function orphan_ttl”pub fn orphan_ttl() -> DurationDescription
The configured orphan TTL.