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,11 +337,17 @@ 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) ->
case ets:lookup(?TAB, Name) of try
[#metric{idx = Idx}] -> case ets:lookup(?TAB, Name) of
CRef = persistent_term:get(?MODULE), [#metric{idx = Idx}] ->
counters:get(CRef, Idx); CRef = persistent_term:get(?MODULE),
[] -> counters:get(CRef, Idx);
[] ->
0
end
%% application will restart when join cluster, then ets not exist.
catch
error:badarg ->
0 0
end. end.

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 {