Skip to content

Commit fd1a3fb

Browse files
committed
ra_log:set_last_index/2 fix
1 parent c5ebfca commit fd1a3fb

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/ra_log.erl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,13 @@ set_last_index(Idx, #?MODULE{cfg = Cfg,
751751
last_written_index_term = Cur}};
752752
{Term, State1} ->
753753
LWIdx = min(Idx, LWIdx0),
754-
{LWTerm, State2} = fetch_term(LWIdx, State1),
754+
{LWTerm, State2} = case Cur of
755+
{LWIdx, SnapTerm} ->
756+
{SnapTerm, State1};
757+
_ ->
758+
fetch_term(LWIdx, State1)
759+
end,
760+
755761
%% this should always be found but still assert just in case
756762
%% _if_ this ends up as a genuine reversal next time we try
757763
%% to write to the mem table it will detect this and open

src/ra_server.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,12 @@ handle_leader({command, Cmd}, #{cfg := #cfg{id = Self,
610610
State = State0#{condition =>
611611
#{predicate_fun => fun wal_down_condition/2,
612612
transition_to => leader,
613-
%% TODO: make duration configurable?
614613
timeout => #{duration => 5000,
615614
effects => CondEffs,
616615
transition_to => leader}}},
617616

618-
{await_condition, State, Effects0};
617+
Effects = append_error_reply(Cmd, wal_down, Effects0),
618+
{await_condition, State, Effects};
619619
{not_appended, Reason, State, Effects0} ->
620620
?WARN("~ts command ~W NOT appended to log. Reason ~w",
621621
[LogId, Cmd, 10, Reason]),

test/ra_log_2_SUITE.erl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,9 +1445,12 @@ snapshot_installation(Config) ->
14451445
% after a snapshot we need a "truncating write" that ignores missing
14461446
% indexes
14471447
Log5 = write_n(16, 20, 2, Log4),
1448-
{[], _} = ra_log_take(1, 9, Log5),
1449-
{[_, _], _} = ra_log_take(16, 17, Log5),
1450-
Log6 = assert_log_events(Log5, fun (L) ->
1448+
%% check that the log can be reset to a pending write index
1449+
{ok, Log5b} = ra_log:set_last_index(19, Log5),
1450+
1451+
{[], _} = ra_log_take(1, 9, Log5b),
1452+
{[_, _], _} = ra_log_take(16, 17, Log5b),
1453+
Log6 = assert_log_events(Log5b, fun (L) ->
14511454
{19, 2} == ra_log:last_written(L)
14521455
end),
14531456
{[], _} = ra_log_take(1, 9, Log6),

0 commit comments

Comments
 (0)