Xiang Li 2013-07-17 14:24:31 -07:00
commit bcdc237b3e
1 changed files with 3 additions and 0 deletions

View File

@ -677,6 +677,7 @@ func (s *Server) AppendEntries(req *AppendEntriesRequest) *AppendEntriesResponse
// Processes the "append entries" request.
func (s *Server) processAppendEntriesRequest(req *AppendEntriesRequest) (*AppendEntriesResponse, bool) {
s.traceln("server.ae.process")
if req.Term < s.currentTerm {
@ -712,6 +713,7 @@ func (s *Server) processAppendEntriesRequest(req *AppendEntriesRequest) (*Append
// processed when the server is a leader. Responses received during other
// states are dropped.
func (s *Server) processAppendEntriesResponse(resp *AppendEntriesResponse) {
// If we find a higher term then change to a follower and exit.
if resp.Term > s.currentTerm {
s.setCurrentTerm(resp.Term, "", false)
@ -782,6 +784,7 @@ func (s *Server) RequestVote(req *RequestVoteRequest) *RequestVoteResponse {
// Processes a "request vote" request.
func (s *Server) processRequestVoteRequest(req *RequestVoteRequest) (*RequestVoteResponse, bool) {
// If the request is coming from an old term then reject it.
if req.Term < s.currentTerm {
s.debugln("server.rv.error: stale term")