Skip to content

Commit e735f57

Browse files
committed
rabbit.schema: Add config options for per-queue-type disk limits
1 parent 300ff60 commit e735f57

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,73 @@ fun(Conf) ->
12381238
end
12391239
end}.
12401240

1241+
%% Per-queue-type / per-mount disk alarms
1242+
{mapping, "disk_free_limits.$num.name", "rabbit.disk_free_limits", [
1243+
{datatype, [binary]}
1244+
]}.
1245+
{mapping, "disk_free_limits.$num.mount", "rabbit.disk_free_limits", [
1246+
{datatype, [string]}
1247+
]}.
1248+
{mapping, "disk_free_limits.$num.limit", "rabbit.disk_free_limits", [
1249+
{datatype, [integer, string]},
1250+
{validators, ["is_supported_information_unit"]}
1251+
]}.
1252+
{mapping, "disk_free_limits.$num.queue_types", "rabbit.disk_free_limits", [
1253+
{datatype, [binary]}
1254+
]}.
1255+
1256+
{translation, "rabbit.disk_free_limits",
1257+
fun(Conf) ->
1258+
case cuttlefish_variable:filter_by_prefix("disk_free_limits", Conf) of
1259+
[] ->
1260+
cuttlefish:unset();
1261+
Settings ->
1262+
Ls = lists:foldl(
1263+
fun ({["disk_free_limits", Num, Key0], Value0}, Acc) ->
1264+
Idx = case string:to_integer(Num) of
1265+
{N, []} -> N;
1266+
_ -> cuttlefish:invalid(lists:flatten(io_lib:format("~p could not be parsed as a number", [Num])))
1267+
end,
1268+
Key = case Key0 of
1269+
"name" -> name;
1270+
"mount" -> mount;
1271+
"limit" -> limit;
1272+
"queue_types" -> queue_types;
1273+
_ -> cuttlefish:invalid(lists:flatten(io_lib:format("~p is invalid", [Key0])))
1274+
end,
1275+
Value = case Key of
1276+
queue_types -> string:split(Value0, ",");
1277+
_ -> Value0
1278+
end,
1279+
maps:update_with(
1280+
Idx,
1281+
fun (#{Key := ExistingValue} = Limit) ->
1282+
cuttlefish:warn(
1283+
io_lib:format("Disk limit ~b has duplicate setting ~ts, "
1284+
"using ~tp instead of ~tp",
1285+
[Idx, Key, Value, ExistingValue])),
1286+
Limit#{Key := Value};
1287+
(Limit) ->
1288+
Limit#{Key => Value}
1289+
end, #{Key => Value}, Acc);
1290+
(Other, _Acc) ->
1291+
cuttlefish:invalid(
1292+
lists:flatten(io_lib:format("~p is invalid", [Other])))
1293+
end, #{}, Settings),
1294+
maps:fold(
1295+
fun(_Idx, #{name := Name}, Names) ->
1296+
case sets:is_element(Name, Names) of
1297+
true ->
1298+
cuttlefish:invalid(
1299+
lists:flatten(io_lib:format("name ~ts is used by multiple mounts", [Name])));
1300+
false ->
1301+
sets:add_element(Name, Names)
1302+
end
1303+
end, sets:new([{version, 2}]), Ls),
1304+
Ls
1305+
end
1306+
end}.
1307+
12411308
%%
12421309
%% Clustering
12431310
%% =====================

deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,26 @@ tcp_listen_options.exit_on_close = false",
467467
"total_memory_available_override_value = 1024MB",
468468
[{rabbit,[{total_memory_available_override_value, "1024MB"}]}],
469469
[]},
470+
{disk_free_limits_per_mount,
471+
"disk_free_limits.1.name = messaging
472+
disk_free_limits.1.mount = /data/queues
473+
disk_free_limits.1.limit = 2GB
474+
disk_free_limits.1.queue_types = classic,quorum
475+
476+
disk_free_limits.2.name = streaming
477+
disk_free_limits.2.mount = /data/streams
478+
disk_free_limits.2.limit = 2GB
479+
disk_free_limits.2.queue_types = stream",
480+
[{rabbit,[{disk_free_limits,
481+
#{1 => #{name => <<"messaging">>,
482+
mount => "/data/queues",
483+
limit => "2GB",
484+
queue_types => [<<"classic">>, <<"quorum">>]},
485+
2 => #{name => <<"streaming">>,
486+
mount => "/data/streams",
487+
limit => "2GB",
488+
queue_types => [<<"stream">>]}}}]}],
489+
[]},
470490
{ranch_connection_max,
471491
"ranch_connection_max = 999",
472492
[{rabbit,[{ranch_connection_max, 999}]}],

0 commit comments

Comments
 (0)