diff --git a/src/ra_server.erl b/src/ra_server.erl index 8f96d52f..54ec223f 100644 --- a/src/ra_server.erl +++ b/src/ra_server.erl @@ -462,6 +462,13 @@ handle_leader({PeerId, #append_entries_reply{term = Term}}, [LogId, PeerId, Term, CurTerm]), {follower, update_term(Term, State0#{leader_id => undefined}), []} end; +handle_leader({PeerId, #append_entries_reply{success = false}}, + State0 = #{cfg := #cfg{log_id = LogId}, + cluster := Nodes}) + when not is_map_key(PeerId, Nodes) -> + ?WARN("~ts: saw append_entries_reply from unknown peer ~w", + [LogId, PeerId]), + {leader, State0, []}; handle_leader({PeerId, #append_entries_reply{success = false, next_index = NextIdx, last_index = LastIdx, diff --git a/test/ra_server_SUITE.erl b/test/ra_server_SUITE.erl index 64685dbf..24808907 100644 --- a/test/ra_server_SUITE.erl +++ b/test/ra_server_SUITE.erl @@ -23,6 +23,7 @@ all() -> append_entries_reply_success_promotes_nonvoter, append_entries_reply_success, append_entries_reply_no_success, + append_entries_reply_no_success_from_unknown_peer, follower_request_vote, follower_pre_vote, pre_vote_receives_pre_vote, @@ -974,6 +975,21 @@ append_entries_reply_no_success(_Config) -> ]} = ra_server:handle_leader(Msg, State), ok. +append_entries_reply_no_success_from_unknown_peer(_Config) -> + N1 = ?N1, N2 = ?N2, + Cluster = #{N1 => new_peer()}, + State = (base_state(3, ?FUNCTION_NAME))#{commit_index => 1, + last_applied => 1, + cluster => Cluster, + machine_state => <<"hi1">>}, + % n2 is an unknown peer + Msg = {N2, #append_entries_reply{term = 5, success = false, next_index = 2, + last_index = 1, last_term = 1}}, + % The reply from n2 is ignored + {leader, State, []} = ra_server:handle_leader(Msg, State), + + ok. + follower_request_vote(_Config) -> N2 = ?N2, N3 = ?N3, State = base_state(3, ?FUNCTION_NAME),