barrel_docdb_reader (barrel_docdb v1.1.1)
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.
Fold over documents under one snapshot, in the caller's process (off the writer loop). Honors id_prefix by bounding the scan to the matching key range instead of scanning the whole database, and include_deleted. The fold fun gets (Doc, Acc) and returns {ok, Acc} / {stop, Acc} / stop, like barrel_docdb:fold_docs/4.
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 fold_docs(barrel_store_rocksdb:db_ref(), db_name(), fun(), term(), map()) -> {ok, term()} | {error, term()}.
Fold over documents under one snapshot, in the caller's process (off the writer loop). Honors id_prefix by bounding the scan to the matching key range instead of scanning the whole database, and include_deleted. The fold fun gets (Doc, Acc) and returns {ok, Acc} / {stop, Acc} / stop, like barrel_docdb:fold_docs/4.
-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.