Skip to content

Commit 92261a4

Browse files
authored
Merge pull request #1597 from rabbitmq/rabbitmq-server-1590
Hard cap for maximum priorities
2 parents 117eb9b + 75cee2c commit 92261a4

File tree

6 files changed

+192
-9
lines changed

6 files changed

+192
-9
lines changed

src/rabbit_amqqueue.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ declare_args() ->
575575
{<<"x-dead-letter-routing-key">>, fun check_dlxrk_arg/2},
576576
{<<"x-max-length">>, fun check_non_neg_int_arg/2},
577577
{<<"x-max-length-bytes">>, fun check_non_neg_int_arg/2},
578-
{<<"x-max-priority">>, fun check_non_neg_int_arg/2},
578+
{<<"x-max-priority">>, fun check_max_priority_arg/2},
579579
{<<"x-overflow">>, fun check_overflow/2},
580580
{<<"x-queue-mode">>, fun check_queue_mode/2}].
581581

@@ -611,6 +611,13 @@ check_message_ttl_arg({Type, Val}, Args) ->
611611
Error -> Error
612612
end.
613613

614+
check_max_priority_arg({Type, Val}, Args) ->
615+
case check_non_neg_int_arg({Type, Val}, Args) of
616+
ok when Val =< ?MAX_SUPPORTED_PRIORITY -> ok;
617+
ok -> {error, {max_value_exceeded, Val}};
618+
Error -> Error
619+
end.
620+
614621
%% Note that the validity of x-dead-letter-exchange is already verified
615622
%% by rabbit_channel's queue.declare handler.
616623
check_dlxname_arg({longstr, _}, _) -> ok;

