From 86720c8aad8d8329e8c029a0f9c5fa90d9e04adf Mon Sep 17 00:00:00 2001 From: Brad Anderson Date: Tue, 15 Jun 2010 10:23:38 -0400 Subject: add membership events back into mem3, and add dbs handlers --- ebin/membership.app | 1 + src/dbs.erl | 2 +- src/mem3.erl | 12 +++++++++++- src/membership_sup.erl | 8 +++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ebin/membership.app b/ebin/membership.app index 82f0b299..4773b636 100644 --- a/ebin/membership.app +++ b/ebin/membership.app @@ -8,6 +8,7 @@ [ dbs, dbs_cache, + dbs_event, membership, membership_app, membership_sup, diff --git a/src/dbs.erl b/src/dbs.erl index b5e17b6a..345788ef 100644 --- a/src/dbs.erl +++ b/src/dbs.erl @@ -12,7 +12,7 @@ init([]) -> {ok, MemNodes} = mem3:nodes(), LiveNodes = nodes(), ChildSpecs = [childspec(N) || N <- MemNodes, lists:member(N, LiveNodes)], - %gen_event:add_handler(membership_events, showroom_dbs_event, []), + gen_event:add_handler(membership_events, dbs_event, []), {ok, {{one_for_one, 10, 8}, ChildSpecs}}. childspec(Node) -> diff --git a/src/mem3.erl b/src/mem3.erl index 55a8a541..d715e657 100644 --- a/src/mem3.erl +++ b/src/mem3.erl @@ -202,12 +202,14 @@ handle_cast(Msg, State) -> %% net_kernel:monitor_nodes(true) handle_info({nodedown, Node}, State) -> showroom_log:message(alert, "membership: nodedown ~p", [Node]), + notify(nodedown, [Node]), {noreply, State}; %% @doc handle nodeup messages because we have %% net_kernel:monitor_nodes(true) handle_info({nodeup, Node}, State) -> showroom_log:message(alert, "membership: nodeup ~p", [Node]), + notify(nodeup, [Node]), {noreply, State}; %% ignored info @@ -296,10 +298,12 @@ handle_join(replace, {OldNode, NewOpts}, PingNode, _State) -> OldState = #mem{nodes=OldNodes} = get_pingnode_state(PingNode), {Order, OldNode, _OldOpts} = lists:keyfind(OldNode, 2, OldNodes), NewNodes = lists:keyreplace(OldNode, 2, OldNodes, {Order, node(), NewOpts}), + notify(node_leave, [OldNode]), int_join([], OldState#mem{nodes=NewNodes}); % leave -handle_join(leave, [_OldNode | _], _PingNode, _State) -> +handle_join(leave, [OldNode | _], _PingNode, _State) -> % TODO implement me + notify(node_leave, [OldNode]), ok; handle_join(JoinType, _, PingNode, _) -> @@ -311,6 +315,7 @@ handle_join(JoinType, _, PingNode, _) -> int_join(ExtNodes, #mem{nodes=Nodes, clock=Clock} = State) -> NewNodes = lists:foldl(fun({Pos, N, _Options}=New, AccIn) -> check_pos(Pos, N, Nodes), + notify(node_join, [N]), [New|AccIn] end, Nodes, ExtNodes), NewNodes1 = lists:sort(NewNodes), @@ -530,3 +535,8 @@ compare_state_with_rest(#mem{clock=Clock} = _State, States) -> length(BadResults) == 0 -> match; true -> {bad_state_match, node(), BadResults} end. + +notify(Type, Nodes) -> + lists:foreach(fun(Node) -> + gen_event:notify(membership_events, {Type, Node}) + end, Nodes). diff --git a/src/membership_sup.erl b/src/membership_sup.erl index 27e547ff..f203924d 100644 --- a/src/membership_sup.erl +++ b/src/membership_sup.erl @@ -21,6 +21,12 @@ init(_Args) -> 1000, worker, [mem3]}, + MemEventMgr = {mem_event_manager, + {gen_event, start_link, [{local, membership_events}]}, + permanent, + 1000, + worker, + []}, DbsRepl = {dbs, {dbs, start_link, []}, @@ -35,4 +41,4 @@ init(_Args) -> 1000, worker, [dbs_cache]}, - {ok, {{one_for_one,10,1}, [Membership, DbsRepl, DbsCache]}}. + {ok, {{one_for_one,10,1}, [Membership, MemEventMgr, DbsRepl, DbsCache]}}. -- cgit v1.2.3