Skip to content

Commit 15d3d5a

Browse files
Merge pull request #12674 from rabbitmq/add-is_feature_used-callback-to-transient_nonexcl_queues-depr-feature
rabbit_amqqueue: Add `is_feature_used` callback to `transient_nonexcl_queues` depr. feature
2 parents c888689 + 638e3a4 commit 15d3d5a

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

deps/rabbit/src/rabbit_amqqueue.erl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
-export([internal_declare/2, internal_delete/2, run_backing_queue/3,
7777
emit_consumers_local/3, internal_delete/3]).
7878

79+
%% Deprecated feature callback.
80+
-export([are_transient_nonexcl_used/1]).
81+
7982
-include_lib("rabbit_common/include/rabbit.hrl").
8083
-include_lib("stdlib/include/qlc.hrl").
8184
-include("amqqueue.hrl").
@@ -110,9 +113,19 @@
110113
-rabbit_deprecated_feature(
111114
{transient_nonexcl_queues,
112115
#{deprecation_phase => permitted_by_default,
113-
doc_url => "https://blog.rabbitmq.com/posts/2021/08/4.0-deprecation-announcements/#removal-of-transient-non-exclusive-queues"
116+
doc_url => "https://blog.rabbitmq.com/posts/2021/08/4.0-deprecation-announcements/#removal-of-transient-non-exclusive-queues",
117+
callbacks => #{is_feature_used => {?MODULE, are_transient_nonexcl_used}}
114118
}}).
115119

120+
are_transient_nonexcl_used(_) ->
121+
case rabbit_db_queue:list_transient() of
122+
{ok, Queues} ->
123+
NonExclQueues = [Q || Q <- Queues, not is_exclusive(Q)],
124+
length(NonExclQueues) > 0;
125+
{error, _} ->
126+
undefined
127+
end.
128+
116129
-define(CONSUMER_INFO_KEYS,
117130
[queue_name, channel_pid, consumer_tag, ack_required, prefetch_count,
118131
active, activity_status, arguments]).

deps/rabbit/src/rabbit_db_queue.erl

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646

4747
%% Used by on_node_up and on_node_down.
4848
%% Can be deleted once transient entities/mnesia are removed.
49-
-export([foreach_transient/1,
49+
-export([list_transient/0,
50+
foreach_transient/1,
5051
delete_transient/1]).
5152

5253
%% Only used by rabbit_amqqueue:forget_node_for_queue, which is only called
@@ -965,6 +966,40 @@ set_in_khepri(Q) ->
965966
Path = khepri_queue_path(amqqueue:get_name(Q)),
966967
rabbit_khepri:put(Path, Q).
967968

969+
%% -------------------------------------------------------------------
970+
%% list_transient().
971+
%% -------------------------------------------------------------------
972+
973+
-spec list_transient() -> {ok, Queues} | {error, any()} when
974+
Queues :: [amqqueue:amqqueue()].
975+
%% @doc Applies `UpdateFun' to all transient queue records.
976+
%%
977+
%% @private
978+
979+
list_transient() ->
980+
rabbit_khepri:handle_fallback(
981+
#{mnesia => fun() -> list_transient_in_mnesia() end,
982+
khepri => fun() -> list_transient_in_khepri() end
983+
}).
984+
985+
list_transient_in_mnesia() ->
986+
Pattern = amqqueue:pattern_match_all(),
987+
AllQueues = mnesia:dirty_match_object(
988+
?MNESIA_TABLE,
989+
Pattern),
990+
{ok, AllQueues}.
991+
992+
list_transient_in_khepri() ->
993+
try
994+
List = ets:match_object(
995+
?KHEPRI_PROJECTION,
996+
amqqueue:pattern_match_on_durable(false)),
997+
{ok, List}
998+
catch
999+
error:badarg ->
1000+
{error, {khepri_projection_missing, ?KHEPRI_WILDCARD_STAR}}
1001+
end.
1002+
9681003
%% -------------------------------------------------------------------
9691004
%% delete_transient().
9701005
%% -------------------------------------------------------------------

0 commit comments

Comments
 (0)