From 4ad1897c6c3baff326012c5f660f74a97bd25347 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Wed, 2 Sep 2009 04:48:36 +0000 Subject: fix continuous replication occurring after identical normal one Both forms of replication had the same child ID in the replication supervisor. As a result, a continuous replication triggered after an otherwise-identical normal replication would "forget" that it was continuous. The tricky part about this patch is that it lets a normal and a continuous replication with the same source and target execute simultaneously. That's inefficient, but other solutions are convoluted or give surprising results to the client. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@810358 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_rep.erl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/couchdb/couch_rep.erl') diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl index fa4d33bd..1411716f 100644 --- a/src/couchdb/couch_rep.erl +++ b/src/couchdb/couch_rep.erl @@ -56,9 +56,9 @@ replicate(Source, Target) when is_binary(Source), is_binary(Target) -> %% function handling POST to _replicate replicate({Props}=PostBody, UserCtx) -> - RepId = make_replication_id(PostBody, UserCtx), - Replicator = {RepId, - {gen_server, start_link, [?MODULE, [RepId, PostBody, UserCtx], []]}, + {BaseId, Extension} = make_replication_id(PostBody, UserCtx), + Replicator = {BaseId ++ Extension, + {gen_server, start_link, [?MODULE, [BaseId, PostBody, UserCtx], []]}, transient, 1, worker, @@ -69,7 +69,7 @@ replicate({Props}=PostBody, UserCtx) -> case proplists:get_value(<<"continuous">>, Props, false) of true -> - {ok, {continuous, ?l2b(RepId)}}; + {ok, {continuous, ?l2b(BaseId)}}; false -> get_result(Server, PostBody, UserCtx) end. @@ -361,7 +361,14 @@ make_replication_id({Props}, UserCtx) -> % Port = mochiweb_socket_server:get(couch_httpd, port), Src = get_rep_endpoint(UserCtx, proplists:get_value(<<"source">>, Props)), Tgt = get_rep_endpoint(UserCtx, proplists:get_value(<<"target">>, Props)), - couch_util:to_hex(erlang:md5(term_to_binary([HostName, Src, Tgt]))). + Base = couch_util:to_hex(erlang:md5(term_to_binary([HostName, Src, Tgt]))), + Extension = case proplists:get_value(<<"continuous">>, Props, false) of + true -> + "+continuous"; + false -> + "" + end, + {Base, Extension}. maybe_add_trailing_slash(Url) -> re:replace(Url, "[^/]$", "&/", [{return, list}]). -- cgit v1.2.3