Skip to content

Commit e2b0e9b

Browse files
committed
cluster wide queue limit
1 parent 8ce0a20 commit e2b0e9b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,21 @@ fun(Conf) ->
14371437
end}.
14381438

14391439

1440+
{mapping, "cluster_queue_limit", "rabbit.cluster_queue_limit",
1441+
[{datatype, [{atom, infinity}, integer]}]}.
1442+
1443+
{translation, "rabbit.cluster_queue_limit",
1444+
fun(Conf) ->
1445+
case cuttlefish:conf_get("cluster_queue_limit", Conf, undefined) of
1446+
undefined -> cuttlefish:unset();
1447+
infinity -> infinity;
1448+
Val when is_integer(Val) andalso Val > 0 -> Val;
1449+
_ -> cuttlefish:invalid("should be positive integer or 'infinity'")
1450+
end
1451+
end
1452+
}.
1453+
1454+
14401455
%% Interval (in milliseconds) at which we send keepalive messages
14411456
%% to other cluster members. Note that this is not the same thing
14421457
%% as net_ticktime; missed keepalive messages will not cause nodes

deps/rabbit/src/rabbit_channel.erl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,21 @@ check_vhost_queue_limit(#resource{name = QueueName}, VHost) ->
10651065

10661066
end.
10671067

1068+
check_cluster_queue_limit(#resource{name = QueueName}) ->
1069+
case rabbit_misc:get_env(rabbit, cluster_queue_limit, infinity) of
1070+
infinity ->
1071+
false;
1072+
Limit ->
1073+
case rabbit_db_queue:count() >= Limit of
1074+
true ->
1075+
rabbit_misc:precondition_failed("cannot declare queue '~ts': "
1076+
"queue limit in cluster (~tp) is reached",
1077+
[QueueName, Limit]);
1078+
false ->
1079+
ok
1080+
end
1081+
end.
1082+
10681083
qbin_to_resource(QueueNameBin, VHostPath) ->
10691084
name_to_resource(queue, QueueNameBin, VHostPath).
10701085

@@ -2526,6 +2541,7 @@ handle_method(#'queue.declare'{queue = QueueNameBin,
25262541
{error, not_found} ->
25272542
%% enforce the limit for newly declared queues only
25282543
check_vhost_queue_limit(QueueName, VHostPath),
2544+
check_cluster_queue_limit(QueueName),
25292545
DlxKey = <<"x-dead-letter-exchange">>,
25302546
case rabbit_misc:r_arg(VHostPath, exchange, Args, DlxKey) of
25312547
undefined ->

0 commit comments

Comments
 (0)