Skip to content

Commit a319282

Browse files
author
Erlang/OTP
committed
Merge branch 'michal/kernel/decreasing-disk-log-size-causes-crash/OTP-19605' into maint-27
* michal/kernel/decreasing-disk-log-size-causes-crash/OTP-19605: Modify test to verify that chunk_step can step into previos max log file Remove function overload that is no longer needed Add test for chunk_step crash after decreasing log size Fix disk_log crash when using chunk_step after decreasing log size
2 parents b1a6d7e + c9f9fe7 commit a319282

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/kernel/src/disk_log_1.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,9 +1564,10 @@ inc_wrap(FName, CurF, MaxF) ->
15641564
{NewFt, MaxF}
15651565
end.
15661566

1567-
inc(N, {_NewMax, OldMax}) -> inc(N, OldMax, 1);
15681567
inc(N, Max) -> inc(N, Max, 1).
15691568

1569+
inc(N, {_NewMax, OldMax}, Step) ->
1570+
inc(N, OldMax, Step);
15701571
inc(N, Max, Step) ->
15711572
Nx = (N + Step) rem Max,
15721573
if

lib/kernel/test/disk_log_SUITE.erl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@
9090

9191
change_attribute/1,
9292

93-
otp_6278/1, otp_10131/1, otp_16768/1, otp_16809/1]).
93+
otp_6278/1, otp_10131/1, otp_16768/1, otp_16809/1,
94+
95+
decrease_size_with_chunk_step/1]).
9496

9597
-export([head_fun/1, hf/0, hf_bin/0, lserv/1,
9698
measure/0, init_m/1, xx/0]).
@@ -167,7 +169,7 @@ groups() ->
167169
{change_size, [],
168170
[change_size_before, change_size_during,
169171
change_size_after, default_size, change_size2,
170-
change_size_truncate]}].
172+
change_size_truncate, decrease_size_with_chunk_step]}].
171173

172174
init_per_suite(Config) ->
173175
Config.
@@ -4419,6 +4421,32 @@ otp_16809(Conf) when is_list(Conf) ->
44194421
HeadFunc2 = info(Log, head, undef),
44204422
ok = disk_log:close(Log).
44214423

4424+
decrease_size_with_chunk_step(Conf) when is_list(Conf) ->
4425+
Dir = ?privdir(Conf),
4426+
Log = decrease_size_with_chunk_step,
4427+
File = filename:join(Dir, lists:concat([Log, ".LOG"])),
4428+
{ok, Log} = disk_log:open([{size, {50, 3}}, {name, Log}, {type, wrap},
4429+
{file, File}, {notify, true}]),
4430+
eof = disk_log:chunk(Log, start, 1),
4431+
{error, end_of_log} = disk_log:chunk_step(Log, start, 1),
4432+
ok = disk_log:log_terms(Log, [1, 2, 3, 4, 5, 6, 7, 8, 9]),
4433+
ok = disk_log:close(Log),
4434+
{ok, Log} = disk_log:open([{name, Log}, {type, wrap}, {file, File},
4435+
{notify, true}]),
4436+
%% Decrease maximum number of files from 3 to 2.
4437+
ok = disk_log:change_size(Log, {50, 2}),
4438+
%% The exception error of rem/2 operator should not occur in here.
4439+
{ok, Cont} = disk_log:chunk_step(Log, start, 2),
4440+
%% Verify that chunk_step has stepped to old max file (3)
4441+
{_, [7, 8, 9]} = disk_log:chunk(Log, Cont),
4442+
%% Continue to append the items to the log in order to make sure it can work
4443+
%% as normal.
4444+
ok = disk_log:log_terms(Log, [9, 8, 7, 6, 5, 4, 3, 2, 1]),
4445+
%% Verify that log files were decreased to 2 after wrapping
4446+
[6, 5, 4, 3, 2, 1] = get_all_terms(Log),
4447+
ok = disk_log:close(Log),
4448+
del(File, 2).
4449+
44224450
mark(FileName, What) ->
44234451
{ok,Fd} = file:open(FileName, [raw, binary, read, write]),
44244452
{ok,_} = file:position(Fd, 4),

0 commit comments

Comments
 (0)