Skip to content
Query.Farm
Talk with Us

State storage

On this page

State that outlives one call, or crosses worker processes.

source
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.

source
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.

source
pub struct FsStorage {
base: PathBuf,
}

Description

Cross-process append-log + kv + queue store backed by the filesystem.

source
pub type SharedStorage = Arc<dyn FunctionStorage>;

Description

A shared, thread-safe handle to the worker’s storage backend.

source
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.

source
pub fn orphan_ttl() -> Duration

Description

The configured orphan TTL.