|
26 | 26 | -export([update_limit/4, clear_limit/3, get_limit/2]).
|
27 | 27 | -export([validate/5, notify/5, notify_clear/4]).
|
28 | 28 | -export([connection_limit/1, queue_limit/1,
|
29 |
| - is_over_queue_limit/1, is_over_connection_limit/1]). |
| 29 | + is_over_queue_limit/1, would_exceed_queue_limit/2, |
| 30 | + is_over_connection_limit/1]). |
30 | 31 |
|
31 | 32 | -import(rabbit_misc, [pget/2, pget/3]).
|
32 | 33 |
|
@@ -106,28 +107,40 @@ is_over_connection_limit(VirtualHost) ->
|
106 | 107 | {ok, _Limit} -> false
|
107 | 108 | end.
|
108 | 109 |
|
| 110 | +-spec would_exceed_queue_limit(non_neg_integer(), rabbit_types:vhost()) -> |
| 111 | + {true, non_neg_integer(), non_neg_integer()} | false. |
109 | 112 |
|
110 |
| --spec is_over_queue_limit(rabbit_types:vhost()) -> {true, non_neg_integer()} | false. |
111 |
| - |
112 |
| -is_over_queue_limit(VirtualHost) -> |
| 113 | +would_exceed_queue_limit(AdditionalCount, VirtualHost) -> |
113 | 114 | case queue_limit(VirtualHost) of
|
114 |
| - %% no limit configured |
115 |
| - undefined -> false; |
116 |
| - %% with limit = 0, no queues can be declared (perhaps not very |
117 |
| - %% useful but consistent with the connection limit) |
118 |
| - {ok, 0} -> {true, 0}; |
| 115 | + undefined -> |
| 116 | + %% no limit configured |
| 117 | + false; |
| 118 | + {ok, 0} -> |
| 119 | + %% with limit = 0, no queues can be declared (perhaps not very |
| 120 | + %% useful but consistent with the connection limit) |
| 121 | + {true, 0, 0}; |
119 | 122 | {ok, Limit} when is_integer(Limit) andalso Limit > 0 ->
|
120 | 123 | QueueCount = rabbit_amqqueue:count(VirtualHost),
|
121 |
| - case QueueCount >= Limit of |
| 124 | + case (AdditionalCount + QueueCount) > Limit of |
122 | 125 | false -> false;
|
123 |
| - true -> {true, Limit} |
| 126 | + true -> {true, Limit, QueueCount} |
124 | 127 | end;
|
125 |
| - %% any negative value means "no limit". Note that parameter validation |
126 |
| - %% will replace negative integers with 'undefined', so this is to be |
127 |
| - %% explicit and extra defensive |
128 |
| - {ok, Limit} when is_integer(Limit) andalso Limit < 0 -> false; |
129 |
| - %% ignore non-integer limits |
130 |
| - {ok, _Limit} -> false |
| 128 | + {ok, Limit} when is_integer(Limit) andalso Limit < 0 -> |
| 129 | + %% any negative value means "no limit". Note that parameter validation |
| 130 | + %% will replace negative integers with 'undefined', so this is to be |
| 131 | + %% explicit and extra defensive |
| 132 | + false; |
| 133 | + {ok, _Limit} -> |
| 134 | + %% ignore non-integer limits |
| 135 | + false |
| 136 | + end. |
| 137 | + |
| 138 | +-spec is_over_queue_limit(rabbit_types:vhost()) -> {true, non_neg_integer()} | false. |
| 139 | + |
| 140 | +is_over_queue_limit(VirtualHost) -> |
| 141 | + case would_exceed_queue_limit(1, VirtualHost) of |
| 142 | + {true, Limit, _QueueCount} -> {true, Limit}; |
| 143 | + false -> false |
131 | 144 | end.
|
132 | 145 |
|
133 | 146 | %%----------------------------------------------------------------------------
|
|
0 commit comments