class CouchDB::Replication::Replicator

Overview

Implements the 7-step CouchDB replication protocol between two adapters.

Replication is resumable: a Checkpoint document is written to both source and target after every batch of BATCH_SIZE (100) documents so that an interrupted run can continue from where it left off.

Steps per batch:

  1. Verify peers (fetch info from source and target)
  2. Read checkpoint (determine since sequence)
  3. Fetch changes feed from source
  4. Call revs_diff on target to find missing revisions
  5. Fetch missing documents from source via bulk_get
  6. Write documents to target via bulk_docs(new_edits: false)
  7. Write checkpoint to both source and target

Defined in:

couchdb/replication/replicator.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(source : Adapter, target : Adapter, doc_ids : Array(String) | Nil = nil, filter : Proc(Document, Bool) | Nil = nil, checkpoint_store : Adapter | Nil = nil) #

Creates a replicator that will copy documents from source to target.

doc_ids limits replication to a specific set of document IDs (applied before revs_diff to avoid unnecessary network calls).

filter is an arbitrary predicate applied after bulk_get; only documents for which it returns true are written to the target.

Both options are composable: set both to filter by ID and by content.


[View source]

Instance Method Detail

def replicate : Session #

Runs the full replication loop and returns a Session with transfer statistics.

The loop continues until the changes feed returns fewer results than BATCH_SIZE, indicating that all pending changes have been transferred. On error, returns a failed Session with the exception message in error.


[View source]