barrel_design_index (barrel_design v0.1.0)

View Source

Row layout and reads of a view index.

In the derived store of a database, with V the view's 8-byte id and G a 32-bit generation:

  • r V G Key DocId Ord a row; its value is {Value, ExpiresAt}. Key and DocId use barrel_design_key's encoding, Ord is the emission ordinal, so a document can emit the same key twice;
  • b V G DocId the document's current rows and revision;
  • e V G DocId the error of the document's last map, if any;
  • s V the view state: generations, definitions, checkpoints.

The indexer replaces a document's rows, its reverse entry, its error and the state's checkpoint in one write batch.

Summary

Functions

Raw key bounds [Lower, Upper) for the selection options: key, key_prefix, start_key/end_key with inclusive_end (default true), and bounds (already encoded).

Operations replacing one document's contributions. Old is its reverse entry (or none); Result is the map's outcome for the current revision (skip when the document is gone or not selected).

Key ranges holding a generation's rows, reverse entries and errors.

Every view state the store holds, running or not.

Read rows or grouped totals of the published generation G under Snap, the snapshot the caller read the view state with. reduce totals with the view's reducer, grouped by the first group_level key components (exact for whole keys); limit rows or groups per call; max_scan rows folded per call, expired ones included.

Reverse entry keys for a batch of document ids.

Key ranges holding every generation of a view: its rows, reverse entries and errors, whatever its persisted state says.

Functions

bounds_for(View, Opts)

-spec bounds_for(map(), map()) -> {ok, {binary(), binary() | infinity}} | {error, term()}.

Raw key bounds [Lower, Upper) for the selection options: key, key_prefix, start_key/end_key with inclusive_end (default true), and bounds (already encoded).

doc_ops(V, G, Id, _, Old, Result)

-spec doc_ops(binary(),
              non_neg_integer(),
              binary(),
              {binary(), non_neg_integer()},
              not_found | {ok, binary()} | {error, term()},
              {ok, [term()]} | {error, term()} | skip) ->
                 list().

Operations replacing one document's contributions. Old is its reverse entry (or none); Result is the map's outcome for the current revision (skip when the document is gone or not selected).

generation_ranges(V, G)

-spec generation_ranges(binary(), non_neg_integer()) -> [{binary(), binary()}].

Key ranges holding a generation's rows, reverse entries and errors.

persisted_states(Store)

-spec persisted_states(barrel_design_store:store()) -> [{binary(), map()}].

Every view state the store holds, running or not.

query(Store, Snap, V, G, View, Opts)

-spec query(barrel_design_store:store(),
            rocksdb:snapshot_handle(),
            binary(),
            non_neg_integer(),
            map(),
            map()) ->
               {ok, [map()], map()} | {error, term()}.

Read rows or grouped totals of the published generation G under Snap, the snapshot the caller read the view state with. reduce totals with the view's reducer, grouped by the first group_level key components (exact for whole keys); limit rows or groups per call; max_scan rows folded per call, expired ones included.

position resumes a read at a position an earlier page returned, and now fixes the instant expiry is judged at. The meta carries start, the position of this page's first row, next, the position after it when more may follow, and now.

read_state(Store, V)

-spec read_state(barrel_design_store:store(), binary()) -> {ok, map()} | not_found.

read_state(Store, V, Snap)

-spec read_state(barrel_design_store:store(), binary(), rocksdb:snapshot_handle()) ->
                    {ok, map()} | not_found.

reduce_mode(_, Opts)

resume_key(_, Default)

-spec resume_key(map(), binary()) -> binary().

reverse_keys(V, G, Ids)

-spec reverse_keys(binary(), non_neg_integer(), [binary()]) -> [binary()].

Reverse entry keys for a batch of document ids.

state_key(V)

state_op(V, State)

view_id(Design, View)

-spec view_id(binary(), binary()) -> binary().

view_ranges(V)

-spec view_ranges(binary()) -> [{binary(), binary()}].

Key ranges holding every generation of a view: its rows, reverse entries and errors, whatever its persisted state says.