anchor.diff:  
       %% latency in millisecond
       TotalLatency = round(timer:now_diff(now(), Start) div 1000),
  -    Latency = case is_pid(XMemSrv) of
  -                  true ->
  +    Latency = case XMemLoc of
  +                  nil ->
  +                      TotalLatency;
  +                  _ ->
                         %% xmem is single doc based
                         try (TotalLatency div BigDocCount) of
                             X -> X
                         catch
                             error:badarith -> 0
  -                      end;
  +                      end
  +              end,
  +
  +
  +    RepMode = case XMemLoc of
  +                  nil ->
  +                      "capi";
                     _ ->
  -                      TotalLatency
  -              end,
  -
  -
  -    RepMode = case is_pid(XMemSrv) of
  -                  true ->
  -                      "xmem";
  -                  _ ->
  -                      "capi"
  +                      "xmem"
                 end,
       ?xdcr_trace("[replication mode: ~p] out of all ~p docs, number of small docs (including dels: ~p) is ~p, "
                   "number of big docs is ~p, threshold is ~p bytes, ~n\t"
  
positive.code: local_doc_handler(_, Acc) ->
      {ok, Acc}.
  
  -spec maybe_flush_docs(#httpdb{}, #batch{}, #doc{}, integer(), integer(), integer(), pid() | nil) ->
                                {#batch{}, integer()}.
  maybe_flush_docs(#httpdb{} = Target, Batch, Doc, DataFlushed, BatchSize, BatchItems, nil) ->
      maybe_flush_docs_capi(Target, Batch, Doc, DataFlushed, BatchSize, BatchItems);
  
  maybe_flush_docs(#httpdb{} = _Target, Batch, Doc, DataFlushed, BatchSize, BatchItems, XMemSrv) ->
      maybe_flush_docs_xmem(XMemSrv, Batch, Doc, DataFlushed, BatchSize, BatchItems).
  
  -spec flush_docs_helper(any(), list(), term()) -> ok.
  flush_docs_helper(Target, DocsList, nil) ->
  
negative.code:     end.
  
  
  local_process_batch([], _Cp, _Src, _Tgt, #batch{docs = []}, _BatchSize, _BatchItems, _XMemLoc) ->
      {ok, 0};
  local_process_batch([], Cp, #db{} = Source, #httpdb{} = Target,
                      #batch{docs = Docs, size = Size}, BatchSize, BatchItems, XMemLoc) ->
      ?xdcr_trace("worker process flushing a batch docs of total size ~p bytes",
                  [Size]),
      ok = flush_docs_helper(Target, Docs, XMemLoc),
      {ok, DataRepd1} = local_process_batch([], Cp, Source, Target, #batch{}, BatchSize, BatchItems, XMemLoc),
      {ok, DataRepd1 + Size};
  
  local_process_batch([DocInfo | Rest], Cp, #db{} = Source,
                      #httpdb{} = Target, Batch, BatchSize, BatchItems, XMemLoc) ->
      {ok, {_, DocsList, _}} = fetch_doc(
                                        Source, DocInfo, fun local_doc_handler/2,
                                        {Target, [], Cp}),
      {Batch2, DataFlushed} = lists:foldl(
                           fun(Doc, {Batch0, DataFlushed1}) ->
                                   maybe_flush_docs(Target, Batch0, Doc, DataFlushed1, BatchSize, BatchItems, XMemLoc)
                           end,
                           {Batch, 0}, DocsList),
      {ok, DataFlushed2} = local_process_batch(Rest, Cp, Source, Target, Batch2, BatchSize, BatchItems, XMemLoc),
      %% return total data flushed
      {ok, DataFlushed + DataFlushed2}.
  
  