Skip to content

Commit

Permalink
mcs: wait until API server is ready (#7814)
Browse files Browse the repository at this point in the history
ref #5839

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
rleungx and ti-chi-bot[bot] authored Feb 9, 2024
1 parent 7b1fb52 commit 5e18408
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 0 additions & 2 deletions pkg/mcs/utils/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package utils
import "time"

const (
// MaxRetryTimesWaitAPIService is the max retry times for initializing the cluster ID.
MaxRetryTimesWaitAPIService = 360
// RetryIntervalWaitAPIService is the interval to retry.
// Note: the interval must be less than the timeout of tidb and tikv, which is 2s by default in tikv.
RetryIntervalWaitAPIService = 500 * time.Millisecond
Expand Down
13 changes: 7 additions & 6 deletions pkg/mcs/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,23 @@ func WaitAPIServiceReady(s server) error {
)
ticker := time.NewTicker(RetryIntervalWaitAPIService)
defer ticker.Stop()
for i := 0; i < MaxRetryTimesWaitAPIService; i++ {
retryTimes := 0
for {
ready, err = isAPIServiceReady(s)
if err == nil && ready {
return nil
}
log.Debug("api server is not ready, retrying", errs.ZapError(err), zap.Bool("ready", ready))
select {
case <-s.Context().Done():
return errors.New("context canceled while waiting api server ready")
case <-ticker.C:
retryTimes++
if retryTimes/500 > 0 {
log.Warn("api server is not ready, retrying", errs.ZapError(err))
retryTimes /= 500
}
}
}
if err != nil {
log.Warn("failed to check api server ready", errs.ZapError(err))
}
return errors.Errorf("failed to wait api server ready after retrying %d times", MaxRetryTimesWaitAPIService)
}

func isAPIServiceReady(s server) (bool, error) {
Expand Down

0 comments on commit 5e18408

Please sign in to comment.