Skip to main content

Module object

Module object 

Expand description

Keyed objects: handlers per key with key/value state, built from Fusee’s records.

An object type is a set of handlers; each key of the type is one object with its own key/value state (JSON values under string keys). A key is a long-lived run with workflow ID <type>/<key>, marked policy::OBJECT in its Start record, and each call is an update of that run. So there is no new kind of storage: a key is recovered, replicated, parked, listed and exported as a run, and every client that can send an update-with-start can call an object.

What the engine adds (in [crate::runtime]):

  • Exclusive calls run one at a time per key, in the order they reach the key’s shard. A call is accepted (its Update record appended) when its handler starts; an exclusive call that arrives while another runs waits for the key, in memory, in arrival order. Shared calls are accepted at once.
  • State lives next to the run. Reads are synchronous host calls and are not journaled. An exclusive handler’s writes are its own until it returns; then they are committed with its result, in its UpdateDone record (encode_delta). A failed handler commits nothing. Commits happen when handlers return, at positions the journal fixes, so a replayed handler reads what it read the first time.
  • Calls from workflow code are Child operations flagged policy::OBJECT (encode_call): they go through the durable outbox, the key’s Update record names the caller, and its UpdateDone sends the result back as a child result.
  • Retries with an ID run once: within a run by the update ID, and across compaction through the calls the snapshot keeps (Kept).
  • Compaction: when no handler runs and the key’s run has made COMPACT_OPS journal operations, or it is idle and about to be parked, the engine continues the run as new with a Snapshot as the new run’s input. Loading or recovering a key replays at most that much handler code, and an idle key’s journal is one record.

See docs/features.md#objects-keyed-state for the semantics.

Re-exports§

pub use edit::EDIT_HANDLER;

Modules§

edit
Edits of a key’s state from outside its handlers.

Structs§

CallOptions
The options of a call to an object’s handler.
Kept
A finished call a key remembers across compaction, so a retry with its ID gets its result instead of running again.
Object
A registered object type.
ObjectCall
A key of an object type, called from workflow code (or another object’s handler): Ctx::object.
ObjectCtx
What an object’s handler gets: the workflow context of the key’s run, plus its state and key.
ObjectDef
What the runtime knows about an object type: which handlers are shared (every other handler is exclusive).
ObjectDetail
What inspect adds for an object run.
ObjectHandlers
An object type’s handlers, and the workflow code they become: what ObjectType registers on an engine, and what a simulator or another registry takes (into_code).
ObjectRef
A key of an object type, to call from outside workflow code.
ObjectType
An object type being defined: Engine::object, then its handlers, then register.
PendingCall
A call to a key that has not finished: running, or waiting for the key.
Snapshot
A key’s state and remembered calls: the input of each of its runs.
State
A key’s state, as a handler sees it.

Constants§

COMPACT_OPS
Journal operations after which a key’s run is compacted at the next moment no handler runs.
KEPT_CALLS
Calls with IDs a key remembers across compaction, at most.
KEPT_CALL_MS
How long a key remembers a call’s ID and result after compaction.
MAX_WAITING
Calls that may wait for one key at once; more are refused as busy.
SEND_PREFIX
Update IDs of one-way calls (send) start with this: their callers are answered once the call is accepted, not when it finishes.
STATE_QUERY
The query every object answers with its committed state.

Functions§

check_type
Checks an object type’s name: it is the first part of its keys’ IDs.
decode_call
encode_call back: (handler, id, argument).
decode_delta
encode_call
A call from workflow code, as a Child record’s input: the handler, the call’s ID (made from the caller’s journal position) and the argument.
encode_delta
One handler’s committed state changes, as its UpdateDone carries them: a JSON object, null for a cleared key.
is_auto_id
Whether an update ID was made up by the engine (no caller ID to keep).
is_object_journal
Whether a journal is an object run’s.
is_send
Whether the update is a one-way call.
key_of
The key of an object run’s workflow ID.
object_id
The workflow ID of key key of object type wtype.
state_json
The state as one JSON object.
view
An object run’s committed state and running calls from its journal alone: the snapshot, then every recorded commit in order. No code runs. open removes the codec from a sealed payload.