couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [17/50] fabric commit: updated refs/heads/master to a71701c
Date Thu, 28 Aug 2014 12:20:52 GMT
Calculate safe worker seq on shard replacement

When a shard is being replaced in the changes feed the RPC workers for
the other shard copies can leverage epoch and checkpoint information to
start from a sequence greater than zero.  This commit (and an associated
one in mem3) make that possible, though we still need to teach the
coordinator to share the fact that the worker is being summoned to
replace another copy that previously contributed to the feed.

BugzID: 22698


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

Branch: refs/heads/master
Commit: 5d52436339d395d324fdf12722b32cbd717b5742
Parents: 5e2d376
Author: Adam Kocoloski <adam@cloudant.com>
Authored: Sun Nov 17 12:01:05 2013 -0500
Committer: Robert Newson <rnewson@apache.org>
Committed: Fri Aug 1 15:33:42 2014 +0100

----------------------------------------------------------------------
 src/fabric_rpc.erl | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/5d524363/src/fabric_rpc.erl
----------------------------------------------------------------------
diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl
index 6f8e810..b0ce9b1 100644
--- a/src/fabric_rpc.erl
+++ b/src/fabric_rpc.erl
@@ -420,6 +420,18 @@ calculate_start_seq(Db, Node, {Seq, Uuid}) ->
             %% The file was rebuilt, most likely in a different
             %% order, so rewind.
             0
+    end;
+calculate_start_seq(Db, _Node, {replace, OriginalNode, Uuid, Seq}) ->
+    case is_prefix(Uuid, couch_db:get_uuid(Db)) of
+        true ->
+            start_seq(get_epochs(Db), OriginalNode, Seq);
+        false ->
+            %% Scan history looking for an entry with
+            %%  * target_node == TargetNode
+            %%  * target_uuid == TargetUUID
+            %%  * target_seq  =< TargetSeq
+            %% If such an entry is found, stream from associated source_seq
+            mem3_rep:find_source_seq(Db, OriginalNode, Uuid, Seq)
     end.
 
 is_prefix(Pattern, Subject) ->
@@ -436,6 +448,24 @@ owner_of(Seq, [{EpochNode, EpochSeq} | _Rest]) when Seq > EpochSeq
->
 owner_of(Seq, [_ | Rest]) ->
     owner_of(Seq, Rest).
 
+get_epochs(Db) ->
+    Epochs = couch_db:get_epochs(Db),
+    validate_epochs(Epochs),
+    Epochs.
+
+start_seq([{OrigNode, EpochSeq} | _], OrigNode, Seq) when Seq > EpochSeq ->
+    %% OrigNode is the owner of the Seq so we can safely stream from there
+    Seq;
+start_seq([{_, NewSeq}, {OrigNode, _} | _], OrigNode, Seq) when Seq > NewSeq ->
+    %% We transferred this file before Seq was written on OrigNode, so we need
+    %% to stream from the beginning of the next epoch. Note that it is _not_
+    %% necessary for the current node to own the epoch beginning at NewSeq
+    NewSeq;
+start_seq([_ | Rest], OrigNode, Seq) ->
+    start_seq(Rest, OrigNode, Seq);
+start_seq([], OrigNode, Seq) ->
+    erlang:error({epoch_mismatch, OrigNode, Seq}).
+
 validate_epochs(Epochs) ->
     %% Assert uniqueness.
     case length(Epochs) == length(lists:ukeysort(2, Epochs)) of


Mime
View raw message