chore(metrics): update ets table in the metrics proc

This commit is contained in:
JianBo He 2021-05-13 19:02:21 +08:00 committed by Zaiming (Stone) Shi
parent 53291ac3ff
commit c929306cb9
1 changed files with 9 additions and 10 deletions

View File

@ -201,16 +201,8 @@ stop() -> gen_server:stop(?SERVER).
%% BACKW: v4.3.0 %% BACKW: v4.3.0
upgrade_retained_delayed_counter_type() -> upgrade_retained_delayed_counter_type() ->
case ets:info(?TAB, name) of Ks = ['messages.retained', 'messages.delayed'],
?TAB -> gen_server:call(?SERVER, {set_type_to_counter, Ks}).
[M1] = ets:lookup(?TAB, 'messages.retained'),
[M2] = ets:lookup(?TAB, 'messages.delayed'),
true = ets:insert(?TAB, M1#metric{type = counter}),
true = ets:insert(?TAB, M2#metric{type = counter}),
ok;
_ ->
ok
end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Metrics API %% Metrics API
@ -467,6 +459,13 @@ handle_call({create, Type, Name}, _From, State = #state{next_idx = NextIdx}) ->
{reply, {ok, NextIdx}, State#state{next_idx = NextIdx + 1}} {reply, {ok, NextIdx}, State#state{next_idx = NextIdx + 1}}
end; end;
handle_call({set_type_to_counter, Keys}, _From, State) ->
lists:foreach(
fun(K) ->
ets:update_element(?TAB, K, {#metric.type, counter})
end, Keys),
{reply, ok, State};
handle_call(Req, _From, State) -> handle_call(Req, _From, State) ->
?LOG(error, "Unexpected call: ~p", [Req]), ?LOG(error, "Unexpected call: ~p", [Req]),
{reply, ignored, State}. {reply, ignored, State}.