@@ -1346,14 +1346,17 @@ handle_follower(#heartbeat_rpc{leader_id = LeaderId,
1346
1346
cfg := # cfg {id = Id }} = State ) ->
1347
1347
Reply = heartbeat_reply (CurTerm , QueryIndex ),
1348
1348
{follower , State , [cast_reply (Id , LeaderId , Reply )]};
1349
- handle_follower ({ra_log_event , {written , _ , _ } = Evt },
1349
+ handle_follower ({ra_log_event , {written , TERM , _ } = Evt },
1350
1350
State0 = #{log := Log0 ,
1351
1351
cfg := # cfg {id = Id },
1352
1352
leader_id := LeaderId ,
1353
- current_term := Term })
1353
+ current_term := TERM = Term })
1354
1354
when LeaderId =/= undefined ->
1355
1355
{Log , Effects } = ra_log :handle_event (Evt , Log0 ),
1356
1356
State = State0 #{log => Log },
1357
+ % % only reply with success if the written event relates to the current
1358
+ % % term. this avoids accidentally confirming overwritten indexes too
1359
+ % % early
1357
1360
Reply = append_entries_reply (Term , true , State ),
1358
1361
{follower , State , [cast_reply (Id , LeaderId , Reply ) | Effects ]};
1359
1362
handle_follower ({ra_log_event , Evt }, State = #{log := Log0 }) ->
0 commit comments