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 9, 2018
1 parent 3c17578 commit fad0db1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,33 @@ 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):
// advancing ticks would have no effect when:
// 1. all connections failed, or
// 2. no active peers, or
// 3. restarted single-node with no snapshot
plog.Infof("%s waited %s but no active peer found (or restarted 1-node cluster); currently, %d member(s)", srv.ID(), rafthttp.ConnReadTimeout, len(cl.Members()))
}
})
return srv, nil
}

Expand Down

0 comments on commit fad0db1

Please sign in to comment.