Monitor changes of membership

This commit is contained in:
Feng Lee 2017-06-22 12:50:55 +08:00
parent 1f3bab2bcb
commit 0b58719342
2 changed files with 7 additions and 17 deletions

View File

@ -239,27 +239,14 @@ handle_cast({del_local_route, Topic}, State) ->
handle_cast(_Msg, State) ->
{noreply, State}.
handle_info({member_up, _Node}, State) ->
handle_info({membership, {member_up, _Node}}, State) ->
{noreply, State};
handle_info({member_down, Node}, State) ->
handle_info({membership, {member_down, Node}}, State) ->
clean_routes_(Node),
update_stats_(),
{noreply, State, hibernate};
handle_info({mnesia_system_event, {inconsistent_database, Context, Node}}, State) ->
%% 1. Backup and restart
%% 2. Set master nodes
lager:critical("Mnesia inconsistent_database event: ~p, ~p~n", [Context, Node]),
{noreply, State};
handle_info({mnesia_system_event, {mnesia_overload, Details}}, State) ->
lager:critical("Mnesia overload: ~p~n", [Details]),
{noreply, State};
handle_info({mnesia_system_event, _Event}, State) ->
{noreply, State};
handle_info(stats, State) ->
update_stats_(),
{noreply, State, hibernate};

View File

@ -52,7 +52,7 @@ handle_call(Req, _From, State) ->
handle_cast(Msg, State) ->
?UNEXPECTED_MSG(Msg, State).
handle_info({member_down, Node}, State) ->
handle_info({membership, {mnesia_down, Node}}, State) ->
Fun = fun() ->
ClientIds =
mnesia:select(mqtt_session, [{#mqtt_session{client_id = '$1', sess_pid = '$2', _ = '_'},
@ -62,7 +62,10 @@ handle_info({member_down, Node}, State) ->
mnesia:async_dirty(Fun),
{noreply, State};
handle_info({member_up, _Node}, State) ->
handle_info({membership, {mnesia_up, _Node}}, State) ->
{noreply, State};
handle_info({membership, _Event}, State) ->
{noreply, State};
handle_info(tick, State) ->