kocolosk commented on a change in pull request #1370: [5/5] Clustered Purge Implementation URL: https://github.com/apache/couchdb/pull/1370#discussion_r194942869
########## File path: src/mem3/src/mem3_rep.erl ########## @@ -169,20 +200,131 @@ find_source_seq_int(#doc{body={Props}}, SrcNode0, TgtNode0, TgtUUID, TgtSeq) -> end. -repl(#acc{db = Db} = Acc0) -> - erlang:put(io_priority, {internal_repl, couch_db:name(Db)}), - #acc{seq=Seq} = Acc1 = calculate_start_seq(Acc0), - case Seq >= couch_db:get_update_seq(Db) of - true -> - {ok, 0}; - false -> - Fun = fun ?MODULE:changes_enumerator/2, - {ok, Acc2} = couch_db:fold_changes(Db, Seq, Fun, Acc1), - {ok, #acc{seq = LastSeq}} = replicate_batch(Acc2), - {ok, couch_db:count_changes_since(Db, LastSeq)} +repl(#acc{db = Db0} = Acc0) -> + erlang:put(io_priority, {internal_repl, couch_db:name(Db0)}), + Acc1 = calculate_start_seq(Acc0), + try + Acc3 = case config:get_boolean("mem3", "replicate_purges", false) of + true -> + Acc2 = pull_purges(Acc1), + push_purges(Acc2); + false -> + Acc1 + end, + push_changes(Acc3) + catch + throw:{finished, Count} -> + {ok, Count} end. +pull_purges(#acc{} = Acc0) -> + #acc{ + batch_size = Count, + seq = UpdateSeq, + target = Target + } = Acc0, + #shard{ + node = TgtNode, + name = TgtDbName + } = Target, + + with_src_db(Acc0, fun(Db) -> Review comment: So now every invocation of `repl/1` loops back through `couch_server` 3 times to open the database? Is that really necessary? I can see where you need to reopen the DB after executing the purge requests that you pulled from the target but otherwise I'd expect that the source DB is more easily preserved across these calls. Also it's a little weird now that `#acc.db` is set but is the wrong thing to use. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services