diff options
author | Robert Newson <rnewson@apache.org> | 2012-11-14 10:53:07 +0000 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2012-11-14 10:59:31 +0000 |
commit | c6252d6d7f8d7fa3a27bf8e09beecb87033fa2fa (patch) | |
tree | 706b98894efd6599f0e61109fb15ca2e96564056 | |
parent | d7f20376b1a880ba45e0a2699de2dd66df82f671 (diff) | |
download | couchdb-c6252d6d7f8d7fa3a27bf8e09beecb87033fa2fa.tar.gz |
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
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | src/couch_replicator/src/couch_replicator.hrl | 2 | ||||
-rw-r--r-- | src/couch_replicator/src/couch_replicator_utils.erl | 6 | ||||
-rw-r--r-- | src/couchdb/couch_httpd.erl | 4 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_misc_handlers.erl | 1 | ||||
-rw-r--r-- | src/couchdb/couch_server.erl | 11 |
7 files changed, 28 insertions, 2 deletions
@@ -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 @@ -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 ------------- diff --git a/src/couch_replicator/src/couch_replicator.hrl b/src/couch_replicator/src/couch_replicator.hrl index 20c0bc39a..018aa4b64 100644 --- a/src/couch_replicator/src/couch_replicator.hrl +++ b/src/couch_replicator/src/couch_replicator.hrl @@ -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, diff --git a/src/couch_replicator/src/couch_replicator_utils.erl b/src/couch_replicator/src/couch_replicator_utils.erl index 467932151..d7778db87 100644 --- a/src/couch_replicator/src/couch_replicator_utils.erl +++ b/src/couch_replicator/src/couch_replicator_utils.erl @@ -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 diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index eb35ff968..a7c3425a5 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -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 [] -> diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl index f7a4d7533..2150bea62 100644 --- a/src/couchdb/couch_httpd_misc_handlers.erl +++ b/src/couchdb/couch_httpd_misc_handlers.erl @@ -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 [] -> diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index 694daee43..6e2523592 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -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), |