src/rabbit_ctl_usage.erl

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
%% Generated, do not edit!
2+
-module(rabbit_ctl_usage).
3+
-export([usage/0]).
4+
usage() -> "Usage:
5+
rabbitmqctl [-n <node>] [-t <timeout>] [-q] <command> [<command options>]
6+
7+
Options:
8+
-n node
9+
-q
10+
-t timeout
11+
12+
Default node is \"rabbit@server\", where server is the local host. On a host
13+
named \"server.example.com\", the node name of the RabbitMQ Erlang node will
14+
usually be rabbit@server (unless RABBITMQ_NODENAME has been set to some
15+
non-default value at broker startup time). The output of hostname -s is usually
16+
the correct suffix to use after the \"@\" sign. See rabbitmq-server(1) for
17+
details of configuring the RabbitMQ broker.
18+
19+
Quiet output mode is selected with the \"-q\" flag. Informational messages are
20+
suppressed when quiet mode is in effect.
21+
22+
Operation timeout in seconds. Only applicable to \"list\" commands. Default is
23+
\"infinity\".
24+
25+
Commands:
26+
stop [<pid_file>]
27+
shutdown
28+
stop_app
29+
start_app
30+
wait <pid_file>
31+
reset
32+
force_reset
33+
rotate_logs <suffix>
34+
hipe_compile <directory>
35+
36+
join_cluster <clusternode> [--ram]
37+
cluster_status
38+
change_cluster_node_type disc | ram
39+
forget_cluster_node [--offline]
40+
rename_cluster_node oldnode1 newnode1 [oldnode2] [newnode2 ...]
41+
update_cluster_nodes clusternode
42+
force_boot
43+
sync_queue [-p <vhost>] queue
44+
cancel_sync_queue [-p <vhost>] queue
45+
purge_queue [-p <vhost>] queue
46+
set_cluster_name name
47+
48+
add_user <username> <password>
49+
delete_user <username>
50+
change_password <username> <newpassword>
51+
clear_password <username>
52+
authenticate_user <username> <password>
53+
set_user_tags <username> <tag> ...
54+
list_users
55+
56+
add_vhost <vhost>
57+
delete_vhost <vhost>
58+
list_vhosts [<vhostinfoitem> ...]
59+
set_permissions [-p <vhost>] <user> <conf> <write> <read>
60+
clear_permissions [-p <vhost>] <username>
61+
list_permissions [-p <vhost>]
62+
list_user_permissions <username>
63+
64+
set_parameter [-p <vhost>] <component_name> <name> <value>
65+
clear_parameter [-p <vhost>] <component_name> <key>
66+
list_parameters [-p <vhost>]
67+
set_global_parameter <name> <value>
68+
clear_global_parameter <name>
69+
list_global_parameters
70+
71+
set_policy [-p <vhost>] [--priority <priority>] [--apply-to <apply-to>]
72+
<name> <pattern> <definition>
73+
clear_policy [-p <vhost>] <name>
74+
list_policies [-p <vhost>]
75+
76+
list_queues [-p <vhost>] [--offline|--online|--local] [<queueinfoitem> ...]
77+
list_exchanges [-p <vhost>] [<exchangeinfoitem> ...]
78+
list_bindings [-p <vhost>] [<bindinginfoitem> ...]
79+
list_connections [<connectioninfoitem> ...]
80+
list_channels [<channelinfoitem> ...]
81+
list_consumers [-p <vhost>]
82+
status
83+
node_health_check
84+
environment
85+
report
86+
eval <expr>
87+
88+
close_connection <connectionpid> <explanation>
89+
trace_on [-p <vhost>]
90+
trace_off [-p <vhost>]
91+
set_vm_memory_high_watermark <fraction>
92+
set_vm_memory_high_watermark absolute <memory_limit>
93+
set_disk_free_limit <disk_limit>
94+
set_disk_free_limit mem_relative <fraction>
95+
encode [--decode] [<value>] [<passphrase>] [--list-ciphers] [--list-hashes]
96+
[--cipher <cipher>] [--hash <hash>] [--iterations <iterations>]
97+
decode [<value>] [<passphrase>][--cipher <cipher>] [--hash <hash>]
98+
[--iterations <iterations>]
99+
list_hashes
100+
list_ciphers
101+
102+
<vhostinfoitem> must be a member of the list [name, tracing].
103+
104+
The list_queues, list_exchanges and list_bindings commands accept an optional
105+
virtual host parameter for which to display results. The default value is \"/\".
106+
107+
<queueinfoitem> must be a member of the list [name, durable, auto_delete,
108+
arguments, policy, pid, owner_pid, exclusive, exclusive_consumer_pid,
109+
exclusive_consumer_tag, messages_ready, messages_unacknowledged, messages,
110+
messages_ready_ram, messages_unacknowledged_ram, messages_ram,
111+
messages_persistent, message_bytes, message_bytes_ready,
112+
message_bytes_unacknowledged, message_bytes_ram, message_bytes_persistent,
113+
head_message_timestamp, disk_reads, disk_writes, consumers,
114+
consumer_utilisation, memory, slave_pids, synchronised_slave_pids, state].
115+
116+
<exchangeinfoitem> must be a member of the list [name, type, durable,
117+
auto_delete, internal, arguments, policy].
118+
119+
<bindinginfoitem> must be a member of the list [source_name, source_kind,
120+
destination_name, destination_kind, routing_key, arguments].
121+
122+
<connectioninfoitem> must be a member of the list [pid, name, port, host,
123+
peer_port, peer_host, ssl, ssl_protocol, ssl_key_exchange, ssl_cipher,
124+
ssl_hash, peer_cert_subject, peer_cert_issuer, peer_cert_validity, state,
125+
channels, protocol, auth_mechanism, user, vhost, timeout, frame_max,
126+
channel_max, client_properties, recv_oct, recv_cnt, send_oct, send_cnt,
127+
send_pend, connected_at].
128+
129+
<channelinfoitem> must be a member of the list [pid, connection, name, number,
130+
user, vhost, transactional, confirm, consumer_count, messages_unacknowledged,
131+
messages_uncommitted, acks_uncommitted, messages_unconfirmed, prefetch_count,
132+
global_prefetch_count].
133+
134+
135+
".

src/rabbit_plugins_usage.erl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%% Generated, do not edit!
2+
-module(rabbit_plugins_usage).
3+
-export([usage/0]).
4+
usage() -> "Usage:
5+
rabbitmq-plugins [-n <node>] <command> [<command options>]
6+
7+
Commands:
8+
list [-v] [-m] [-E] [-e] [<pattern>]
9+
enable [--offline] [--online] <plugin> ...
10+
disable [--offline] [--online] <plugin> ...
11+
set [--offline] [--online] <plugin> ...
12+
13+
14+
".

