Skip to content

Commit 6e7bf23

Browse files
Make sure that "Other ETS" and "Other system" memory metrics are never negative
They can become negative due to ETS tables being concurrently added, removed and updated. So simply report 0 in such cases.
1 parent bfb3a72 commit 6e7bf23

2 files changed

Lines changed: 76 additions & 2 deletions

File tree

deps/rabbit/src/rabbit_vm.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ memory() ->
117117
[
118118
{mnesia, MnesiaETS},
119119
{metadata_store_ets, MetadataStoreETS},
120-
{other_ets, ETS - MnesiaETS - MetricsETS - MgmtDbETS - MsgIndexETS - MetadataStoreETS - lists:sum(QueuesEtsStats)},
120+
{other_ets, max(0, ETS - MnesiaETS - MetricsETS - MgmtDbETS - MsgIndexETS - MetadataStoreETS - lists:sum(QueuesEtsStats))},
121121

122122
%% Messages (mostly, some binaries are not messages)
123123
{binary, Bin},
@@ -126,7 +126,7 @@ memory() ->
126126
%% System
127127
{code, Code},
128128
{atom, Atom},
129-
{other_system, System - ETS - Bin - Code - Atom},
129+
{other_system, max(0, System - ETS - Bin - Code - Atom)},
130130
{allocated_unused, AllocatedUnused},
131131
{reserved_unallocated, OSReserved},
132132
{strategy, Strategy},
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2026 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
8+
-module(unit_rabbit_vm_SUITE).
9+
10+
-include_lib("eunit/include/eunit.hrl").
11+
12+
-compile(export_all).
13+
14+
all() ->
15+
[
16+
{group, sequential_tests}
17+
].
18+
19+
groups() ->
20+
[
21+
{sequential_tests, [], [
22+
memory_breakdown_non_negative
23+
]}
24+
].
25+
26+
%% -------------------------------------------------------------------
27+
%% Test suite setup/teardown
28+
%% -------------------------------------------------------------------
29+
30+
init_per_suite(Config) ->
31+
rabbit_ct_helpers:log_environment(),
32+
rabbit_ct_helpers:run_setup_steps(Config).
33+
34+
end_per_suite(Config) ->
35+
rabbit_ct_helpers:run_teardown_steps(Config).
36+
37+
init_per_group(Group, Config) ->
38+
Config1 = rabbit_ct_helpers:set_config(Config, [
39+
{rmq_nodename_suffix, Group},
40+
{rmq_nodes_count, 1}
41+
]),
42+
rabbit_ct_helpers:run_steps(Config1,
43+
rabbit_ct_broker_helpers:setup_steps() ++
44+
rabbit_ct_client_helpers:setup_steps()).
45+
46+
end_per_group(_Group, Config) ->
47+
rabbit_ct_helpers:run_steps(Config,
48+
rabbit_ct_client_helpers:teardown_steps() ++
49+
rabbit_ct_broker_helpers:teardown_steps()).
50+
51+
init_per_testcase(Testcase, Config) ->
52+
rabbit_ct_helpers:testcase_started(Config, Testcase).
53+
54+
end_per_testcase(Testcase, Config) ->
55+
rabbit_ct_helpers:testcase_finished(Config, Testcase).
56+
57+
%% -------------------------------------------------------------------
58+
%% Test cases
59+
%% -------------------------------------------------------------------
60+
61+
memory_breakdown_non_negative(Config) ->
62+
ok = rabbit_ct_broker_helpers:rpc(Config, 0,
63+
?MODULE, memory_breakdown_non_negative1, []).
64+
65+
memory_breakdown_non_negative1() ->
66+
Memory = rabbit_vm:memory(),
67+
Keys = [other_proc, other_ets, other_system],
68+
lists:foreach(
69+
fun(Key) ->
70+
Value = proplists:get_value(Key, Memory),
71+
?assert(is_integer(Value)),
72+
?assert(Value >= 0)
73+
end, Keys),
74+
ok.

0 commit comments

Comments
 (0)