Permalink
Browse files

Stabilize replication id

This patch introduces a stable server-wide UUID which is used in place
of the local hostname and port number in new replication ids. This
allows CouchDB to find a valid checkpoint even if the coordinating
node's port has changed (it might be using a dynamic port, for example).

COUCHDB-1259
  • Loading branch information...
rnewson committed Nov 14, 2012
1 parent d7f2037 commit c6252d6d7f8d7fa3a27bf8e09beecb87033fa2fa
View
@@ -22,6 +22,11 @@ HTTP Interface:
* Make password hashing synchronous when using the /_config/admins API.
* Include user name in show/list ETags.
+Replicator:
+
+ * The replicator will use a new server-wide UUID in checkpoint ids to
+ * improve the chances of an efficient resume.
+
Storage System:
* Fixed unnecessary conflict when deleting and creating a
View
1 NEWS
@@ -26,6 +26,7 @@ This version has not been released yet.
* Encode database name during URL rewriting.
* Include user name in show/list ETags.
* Per module log levels.
+ * server-wide UUID in some replication ids.
Version 1.2.1
-------------
@@ -10,7 +10,7 @@
% License for the specific language governing permissions and limitations under
% the License.
--define(REP_ID_VERSION, 2).
+-define(REP_ID_VERSION, 3).
-record(rep, {
id,
@@ -59,6 +59,12 @@ replication_id(#rep{options = Options} = Rep) ->
% If a change is made to how replications are identified,
% please add a new clause and increase ?REP_ID_VERSION.
+replication_id(#rep{user_ctx = UserCtx} = Rep, 3) ->
+ UUID = couch_server:get_uuid(),
+ Src = get_rep_endpoint(UserCtx, Rep#rep.source),
+ Tgt = get_rep_endpoint(UserCtx, Rep#rep.target),
+ maybe_append_filters([UUID, Src, Tgt], Rep);
+
replication_id(#rep{user_ctx = UserCtx} = Rep, 2) ->
{ok, HostName} = inet:gethostname(),
Port = case (catch mochiweb_socket_server:get(couch_httpd, port)) of
@@ -128,6 +128,10 @@ start_link(Name, Options) ->
set_auth_handlers(),
+ % ensure uuid is set so that concurrent replications
+ % get the same value.
+ couch_server:get_uuid(),
+
Loop = fun(Req)->
case SocketOptions of
[] ->
@@ -32,6 +32,7 @@
handle_welcome_req(#httpd{method='GET'}=Req, WelcomeMessage) ->
send_json(Req, {[
{couchdb, WelcomeMessage},
+ {uuid, couch_server:get_uuid()},
{version, list_to_binary(couch_server:get_version())}
] ++ case couch_config:get("vendor") of
[] ->
@@ -13,7 +13,7 @@
-module(couch_server).
-behaviour(gen_server).
--export([open/2,create/2,delete/2,get_version/0]).
+-export([open/2,create/2,delete/2,get_version/0,get_uuid/0]).
-export([all_databases/0, all_databases/2]).
-export([init/1, handle_call/3,sup_start_link/0]).
-export([handle_cast/2,code_change/3,handle_info/2,terminate/2]).
@@ -43,6 +43,15 @@ get_version() ->
"0.0.0"
end.
+get_uuid() ->
+ case couch_config:get("couchdb", "uuid", nil) of
+ nil ->
+ UUID = couch_uuids:random(),
+ couch_config:set("couchdb", "uuid", ?b2l(UUID)),
+ UUID;
+ UUID -> ?l2b(UUID)
+ end.
+
get_stats() ->
{ok, #server{start_time=Time,dbs_open=Open}} =
gen_server:call(couch_server, get_server),

0 comments on commit c6252d6

Please sign in to comment.