Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Make mem3:ushards zone aware
mem3:ushards now prefers nodes in the local zone to any other zone.

BugzID: 13470
  • Loading branch information
Robert Newson committed Apr 17, 2012
1 parent 97af374 commit 370d667d7016ca5d33f4106e736e6526e96abd5a
Showing 1 changed file with 10 additions and 1 deletion.
@@ -18,6 +18,7 @@
choose_shards/2, n/1, dbname/1, ushards/1]).
-export([sync_security/0, sync_security/1]).
-export([compare_nodelists/0, compare_shards/1]).
-export([group_by_proximity/1]).

-include("mem3.hrl").

@@ -123,12 +124,20 @@ shards(DbName, DocId) ->
ushards(DbName) ->
lists:usort(fun(#shard{name=A}, #shard{name=B}) ->
A =< B
end, lists:sort(live_shards(DbName))).
end, begin {L,S,D} = group_by_proximity(live_shards(DbName)), L ++ S ++ D end).

live_shards(DbName) ->
Nodes = [node()|erlang:nodes()],
[S || #shard{node=Node} = S <- shards(DbName), lists:member(Node, Nodes)].

group_by_proximity(Shards) ->
{Local, Remote} = lists:partition(fun(S) -> S#shard.node =:= node() end,
Shards),
LocalZone = mem3:node_info(node(), <<"zone">>),
Fun = fun(S) -> mem3:node_info(S#shard.node, <<"zone">>) =:= LocalZone end,
{SameZone, DifferentZone} = lists:partition(Fun, Remote),
{Local, SameZone, DifferentZone}.

sync_security() ->
mem3_sync_security:go().

0 comments on commit 370d667

Please sign in to comment.