Skip to content

Pull replication: attachment bodies (phase 2)#214

Open
benoitc wants to merge 2 commits into
masterfrom
feature/pull-replicator-phase2
Open

Pull replication: attachment bodies (phase 2)#214
benoitc wants to merge 2 commits into
masterfrom
feature/pull-replicator-phase2

Conversation

@benoitc

@benoitc benoitc commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Phase 2 of 2 (builds on #213). Adds attachment-body replication to the pull replicator. The target behaviour contract is unchanged from phase 1.

What changed

  • couchbeam_replicator: fetch_rev now requests each revision with {revs,true} and attachments=true, reassembling the document and its attachment bodies via the multipart couchbeam:stream_doc/1 path. Each target entry is {Doc, #{AttName => Bin}}; a revision with no attachments (or a deletion) still comes back as plain JSON with #{}. Bytes are stored as delivered (the doc's _attachments records content type and any encoding, e.g. gzip for compressible types).
  • couchbeam: fixed the open_doc/3 and stream_doc/1 -specs, which omitted the real multipart returns ({ok, {multipart, _}} and {doc, Doc, doc_stream()}). dialyzer caught the mismatch via the replicator; the specs now match runtime behaviour.

Tests

pull_replication_attachments (in the pull_replication_ops group) puts an attachment on a source doc, replicates into the ets target, and asserts the body is replicated verbatim and the _attachments stub is preserved.

Verified: rebar3 eunit (32), xref, dialyzer clean; make e2e green across all groups (replication group now 3 tests) on CouchDB 3.5.x.

benoitc added 2 commits June 10, 2026 14:54
Fetch each missing revision via the multipart open_doc path and reassemble the
document together with its attachment bodies, handed to the target as
{Doc, #{AttName => Bin}}. Bytes are kept as delivered (encoding recorded in the
doc's _attachments). The target behaviour contract is unchanged from phase 1.

- couchbeam_replicator: fetch_rev uses {revs,true} + attachments via stream_doc
- couchbeam: fix open_doc/3 and stream_doc/1 specs to include the multipart
  returns ({ok,{multipart,_}} and {doc, Doc, doc_stream()}) so dialyzer passes
- e2e: pull_replication_attachments asserts the body is replicated verbatim and
  the _attachments stub is preserved
- guide + CHANGELOG updated
- pull_replication_conflicts: a doc with two conflicting leaf revisions
  (built via bulk_docs new_edits=false) replicates all leaves with history
- pull_replication_continuous: continuous mode imports a doc added while the
  replicator is running, then stops cleanly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant