Skip to content

Commit 47949a5

Browse files
Merge branch 'master' into rabbitmq-server-close-connection-on-vhost-down
2 parents 7fa82b3 + e66809b commit 47949a5

File tree

3 files changed

+65
-42
lines changed

3 files changed

+65
-42
lines changed

src/rabbit_amqqueue.erl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ list_local_names() ->
597597
State =/= crashed,
598598
node() =:= node(QPid) ].
599599

600-
list(VHostPath) -> list(VHostPath, rabbit_queue).
600+
list(VHostPath) ->
601+
list(VHostPath, rabbit_queue).
601602

602603
%% Not dirty_match_object since that would not be transactional when used in a
603604
%% tx context
@@ -611,12 +612,16 @@ list(VHostPath, TableName) ->
611612
end).
612613

613614
list_down(VHostPath) ->
614-
Present = list(VHostPath),
615-
Durable = list(VHostPath, rabbit_durable_queue),
616-
PresentS = sets:from_list([N || #amqqueue{name = N} <- Present]),
617-
sets:to_list(sets:filter(fun (#amqqueue{name = N}) ->
618-
not sets:is_element(N, PresentS)
619-
end, sets:from_list(Durable))).
615+
case rabbit_vhost:exists(VHostPath) of
616+
false -> [];
617+
true ->
618+
Present = list(VHostPath),
619+
Durable = list(VHostPath, rabbit_durable_queue),
620+
PresentS = sets:from_list([N || #amqqueue{name = N} <- Present]),
621+
sets:to_list(sets:filter(fun (#amqqueue{name = N}) ->
622+
not sets:is_element(N, PresentS)
623+
end, sets:from_list(Durable)))
624+
end.
620625

621626
count(VHost) ->
622627
try

src/rabbit_vhost_limit.erl

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
-export([update_limit/4, clear_limit/3, get_limit/2]).
2727
-export([validate/5, notify/5, notify_clear/4]).
2828
-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]).
3031

3132
-import(rabbit_misc, [pget/2, pget/3]).
3233

@@ -106,28 +107,40 @@ is_over_connection_limit(VirtualHost) ->
106107
{ok, _Limit} -> false
107108
end.
108109

110+
-spec would_exceed_queue_limit(non_neg_integer(), rabbit_types:vhost()) ->
111+
{true, non_neg_integer(), non_neg_integer()} | false.
109112

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) ->
113114
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};
119122
{ok, Limit} when is_integer(Limit) andalso Limit > 0 ->
120123
QueueCount = rabbit_amqqueue:count(VirtualHost),
121-
case QueueCount >= Limit of
124+
case (AdditionalCount + QueueCount) > Limit of
122125
false -> false;
123-
true -> {true, Limit}
126+
true -> {true, Limit, QueueCount}
124127
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
131144
end.
132145

133146
%%----------------------------------------------------------------------------

src/rabbit_vm.erl

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,32 @@ memory() ->
4040
[aggregate(Names, Sums, memory, fun (X) -> X end)
4141
|| Names <- distinguished_interesting_sups()],
4242

43-
MnesiaETS = mnesia_memory(),
44-
MsgIndexETS = ets_memory(msg_stores()),
45-
MetricsETS = ets_memory([rabbit_metrics]),
46-
MetricsProc =
47-
try
48-
[{_, M}] = process_info(whereis(rabbit_metrics), [memory]),
49-
M
50-
catch
51-
error:badarg ->
52-
0
53-
end,
54-
MgmtDbETS = ets_memory([rabbit_mgmt_storage]),
55-
OsTotal = vm_memory_monitor:get_process_memory(),
56-
57-
[{processes, Processes},
43+
MnesiaETS = mnesia_memory(),
44+
MsgIndexETS = ets_memory(msg_stores()),
45+
MetricsETS = ets_memory([rabbit_metrics]),
46+
MetricsProc = try
47+
[{_, M}] = process_info(whereis(rabbit_metrics), [memory]),
48+
M
49+
catch
50+
error:badarg ->
51+
0
52+
end,
53+
MgmtDbETS = ets_memory([rabbit_mgmt_storage]),
54+
VMTotal = vm_memory_monitor:get_process_memory(),
55+
56+
[{total, ErlangTotal},
57+
{processes, Processes},
5858
{ets, ETS},
5959
{atom, Atom},
6060
{binary, Bin},
6161
{code, Code},
6262
{system, System}] =
63-
erlang:memory([processes, ets, atom, binary, code, system]),
63+
erlang:memory([total, processes, ets, atom, binary, code, system]),
64+
65+
Unaccounted = case VMTotal - ErlangTotal of
66+
GTZ when GTZ > 0 -> GTZ;
67+
_LTZ -> 0
68+
end,
6469

6570
OtherProc = Processes
6671
- ConnsReader - ConnsWriter - ConnsChannel - ConnsOther
@@ -96,9 +101,9 @@ memory() ->
96101
%% System
97102
{code, Code},
98103
{atom, Atom},
99-
{other_system, System - ETS - Bin - Code - Atom},
104+
{other_system, System - ETS - Bin - Code - Atom + Unaccounted},
100105

101-
{total, OsTotal}
106+
{total, VMTotal}
102107
].
103108
%% [1] - erlang:memory(processes) can be less than the sum of its
104109
%% parts. Rather than display something nonsensical, just silence any

0 commit comments

Comments
 (0)