barrel_rep_alg (barrel_docdb v1.0.0)

View Source

barrel_rep_alg - Replication algorithm

Implements the core version-vector replication algorithm: one diff_versions round-trip per batch of changes, then a get_doc + put_version per missing document. Conflict handling lives entirely in the target's put_version (fast-forward, ignore, or record a conflict sibling), so the algorithm itself needs no ancestor negotiation.

Summary

Functions

Replicate a list of changes from source to target.

Replicate changes in batches with checkpoint callback

Types

att_info/0

-type att_info() ::
          #{name := binary(),
            content_type := binary(),
            length := non_neg_integer(),
            digest := binary(),
            chunked => boolean(),
            chunk_size => pos_integer(),
            chunk_count => pos_integer()}.

change/0

-type change() :: map().

db_config/0

-type db_config() :: #{path => string(), store => module(), atom() => term()}.

db_name/0

-type db_name() :: binary().

db_ref/0

-type db_ref() :: pid() | atom().

doc/0

-type doc() :: #{binary() => term()}.

doc_info/0

-type doc_info() :: #{id := docid(), rev := revid(), deleted := boolean(), revtree := revtree()}.

docid/0

-type docid() :: binary().

endpoint/0

-type endpoint() :: db_name() | {node(), db_name()} | {module(), term()}.

rep_options/0

-type rep_options() ::
          #{continuous => boolean(),
            since => seq_string(),
            filter => fun((doc()) -> boolean()),
            atom() => term()}.

rev_info/0

-type rev_info() ::
          #{id := revid(),
            parent := revid() | undefined,
            deleted := boolean(),
            attachments => #{binary() => att_info()}}.

revid/0

-type revid() :: binary().

revtree/0

-type revtree() :: #{revid() => rev_info()}.

seq/0

-type seq() :: barrel_hlc:timestamp().

seq_string/0

-type seq_string() :: binary().

view_name/0

-type view_name() :: binary().

view_result/0

-type view_result() :: #{key := term(), value := term(), id := docid()}.

Functions

replicate(Source, Target, SourceTransport, TargetTransport, Changes)

-spec replicate(term(), term(), module(), module(), [map()]) -> {ok, map()} | {error, term()}.

Replicate a list of changes from source to target.

replicate_batch(Source, Target, SourceTransport, TargetTransport, Opts)

-spec replicate_batch(term(), term(), module(), module(), map()) -> {ok, map()} | {error, term()}.

Replicate changes in batches with checkpoint callback