Skip to content

Commit 5f23cb9

Browse files
committed
DQT: fall back to node-wide default
Partial Backport of rabbitmq#12109 Bump
1 parent fc0422b commit 5f23cb9

File tree

2 files changed

+69
-27
lines changed

2 files changed

+69
-27
lines changed

deps/rabbit/src/rabbit_amqqueue.erl

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -778,31 +778,38 @@ augment_declare_args(VHost, Durable, Exclusive, AutoDelete, Args0) ->
778778
#{default_queue_type := DefaultQueueType}
779779
when is_binary(DefaultQueueType) andalso
780780
not HasQTypeArg ->
781-
Type = rabbit_queue_type:discover(DefaultQueueType),
782-
IsPermitted = is_queue_args_combination_permitted(
783-
Durable, Exclusive),
784-
IsCompatible = rabbit_queue_type:is_compatible(
785-
Type, Durable, Exclusive, AutoDelete),
786-
case IsPermitted andalso IsCompatible of
787-
true ->
788-
%% patch up declare arguments with x-queue-type if there
789-
%% is a vhost default set the queue is durable and not exclusive
790-
%% and there is no queue type argument
791-
%% present
792-
rabbit_misc:set_table_value(Args0,
793-
<<"x-queue-type">>,
794-
longstr,
795-
DefaultQueueType);
796-
false ->
797-
%% if the properties are incompatible with the declared
798-
%% DQT, use the fall back type
799-
rabbit_misc:set_table_value(Args0,
800-
<<"x-queue-type">>,
801-
longstr,
802-
rabbit_queue_type:short_alias_of(rabbit_queue_type:fallback()))
803-
end;
781+
update_args_table_with_queue_type(DefaultQueueType, Durable, Exclusive, AutoDelete, Args0);
804782
_ ->
805-
Args0
783+
case HasQTypeArg of
784+
true -> Args0;
785+
false ->
786+
update_args_table_with_queue_type(rabbit_queue_type:short_alias_of(rabbit_queue_type:default()), Durable, Exclusive, AutoDelete, Args0)
787+
end
788+
end.
789+
790+
update_args_table_with_queue_type(DefaultQueueType, Durable, Exclusive, AutoDelete, Args) ->
791+
Type = rabbit_queue_type:discover(DefaultQueueType),
792+
IsPermitted = is_queue_args_combination_permitted(
793+
Durable, Exclusive),
794+
IsCompatible = rabbit_queue_type:is_compatible(
795+
Type, Durable, Exclusive, AutoDelete),
796+
case IsPermitted andalso IsCompatible of
797+
true ->
798+
%% patch up declare arguments with x-queue-type if there
799+
%% is a vhost default set the queue is durable and not exclusive
800+
%% and there is no queue type argument
801+
%% present
802+
rabbit_misc:set_table_value(Args,
803+
<<"x-queue-type">>,
804+
longstr,
805+
DefaultQueueType);
806+
false ->
807+
%% if the properties are incompatible with the declared
808+
%% DQT, use the fall back type
809+
rabbit_misc:set_table_value(Args,
810+
<<"x-queue-type">>,
811+
longstr,
812+
rabbit_queue_type:short_alias_of(rabbit_queue_type:fallback()))
806813
end.
807814

808815
-spec check_exclusive_access(amqqueue:amqqueue(), pid()) ->

deps/rabbit/test/quorum_queue_SUITE.erl

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ all_tests() ->
143143
idempotent_recover,
144144
vhost_with_quorum_queue_is_deleted,
145145
vhost_with_default_queue_type_declares_quorum_queue,
146+
node_wide_default_queue_type_declares_quorum_queue,
146147
delete_immediately_by_resource,
147148
consume_redelivery_count,
148149
subscribe_redelivery_count,
@@ -597,7 +598,7 @@ start_queue_concurrent(Config) ->
597598
quorum_cluster_size_3(Config) ->
598599
case rabbit_ct_helpers:is_mixed_versions() of
599600
true ->
600-
{skip, "quorum_cluster_size_3 tests isn't mixed version reliable"};
601+
{skip, "quorum_cluster_size_3 test isn't mixed version reliable"};
601602
false ->
602603
quorum_cluster_size_x(Config, 3, 3)
603604
end.
@@ -822,6 +823,40 @@ vhost_with_default_queue_type_declares_quorum_queue(Config) ->
822823
amqp_connection:close(Conn),
823824
ok.
824825

826+
node_wide_default_queue_type_declares_quorum_queue(Config) ->
827+
case rabbit_ct_helpers:is_mixed_versions() of
828+
true ->
829+
{skip, "node_wide_default_queue_type_declares_quorum_queue test isn't mixed version compatible"};
830+
false ->
831+
node_wide_default_queue_type_declares_quorum_queue0(Config)
832+
end.
833+
834+
node_wide_default_queue_type_declares_quorum_queue0(Config) ->
835+
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
836+
rpc:call(Node, application, set_env, [rabbit, default_queue_type, rabbit_quorum_queue]),
837+
VHost = atom_to_binary(?FUNCTION_NAME, utf8),
838+
QName = atom_to_binary(?FUNCTION_NAME, utf8),
839+
User = ?config(rmq_username, Config),
840+
841+
AddVhostArgs = [VHost, #{}, User],
842+
ok = rabbit_ct_broker_helpers:rpc(Config, Node, rabbit_vhost, add,
843+
AddVhostArgs),
844+
ok = rabbit_ct_broker_helpers:set_full_permissions(Config, User, VHost),
845+
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config, Node, VHost),
846+
{ok, Ch} = amqp_connection:open_channel(Conn),
847+
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare(Ch, QName, [])),
848+
assert_queue_type(Node, VHost, QName, rabbit_quorum_queue),
849+
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare(Ch, QName, [])),
850+
?assertEqual({'queue.declare_ok', QName, 0, 0},
851+
declare(Ch, QName, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
852+
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare_passive(Ch, QName, [])),
853+
?assertEqual({'queue.declare_ok', QName, 0, 0},
854+
declare_passive(Ch, QName, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
855+
amqp_connection:close(Conn),
856+
857+
rpc:call(Node, application, set_env, [rabbit, default_queue_type, rabbit_classic_queue]),
858+
ok.
859+
825860
restart_all_types(Config) ->
826861
%% Test the node restart with both types of queues (quorum and classic) to
827862
%% ensure there are no regressions
@@ -1049,7 +1084,7 @@ shrink_all(Config) ->
10491084
rebalance(Config) ->
10501085
case rabbit_ct_helpers:is_mixed_versions() of
10511086
true ->
1052-
{skip, "rebalance tests isn't mixed version compatible"};
1087+
{skip, "rebalance test isn't mixed version compatible"};
10531088
false ->
10541089
rebalance0(Config)
10551090
end.
@@ -1512,7 +1547,7 @@ leadership_takeover(Config) ->
15121547
metrics_cleanup_on_leadership_takeover(Config) ->
15131548
case rabbit_ct_helpers:is_mixed_versions() of
15141549
true ->
1515-
{skip, "metrics_cleanup_on_leadership_takeover tests isn't mixed version compatible"};
1550+
{skip, "metrics_cleanup_on_leadership_takeover test isn't mixed version compatible"};
15161551
false ->
15171552
metrics_cleanup_on_leadership_takeover0(Config)
15181553
end.

0 commit comments

Comments
 (0)