barrel_docdb_reader (barrel_docdb v1.0.0)
View SourceCaller-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
-type att_info() :: #{name := binary(), content_type := binary(), length := non_neg_integer(), digest := binary(), chunked => boolean(), chunk_size => pos_integer(), chunk_count => pos_integer()}.
-type change() :: map().
-type db_name() :: binary().
-type docid() :: binary().
-type revid() :: binary().
-type seq() :: barrel_hlc:timestamp().
-type seq_string() :: binary().
-type view_name() :: binary().
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.
-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).
-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.
-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.