summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Klishin <michael@novemberain.com>2017-07-20 02:26:15 +0300
committerGitHub <noreply@github.com>2017-07-20 02:26:15 +0300
commita36c7f3d21cb6ac64ed87b7406847e04392b313c (patch)
treeba80158b5bc4af834eb17524f743d5b98278a87e /src
parent49a6cff7e04172e252d958026fd787443227ba71 (diff)
parent17d5ab0746e94822a868a2f445dca838965d55ea (diff)
downloadrabbitmq-server-git-a36c7f3d21cb6ac64ed87b7406847e04392b313c.tar.gz
Merge pull request #1282 from rabbitmq/rabbitmq-management-423rabbitmq_v3_7_0_milestone17
Add function to check if adding queues would exceed limit
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_vhost_limit.erl47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/rabbit_vhost_limit.erl b/src/rabbit_vhost_limit.erl
index 58c0ce065f..7b797e46b2 100644
--- a/src/rabbit_vhost_limit.erl
+++ b/src/rabbit_vhost_limit.erl
@@ -26,7 +26,8 @@
-export([update_limit/4, clear_limit/3, get_limit/2]).
-export([validate/5, notify/5, notify_clear/4]).
-export([connection_limit/1, queue_limit/1,
- is_over_queue_limit/1, is_over_connection_limit/1]).
+ is_over_queue_limit/1, would_exceed_queue_limit/2,
+ is_over_connection_limit/1]).
-import(rabbit_misc, [pget/2, pget/3]).
@@ -106,28 +107,40 @@ is_over_connection_limit(VirtualHost) ->
{ok, _Limit} -> false
end.
+-spec would_exceed_queue_limit(non_neg_integer(), rabbit_types:vhost()) ->
+ {true, non_neg_integer(), non_neg_integer()} | false.
--spec is_over_queue_limit(rabbit_types:vhost()) -> {true, non_neg_integer()} | false.
-
-is_over_queue_limit(VirtualHost) ->
+would_exceed_queue_limit(AdditionalCount, VirtualHost) ->
case queue_limit(VirtualHost) of
- %% no limit configured
- undefined -> false;
- %% with limit = 0, no queues can be declared (perhaps not very
- %% useful but consistent with the connection limit)
- {ok, 0} -> {true, 0};
+ undefined ->
+ %% no limit configured
+ false;
+ {ok, 0} ->
+ %% with limit = 0, no queues can be declared (perhaps not very
+ %% useful but consistent with the connection limit)
+ {true, 0, 0};
{ok, Limit} when is_integer(Limit) andalso Limit > 0 ->
QueueCount = rabbit_amqqueue:count(VirtualHost),
- case QueueCount >= Limit of
+ case (AdditionalCount + QueueCount) > Limit of
false -> false;
- true -> {true, Limit}
+ true -> {true, Limit, QueueCount}
end;
- %% any negative value means "no limit". Note that parameter validation
- %% will replace negative integers with 'undefined', so this is to be
- %% explicit and extra defensive
- {ok, Limit} when is_integer(Limit) andalso Limit < 0 -> false;
- %% ignore non-integer limits
- {ok, _Limit} -> false
+ {ok, Limit} when is_integer(Limit) andalso Limit < 0 ->
+ %% any negative value means "no limit". Note that parameter validation
+ %% will replace negative integers with 'undefined', so this is to be
+ %% explicit and extra defensive
+ false;
+ {ok, _Limit} ->
+ %% ignore non-integer limits
+ false
+ end.
+
+-spec is_over_queue_limit(rabbit_types:vhost()) -> {true, non_neg_integer()} | false.
+
+is_over_queue_limit(VirtualHost) ->
+ case would_exceed_queue_limit(1, VirtualHost) of
+ {true, Limit, _QueueCount} -> {true, Limit};
+ false -> false
end.
%%----------------------------------------------------------------------------