Merge pull request #5313 from xiang90/fix_raft_abort

raft: simplify leadership transfer
This commit is contained in:
Xiang Li 2016-05-13 09:26:01 -07:00
commit 4d2424210f

View File

@ -397,7 +397,7 @@ func (r *raft) reset(term uint64) {
r.heartbeatElapsed = 0 r.heartbeatElapsed = 0
r.resetRandomizedElectionTimeout() r.resetRandomizedElectionTimeout()
r.leadTransferee = None r.abortLeaderTransfer()
r.votes = make(map[uint64]bool) r.votes = make(map[uint64]bool)
for id := range r.prs { for id := range r.prs {
@ -583,7 +583,6 @@ func (r *raft) Step(m pb.Message) error {
type stepFunc func(r *raft, m pb.Message) type stepFunc func(r *raft, m pb.Message)
func stepLeader(r *raft, m pb.Message) { func stepLeader(r *raft, m pb.Message) {
// These message types do not require any progress for m.From. // These message types do not require any progress for m.From.
switch m.Type { switch m.Type {
case pb.MsgBeat: case pb.MsgBeat:
@ -718,14 +717,10 @@ func stepLeader(r *raft, m pb.Message) {
return return
} }
r.abortLeaderTransfer() r.abortLeaderTransfer()
r.logger.Infof("%x [term %d] abort transfer leadership to %x", r.id, r.Term, lastLeadTransferee) r.logger.Infof("%x [term %d] abort previous transferring leadership to %x", r.id, r.Term, lastLeadTransferee)
} }
if leadTransferee == r.id { if leadTransferee == r.id {
if lastLeadTransferee == None { r.logger.Debugf("%x is already leader. Ignored transferring leadership to self", r.id)
r.logger.Debugf("%x is already leader. Ignored transfer leadership to %x", r.id, r.id)
} else {
r.logger.Debugf("%x abort transfer leadership to %x, transfer to current leader %x.", r.id, lastLeadTransferee, r.id)
}
return return
} }
// Transfer leadership to third party. // Transfer leadership to third party.