You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2012/12/06 22:06:54 UTC

[19/27] git commit: Stabilize replication id

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


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/c6252d6d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/c6252d6d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/c6252d6d

Branch: refs/heads/1597-update-erlang-oauth-1-3-0
Commit: c6252d6d7f8d7fa3a27bf8e09beecb87033fa2fa
Parents: d7f2037
Author: Robert Newson <rn...@apache.org>
Authored: Wed Nov 14 10:53:07 2012 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Nov 14 10:59:31 2012 +0000

----------------------------------------------------------------------
 CHANGES                                            |    5 +++++
 NEWS                                               |    1 +
 src/couch_replicator/src/couch_replicator.hrl      |    2 +-
 .../src/couch_replicator_utils.erl                 |    6 ++++++
 src/couchdb/couch_httpd.erl                        |    4 ++++
 src/couchdb/couch_httpd_misc_handlers.erl          |    1 +
 src/couchdb/couch_server.erl                       |   11 ++++++++++-
 7 files changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/c6252d6d/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 70fdde5..ef5e961 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c6252d6d/NEWS
----------------------------------------------------------------------
diff --git a/NEWS b/NEWS
index dd4e67d..b1fda8e 100644
--- a/NEWS
+++ b/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
 -------------

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c6252d6d/src/couch_replicator/src/couch_replicator.hrl
----------------------------------------------------------------------
diff --git a/src/couch_replicator/src/couch_replicator.hrl b/src/couch_replicator/src/couch_replicator.hrl
index 20c0bc3..018aa4b 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,

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c6252d6d/src/couch_replicator/src/couch_replicator_utils.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator/src/couch_replicator_utils.erl b/src/couch_replicator/src/couch_replicator_utils.erl
index 4679321..d7778db 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

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c6252d6d/src/couchdb/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index eb35ff9..a7c3425 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
         [] ->

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c6252d6d/src/couchdb/couch_httpd_misc_handlers.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl
index f7a4d75..2150bea 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
         [] ->

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c6252d6d/src/couchdb/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
index 694daee..6e25235 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),