summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrad Anderson <brad@cloudant.com>2010-03-31 12:40:50 -0400
committerBrad Anderson <brad@cloudant.com>2010-05-09 22:56:23 -0400
commit99a4d65b3b4158e26bdf97c644b8a60f6146c92d (patch)
treee77681ed6a3dfd694c688fa43dfbb3644d6cf90c /src
parent23c494acf0967770a08ba9d72085887dedbc8ccd (diff)
first stab at mem3's join new node functionality
Diffstat (limited to 'src')
-rw-r--r--src/mem3.erl26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/mem3.erl b/src/mem3.erl
index b64915d6..44ab4d4c 100644
--- a/src/mem3.erl
+++ b/src/mem3.erl
@@ -106,14 +106,14 @@ nodes_for_part(Part) ->
nodes_for_part(Part, NodePartList) ->
- Filtered = lists:filter(fun({_N, P, _T}) -> P =:= Part end, NodePartList),
- {Nodes, _Parts, _Types} = lists:unzip3(Filtered),
+ Filtered = lists:filter(fun({_N, P}) -> P =:= Part end, NodePartList),
+ {Nodes, _Parts} = lists:unzip(Filtered),
lists:usort(Nodes).
%% @doc return the partitions that reside on a given node
parts_for_node(Node) ->
- lists:sort(lists:foldl(fun({N,P,_Type}, AccIn) ->
+ lists:sort(lists:foldl(fun({N,P}, AccIn) ->
case N of
Node -> [P | AccIn];
_ -> AccIn
@@ -245,15 +245,14 @@ handle_init(_OldState) ->
%% handle join activities, return NewState
-handle_join(first, ExtNodes, #mem{node=Node, clock=Clock} = State, Config) ->
- {Pmap, Fullmap} = create_maps(Config, ExtNodes),
+handle_join(JoinType, ExtNodes, #mem{node=Node, clock=Clock} = State, Config)
+ when JoinType == first orelse JoinType == new ->
+ {Pmap, Fullmap} = create_maps(Config, JoinType, ExtNodes),
update_cache(Pmap, Fullmap),
NewClock = vector_clock:increment(Node, Clock),
+ % TODO: gossip
State#mem{nodes=ExtNodes, clock=NewClock};
-handle_join(new, _ExtNodes, _State, _Config) ->
- ok;
-
handle_join(replace, [_OldNode | _], _State, _Config) ->
ok;
@@ -300,14 +299,17 @@ read_latest_state_file(_, Config) ->
%% @doc given Config and a list of Nodes, construct a {Pmap,Fullmap}
%% This is basically replaying all the mem events that have happened.
-create_maps(#config{q=Q} = Config, Nodes) ->
+create_maps(#config{q=Q} = Config, JoinType, Nodes) ->
[{_,FirstNode,_}|_] = Nodes,
Fun = fun({_Pos, Node, Options}, Map) ->
Hints = proplists:get_value(hints, Options),
{ok, NewMap} = partitions:join(Node, Map, Hints),
NewMap
end,
- Acc0 = partitions:create_partitions(Q, FirstNode),
+ Acc0 = case JoinType of
+ first -> partitions:create_partitions(Q, FirstNode);
+ new -> mochiglobal:get(pmap)
+ end,
Pmap = lists:foldl(Fun, Acc0, lists:keysort(1, Nodes)),
{Pmap, make_fullmap(Pmap, Config)}.
@@ -319,8 +321,8 @@ make_fullmap(PMap, Config) ->
NodeParts = lists:flatmap(
fun({Node,Part}) ->
Partners = replication:partners(Node, lists:usort(Nodes), Config),
- PartnerList = [{Partner, Part, partner} || Partner <- Partners],
- [{Node, Part, primary} | PartnerList]
+ PartnerList = [{Partner, Part} || Partner <- Partners],
+ [{Node, Part} | PartnerList]
end, PMap),
NodeParts.