couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [38/48] mem3 commit: updated refs/heads/windsor-merge to ff02b9a
Date Fri, 01 Aug 2014 09:11:24 GMT
Refactor global candidate selection

The old approach was getting unwieldy, hopefully this makes the tests
more explicit.

BugzID: 24466


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

Branch: refs/heads/windsor-merge
Commit: 5c3c9c93ec19dfa50530f79dc6bb743bcb26ce81
Parents: 5ec7d04
Author: Adam Kocoloski <adam@cloudant.com>
Authored: Wed Oct 30 13:10:42 2013 -0400
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed Jul 23 18:46:27 2014 +0100

----------------------------------------------------------------------
 src/mem3_rebalance.erl | 51 ++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/5c3c9c93/src/mem3_rebalance.erl
----------------------------------------------------------------------
diff --git a/src/mem3_rebalance.erl b/src/mem3_rebalance.erl
index 234cad2..b7d161c 100644
--- a/src/mem3_rebalance.erl
+++ b/src/mem3_rebalance.erl
@@ -175,33 +175,40 @@ donate_fold(#shard{node = Node} = Shard, #gacc{node = Node} = Acc0)
->
     Shards = apply_shard_moves(mem3:shards(Shard#shard.dbname), Moves),
     InZone = filter_map_by_zone(shards_by_node(Shards, Nodes), Zone),
     SortedByCount = lists:sort(smallest_first(Moves), InZone),
-    Candidates = lists:dropwhile(fun({_Node, OwnShards}) ->
-        lists:keymember(Shard#shard.range, #shard.range, OwnShards)
-    end, SortedByCount),
-    case {lists:member(Shard, Shards), Candidates} of
+    SourceCount = get_shard_count(Node, SortedByCount),
+    Fun = fun({CandidateNode, OwnShards}) ->
+        HasRange = lists:keymember(Shard#shard.range, #shard.range, OwnShards),
+        TargetCount = get_shard_count(CandidateNode, SortedByCount),
+        NodeKey = couch_util:to_binary(CandidateNode),
+        Total = couch_util:get_value(NodeKey, shard_count_by_node(Moves)),
+        if
+            CandidateNode =:= Node ->
+                % Can't move a shard to ourselves
+                true;
+            HasRange ->
+                % The candidate already has this shard
+                true;
+            TargetCount >= SourceCount ->
+                % Executing this move would create a local imbalance in the DB
+                true;
+            Total >= TargetLevel ->
+                % The candidate has already achieved the target level
+                true;
+            true ->
+                false
+        end
+    end,
+    case {lists:member(Shard, Shards), lists:dropwhile(Fun, SortedByCount)} of
         {false, _} ->
             Acc0;
         {true, []} ->
             Acc0;
-        {true, [{Node, _} | _]} ->
-            Acc0;
         {true, [{Target, _} | _]} ->
-            % Execute the move only if the target has fewer shards for this DB
-            % than the source. Otherwise we'd generate a local imbalance.
-            SourceCount = get_shard_count(Node, SortedByCount),
-            TargetCount = get_shard_count(Target, SortedByCount),
-            % Execute the move only if the target needs shards.
-            NodeKey = couch_util:to_binary(Target),
-            Total = couch_util:get_value(NodeKey, shard_count_by_node(Moves)),
-            if (TargetCount < SourceCount), (Total < TargetLevel) ->
-                print({move, Shard, Target}),
-                Acc0#gacc{
-                    moves = [{move, Shard, Target} | Moves],
-                    limit = DC - 1
-                };
-            true ->
-                Acc0
-            end
+            print({move, Shard, Target}),
+            Acc0#gacc{
+                moves = [{move, Shard, Target} | Moves],
+                limit = DC - 1
+            }
     end;
 donate_fold(_Shard, Acc) ->
     Acc.


Mime
View raw message