Skip to content

Commit 179f229

Browse files
Merge pull request #1523 from rabbitmq/rabbitmq-server-1522-net-ticktime-in-new-config-format
Support kernel.net_ticktime in Cuttlefish configuration
2 parents da98806 + 7bb8c75 commit 179f229

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

docs/rabbitmq.conf.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@
459459
# Kernel section
460460
# ======================================
461461

462-
# kernel.net_ticktime = 60
462+
# net_ticktime = 60
463463

464464
## ----------------------------------------------------------------------------
465465
## RabbitMQ Management Plugin

priv/schema/rabbit.schema

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,15 @@ end}.
11501150
{datatype, {enum, [debug, info, notice, warning, error, critical, alert, emergency, none]}}
11511151
]}.
11521152

1153+
% ==========================
1154+
% Kernel section
1155+
% ==========================
1156+
1157+
{mapping, "net_ticktime", "kernel.net_ticktime",[
1158+
{datatype, [integer]},
1159+
{validators, ["non_zero_positive_integer"]}
1160+
]}.
1161+
11531162
% ===============================
11541163
% Validators
11551164
% ===============================
@@ -1199,3 +1208,8 @@ end}.
11991208
fun(Int) when is_integer(Int) ->
12001209
Int >= 0
12011210
end}.
1211+
1212+
{validator, "non_zero_positive_integer", "number should be greater or equal to one",
1213+
fun(Int) when is_integer(Int) ->
1214+
Int >= 1
1215+
end}.

src/rabbit_config.erl

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,10 @@ update_app_config(ConfigFile) ->
7272
%% For application config to be updated, applications should
7373
%% be unloaded first.
7474
%% If an application is already running, print an error.
75-
lists:foreach(fun({App, _Config}) ->
75+
lists:foreach(fun({App, AppConfig}) ->
7676
case lists:member(App, RunningApps) of
7777
true ->
78-
io:format(standard_error,
79-
"~nUnable to update config for app ~p from *.conf file."
80-
" App is already running. Use advanced.config instead.~n",
81-
[App]);
78+
maybe_print_warning_for_running_app(App, AppConfig);
8279
false ->
8380
case lists:member(App, LoadedApps) of
8481
true -> application:unload(App);
@@ -87,11 +84,48 @@ update_app_config(ConfigFile) ->
8784
end
8885
end,
8986
Config),
87+
maybe_set_net_ticktime(proplists:get_value(kernel, Config)),
9088
ok = application_controller:change_application_data([], [ConfigFile]),
9189
%% Make sure to load all the applications we're unloaded
9290
lists:foreach(fun(App) -> application:load(App) end, LoadedApps),
9391
ok.
9492

93+
maybe_print_warning_for_running_app(kernel, Config) ->
94+
ConfigWithoutSupportedEntry = proplists:delete(net_ticktime, Config),
95+
case length(ConfigWithoutSupportedEntry) > 0 of
96+
true -> io:format(standard_error,
97+
"~nUnable to update config for app ~p from a .conf file."
98+
" The app is already running. Use advanced.config instead.~n", [kernel]);
99+
false -> ok
100+
end;
101+
maybe_print_warning_for_running_app(App, _Config) ->
102+
io:format(standard_error,
103+
"~nUnable to update config for app ~p from a .conf file: "
104+
" The app is already running.~n",
105+
[App]).
106+
107+
maybe_set_net_ticktime(undefined) ->
108+
ok;
109+
maybe_set_net_ticktime(KernelConfig) ->
110+
case proplists:get_value(net_ticktime, KernelConfig) of
111+
undefined ->
112+
ok;
113+
NetTickTime ->
114+
case net_kernel:set_net_ticktime(NetTickTime, 0) of
115+
unchanged ->
116+
ok;
117+
change_initiated ->
118+
ok;
119+
{ongoing_change_to, NewNetTicktime} ->
120+
io:format(standard_error,
121+
"~nCouldn't set net_ticktime to ~p "
122+
"as net_kernel is busy changing net_ticktime to ~p seconds ~n",
123+
[NetTickTime, NewNetTicktime]);
124+
_ ->
125+
ok
126+
end
127+
end.
128+
95129
generate_config_file(ConfFiles, ConfDir, ScriptDir) ->
96130
generate_config_file(ConfFiles, ConfDir, ScriptDir,
97131
schema_dir(), get_advanced_config()).

test/config_schema_SUITE_data/rabbit.snippets

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,11 @@ credential_validator.regexp = ^abc\\d+",
528528
[{rabbit, [
529529
{delegate_count, 64}
530530
]}],
531-
[]}
531+
[]},
532+
{kernel_net_ticktime,
533+
"net_ticktime = 20",
534+
[{kernel, [
535+
{net_ticktime, 20}
536+
]}],
537+
[]}
532538
].

0 commit comments

Comments
 (0)