wasm_redb_proto (wasm_redb v0.1.0)
View SourceEncodes requests to the redb guest and decodes its responses.
This is the Erlang half of engines/redb/src/abi.rs; the layouts are
described there and in docs/abi.md. Each request function returns
{Op, Payload} for wasm_storage_guest:call/4; decode/2 turns the
guest's answer to that op into a term.
Transaction id 0 asks the guest for an implicit transaction: a fresh read
transaction for a read, a fresh write transaction committed with the
database's default durability for a write.
call/2 encodes a request in the caller's process, everything but the
transaction id, which only the database process knows; in_txn/2 adds it
there. A bad argument therefore fails in the caller, with
{badarg, {What, Value}}, and never reaches the database process.
Summary
Functions
Opts: durability, two_phase_commit, quick_repair.
Encode a request that runs in a transaction, all but the transaction id.
F names one of the functions below that take a transaction first, and
Args are its other arguments. Raises {badarg, {What, Value}}.
Decode the body of a successful response to Op.
Whether the operation Op ends the transaction it runs in.
Whether an error Reason leaves the guest in a state that cannot be
trusted: the database replaces the guest and reopens the file.
Merge writes that run in one transaction into as few guest calls as their
layout allows: a run of puts and batches becomes one batch, which opens each
table once for all of them; any other write keeps a call of its own. Each
step is the number of writes it stands for, and its call, as call/2
encodes it.
Opts: backend (host for device 0, memory for redb's in-guest
memory), cache_size in bytes, durability (immediate or none, the
default of implicit and explicit write transactions), two_phase_commit and
quick_repair (booleans), and mode: exclusive (the default),
single_writer (a writer that read-only guests may share the file with,
through the host's locks) or read_only (one of those readers).
A chunk of a range. Opts: reverse (boolean), max_items (0 for no
limit), max_bytes (at least one entry is always returned).
The atom for a guest error code (engines/redb/src/engine.rs, Code). Keep
the two in step: the codes are numbered by hand on both sides.
Types
Functions
-spec batch(non_neg_integer(), [op()]) -> {non_neg_integer(), iodata()}.
Opts: durability, two_phase_commit, quick_repair.
Encode a request that runs in a transaction, all but the transaction id.
F names one of the functions below that take a transaction first, and
Args are its other arguments. Raises {badarg, {What, Value}}.
Decode the body of a successful response to Op.
-spec ends_transaction(non_neg_integer()) -> boolean().
Whether the operation Op ends the transaction it runs in.
Whether an error Reason leaves the guest in a state that cannot be
trusted: the database replaces the guest and reopens the file.
-spec in_txn({atom(), binary()}, non_neg_integer()) -> {non_neg_integer(), iodata()}.
A request call/2 encoded, in transaction Txn.
-spec merge_writes([{atom(), binary()}]) -> [{pos_integer(), {atom(), binary()}}].
Merge writes that run in one transaction into as few guest calls as their
layout allows: a run of puts and batches becomes one batch, which opens each
table once for all of them; any other write keeps a call of its own. Each
step is the number of writes it stands for, and its call, as call/2
encodes it.
Opts: backend (host for device 0, memory for redb's in-guest
memory), cache_size in bytes, durability (immediate or none, the
default of implicit and explicit write transactions), two_phase_commit and
quick_repair (booleans), and mode: exclusive (the default),
single_writer (a writer that read-only guests may share the file with,
through the host's locks) or read_only (one of those readers).
-spec range(non_neg_integer(), binary(), bound(), bound(), map()) -> {non_neg_integer(), iodata()}.
A chunk of a range. Opts: reverse (boolean), max_items (0 for no
limit), max_bytes (at least one entry is always returned).
The atom for a guest error code (engines/redb/src/engine.rs, Code). Keep
the two in step: the codes are numbered by hand on both sides.
Whether Call is a request call/2 could have returned.