summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2017-07-22 22:02:26 +0300
committerMichael Klishin <michael@clojurewerkz.org>2017-07-22 22:02:26 +0300
commit47949a5970603f20d9227484b5839e37101ce642 (patch)
tree47ee04dd27f2bff9c73b901848454ae4d51b9dea /src
parent7fa82b3d923a2c1179fb0ae460dde46e89414a5a (diff)
parente66809bbcd33593de73866dac6718726ef9053d8 (diff)
downloadrabbitmq-server-git-47949a5970603f20d9227484b5839e37101ce642.tar.gz
Merge branch 'master' into rabbitmq-server-close-connection-on-vhost-down
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_amqqueue.erl19
-rw-r--r--src/rabbit_vhost_limit.erl47
-rw-r--r--src/rabbit_vm.erl41
3 files changed, 65 insertions, 42 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl
index 76f3fa6bf3..ff57593374 100644
--- a/src/rabbit_amqqueue.erl
+++ b/src/rabbit_amqqueue.erl
@@ -597,7 +597,8 @@ list_local_names() ->
State =/= crashed,
node() =:= node(QPid) ].
-list(VHostPath) -> list(VHostPath, rabbit_queue).
+list(VHostPath) ->
+ list(VHostPath, rabbit_queue).
%% Not dirty_match_object since that would not be transactional when used in a
%% tx context
@@ -611,12 +612,16 @@ list(VHostPath, TableName) ->
end).
list_down(VHostPath) ->
- Present = list(VHostPath),
- Durable = list(VHostPath, rabbit_durable_queue),
- PresentS = sets:from_list([N || #amqqueue{name = N} <- Present]),
- sets:to_list(sets:filter(fun (#amqqueue{name = N}) ->
- not sets:is_element(N, PresentS)
- end, sets:from_list(Durable))).
+ case rabbit_vhost:exists(VHostPath) of
+ false -> [];
+ true ->
+ Present = list(VHostPath),
+ Durable = list(VHostPath, rabbit_durable_queue),
+ PresentS = sets:from_list([N || #amqqueue{name = N} <- Present]),
+ sets:to_list(sets:filter(fun (#amqqueue{name = N}) ->
+ not sets:is_element(N, PresentS)
+ end, sets:from_list(Durable)))
+ end.
count(VHost) ->
try
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.
%%----------------------------------------------------------------------------
diff --git a/src/rabbit_vm.erl b/src/rabbit_vm.erl
index 3ae482a934..88062dc32a 100644
--- a/src/rabbit_vm.erl
+++ b/src/rabbit_vm.erl
@@ -40,27 +40,32 @@ memory() ->
[aggregate(Names, Sums, memory, fun (X) -> X end)
|| Names <- distinguished_interesting_sups()],
- MnesiaETS = mnesia_memory(),
- MsgIndexETS = ets_memory(msg_stores()),
- MetricsETS = ets_memory([rabbit_metrics]),
- MetricsProc =
- try
- [{_, M}] = process_info(whereis(rabbit_metrics), [memory]),
- M
- catch
- error:badarg ->
- 0
- end,
- MgmtDbETS = ets_memory([rabbit_mgmt_storage]),
- OsTotal = vm_memory_monitor:get_process_memory(),
-
- [{processes, Processes},
+ MnesiaETS = mnesia_memory(),
+ MsgIndexETS = ets_memory(msg_stores()),
+ MetricsETS = ets_memory([rabbit_metrics]),
+ MetricsProc = try
+ [{_, M}] = process_info(whereis(rabbit_metrics), [memory]),
+ M
+ catch
+ error:badarg ->
+ 0
+ end,
+ MgmtDbETS = ets_memory([rabbit_mgmt_storage]),
+ VMTotal = vm_memory_monitor:get_process_memory(),
+
+ [{total, ErlangTotal},
+ {processes, Processes},
{ets, ETS},
{atom, Atom},
{binary, Bin},
{code, Code},
{system, System}] =
- erlang:memory([processes, ets, atom, binary, code, system]),
+ erlang:memory([total, processes, ets, atom, binary, code, system]),
+
+ Unaccounted = case VMTotal - ErlangTotal of
+ GTZ when GTZ > 0 -> GTZ;
+ _LTZ -> 0
+ end,
OtherProc = Processes
- ConnsReader - ConnsWriter - ConnsChannel - ConnsOther
@@ -96,9 +101,9 @@ memory() ->
%% System
{code, Code},
{atom, Atom},
- {other_system, System - ETS - Bin - Code - Atom},
+ {other_system, System - ETS - Bin - Code - Atom + Unaccounted},
- {total, OsTotal}
+ {total, VMTotal}
].
%% [1] - erlang:memory(processes) can be less than the sum of its
%% parts. Rather than display something nonsensical, just silence any