barrel_design_guest (barrel_design v0.1.0)

View Source

Run a guest map over a batch of documents.

A batch runs in one job process spawned by the caller, with a heap cap that kills it. Each document gets a fresh instance (no state survives from one document to the next), finite fuel, a call depth, a host-call and a page limit, and is destroyed after its call. The caller enforces a wall-clock deadline per document by killing the job; the remaining documents continue in a new one. Rows a guest emits are staged in the job and reported only when its call returns.

Guest imports (barrel_v1):

  • field(slot, dest, capacity) -> len: copies the slot's value, as wire CBOR, to guest memory and returns its length, or -1 when the document lacks the field or it has another type. A value larger than the capacity traps.
  • emit(key, key_len, value, value_len): stages one row. Key and value are CBOR (integers, UTF-8 texts, booleans, null, arrays) and must match the view's declared types.
  • input(dest, capacity) -> len: for a reducer, copies its batch, a CBOR array of values (or of partials when rereducing), and returns its length. A batch larger than the capacity traps.
  • output(ptr, len): for a reducer, its result, CBOR of the reducer's value type within max_value_bytes, given exactly once.

Every instance is given all four imports, because instantiation resolves them all; each call fixes its role. A map that calls input or output, or a reducer that calls field or emit, traps with {import_not_allowed, Role, Name}.

Summary

Functions

Run a reducer once over Batch: values (rereduce false) or partials (true). Spec: export, value (the reducer's value spec) and the view's limits. Opts: the caller's slot (required) and an optional absolute deadline (monotonic milliseconds) that shortens the call's own timeout_ms. Returns the reducer's output or why it failed; the instance is fresh and destroyed after the call.

Map each document; results come back in document order. Opts: slot, the barrel_design_slots slot the caller holds (required: no guest runs outside the node's budget), and retries for a document that timed out or whose job died (default 2) before its error is reported.

Types

result/0

-type result() :: {ok, [{barrel_design_key:key(), barrel_design_key:key()}]} | {error, term()}.

Functions

bind_job(Slot, Job)

-spec bind_job(barrel_design_slots:slot(), pid()) -> ok | {error, revoked}.

reduce(Module, Spec, Batch, Rereduce, Opts)

-spec reduce(term(), map(), [term()], boolean(), map()) -> {ok, term()} | {error, term()}.

Run a reducer once over Batch: values (rereduce false) or partials (true). Spec: export, value (the reducer's value spec) and the view's limits. Opts: the caller's slot (required) and an optional absolute deadline (monotonic milliseconds) that shortens the call's own timeout_ms. Returns the reducer's output or why it failed; the instance is fresh and destroyed after the call.

run(Module, Spec, Docs, Opts)

-spec run(term(), map(), [map()], map()) -> [result()].

Map each document; results come back in document order. Opts: slot, the barrel_design_slots slot the caller holds (required: no guest runs outside the node's budget), and retries for a document that timed out or whose job died (default 2) before its error is reported.