adjust election timeout to 10 seconds

This commit is contained in:
Chris Lu 2020-10-23 23:06:44 -07:00
parent ef9c32ea0d
commit 1b17f71939
2 changed files with 5 additions and 4 deletions

View file

@ -126,7 +126,7 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
}
// start raftServer
raftServer, err := weed_server.NewRaftServer(security.LoadClientTLS(util.GetViper(), "grpc.master"),
peers, myMasterAddress, util.ResolvePath(*masterOption.metaFolder), ms.Topo, 5, *masterOption.raftResumeState)
peers, myMasterAddress, util.ResolvePath(*masterOption.metaFolder), ms.Topo, *masterOption.raftResumeState)
if raftServer == nil {
glog.Fatalf("please verify %s is writable, see https://github.com/chrislusf/seaweedfs/issues/717: %s", *masterOption.metaFolder, err)
}

View file

@ -2,6 +2,7 @@ package weed_server
import (
"encoding/json"
"math/rand"
"os"
"path"
"sort"
@ -50,7 +51,7 @@ func (s StateMachine) Recovery(data []byte) error {
return nil
}
func NewRaftServer(grpcDialOption grpc.DialOption, peers []string, serverAddr, dataDir string, topo *topology.Topology, pulseSeconds int, raftResumeState bool) (*RaftServer, error) {
func NewRaftServer(grpcDialOption grpc.DialOption, peers []string, serverAddr, dataDir string, topo *topology.Topology, raftResumeState bool) (*RaftServer, error) {
s := &RaftServer{
peers: peers,
serverAddr: serverAddr,
@ -84,8 +85,8 @@ func NewRaftServer(grpcDialOption grpc.DialOption, peers []string, serverAddr, d
glog.V(0).Infoln(err)
return nil, err
}
s.raftServer.SetHeartbeatInterval(500 * time.Millisecond)
s.raftServer.SetElectionTimeout(time.Duration(pulseSeconds) * 500 * time.Millisecond)
s.raftServer.SetHeartbeatInterval(time.Duration(300+rand.Intn(150)) * time.Millisecond)
s.raftServer.SetElectionTimeout(10 * time.Second)
if err := s.raftServer.LoadSnapshot(); err != nil {
return nil, err
}