integration: adjust election ticks using env var
This commit is contained in:
@ -43,6 +43,9 @@ type ServerConfig struct {
|
|||||||
NewCluster bool
|
NewCluster bool
|
||||||
ForceNewCluster bool
|
ForceNewCluster bool
|
||||||
Transport *http.Transport
|
Transport *http.Transport
|
||||||
|
|
||||||
|
// Only for testing purpose
|
||||||
|
ElectionTimeoutTicks int
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyBootstrapConfig sanity-checks the initial config and returns an error
|
// VerifyBootstrapConfig sanity-checks the initial config and returns an error
|
||||||
|
@ -867,8 +867,12 @@ func startNode(cfg *ServerConfig, ids []types.ID) (id types.ID, n raft.Node, s *
|
|||||||
}
|
}
|
||||||
id = member.ID
|
id = member.ID
|
||||||
log.Printf("etcdserver: start member %s in cluster %s", id, cfg.Cluster.ID())
|
log.Printf("etcdserver: start member %s in cluster %s", id, cfg.Cluster.ID())
|
||||||
|
election := cfg.ElectionTimeoutTicks
|
||||||
|
if election == 0 {
|
||||||
|
election = 10
|
||||||
|
}
|
||||||
s = raft.NewMemoryStorage()
|
s = raft.NewMemoryStorage()
|
||||||
n = raft.StartNode(uint64(id), peers, 10, 1, s)
|
n = raft.StartNode(uint64(id), peers, election, 1, s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,13 +881,17 @@ func restartNode(cfg *ServerConfig, index uint64, snapshot *raftpb.Snapshot) (ty
|
|||||||
cfg.Cluster.SetID(cid)
|
cfg.Cluster.SetID(cid)
|
||||||
|
|
||||||
log.Printf("etcdserver: restart member %s in cluster %s at commit index %d", id, cfg.Cluster.ID(), st.Commit)
|
log.Printf("etcdserver: restart member %s in cluster %s at commit index %d", id, cfg.Cluster.ID(), st.Commit)
|
||||||
|
election := cfg.ElectionTimeoutTicks
|
||||||
|
if election == 0 {
|
||||||
|
election = 10
|
||||||
|
}
|
||||||
s := raft.NewMemoryStorage()
|
s := raft.NewMemoryStorage()
|
||||||
if snapshot != nil {
|
if snapshot != nil {
|
||||||
s.ApplySnapshot(*snapshot)
|
s.ApplySnapshot(*snapshot)
|
||||||
}
|
}
|
||||||
s.SetHardState(st)
|
s.SetHardState(st)
|
||||||
s.Append(ents)
|
s.Append(ents)
|
||||||
n := raft.RestartNode(uint64(id), 10, 1, s)
|
n := raft.RestartNode(uint64(id), election, 1, s)
|
||||||
return id, n, s, w
|
return id, n, s, w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -49,9 +50,18 @@ const (
|
|||||||
requestTimeout = 2 * time.Second
|
requestTimeout = 2 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
electionTicks = 10
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// open microsecond-level time log for integration test debugging
|
// open microsecond-level time log for integration test debugging
|
||||||
log.SetFlags(log.Ltime | log.Lmicroseconds | log.Lshortfile)
|
log.SetFlags(log.Ltime | log.Lmicroseconds | log.Lshortfile)
|
||||||
|
if t := os.Getenv("ETCD_ELECTION_TIMEOUT_TICKS"); t != "" {
|
||||||
|
if i, err := strconv.ParseInt(t, 10, 64); err == nil {
|
||||||
|
electionTicks = int(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClusterOf1(t *testing.T) { testCluster(t, 1) }
|
func TestClusterOf1(t *testing.T) { testCluster(t, 1) }
|
||||||
@ -431,6 +441,7 @@ func mustNewMember(t *testing.T, name string) *member {
|
|||||||
}
|
}
|
||||||
m.NewCluster = true
|
m.NewCluster = true
|
||||||
m.Transport = mustNewTransport(t)
|
m.Transport = mustNewTransport(t)
|
||||||
|
m.ElectionTimeoutTicks = electionTicks
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,6 +471,7 @@ func (m *member) Clone(t *testing.T) *member {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
mm.Transport = mustNewTransport(t)
|
mm.Transport = mustNewTransport(t)
|
||||||
|
mm.ElectionTimeoutTicks = m.ElectionTimeoutTicks
|
||||||
return mm
|
return mm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user