refactor(resman): rename `ets_lookup` → `lookup_cached`
That way we hide the impementation details + the interface becomes cleaner and more obvious.
This commit is contained in:
parent
29907875bf
commit
a9bc8a4464
|
@ -260,7 +260,7 @@ query(ResId, Request) ->
|
||||||
-spec query(resource_id(), Request :: term(), query_opts()) ->
|
-spec query(resource_id(), Request :: term(), query_opts()) ->
|
||||||
Result :: term().
|
Result :: term().
|
||||||
query(ResId, Request, Opts) ->
|
query(ResId, Request, Opts) ->
|
||||||
case emqx_resource_manager:ets_lookup(ResId) of
|
case emqx_resource_manager:lookup_cached(ResId) of
|
||||||
{ok, _Group, #{query_mode := QM, mod := Module}} ->
|
{ok, _Group, #{query_mode := QM, mod := Module}} ->
|
||||||
IsBufferSupported = is_buffer_supported(Module),
|
IsBufferSupported = is_buffer_supported(Module),
|
||||||
case {IsBufferSupported, QM} of
|
case {IsBufferSupported, QM} of
|
||||||
|
@ -311,7 +311,7 @@ set_resource_status_connecting(ResId) ->
|
||||||
-spec get_instance(resource_id()) ->
|
-spec get_instance(resource_id()) ->
|
||||||
{ok, resource_group(), resource_data()} | {error, Reason :: term()}.
|
{ok, resource_group(), resource_data()} | {error, Reason :: term()}.
|
||||||
get_instance(ResId) ->
|
get_instance(ResId) ->
|
||||||
emqx_resource_manager:ets_lookup(ResId, [metrics]).
|
emqx_resource_manager:lookup_cached(ResId, [metrics]).
|
||||||
|
|
||||||
-spec fetch_creation_opts(map()) -> creation_opts().
|
-spec fetch_creation_opts(map()) -> creation_opts().
|
||||||
fetch_creation_opts(Opts) ->
|
fetch_creation_opts(Opts) ->
|
||||||
|
|
|
@ -885,7 +885,7 @@ handle_async_worker_down(Data0, Pid) ->
|
||||||
|
|
||||||
call_query(QM0, Id, Index, Ref, Query, QueryOpts) ->
|
call_query(QM0, Id, Index, Ref, Query, QueryOpts) ->
|
||||||
?tp(call_query_enter, #{id => Id, query => Query, query_mode => QM0}),
|
?tp(call_query_enter, #{id => Id, query => Query, query_mode => QM0}),
|
||||||
case emqx_resource_manager:ets_lookup(Id) of
|
case emqx_resource_manager:lookup_cached(Id) of
|
||||||
{ok, _Group, #{status := stopped}} ->
|
{ok, _Group, #{status := stopped}} ->
|
||||||
?RESOURCE_ERROR(stopped, "resource stopped or disabled");
|
?RESOURCE_ERROR(stopped, "resource stopped or disabled");
|
||||||
{ok, _Group, Resource} ->
|
{ok, _Group, Resource} ->
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
lookup/1,
|
lookup/1,
|
||||||
list_all/0,
|
list_all/0,
|
||||||
list_group/1,
|
list_group/1,
|
||||||
ets_lookup/1,
|
lookup_cached/1,
|
||||||
ets_lookup/2,
|
lookup_cached/2,
|
||||||
get_metrics/1,
|
get_metrics/1,
|
||||||
reset_metrics/1
|
reset_metrics/1
|
||||||
]).
|
]).
|
||||||
|
@ -231,21 +231,21 @@ set_resource_status_connecting(ResId) ->
|
||||||
-spec lookup(resource_id()) -> {ok, resource_group(), resource_data()} | {error, not_found}.
|
-spec lookup(resource_id()) -> {ok, resource_group(), resource_data()} | {error, not_found}.
|
||||||
lookup(ResId) ->
|
lookup(ResId) ->
|
||||||
case safe_call(ResId, lookup, ?T_LOOKUP) of
|
case safe_call(ResId, lookup, ?T_LOOKUP) of
|
||||||
{error, timeout} -> ets_lookup(ResId, [metrics]);
|
{error, timeout} -> lookup_cached(ResId, [metrics]);
|
||||||
Result -> Result
|
Result -> Result
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc Lookup the group and data of a resource from the cache
|
%% @doc Lookup the group and data of a resource from the cache
|
||||||
-spec ets_lookup(resource_id()) -> {ok, resource_group(), resource_data()} | {error, not_found}.
|
-spec lookup_cached(resource_id()) -> {ok, resource_group(), resource_data()} | {error, not_found}.
|
||||||
ets_lookup(ResId) ->
|
lookup_cached(ResId) ->
|
||||||
ets_lookup(ResId, []).
|
lookup_cached(ResId, []).
|
||||||
|
|
||||||
%% @doc Lookup the group and data of a resource from the cache
|
%% @doc Lookup the group and data of a resource from the cache
|
||||||
-spec ets_lookup(resource_id(), [Option]) ->
|
-spec lookup_cached(resource_id(), [Option]) ->
|
||||||
{ok, resource_group(), resource_data()} | {error, not_found}
|
{ok, resource_group(), resource_data()} | {error, not_found}
|
||||||
when
|
when
|
||||||
Option :: metrics.
|
Option :: metrics.
|
||||||
ets_lookup(ResId, Options) ->
|
lookup_cached(ResId, Options) ->
|
||||||
NeedMetrics = lists:member(metrics, Options),
|
NeedMetrics = lists:member(metrics, Options),
|
||||||
case read_cache(ResId) of
|
case read_cache(ResId) of
|
||||||
{Group, Data} when NeedMetrics ->
|
{Group, Data} when NeedMetrics ->
|
||||||
|
|
Loading…
Reference in New Issue