couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [2/2] git commit: Stabilize replication id
Date Wed, 14 Nov 2012 10:59:47 GMT
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/e1136a70
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/e1136a70
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/e1136a70

Branch: refs/heads/1.3.x
Commit: e1136a70655a0163b08d8c59f6e41549d94e4b22
Parents: bbb6b95
Author: Robert Newson <rnewson@apache.org>
Authored: Wed Nov 14 10:53:07 2012 +0000
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed Nov 14 10:58:27 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/e1136a70/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 82f26d0..a41f4bc 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/e1136a70/NEWS
----------------------------------------------------------------------
diff --git a/NEWS b/NEWS
index 62db51f..3d6955c 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ This version has not been released yet.
  * Added utc_id UUID algorithm.
  * encode database name during URL rewriting.
  * Include user name in show/list ETags.
+ * server-wide UUID in some replication ids.
 
 Version 1.2.1
 -------------

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e1136a70/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/e1136a70/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/e1136a70/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/e1136a70/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/e1136a70/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),


Mime
View raw message