barrel_design_reduce (barrel_design v0.1.0)

View Source

One group totalled by a Wasm reducer at read time, within bounds.

Values arrive in index order (key, document id, ordinal). A leaf call takes 1 to max_reduce_values values within max_reduce_bytes; a rereduce call takes 2 to max_reduce_values partials within the same bytes. Every value and partial is at most max_value_bytes, and max_reduce_bytes >= 2 * max_value_bytes + 16, so two partials always fit one call and combining always makes progress.

The state is a carried partial P, covering the group from its first row to the row at key K, plus pending partials and a leaf buffer after K: at most two max_reduce_bytes of values and P. When the pending partials and P could no longer take another partial, they combine into a new P. A deadline stop carries P and K without a guest call; a scan stop first combines everything into P. The reducer is never called with zero values.

Summary

Functions

What a deadline stop can carry without calling the guest: the partial P and the key it covers up to, or none.

Everything folded into one partial, for a scan stop: {P, K}.

The group's result.

A group whose first row is at key First.

A group carried in a continuation: P covers it up to key K.

Types

reducer/0

-type reducer() ::
          #{call := fun(([term()], boolean()) -> {ok, term()} | {error, term()}),
            values := pos_integer(),
            bytes := pos_integer(),
            value_bytes := pos_integer()}.

state/0

-type state() :: map().

step/0

-type step() :: {ok, state()} | {deadline, state()} | {error, term()}.

Functions

add(V, Key, S)

-spec add(term(), binary(), state()) -> step().

carry(_)

-spec carry(state()) -> {term(), binary()} | none.

What a deadline stop can carry without calling the guest: the partial P and the key it covers up to, or none.

checkpoint(S)

-spec checkpoint(state()) -> {ok, {term(), binary()}} | {deadline, state()} | {error, term()}.

Everything folded into one partial, for a scan stop: {P, K}.

finish(S)

-spec finish(state()) -> {ok, term()} | {deadline, state()} | {error, term()}.

The group's result.

new(R, First)

-spec new(reducer(), binary()) -> state().

A group whose first row is at key First.

resume(R, P, K)

-spec resume(reducer(), term(), binary()) -> state().

A group carried in a continuation: P covers it up to key K.