refactor retryTime
parent
f072217b35
commit
926edc327a
13
etcd.go
13
etcd.go
|
@ -54,7 +54,7 @@ var maxSize int
|
||||||
|
|
||||||
var snapshot bool
|
var snapshot bool
|
||||||
|
|
||||||
var retryTime int
|
var retryTimes int
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.BoolVar(&verbose, "v", false, "verbose logging")
|
flag.BoolVar(&verbose, "v", false, "verbose logging")
|
||||||
|
@ -83,7 +83,7 @@ func init() {
|
||||||
|
|
||||||
flag.IntVar(&maxSize, "m", 1024, "the max size of result buffer")
|
flag.IntVar(&maxSize, "m", 1024, "the max size of result buffer")
|
||||||
|
|
||||||
flag.IntVar(&retryTime, "r", 3, "the max retry number when try to join a cluster")
|
flag.IntVar(&retryTimes, "r", 3, "the max retry number when try to join a cluster")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
|
@ -105,7 +105,8 @@ const (
|
||||||
// Timeout for internal raft http connection
|
// Timeout for internal raft http connection
|
||||||
// The original timeout for http is 45 seconds
|
// The original timeout for http is 45 seconds
|
||||||
// which is too long for our usage.
|
// which is too long for our usage.
|
||||||
HTTPTIMEOUT = 10 * time.Second
|
HTTPTIMEOUT = 10 * time.Second
|
||||||
|
RETRYINTERVAL = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -260,7 +261,7 @@ func startRaft(securityType int) {
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 20)
|
time.Sleep(time.Millisecond * 20)
|
||||||
|
|
||||||
for i := 0; i < retryTime; i++ {
|
for i := 0; i < retryTimes; i++ {
|
||||||
|
|
||||||
success := false
|
success := false
|
||||||
for _, machine := range cluster {
|
for _, machine := range cluster {
|
||||||
|
@ -280,8 +281,8 @@ func startRaft(securityType int) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
warn("cannot join to cluster via all given machines, retry after 10 seconds")
|
warn("cannot join to cluster via all given machines, retry in %d seconds", RETRYINTERVAL)
|
||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * RETRYINTERVAL)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal("cannot join to cluster via all given machines after retry!")
|
fatal("cannot join to cluster via all given machines after retry!")
|
||||||
|
|
Loading…
Reference in New Issue