From 30544541588e4658d8da28a00e98d24fdc54bef5 Mon Sep 17 00:00:00 2001 From: Karl Nilsson Date: Fri, 24 May 2024 13:02:18 +0100 Subject: [PATCH] eff --- src/ra_log.erl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ra_log.erl b/src/ra_log.erl index 4b340886..f32a64cc 100644 --- a/src/ra_log.erl +++ b/src/ra_log.erl @@ -589,15 +589,19 @@ handle_event({snapshot_written, {SnapIdx, _} = Snap, SnapKind}, CPEffects = [{delete_snapshot, ra_snapshot:directory(SnapState, checkpoint), Checkpoint} || Checkpoint <- Checkpoints], - Effects = [DeleteCurrentSnap | CPEffects] ++ Effects0, + Effects1 = [DeleteCurrentSnap | CPEffects] ++ Effects0, %% do not set last written index here as the snapshot may %% be for a past index - LWIdxTerm = case LastWrittenIdx > SnapIdx of - true -> - LWIdx; - false -> - Snap - end, + {LWIdxTerm, Effects} = + case LastWrittenIdx > SnapIdx of + true -> + {LWIdx, Effects1}; + false -> + {Snap, + [{next_event, + {ra_log_event, + {truncate_cache, LastWrittenIdx, SnapIdx}}} | Effects1]} + end, {State#?MODULE{first_index = SnapIdx + 1, last_index = max(LstIdx, SnapIdx),