Skip to content

Commit

Permalink
etcdserver: adjust election ticks on restart
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed Mar 10, 2018
1 parent cb65549 commit 60b3d7f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,32 @@ func NewServer(cfg ServerConfig) (srv *EtcdServer, err error) {
}
srv.r.transport = tr

srv.goAttach(func() {
clusterN := len(cl.Members())

// single-node fresh start, or single-node recovers from snapshot
if clusterN == 1 {
ticks := cfg.ElectionTicks - 1
plog.Infof("%s as single-node; fast-forwarding %d ticks (election ticks %d) with %d found member(s)", srv.ID(), ticks, cfg.ElectionTicks, clusterN)
srv.advanceRaftTicks(ticks)
return
}

select {
case <-tr.InitialPeerNotify():
// multi-node received peer connection reports
// adjust ticks, in case slow leader message receive
ticks := cfg.ElectionTicks - 2
plog.Infof("%s initialzed peer connection; fast-forwarding %d ticks (election ticks %d) with %d found member(s)", srv.ID(), ticks, cfg.ElectionTicks, len(cl.Members()))
srv.advanceRaftTicks(ticks)

case <-time.After(rafthttp.ConnReadTimeout):
// 1. all connections failed, or
// 2. no active peers, or
// 3. restarted single-node with no snapshot
// do nothing, because advancing ticks would have no effect
}
})
return srv, nil
}

Expand Down

0 comments on commit 60b3d7f

Please sign in to comment.