Skip to content

Commit 9eb8786

Browse files
Do not clear pending if points to the checkpoint
When a new checkpoint write is in progress and release_cursor fires promote_checkpoint, the pending field gets overwritten, and the subsequent checkpoint completion clobbers the snapshot's pending state.
1 parent dfbeb60 commit 9eb8786

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/ra_snapshot.erl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,16 @@ complete_snapshot({Idx, _} = IdxTerm, snapshot, LiveIndexes, SnapshotSize,
724724
current = IdxTerm,
725725
snapshot_size = SnapshotSize};
726726
complete_snapshot(IdxTerm, checkpoint, _LiveIndexes, _SnapshotSize,
727-
#?MODULE{checkpoints = Checkpoints0} = State) ->
728-
State#?MODULE{pending = undefined,
727+
#?MODULE{pending = Pending,
728+
checkpoints = Checkpoints0} = State) ->
729+
%% Only clear pending if it still points at this checkpoint.
730+
%% A concurrent promote_checkpoint may have overwritten pending
731+
%% with a snapshot entry that must not be discarded.
732+
NewPending = case Pending of
733+
{IdxTerm, checkpoint} -> undefined;
734+
_ -> Pending
735+
end,
736+
State#?MODULE{pending = NewPending,
729737
checkpoints = [IdxTerm | Checkpoints0]}.
730738

731739
-spec begin_accept(meta(), state()) ->

0 commit comments

Comments
 (0)