anchor.diff:  
   replicate_change(Source, Target, StartSeq, Metrics) ->
     {LastSeq, Changes} = changes(Source, StartSeq),
  -  Results = maps:get(<<"results">>, Changes),
     Results = maps:get(<<"results">>, Changes) ,
     {ok, Metrics2} = lists:foldl(fun(C, {ok, Acc}) ->
                              sync_change(Source, Target, C, Acc)
  
positive.code:   Mod:get(ModState, Id, Opts);
  get(Conn, Id, Opts) when is_map(Conn) ->
    barrel_db:get(Conn, Id, Opts).
  
  %% put({Mod,_Db}=DbRef, Id, Doc, Opts) ->
  %%   Mod:put(DbRef, Id, Doc, Opts);
  %% put(Db, Id, Doc, Opts) when is_binary(Db) ->
  %%   barrel_db:put(Db, Id, Doc, Opts).
  
  put_rev({Mod, ModState}, Id, Doc, History, Opts) ->
    Mod:put_rev(ModState, Id, Doc, History, Opts);
  
negative.code:   {ok, LastSeq, Metrics2}.
  
  sync_change(Source, Target, Change, Metrics) ->
    #{id := DocId, changes := History} = Change,
    {ok, MissingRevisions, _PossibleAncestors} = barrel:revsdiff(Target, DocId, History),
    Metrics2 = lists:foldl(fun(Revision, Acc) ->
                               sync_revision(Source, Target, DocId, Revision, Acc)
                           end, Metrics, MissingRevisions),
    {ok, Metrics2}.
  
  sync_revision(Source, Target, DocId, Revision, Metrics) ->
    {Doc, Metrics2} = read_doc_with_history(Source, DocId, Revision, Metrics),
    History = barrel_doc:parse_revisions(Doc),
    DocWithoutRevisions = maps:remove(<<"_revisions">>, Doc),
    Metrics3 = write_doc(Target, DocId, DocWithoutRevisions, History, Metrics2),
    Metrics3.
  
  read_doc_with_history(Source, Id, Rev, Metrics) ->
    Get = fun() -> get(Source, Id, [{rev, Rev}, {history, true}]) end,
    case timer:tc(Get) of
      {Time, {ok, Doc}} ->
        Metrics2 = barrel_metrics:inc(docs_read, Metrics, 1),
        Metrics3 = barrel_metrics:update_times(doc_read_times, Time, Metrics2),
        {Doc, Metrics3};
      _ ->
        Metrics2 = barrel_metrics:inc(doc_read_failures, Metrics, 1),
        {undefined, Metrics2}
    end.
  
  write_doc(_, _, undefined, _, Metrics) ->
    Metrics;
  