couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [11/50] fabric commit: updated refs/heads/windsor-merge-121 to 79e6e2f
Date Fri, 01 Aug 2014 09:11:59 GMT
Revert "Merge pull request #99 from cloudant/fix-fencepost"

This reverts commit 1cf3128d139ebd4e1d6055cdcfbdede43febe1be, reversing
changes made to 82223b0e44c83fb60e93f7653a3bebd22ea98bfe.


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

Branch: refs/heads/windsor-merge-121
Commit: d4620448cc0ae410614f9a5adf54426b2d9554db
Parents: a698d48
Author: Robert Newson <robert.newson@cloudant.com>
Authored: Wed Aug 14 17:28:11 2013 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu Jul 31 10:54:50 2014 +0100

----------------------------------------------------------------------
 src/fabric_rpc.erl | 49 +++++++++++++++++--------------------------------
 1 file changed, 17 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/d4620448/src/fabric_rpc.erl
----------------------------------------------------------------------
diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl
index bc0486a..870ac57 100644
--- a/src/fabric_rpc.erl
+++ b/src/fabric_rpc.erl
@@ -373,7 +373,7 @@ calculate_start_seq(_Db, Seq) when is_integer(Seq) ->
 calculate_start_seq(Db, {Seq, Uuid, Node}) ->
     case couch_db:get_uuid(Db) == Uuid of
         true ->
-            case is_owner(Node, Seq, couch_db:get_epochs(Db)) of
+            case owner(Node, Seq, couch_db:get_epochs(Db)) of
                 true -> Seq;
                 false -> 0
             end;
@@ -383,28 +383,16 @@ calculate_start_seq(Db, {Seq, Uuid, Node}) ->
             0
     end.
 
-is_owner(Node, Seq, Epochs) ->
-    validate_epochs(Epochs),
-    Node =:= owner_of(Seq, Epochs).
-
-owner_of(_Seq, []) ->
-    undefined;
-owner_of(Seq, [{EpochNode, EpochSeq} | _Rest]) when Seq > EpochSeq ->
-    EpochNode;
-owner_of(Seq, [_ | Rest]) ->
-    owner_of(Seq, Rest).
-
-validate_epochs(Epochs) ->
-    %% Assert uniqueness.
-    case length(Epochs) == length(lists:ukeysort(2, Epochs)) of
-        true  -> ok;
-        false -> erlang:error(duplicate_epoch)
-    end,
-    %% Assert order.
-    case Epochs == lists:sort(fun({_, A}, {_, B}) -> B =< A end, Epochs) of
-        true  -> ok;
-        false -> erlang:error(epoch_order)
-    end.
+owner(Node, Seq, Epochs) ->
+    owner(Node, Seq, Epochs, infinity).
+
+owner(_Node, _Seq, [], _HighSeq) ->
+    false;
+owner(Node, Seq, [{EpochNode, EpochSeq} | _Rest], HighSeq)
+  when Node =:= EpochNode andalso Seq < HighSeq andalso Seq >= EpochSeq ->
+    true;
+owner(Node, Seq, [{_EpochNode, EpochSeq} | Rest], _HighSeq) ->
+    owner(Node, Seq, Rest, EpochSeq).
 
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").
@@ -423,14 +411,11 @@ calculate_start_seq_test() ->
     %% return integer if we didn't get a vector.
     ?assertEqual(4, calculate_start_seq(#db{}, 4)).
 
-is_owner_test() ->
-    ?assertNot(is_owner(foo, 1, [])),
-    ?assertNot(is_owner(foo, 1, [{foo, 1}])),
-    ?assert(is_owner(foo, 2, [{foo, 1}])),
-    ?assert(is_owner(foo, 50, [{bar, 100}, {foo, 1}])),
-    ?assert(is_owner(foo, 50, [{baz, 200}, {bar, 100}, {foo, 1}])),
-    ?assert(is_owner(bar, 150, [{baz, 200}, {bar, 100}, {foo, 1}])),
-    ?assertError(duplicate_epoch, is_owner(foo, 1, [{foo, 1}, {bar, 1}])),
-    ?assertError(epoch_order, is_owner(foo, 1, [{foo, 100}, {bar, 200}])).
+owner_test() ->
+    ?assertNot(owner(foo, 1, [])),
+    ?assert(owner(foo, 1, [{foo, 1}])),
+    ?assert(owner(foo, 50, [{bar, 100}, {foo, 1}])),
+    ?assert(owner(foo, 50, [{baz, 200}, {bar, 100}, {foo, 1}])),
+    ?assert(owner(bar, 150, [{baz, 200}, {bar, 100}, {foo, 1}])).
 
 -endif.


Mime
View raw message