Skip to content

Commit

Permalink
pd-client: add some retries when initializing cluster id
Browse files Browse the repository at this point in the history
TiDB can not start some times if it starts at the same time with PD,
because PD may need some time before serving requests.
  • Loading branch information
huachaohuang committed Dec 6, 2016
1 parent 5ef1be2 commit b1713de
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pd-client/rpc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (
"github.com/twinj/uuid"
)

const maxPipelineRequest = 10000
const (
maxPipelineRequest = 10000
maxInitClusterRetries = 300
)

// errInvalidResponse represents response message is invalid.
var errInvalidResponse = errors.New("invalid response")
Expand Down Expand Up @@ -222,13 +225,17 @@ func (w *rpcWorker) initClusterID() error {
}
defer conn.Close()

clusterID, err := w.getClusterID(conn.ReadWriter)
if err != nil {
return errors.Trace(err)
for i := 0; i < maxInitClusterRetries; i++ {
clusterID, err := w.getClusterID(conn.ReadWriter)
if err == nil {
w.clusterID = clusterID
return nil
}
log.Errorf("[pd] failed to get cluster id: %v", err)
time.Sleep(time.Second)
}

w.clusterID = clusterID
return nil
return errors.New("failed to get cluster id")
}

func (w *rpcWorker) getClusterID(conn *bufio.ReadWriter) (uint64, error) {
Expand Down

0 comments on commit b1713de

Please sign in to comment.