src/rabbit_policies.erl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,3 @@ merge_policy_value(<<"message-ttl">>, Val, OpVal) -> min(Val, OpVal);
117117
merge_policy_value(<<"max-length">>, Val, OpVal) -> min(Val, OpVal);
118118
merge_policy_value(<<"max-length-bytes">>, Val, OpVal) -> min(Val, OpVal);
119119
merge_policy_value(<<"expires">>, Val, OpVal) -> min(Val, OpVal).
120-

src/rabbit_priority_queue.erl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,14 @@ collapse_recovery(QNames, DupNames, Recovery) ->
128128
priorities(#amqqueue{arguments = Args}) ->
129129
Ints = [long, short, signedint, byte, unsignedbyte, unsignedshort, unsignedint],
130130
case rabbit_misc:table_lookup(Args, <<"x-max-priority">>) of
131-
{Type, Max} -> case lists:member(Type, Ints) of
132-
false -> none;
133-
true -> lists:reverse(lists:seq(0, Max))
134-
end;
135-
_ -> none
131+
{Type, RequestedMax} ->
132+
case lists:member(Type, Ints) of
133+
false -> none;
134+
true ->
135+
Max = min(RequestedMax, ?MAX_SUPPORTED_PRIORITY),
136+
lists:reverse(lists:seq(0, Max))
137+
end;
138+
_ -> none
136139
end.
137140

138141
%%----------------------------------------------------------------------------

test/priority_queue_SUITE.erl

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
-module(priority_queue_SUITE).
1818

1919
-include_lib("common_test/include/ct.hrl").
20+
-include_lib("eunit/include/eunit.hrl").
2021
-include_lib("amqp_client/include/amqp_client.hrl").
2122

2223
-compile(export_all).
@@ -46,7 +47,9 @@ groups() ->
4647
simple_order,
4748
straight_through,
4849
invoke,
49-
gen_server2_stats
50+
gen_server2_stats,
51+
negative_max_priorities,
52+
max_priorities_above_hard_limit
5053
]},
5154
{cluster_size_3, [], [
5255
mirror_queue_auto_ack,
@@ -192,6 +195,28 @@ straight_through(Config) ->
192195
rabbit_ct_client_helpers:close_connection(Conn),
193196
passed.
194197

198+
max_priorities_above_hard_limit(Config) ->
199+
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
200+
Q = <<"max_priorities_above_hard_limit">>,
201+
?assertExit(
202+
{{shutdown, {server_initiated_close, 406, _}}, _},
203+
%% Note that lower values (e.g. 300) will cause overflow the byte type here.
204+
%% However, values >= 256 would still be rejected when used by
205+
%% other clients
206+
declare(Ch, Q, 3000)),
207+
rabbit_ct_client_helpers:close_connection(Conn),
208+
passed.
209+
210+
negative_max_priorities(Config) ->
211+
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
212+
Q = <<"negative_max_priorities">>,
213+
?assertExit(
214+
{{shutdown, {server_initiated_close, 406, _}}, _},
215+
declare(Ch, Q, -10)),
216+
rabbit_ct_client_helpers:close_connection(Conn),
217+
passed.
218+
219+
195220
invoke(Config) ->
196221
%% Synthetic test to check the invoke callback, as the bug tested here
197222
%% is only triggered with a race condition.
@@ -669,7 +694,7 @@ get_ok(Ch, Q, Ack, PBin) ->
669694
{#'basic.get_ok'{delivery_tag = DTag}, #amqp_msg{payload = PBin2}} =
670695
amqp_channel:call(Ch, #'basic.get'{queue = Q,
671696
no_ack = Ack =:= no_ack}),
672-
PBin = PBin2,
697+
?assertEqual(PBin, PBin2),
673698
maybe_ack(Ch, Ack, DTag).
674699

675700
get_payload(Ch, Q, Ack, Ps) ->

0 commit comments

Comments
 (0)