Merge pull request #11700 from rabbitmq/md/khepri/projections-ets-try-catch
Use 'try'/'catch' rather than 'ets:whereis/1' for Khepri projections
This commit is contained in:
commit
bd5e9fa2ac
|
|
@ -413,11 +413,11 @@ get_all_in_mnesia() ->
|
||||||
end).
|
end).
|
||||||
|
|
||||||
get_all_in_khepri() ->
|
get_all_in_khepri() ->
|
||||||
case ets:whereis(?KHEPRI_BINDINGS_PROJECTION) of
|
try
|
||||||
undefined ->
|
[B || #route{binding = B} <- ets:tab2list(?KHEPRI_BINDINGS_PROJECTION)]
|
||||||
[];
|
catch
|
||||||
Table ->
|
error:badarg ->
|
||||||
[B || #route{binding = B} <- ets:tab2list(Table)]
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_all(VHostName) -> [Binding] when
|
-spec get_all(VHostName) -> [Binding] when
|
||||||
|
|
@ -444,15 +444,16 @@ get_all_in_mnesia(VHost) ->
|
||||||
[B || #route{binding = B} <- rabbit_db:list_in_mnesia(?MNESIA_TABLE, Match)].
|
[B || #route{binding = B} <- rabbit_db:list_in_mnesia(?MNESIA_TABLE, Match)].
|
||||||
|
|
||||||
get_all_in_khepri(VHost) ->
|
get_all_in_khepri(VHost) ->
|
||||||
case ets:whereis(?KHEPRI_BINDINGS_PROJECTION) of
|
try
|
||||||
undefined ->
|
VHostResource = rabbit_misc:r(VHost, '_'),
|
||||||
[];
|
Match = #route{binding = #binding{source = VHostResource,
|
||||||
Table ->
|
destination = VHostResource,
|
||||||
VHostResource = rabbit_misc:r(VHost, '_'),
|
_ = '_'}},
|
||||||
Match = #route{binding = #binding{source = VHostResource,
|
[B || #route{binding = B} <- ets:match_object(
|
||||||
destination = VHostResource,
|
?KHEPRI_BINDINGS_PROJECTION, Match)]
|
||||||
_ = '_'}},
|
catch
|
||||||
[B || #route{binding = B} <- ets:match_object(Table, Match)]
|
error:badarg ->
|
||||||
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_all(Src, Dst, Reverse) -> [Binding] when
|
-spec get_all(Src, Dst, Reverse) -> [Binding] when
|
||||||
|
|
@ -481,14 +482,15 @@ get_all_in_mnesia(SrcName, DstName, Reverse) ->
|
||||||
mnesia:async_dirty(Fun).
|
mnesia:async_dirty(Fun).
|
||||||
|
|
||||||
get_all_in_khepri(SrcName, DstName) ->
|
get_all_in_khepri(SrcName, DstName) ->
|
||||||
case ets:whereis(?KHEPRI_BINDINGS_PROJECTION) of
|
try
|
||||||
undefined ->
|
MatchHead = #route{binding = #binding{source = SrcName,
|
||||||
[];
|
destination = DstName,
|
||||||
Table ->
|
_ = '_'}},
|
||||||
MatchHead = #route{binding = #binding{source = SrcName,
|
[B || #route{binding = B} <- ets:match_object(
|
||||||
destination = DstName,
|
?KHEPRI_BINDINGS_PROJECTION, MatchHead)]
|
||||||
_ = '_'}},
|
catch
|
||||||
[B || #route{binding = B} <- ets:match_object(Table, MatchHead)]
|
error:badarg ->
|
||||||
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -528,12 +530,13 @@ list_for_route(Route, true) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_all_for_source_in_khepri(Resource) ->
|
get_all_for_source_in_khepri(Resource) ->
|
||||||
case ets:whereis(?KHEPRI_BINDINGS_PROJECTION) of
|
try
|
||||||
undefined ->
|
Route = #route{binding = #binding{source = Resource, _ = '_'}},
|
||||||
[];
|
[B || #route{binding = B} <- ets:match_object(
|
||||||
Table ->
|
?KHEPRI_BINDINGS_PROJECTION, Route)]
|
||||||
Route = #route{binding = #binding{source = Resource, _ = '_'}},
|
catch
|
||||||
[B || #route{binding = B} <- ets:match_object(Table, Route)]
|
error:badarg ->
|
||||||
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -563,13 +566,14 @@ get_all_for_destination_in_mnesia(Dst) ->
|
||||||
mnesia:async_dirty(Fun).
|
mnesia:async_dirty(Fun).
|
||||||
|
|
||||||
get_all_for_destination_in_khepri(Destination) ->
|
get_all_for_destination_in_khepri(Destination) ->
|
||||||
case ets:whereis(?KHEPRI_BINDINGS_PROJECTION) of
|
try
|
||||||
undefined ->
|
Match = #route{binding = #binding{destination = Destination,
|
||||||
[];
|
_ = '_'}},
|
||||||
Table ->
|
[B || #route{binding = B} <- ets:match_object(
|
||||||
Match = #route{binding = #binding{destination = Destination,
|
?KHEPRI_BINDINGS_PROJECTION, Match)]
|
||||||
_ = '_'}},
|
catch
|
||||||
[B || #route{binding = B} <- ets:match_object(Table, Match)]
|
error:badarg ->
|
||||||
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -644,15 +648,16 @@ match_in_mnesia(SrcName, Match) ->
|
||||||
Routes, Match(Binding)].
|
Routes, Match(Binding)].
|
||||||
|
|
||||||
match_in_khepri(SrcName, Match) ->
|
match_in_khepri(SrcName, Match) ->
|
||||||
case ets:whereis(?KHEPRI_BINDINGS_PROJECTION) of
|
try
|
||||||
undefined ->
|
MatchHead = #route{binding = #binding{source = SrcName,
|
||||||
[];
|
_ = '_'}},
|
||||||
Table ->
|
Routes = ets:select(
|
||||||
MatchHead = #route{binding = #binding{source = SrcName,
|
?KHEPRI_BINDINGS_PROJECTION, [{MatchHead, [], [['$_']]}]),
|
||||||
_ = '_'}},
|
[Dest || [#route{binding = Binding = #binding{destination = Dest}}] <-
|
||||||
Routes = ets:select(Table, [{MatchHead, [], [['$_']]}]),
|
Routes, Match(Binding)]
|
||||||
[Dest || [#route{binding = Binding = #binding{destination = Dest}}] <-
|
catch
|
||||||
Routes, Match(Binding)]
|
error:badarg ->
|
||||||
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Routing - HOT CODE PATH
|
%% Routing - HOT CODE PATH
|
||||||
|
|
@ -686,26 +691,22 @@ match_routing_key_in_mnesia(SrcName, RoutingKeys, UseIndex) ->
|
||||||
route_in_mnesia_v1(SrcName, RoutingKeys)
|
route_in_mnesia_v1(SrcName, RoutingKeys)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
match_routing_key_in_khepri(Src, ['_']) ->
|
||||||
|
try
|
||||||
|
MatchHead = #index_route{source_key = {Src, '_'},
|
||||||
|
destination = '$1',
|
||||||
|
_ = '_'},
|
||||||
|
ets:select(?KHEPRI_INDEX_ROUTE_PROJECTION, [{MatchHead, [], ['$1']}])
|
||||||
|
catch
|
||||||
|
error:badarg ->
|
||||||
|
[]
|
||||||
|
end;
|
||||||
match_routing_key_in_khepri(Src, RoutingKeys) ->
|
match_routing_key_in_khepri(Src, RoutingKeys) ->
|
||||||
case ets:whereis(?KHEPRI_INDEX_ROUTE_PROJECTION) of
|
|
||||||
undefined ->
|
|
||||||
[];
|
|
||||||
Table ->
|
|
||||||
do_match_routing_key_in_khepri(Table, Src, RoutingKeys)
|
|
||||||
end.
|
|
||||||
|
|
||||||
do_match_routing_key_in_khepri(Table, Src, ['_']) ->
|
|
||||||
MatchHead = #index_route{source_key = {Src, '_'},
|
|
||||||
destination = '$1',
|
|
||||||
_ = '_'},
|
|
||||||
ets:select(Table, [{MatchHead, [], ['$1']}]);
|
|
||||||
|
|
||||||
do_match_routing_key_in_khepri(Table, Src, RoutingKeys) ->
|
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
fun(RK, Acc) ->
|
fun(RK, Acc) ->
|
||||||
try
|
try
|
||||||
Dst = ets:lookup_element(
|
Dst = ets:lookup_element(
|
||||||
Table,
|
?KHEPRI_INDEX_ROUTE_PROJECTION,
|
||||||
{Src, RK},
|
{Src, RK},
|
||||||
#index_route.destination),
|
#index_route.destination),
|
||||||
Dst ++ Acc
|
Dst ++ Acc
|
||||||
|
|
|
||||||
|
|
@ -183,14 +183,12 @@ get_in_mnesia(Name) ->
|
||||||
rabbit_mnesia:dirty_read({?MNESIA_TABLE, Name}).
|
rabbit_mnesia:dirty_read({?MNESIA_TABLE, Name}).
|
||||||
|
|
||||||
get_in_khepri(Name) ->
|
get_in_khepri(Name) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try ets:lookup(?KHEPRI_PROJECTION, Name) of
|
||||||
undefined ->
|
[X] -> {ok, X};
|
||||||
{error, not_found};
|
[] -> {error, not_found}
|
||||||
Table ->
|
catch
|
||||||
case ets:lookup(Table, Name) of
|
error:badarg ->
|
||||||
[X] -> {ok, X};
|
{error, not_found}
|
||||||
[] -> {error, not_found}
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -233,11 +231,11 @@ get_many_in_mnesia(Table, Names) when is_list(Names) ->
|
||||||
lists:append([ets:lookup(Table, Name) || Name <- Names]).
|
lists:append([ets:lookup(Table, Name) || Name <- Names]).
|
||||||
|
|
||||||
get_many_in_khepri(Names) when is_list(Names) ->
|
get_many_in_khepri(Names) when is_list(Names) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
lists:append([ets:lookup(?KHEPRI_PROJECTION, Name) || Name <- Names])
|
||||||
[];
|
catch
|
||||||
Table ->
|
error:badarg ->
|
||||||
lists:append([ets:lookup(Table, Name) || Name <- Names])
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -110,15 +110,15 @@ get_all_in_mnesia() ->
|
||||||
end).
|
end).
|
||||||
|
|
||||||
get_all_in_khepri() ->
|
get_all_in_khepri() ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
list_with_possible_retry_in_khepri(
|
||||||
undefined ->
|
fun() ->
|
||||||
[];
|
try
|
||||||
Table ->
|
ets:tab2list(?KHEPRI_PROJECTION)
|
||||||
list_with_possible_retry_in_khepri(
|
catch
|
||||||
fun() ->
|
error:badarg ->
|
||||||
ets:tab2list(Table)
|
[]
|
||||||
end)
|
end
|
||||||
end.
|
end).
|
||||||
|
|
||||||
-spec get_all(VHostName) -> [Queue] when
|
-spec get_all(VHostName) -> [Queue] when
|
||||||
VHostName :: vhost:name(),
|
VHostName :: vhost:name(),
|
||||||
|
|
@ -144,16 +144,16 @@ get_all_in_mnesia(VHostName) ->
|
||||||
end).
|
end).
|
||||||
|
|
||||||
get_all_in_khepri(VHostName) ->
|
get_all_in_khepri(VHostName) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
list_with_possible_retry_in_khepri(
|
||||||
undefined ->
|
fun() ->
|
||||||
[];
|
try
|
||||||
Table ->
|
Pattern = amqqueue:pattern_match_on_name(rabbit_misc:r(VHostName, queue)),
|
||||||
list_with_possible_retry_in_khepri(
|
ets:match_object(?KHEPRI_PROJECTION, Pattern)
|
||||||
fun() ->
|
catch
|
||||||
Pattern = amqqueue:pattern_match_on_name(rabbit_misc:r(VHostName, queue)),
|
error:badarg ->
|
||||||
ets:match_object(Table, Pattern)
|
[]
|
||||||
end)
|
end
|
||||||
end.
|
end).
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
%% get_all_durable().
|
%% get_all_durable().
|
||||||
|
|
@ -181,16 +181,16 @@ get_all_durable_in_mnesia() ->
|
||||||
end).
|
end).
|
||||||
|
|
||||||
get_all_durable_in_khepri() ->
|
get_all_durable_in_khepri() ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
list_with_possible_retry_in_khepri(
|
||||||
undefined ->
|
fun() ->
|
||||||
[];
|
try
|
||||||
Table ->
|
Pattern = amqqueue:pattern_match_on_durable(true),
|
||||||
list_with_possible_retry_in_khepri(
|
ets:match_object(?KHEPRI_PROJECTION, Pattern)
|
||||||
fun() ->
|
catch
|
||||||
Pattern = amqqueue:pattern_match_on_durable(true),
|
error:badarg ->
|
||||||
ets:match_object(Table, Pattern)
|
[]
|
||||||
end)
|
end
|
||||||
end.
|
end).
|
||||||
|
|
||||||
-spec get_all_durable_by_type(Type) -> [Queue] when
|
-spec get_all_durable_by_type(Type) -> [Queue] when
|
||||||
Type :: atom(),
|
Type :: atom(),
|
||||||
|
|
@ -213,12 +213,12 @@ get_all_durable_by_type_in_mnesia(Type) ->
|
||||||
rabbit_db:list_in_mnesia(?MNESIA_DURABLE_TABLE, Pattern).
|
rabbit_db:list_in_mnesia(?MNESIA_DURABLE_TABLE, Pattern).
|
||||||
|
|
||||||
get_all_durable_by_type_in_khepri(Type) ->
|
get_all_durable_by_type_in_khepri(Type) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
Pattern = amqqueue:pattern_match_on_type_and_durable(Type, true),
|
||||||
[];
|
ets:match_object(?KHEPRI_PROJECTION, Pattern)
|
||||||
Table ->
|
catch
|
||||||
Pattern = amqqueue:pattern_match_on_type_and_durable(Type, true),
|
error:badarg ->
|
||||||
ets:match_object(Table, Pattern)
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -250,18 +250,18 @@ filter_all_durable_in_mnesia(FilterFun) ->
|
||||||
end).
|
end).
|
||||||
|
|
||||||
filter_all_durable_in_khepri(FilterFun) ->
|
filter_all_durable_in_khepri(FilterFun) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
ets:foldl(
|
||||||
[];
|
fun(Q, Acc0) ->
|
||||||
Table ->
|
case amqqueue:is_durable(Q) andalso FilterFun(Q) of
|
||||||
ets:foldl(
|
true -> [Q | Acc0];
|
||||||
fun(Q, Acc0) ->
|
false -> Acc0
|
||||||
case amqqueue:is_durable(Q) andalso FilterFun(Q) of
|
end
|
||||||
true -> [Q | Acc0];
|
end,
|
||||||
false -> Acc0
|
[], ?KHEPRI_PROJECTION)
|
||||||
end
|
catch
|
||||||
end,
|
error:badarg ->
|
||||||
[], Table)
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -287,12 +287,12 @@ list_in_mnesia() ->
|
||||||
mnesia:dirty_all_keys(?MNESIA_TABLE).
|
mnesia:dirty_all_keys(?MNESIA_TABLE).
|
||||||
|
|
||||||
list_in_khepri() ->
|
list_in_khepri() ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
Pattern = amqqueue:pattern_match_on_name('$1'),
|
||||||
[];
|
ets:select(?KHEPRI_PROJECTION, [{Pattern, [], ['$1']}])
|
||||||
Table ->
|
catch
|
||||||
Pattern = amqqueue:pattern_match_on_name('$1'),
|
error:badarg ->
|
||||||
ets:select(Table, [{Pattern, [], ['$1']}])
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -318,11 +318,12 @@ count_in_mnesia() ->
|
||||||
mnesia:table_info(?MNESIA_TABLE, size).
|
mnesia:table_info(?MNESIA_TABLE, size).
|
||||||
|
|
||||||
count_in_khepri() ->
|
count_in_khepri() ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
case ets:info(?KHEPRI_PROJECTION, size) of
|
||||||
undefined ->
|
undefined ->
|
||||||
|
%% `ets:info/2` on a table that does not exist returns `undefined`.
|
||||||
0;
|
0;
|
||||||
Table ->
|
Size ->
|
||||||
ets:info(Table, size)
|
Size
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec count(VHostName) -> Count when
|
-spec count(VHostName) -> Count when
|
||||||
|
|
@ -361,12 +362,12 @@ list_for_count_in_mnesia(VHostName) ->
|
||||||
end).
|
end).
|
||||||
|
|
||||||
list_for_count_in_khepri(VHostName) ->
|
list_for_count_in_khepri(VHostName) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
Pattern = amqqueue:pattern_match_on_name(rabbit_misc:r(VHostName, queue)),
|
||||||
0;
|
ets:select_count(?KHEPRI_PROJECTION, [{Pattern, [], [true]}])
|
||||||
Table ->
|
catch
|
||||||
Pattern = amqqueue:pattern_match_on_name(rabbit_misc:r(VHostName, queue)),
|
error:badarg ->
|
||||||
ets:select_count(Table, [{Pattern, [], [true]}])
|
0
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -466,11 +467,11 @@ get_many(Names) when is_list(Names) ->
|
||||||
}).
|
}).
|
||||||
|
|
||||||
get_many_in_khepri(Names) ->
|
get_many_in_khepri(Names) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
get_many_in_ets(?KHEPRI_PROJECTION, Names)
|
||||||
[];
|
catch
|
||||||
Table ->
|
error:badarg ->
|
||||||
get_many_in_ets(Table, Names)
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_many_in_ets(Table, [{Name, RouteInfos}])
|
get_many_in_ets(Table, [{Name, RouteInfos}])
|
||||||
|
|
@ -512,14 +513,12 @@ get_in_mnesia(Name) ->
|
||||||
rabbit_mnesia:dirty_read({?MNESIA_TABLE, Name}).
|
rabbit_mnesia:dirty_read({?MNESIA_TABLE, Name}).
|
||||||
|
|
||||||
get_in_khepri(Name) ->
|
get_in_khepri(Name) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try ets:lookup(?KHEPRI_PROJECTION, Name) of
|
||||||
undefined ->
|
[Q] -> {ok, Q};
|
||||||
{error, not_found};
|
[] -> {error, not_found}
|
||||||
Table ->
|
catch
|
||||||
case ets:lookup(Table, Name) of
|
error:badarg ->
|
||||||
[Q] -> {ok, Q};
|
{error, not_found}
|
||||||
[] -> {error, not_found}
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -568,12 +567,12 @@ get_many_durable_in_mnesia(Names) ->
|
||||||
get_many_in_ets(?MNESIA_DURABLE_TABLE, Names).
|
get_many_in_ets(?MNESIA_DURABLE_TABLE, Names).
|
||||||
|
|
||||||
get_many_durable_in_khepri(Names) ->
|
get_many_durable_in_khepri(Names) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
Queues = get_many_in_ets(?KHEPRI_PROJECTION, Names),
|
||||||
[];
|
[Q || Q <- Queues, amqqueue:is_durable(Q)]
|
||||||
Table ->
|
catch
|
||||||
Queues = get_many_in_ets(Table, Names),
|
error:badarg ->
|
||||||
[Q || Q <- Queues, amqqueue:is_durable(Q)]
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -783,11 +782,11 @@ exists_in_mnesia(QName) ->
|
||||||
ets:member(?MNESIA_TABLE, QName).
|
ets:member(?MNESIA_TABLE, QName).
|
||||||
|
|
||||||
exists_in_khepri(QName) ->
|
exists_in_khepri(QName) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
ets:member(?KHEPRI_PROJECTION, QName)
|
||||||
false;
|
catch
|
||||||
Table ->
|
error:badarg ->
|
||||||
ets:member(Table, QName)
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -151,14 +151,12 @@ get_in_mnesia(Key) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_in_khepri(Key) ->
|
get_in_khepri(Key) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try ets:lookup(?KHEPRI_PROJECTION, Key) of
|
||||||
undefined ->
|
[] -> undefined;
|
||||||
undefined;
|
[Record] -> Record
|
||||||
Table ->
|
catch
|
||||||
case ets:lookup(Table, Key) of
|
error:badarg ->
|
||||||
[] -> undefined;
|
undefined
|
||||||
[Record] -> Record
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -182,11 +180,11 @@ get_all_in_mnesia() ->
|
||||||
rabbit_mnesia:dirty_read_all(?MNESIA_TABLE).
|
rabbit_mnesia:dirty_read_all(?MNESIA_TABLE).
|
||||||
|
|
||||||
get_all_in_khepri() ->
|
get_all_in_khepri() ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
ets:tab2list(?KHEPRI_PROJECTION)
|
||||||
[];
|
catch
|
||||||
Table ->
|
error:badarg ->
|
||||||
ets:tab2list(Table)
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_all(VHostName, Comp) -> Ret when
|
-spec get_all(VHostName, Comp) -> Ret when
|
||||||
|
|
@ -224,13 +222,13 @@ get_all_in_khepri(VHostName, Comp) ->
|
||||||
'_' -> ok;
|
'_' -> ok;
|
||||||
_ -> rabbit_vhost:assert(VHostName)
|
_ -> rabbit_vhost:assert(VHostName)
|
||||||
end,
|
end,
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
Match = #runtime_parameters{key = {VHostName, Comp, '_'},
|
||||||
[];
|
_ = '_'},
|
||||||
Table ->
|
ets:match_object(?KHEPRI_PROJECTION, Match)
|
||||||
Match = #runtime_parameters{key = {VHostName, Comp, '_'},
|
catch
|
||||||
_ = '_'},
|
error:badarg ->
|
||||||
ets:match_object(Table, Match)
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -492,54 +492,57 @@ ensure_topic_deletion_ets() ->
|
||||||
%% Khepri topic graph
|
%% Khepri topic graph
|
||||||
|
|
||||||
trie_match_in_khepri(X, Words, BKeys) ->
|
trie_match_in_khepri(X, Words, BKeys) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
trie_match_in_khepri(X, root, Words, BKeys, [])
|
||||||
[];
|
catch
|
||||||
Table ->
|
error:badarg ->
|
||||||
trie_match_in_khepri(Table, X, root, Words, BKeys, [])
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
trie_match_in_khepri(Table, X, Node, [], BKeys, ResAcc0) ->
|
trie_match_in_khepri(X, Node, [], BKeys, ResAcc0) ->
|
||||||
Destinations = trie_bindings_in_khepri(Table, X, Node, BKeys),
|
Destinations = trie_bindings_in_khepri(X, Node, BKeys),
|
||||||
ResAcc = add_matched(Destinations, BKeys, ResAcc0),
|
ResAcc = add_matched(Destinations, BKeys, ResAcc0),
|
||||||
trie_match_part_in_khepri(
|
trie_match_part_in_khepri(
|
||||||
Table, X, Node, <<"#">>,
|
X, Node, <<"#">>,
|
||||||
fun trie_match_skip_any_in_khepri/6, [], BKeys, ResAcc);
|
fun trie_match_skip_any_in_khepri/5, [], BKeys, ResAcc);
|
||||||
trie_match_in_khepri(Table, X, Node, [W | RestW] = Words, BKeys, ResAcc) ->
|
trie_match_in_khepri(X, Node, [W | RestW] = Words, BKeys, ResAcc) ->
|
||||||
lists:foldl(fun ({WArg, MatchFun, RestWArg}, Acc) ->
|
lists:foldl(fun ({WArg, MatchFun, RestWArg}, Acc) ->
|
||||||
trie_match_part_in_khepri(
|
trie_match_part_in_khepri(
|
||||||
Table, X, Node, WArg, MatchFun, RestWArg, BKeys, Acc)
|
X, Node, WArg, MatchFun, RestWArg, BKeys, Acc)
|
||||||
end, ResAcc, [{W, fun trie_match_in_khepri/6, RestW},
|
end, ResAcc, [{W, fun trie_match_in_khepri/5, RestW},
|
||||||
{<<"*">>, fun trie_match_in_khepri/6, RestW},
|
{<<"*">>, fun trie_match_in_khepri/5, RestW},
|
||||||
{<<"#">>,
|
{<<"#">>,
|
||||||
fun trie_match_skip_any_in_khepri/6, Words}]).
|
fun trie_match_skip_any_in_khepri/5, Words}]).
|
||||||
|
|
||||||
trie_match_part_in_khepri(
|
trie_match_part_in_khepri(X, Node, Search, MatchFun, RestW, BKeys, ResAcc) ->
|
||||||
Table, X, Node, Search, MatchFun, RestW, BKeys, ResAcc) ->
|
case trie_child_in_khepri(X, Node, Search) of
|
||||||
case trie_child_in_khepri(Table, X, Node, Search) of
|
{ok, NextNode} -> MatchFun(X, NextNode, RestW, BKeys, ResAcc);
|
||||||
{ok, NextNode} -> MatchFun(Table, X, NextNode, RestW, BKeys, ResAcc);
|
|
||||||
error -> ResAcc
|
error -> ResAcc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
trie_match_skip_any_in_khepri(Table, X, Node, [], BKeys, ResAcc) ->
|
trie_match_skip_any_in_khepri(X, Node, [], BKeys, ResAcc) ->
|
||||||
trie_match_in_khepri(Table, X, Node, [], BKeys, ResAcc);
|
trie_match_in_khepri(X, Node, [], BKeys, ResAcc);
|
||||||
trie_match_skip_any_in_khepri(Table, X, Node, [_ | RestW] = Words, BKeys, ResAcc) ->
|
trie_match_skip_any_in_khepri(X, Node, [_ | RestW] = Words, BKeys, ResAcc) ->
|
||||||
trie_match_skip_any_in_khepri(
|
trie_match_skip_any_in_khepri(
|
||||||
Table, X, Node, RestW, BKeys,
|
X, Node, RestW, BKeys,
|
||||||
trie_match_in_khepri(Table, X, Node, Words, BKeys, ResAcc)).
|
trie_match_in_khepri(X, Node, Words, BKeys, ResAcc)).
|
||||||
|
|
||||||
trie_child_in_khepri(Table, X, Node, Word) ->
|
trie_child_in_khepri(X, Node, Word) ->
|
||||||
case ets:lookup(Table, #trie_edge{exchange_name = X,
|
case ets:lookup(
|
||||||
node_id = Node,
|
?KHEPRI_PROJECTION,
|
||||||
word = Word}) of
|
#trie_edge{exchange_name = X,
|
||||||
|
node_id = Node,
|
||||||
|
word = Word}) of
|
||||||
[#topic_trie_edge{node_id = NextNode}] -> {ok, NextNode};
|
[#topic_trie_edge{node_id = NextNode}] -> {ok, NextNode};
|
||||||
[] -> error
|
[] -> error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
trie_bindings_in_khepri(Table,X, Node, BKeys) ->
|
trie_bindings_in_khepri(X, Node, BKeys) ->
|
||||||
case ets:lookup(Table, #trie_edge{exchange_name = X,
|
case ets:lookup(
|
||||||
node_id = Node,
|
?KHEPRI_PROJECTION,
|
||||||
word = bindings}) of
|
#trie_edge{exchange_name = X,
|
||||||
|
node_id = Node,
|
||||||
|
word = bindings}) of
|
||||||
[#topic_trie_edge{node_id = {bindings, Bindings}}] ->
|
[#topic_trie_edge{node_id = {bindings, Bindings}}] ->
|
||||||
[case BKeys of
|
[case BKeys of
|
||||||
true ->
|
true ->
|
||||||
|
|
|
||||||
|
|
@ -187,14 +187,12 @@ get_in_mnesia(Username) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_in_khepri(Username) ->
|
get_in_khepri(Username) ->
|
||||||
case ets:whereis(?KHEPRI_USERS_PROJECTION) of
|
try ets:lookup(?KHEPRI_USERS_PROJECTION, Username) of
|
||||||
undefined ->
|
[User] -> User;
|
||||||
undefined;
|
_ -> undefined
|
||||||
Table ->
|
catch
|
||||||
case ets:lookup(Table, Username) of
|
error:badarg ->
|
||||||
[User] -> User;
|
undefined
|
||||||
_ -> undefined
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -297,18 +295,16 @@ get_user_permissions_in_mnesia(Username, VHostName) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_user_permissions_in_khepri(Username, VHostName) ->
|
get_user_permissions_in_khepri(Username, VHostName) ->
|
||||||
case ets:whereis(?KHEPRI_PERMISSIONS_PROJECTION) of
|
UserVHost = #user_vhost{username = Username,
|
||||||
undefined ->
|
virtual_host = VHostName},
|
||||||
undefined;
|
try ets:lookup(?KHEPRI_PERMISSIONS_PROJECTION, UserVHost) of
|
||||||
Table ->
|
[UserPermission] ->
|
||||||
UserVHost = #user_vhost{username = Username,
|
UserPermission;
|
||||||
virtual_host = VHostName},
|
_ ->
|
||||||
case ets:lookup(Table, UserVHost) of
|
undefined
|
||||||
[UserPermission] ->
|
catch
|
||||||
UserPermission;
|
error:badarg ->
|
||||||
_ ->
|
undefined
|
||||||
undefined
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -242,11 +242,11 @@ exists_in_mnesia(VHostName) ->
|
||||||
mnesia:dirty_read({?MNESIA_TABLE, VHostName}) /= [].
|
mnesia:dirty_read({?MNESIA_TABLE, VHostName}) /= [].
|
||||||
|
|
||||||
exists_in_khepri(VHostName) ->
|
exists_in_khepri(VHostName) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
ets:member(?KHEPRI_PROJECTION, VHostName)
|
||||||
false;
|
catch
|
||||||
Table ->
|
error:badarg ->
|
||||||
ets:member(Table, VHostName)
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -275,14 +275,12 @@ get_in_mnesia(VHostName) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_in_khepri(VHostName) ->
|
get_in_khepri(VHostName) ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try ets:lookup(?KHEPRI_PROJECTION, VHostName) of
|
||||||
undefined ->
|
[Record] -> Record;
|
||||||
undefined;
|
_ -> undefined
|
||||||
Table ->
|
catch
|
||||||
case ets:lookup(Table, VHostName) of
|
error:badarg ->
|
||||||
[Record] -> Record;
|
undefined
|
||||||
_ -> undefined
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -306,11 +304,11 @@ get_all_in_mnesia() ->
|
||||||
mnesia:dirty_match_object(?MNESIA_TABLE, vhost:pattern_match_all()).
|
mnesia:dirty_match_object(?MNESIA_TABLE, vhost:pattern_match_all()).
|
||||||
|
|
||||||
get_all_in_khepri() ->
|
get_all_in_khepri() ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
ets:tab2list(?KHEPRI_PROJECTION)
|
||||||
[];
|
catch
|
||||||
Table ->
|
error:badarg ->
|
||||||
ets:tab2list(Table)
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
@ -334,11 +332,12 @@ list_in_mnesia() ->
|
||||||
mnesia:dirty_all_keys(?MNESIA_TABLE).
|
mnesia:dirty_all_keys(?MNESIA_TABLE).
|
||||||
|
|
||||||
list_in_khepri() ->
|
list_in_khepri() ->
|
||||||
case ets:whereis(?KHEPRI_PROJECTION) of
|
try
|
||||||
undefined ->
|
ets:select(
|
||||||
[];
|
?KHEPRI_PROJECTION, [{vhost:pattern_match_names(), [], ['$1']}])
|
||||||
Table ->
|
catch
|
||||||
ets:select(Table, [{vhost:pattern_match_names(), [], ['$1']}])
|
error:badarg ->
|
||||||
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue