Pull replication endpoint (gen_statem) - phase 1#213
Merged
Conversation
couchbeam_replicator is a gen_statem that pulls documents and their full
revision history from a source CouchDB into a pluggable local target behaviour.
Pull only, resumable via a target-stored checkpoint. Attachment bodies are
deferred to phase 2 (target entries are {Doc, #{}} for now).
- couchbeam_replicator: engine + target behaviour (revs_diff, write_docs,
read/write_checkpoint); oneshot and continuous modes; status/pause/resume
- couchbeam_replicator_ets: ets/dets reference target preserving _revisions
- guides/replication.md, ex_doc Replication group
- e2e group pull_replication_ops (docs + history + deletion + resume), wired
into run-e2e.sh and the CI CouchDB matrix
- CHANGELOG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of 2. Adds a client-side CouchDB pull replicator. Phase 2 will add attachment bodies; the target behaviour contract is already final so phase 2 is additive.
What it does
couchbeam_replicatoris agen_statemthat reads the changes feed and document revisions from a source CouchDB and writes them into a pluggable local target (a behaviour the app implements). It preserves each document's full revision history (_revisions), handles deletions, and is resumable. Pull only (CouchDB -> app).The source side reuses existing couchbeam APIs:
couchbeam_changes:follow_once/2(withstyle=all_docs,since,limit),couchbeam:open_doc/3({rev,R},{revs,true}to fetch a revision with its history), anddb_info/1. The target does therevs_diff/write_docs, so no push path is involved.API
start_link(Source, TargetMod, TargetArgs, Opts);status/1,pause/1,resume/1,stop/1.mode(oneshot|continuous),batch_size,interval,repl_id,notify,changes_options.init/1,revs_diff/2,write_docs/2,read_checkpoint/2,write_checkpoint/3, optionalterminate/2.write_docstakes[{Doc, Atts}](Atts#{}in phase 1, populated in phase 2).Resume
Stable
repl_id+ target-persisted sourcelast_seq+revs_diff-gated idempotent writes. No CouchDB_localdoc needed. With the dets backend, resume survives a restart.Reference target + docs
couchbeam_replicator_ets(ets or dets backend) stores every revision, leaf revs, and the checkpoint.guides/replication.mddocuments usage, resume, and writing a target.Tests
New e2e group
pull_replication_ops(wired intorun-e2e.shand the CI CouchDB matrix): replicates docs with multi-rev history and a deletion into an ets target and asserts the import; a second run with the samerepl_idresumes from the checkpoint and imports only the new changes.Verified:
rebar3 eunit(32),xref,dialyzerclean;make e2egreen (all 16 groups) against CouchDB 3.5.x.