diff options
author | Robert Newson <rnewson@apache.org> | 2022-10-14 15:40:42 +0100 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2022-10-14 22:46:18 +0100 |
commit | e2aeb6c98be6c7ee97d38b839be85aeb60cede19 (patch) | |
tree | 1a7c45f93ce66f311ffe3cabe291717d5de8e7d0 | |
parent | 1268bb0bb62275baf5533824fd063b9156158090 (diff) | |
download | couchdb-e2aeb6c98be6c7ee97d38b839be85aeb60cede19.tar.gz |
eliminate spurious election
(We start an election when we get a new_election timeout)
-rw-r--r-- | src/couch/src/couch_raft.erl | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/couch/src/couch_raft.erl b/src/couch/src/couch_raft.erl index b847a1b50..461a04fb7 100644 --- a/src/couch/src/couch_raft.erl +++ b/src/couch/src/couch_raft.erl @@ -261,7 +261,12 @@ handle_event({call, From}, #{type := 'ClientRequest'} = Msg, leader, Data) -> handle_event({call, From}, #{type := 'ClientRequest'}, _State, _Data) -> {keep_state_and_data, {reply, From, {error, not_leader}}}; -handle_event(state_timeout, new_election, State, Data) when State == follower; State == candidate -> +handle_event(state_timeout, new_election, follower = State, Data) -> + #{term := Term} = Data, + couch_log:notice("~p election timeout in state ~p, term ~B", [id(Data), State, Term]), + persist({next_state, candidate, Data}); + +handle_event(state_timeout, new_election, candidate = State, Data) -> #{term := Term} = Data, couch_log:notice("~p election timeout in state ~p, term ~B", [id(Data), State, Term]), persist({next_state, candidate, start_election(Data), state_timeout(State)}); @@ -382,6 +387,8 @@ nthterm(N, Data) -> persist({next_state, _NextState, NewData, _Actions} = HandleEventResult) -> persist(NewData, HandleEventResult); +persist({next_state, _NextState, NewData} = HandleEventResult) -> + persist(NewData, HandleEventResult); persist({keep_state, NewData, _Actions} = HandleEventResult) -> persist(NewData, HandleEventResult). |