barrel_rep_checkpoint (barrel_docdb v1.0.0)

View Source

barrel_rep_checkpoint - Checkpoint management for replication

Manages replication checkpoints, which track the progress of replication between source and target databases. Checkpoints are stored as local documents (not replicated).

Summary

Functions

Decode HLC timestamp from storage

Delete checkpoints from both databases

Encode HLC timestamp for storage in checkpoint

Get the last processed HLC

Get the starting HLC for this replication session

Check if checkpoint should be written and write it if needed

Create a new checkpoint state

Set the last processed sequence (HLC timestamp)

Write checkpoint to both source and target databases

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().

checkpoint/0

-opaque checkpoint()

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

decode_seq(Bin)

Decode HLC timestamp from storage

delete(Checkpoint)

-spec delete(checkpoint()) -> ok.

Delete checkpoints from both databases

encode_seq(Hlc)

Encode HLC timestamp for storage in checkpoint

get_last_seq(Checkpoint)

-spec get_last_seq(checkpoint()) -> barrel_hlc:timestamp() | first.

Get the last processed HLC

get_start_seq(Checkpoint)

-spec get_start_seq(checkpoint()) -> barrel_hlc:timestamp() | first.

Get the starting HLC for this replication session

maybe_write_checkpoint(Checkpoint)

-spec maybe_write_checkpoint(checkpoint()) -> checkpoint().

Check if checkpoint should be written and write it if needed

new(RepConfig)

-spec new(map()) -> checkpoint().

Create a new checkpoint state

read_checkpoint_doc(Db, Transport, RepId)

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

Read checkpoint document

set_last_seq(Seq, Checkpoint)

-spec set_last_seq(barrel_hlc:timestamp() | first, checkpoint()) -> checkpoint().

Set the last processed sequence (HLC timestamp)

write_checkpoint(Checkpoint)

-spec write_checkpoint(checkpoint()) -> ok.

Write checkpoint to both source and target databases