barrel_design_view (barrel_design v0.1.0)
View SourceThe indexer of one view: the only writer of its index.
It follows the database's changes feed in batches (barrel_docdb: read_feed/3), maps each changed document and replaces the document's rows, reverse entry, error and the view's checkpoint in one write batch. It keeps running with no readers. A first build reads the feed from the start; the generation becomes complete once a page is short, that is once it has caught up with the database.
A changed definition (or rebuild) fills a new generation while the current one keeps serving and following the feed. When the new one catches up, one batch makes it current and deletes the old rows: a generation is deleted in the same batch as the state write that stops naming it, and on load any generation the state does not name (left by an interrupted run of earlier code) is deleted too. A pass that reads nothing new writes nothing.
A guest call cut by its timeout_ms says nothing about the document (fuel bounds its work): the batch is not applied and is retried after a growing pause, and status reports the view stalled meanwhile. A stall holds only its own generation: while the current one waits for its retry, a building one keeps advancing, so a corrected definition can catch up and take over.
Freshness waits only observe progress; a refresh captures the database's last write once and wakes the indexer. Both answer with the current generation's checkpoint once it covers their target, or with an error carrying the checkpoint reached at their deadline.
Summary
Functions
Catch up with the database's last write as of this call.
Start building a view that has never been built (build => on_first_read); a view already started ignores it.
Wait until the current generation covers Target (#{instance_id, last_seq}) or the deadline passes.
Functions
-spec rebuild(pid()) -> {ok, non_neg_integer()}.
Catch up with the database's last write as of this call.
-spec set_definition(pid(), map(), binary(), pos_integer()) -> {ok, map()}.
-spec start(pid()) -> ok.
Start building a view that has never been built (build => on_first_read); a view already started ignores it.
Wait until the current generation covers Target (#{instance_id, last_seq}) or the deadline passes.