You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/28 14:22:39 UTC

[19/50] mem3 commit: updated refs/heads/master to 64c0c74

Address comments from PR


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

Branch: refs/heads/master
Commit: 94fc76333f924a0f41aca9063521836cca68b24f
Parents: 6d9983f
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Mon Aug 19 09:40:38 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Jul 23 18:46:26 2014 +0100

----------------------------------------------------------------------
 src/mem3_rebalance.erl | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/94fc7633/src/mem3_rebalance.erl
----------------------------------------------------------------------
diff --git a/src/mem3_rebalance.erl b/src/mem3_rebalance.erl
index 28cd32e..08605be 100644
--- a/src/mem3_rebalance.erl
+++ b/src/mem3_rebalance.erl
@@ -27,17 +27,11 @@ rebalance(Shards, TargetNodes) when is_list(Shards) ->
     {OK, MoveThese} = lists:partition(fun(#shard{node=Node}) ->
         lists:member(Node, TargetNodes)
     end, Shards),
-    ShardsByTargetNode0 = lists:foldl(fun(Shard, Acc) ->
+    % ensure every target node is present in the orddict
+    ShardsByTargetNode0 = orddict:from_list([{N,[]} || N <- TargetNodes]),
+    ShardsByTargetNode = lists:foldl(fun(Shard, Acc) ->
         orddict:append(Shard#shard.node, Shard, Acc)
-    end, orddict:new(), OK),
-    ShardsByTargetNode = lists:sort(lists:foldl(fun(Node, Acc) ->
-        case orddict:is_key(Node, ShardsByTargetNode0) of
-            true ->
-                Acc;
-            false ->
-                [{Node, []} | Acc]
-        end
-    end, ShardsByTargetNode0, TargetNodes)),
+    end, ShardsByTargetNode0, OK),
     Moves = find_replacements(MoveThese, ShardsByTargetNode, []),
     Moved = [Shard#shard{node = Node} || {Shard, Node} <- Moves],
     TargetLevel = length(Shards) div length(TargetNodes),
@@ -107,7 +101,7 @@ largest_first({_, A}, {_, B}) ->
     length(A) >= length(B).
 
 smallest_first({_, A}, {_, B}) ->
-    length(A) < length(B).
+    length(A) =< length(B).
 
 replace(A, B, List) ->
     replace(A, B, List, []).