From 1b17f71939ddf9b556521639efa706f598429a8e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 23 Oct 2020 23:06:44 -0700 Subject: [PATCH] adjust election timeout to 10 seconds --- weed/command/master.go | 2 +- weed/server/raft_server.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/weed/command/master.go b/weed/command/master.go index 97ec1bd24..c8eceb265 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -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) } diff --git a/weed/server/raft_server.go b/weed/server/raft_server.go index 073c1ff16..85841e409 100644 --- a/weed/server/raft_server.go +++ b/weed/server/raft_server.go @@ -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 }