Monitor cluster partition event (#2814)

This commit is contained in:
Zhiwei Yu 2019-08-23 09:42:55 +08:00 committed by JianBo He
parent c69a2b1b48
commit 8710df31b2
2 changed files with 14 additions and 1 deletions

View File

@ -3,7 +3,7 @@
{cowboy, "2.6.1"}, % hex
{gproc, "0.8.0"}, % hex
{esockd, "5.5.0"}, %hex
{ekka, "0.6.0"}, %hex
{ekka, "0.6.1"}, %hex
{gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.4.1"}}},
{cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.0.0"}}}
]}.

View File

@ -57,6 +57,10 @@ start_link(Opts) ->
init([Opts]) ->
erlang:system_monitor(self(), parse_opt(Opts)),
emqx_logger:set_proc_metadata(#{sysmon => true}),
%% Monitor cluster partition event
ekka:monitor(partition, fun handle_partition_event/1),
{ok, start_timer(#{timer => undefined, events => []})}.
start_timer(State) ->
@ -156,6 +160,15 @@ terminate(_Reason, #{timer := TRef}) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%%--------------------------------------------------------------------
%% Internal Functions
%%--------------------------------------------------------------------
handle_partition_event({partition, {occurred, Node}}) ->
alarm_handler:set_alarm({partitioned, Node});
handle_partition_event({partition, {healed, Node}}) ->
alarm_handler:clear_alarm(partitioned).
suppress(Key, SuccFun, State = #{events := Events}) ->
case lists:member(Key, Events) of
true -> {noreply, State};