Skip to content

Commit

Permalink
etcdserver: move "advanceRaftTicks" to "NewServer"
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Mar 8, 2018
1 parent a97b9e2 commit 6371853
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 0 additions & 12 deletions etcdserver/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,6 @@ func (r *raftNode) resumeSending() {
p.Resume()
}

// advanceTicksForElection advances ticks to the node for fast election.
// This reduces the time to wait for first leader election if bootstrapping the whole
// cluster, while leaving at least 1 heartbeat for possible existing leader
// to contact it.
func advanceTicksForElection(n raft.Node, electionTicks int) {
for i := 0; i < electionTicks-1; i++ {
n.Tick()
}
}

func startNode(cfg ServerConfig, cl *membership.RaftCluster, ids []types.ID) (id types.ID, n raft.Node, s *raft.MemoryStorage, w *wal.WAL) {
var err error
member := cl.MemberByName(cfg.Name)
Expand Down Expand Up @@ -428,7 +418,6 @@ func startNode(cfg ServerConfig, cl *membership.RaftCluster, ids []types.ID) (id
raftStatusMu.Lock()
raftStatus = n.Status
raftStatusMu.Unlock()
advanceTicksForElection(n, c.ElectionTick)
return id, n, s, w
}

Expand Down Expand Up @@ -463,7 +452,6 @@ func restartNode(cfg ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *member
raftStatusMu.Lock()
raftStatus = n.Status
raftStatusMu.Unlock()
advanceTicksForElection(n, c.ElectionTick)
return id, cl, n, s, w
}

Expand Down
12 changes: 12 additions & 0 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ type EtcdServer struct {
consistIndex consistentIndex // must use atomic operations to access; keep 64-bit aligned.
r raftNode // uses 64-bit atomics; keep 64-bit aligned.

// advanceRaftTicks advances ticks of Raft node.
// This can be used for fast-forwarding election
// ticks in multi data-center deployments, thus
// speeding up election process.
advanceRaftTicks func(ticks int)

readych chan struct{}
Cfg ServerConfig

Expand Down Expand Up @@ -445,6 +451,12 @@ func NewServer(cfg ServerConfig) (srv *EtcdServer, err error) {
hostWhitelist: cfg.HostWhitelist,
}

srv.advanceRaftTicks = func(ticks int) {
for i := 0; i < ticks; i++ {
srv.r.tick()
}
}

srv.applyV2 = &applierV2store{store: srv.v2store, cluster: srv.cluster}

srv.be = be
Expand Down

0 comments on commit 6371853

Please sign in to comment.