diff --git a/apps/emqx_resource/src/emqx_resource_manager.erl b/apps/emqx_resource/src/emqx_resource_manager.erl index 382cf29d9..226f9e927 100644 --- a/apps/emqx_resource/src/emqx_resource_manager.erl +++ b/apps/emqx_resource/src/emqx_resource_manager.erl @@ -384,9 +384,33 @@ handle_event(EventType, EventData, State, Data) -> %%------------------------------------------------------------------------------ insert_cache(ResId, Group, Data = #data{manager_id = MgrId}) -> case get_owner(ResId) of - not_found -> ets:insert(?ETS_TABLE, {ResId, Group, Data}); - MgrId -> ets:insert(?ETS_TABLE, {ResId, Group, Data}); - _ -> self() ! quit + not_found -> + ?SLOG( + debug, + #{ + msg => resource_owner_not_found, + resource_id => ResId, + action => auto_insert_cache + } + ), + ets:insert(?ETS_TABLE, {ResId, Group, Data}); + MgrId -> + ?SLOG( + debug, + #{ + msg => resource_owner_matched, + resource_id => ResId, + action => reinsert_cache + } + ), + ets:insert(?ETS_TABLE, {ResId, Group, Data}); + _ -> + ?SLOG(error, #{ + msg => get_resource_owner_failed, + resource_id => ResId, + action => quit_rusource + }), + self() ! quit end. read_cache(ResId) -> @@ -425,12 +449,14 @@ get_owner(ResId) -> end. handle_disconnected_state_enter(Data) -> + {next_state, disconnected, Data, retry_actions(Data)}. + +retry_actions(Data) -> case maps:get(auto_restart_interval, Data#data.opts, ?AUTO_RESTART_INTERVAL) of undefined -> - {next_state, disconnected, Data}; + []; RetryInterval -> - Actions = [{state_timeout, RetryInterval, auto_retry}], - {next_state, disconnected, Data, Actions} + [{state_timeout, RetryInterval, auto_retry}] end. handle_remove_event(From, ClearMetrics, Data) -> @@ -461,7 +487,7 @@ start_resource(Data, From) -> %% Keep track of the error reason why the connection did not work %% so that the Reason can be returned when the verification call is made. UpdatedData = Data#data{error = Reason}, - Actions = maybe_reply([], From, Err), + Actions = maybe_reply(retry_actions(UpdatedData), From, Err), {next_state, disconnected, UpdatedData, Actions} end.