barrel_docdb_reader (barrel_docdb v1.0.0)

View Source

Caller-side point reads over the document store.

Point reads (get_doc, get_docs) need nothing from the database server state except the store ref and the database name, so they can run in the caller's process against a RocksDB snapshot instead of serializing behind the writer. The snapshot keeps the entity and body reads consistent with each other while a concurrent write batch commits.

Callers resolve the store ref via persistent_term (the {barrel_store, DbName} registry published by barrel_db_server; see barrel_doc_body_store for the same pattern). The server's own get_doc/get_docs handlers delegate here too, so there is a single read implementation.

Summary

Functions

Whether an entity's expires_at column marks the document lazily expired: the TTL sweeper turns these into real tombstones, and reads treat them as gone in the meantime.

Get a document by id, reading entity and body under one snapshot.

Get multiple documents by id under one snapshot (batch read).

Read a document for the replication protocol: body (tombstones included), version token, encoded version vector, and deleted flag, all under one snapshot.

Types

att_info/0

-type att_info() ::
          #{name := binary(),
            content_type := binary(),
            length := non_neg_integer(),
            digest := binary(),
            chunked => boolean(),
            chunk_size => pos_integer(),
            chunk_count => pos_integer()}.

change/0

-type change() :: map().

db_config/0

-type db_config() :: #{path => string(), store => module(), atom() => term()}.

db_name/0

-type db_name() :: binary().

db_ref/0

-type db_ref() :: pid() | atom().

doc/0

-type doc() :: #{binary() => term()}.

doc_info/0

-type doc_info() :: #{id := docid(), rev := revid(), deleted := boolean(), revtree := revtree()}.

docid/0

-type docid() :: binary().

endpoint/0

-type endpoint() :: db_name() | {node(), db_name()} | {module(), term()}.

rep_options/0

-type rep_options() ::
          #{continuous => boolean(),
            since => seq_string(),
            filter => fun((doc()) -> boolean()),
            atom() => term()}.

rev_info/0

-type rev_info() ::
          #{id := revid(),
            parent := revid() | undefined,
            deleted := boolean(),
            attachments => #{binary() => att_info()}}.

revid/0

-type revid() :: binary().

revtree/0

-type revtree() :: #{revid() => rev_info()}.

seq/0

-type seq() :: barrel_hlc:timestamp().

seq_string/0

-type seq_string() :: binary().

view_name/0

-type view_name() :: binary().

view_result/0

-type view_result() :: #{key := term(), value := term(), id := docid()}.

Functions

expired(Columns)

-spec expired([{binary(), term()}]) -> boolean().

Whether an entity's expires_at column marks the document lazily expired: the TTL sweeper turns these into real tombstones, and reads treat them as gone in the meantime.

get_doc(StoreRef, DbName0, DocId, Opts)

-spec get_doc(barrel_store_rocksdb:db_ref(), db_name(), docid(), map()) ->
                 {ok, map()} | {ok, binary(), map()} | {error, term()}.

Get a document by id, reading entity and body under one snapshot.

Same options and results as barrel_docdb:get_doc/3. Returns {error, not_found} if the store is closed underneath the caller (the close race maps to the same result as a missing database).

get_docs(StoreRef, DbName0, DocIds, Opts)

-spec get_docs(barrel_store_rocksdb:db_ref(), db_name(), [docid()], map()) ->
                  [{ok, map()} | {error, term()}].

Get multiple documents by id under one snapshot (batch read).

Same options and results as barrel_docdb:get_docs/3: one result per input id, in order.

get_replication_doc(StoreRef, DbName0, DocId)

-spec get_replication_doc(barrel_store_rocksdb:db_ref(), db_name(), docid()) ->
                             {ok,
                              #{doc := map(), version := binary(), vv := binary(), deleted := boolean()}} |
                             {error, term()}.

Read a document for the replication protocol: body (tombstones included), version token, encoded version vector, and deleted flag, all under one snapshot.