fix: cluster crash

This commit is contained in:
Zhongwen Deng 2022-05-31 11:15:12 +08:00
parent 1345b7e993
commit 26a57a00bb
2 changed files with 12 additions and 5 deletions

View File

@ -337,12 +337,18 @@ all() ->
%% @doc Get metric value %% @doc Get metric value
-spec val(metric_name()) -> non_neg_integer(). -spec val(metric_name()) -> non_neg_integer().
val(Name) -> val(Name) ->
try
case ets:lookup(?TAB, Name) of case ets:lookup(?TAB, Name) of
[#metric{idx = Idx}] -> [#metric{idx = Idx}] ->
CRef = persistent_term:get(?MODULE), CRef = persistent_term:get(?MODULE),
counters:get(CRef, Idx); counters:get(CRef, Idx);
[] -> [] ->
0 0
end
%% application will restart when join cluster, then ets not exist.
catch
error:badarg ->
0
end. end.
%% @doc Increase counter %% @doc Increase counter

View File

@ -13,6 +13,7 @@ node {
cookie: emqxsecretcookie cookie: emqxsecretcookie
data_dir: "{{ platform_data_dir }}" data_dir: "{{ platform_data_dir }}"
etc_dir: "{{ platform_etc_dir }}" etc_dir: "{{ platform_etc_dir }}"
applications: "{{ emqx_machine_boot_apps }}"
} }
log { log {