couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [18/48] mem3 commit: updated refs/heads/windsor-merge to ff02b9a
Date Fri, 01 Aug 2014 09:11:04 GMT
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/windsor-merge
Commit: 94fc76333f924a0f41aca9063521836cca68b24f
Parents: 6d9983f
Author: Adam Kocoloski <adam@cloudant.com>
Authored: Mon Aug 19 09:40:38 2013 -0400
Committer: Robert Newson <rnewson@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, []).


Mime
View raw message