Skip to content

Commit

Permalink
tso: use less interval when waiting api service (tikv#6451)
Browse files Browse the repository at this point in the history
close tikv#6449

Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 authored and rleungx committed Aug 2, 2023
1 parent 16d6338 commit 7fa24f3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pkg/mcs/tso/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ const (
tsoSvcRootPathFormat = msServiceRootPath + "/%d/" + mcsutils.TSOServiceName

// maxRetryTimesWaitAPIService is the max retry times for initializing the cluster ID.
maxRetryTimesWaitAPIService = 60
maxRetryTimesWaitAPIService = 360
// retryIntervalWaitAPIService is the interval to retry.
retryIntervalWaitAPIService = 3 * time.Second
// Note: the interval must be less than the timeout of tidb and tikv, which is 2s by default in tikv.
retryIntervalWaitAPIService = 500 * time.Millisecond
)

var _ bs.Server = (*Server)(nil)
Expand Down Expand Up @@ -535,21 +536,25 @@ func (s *Server) startServer() (err error) {
}

func (s *Server) waitAPIServiceReady() error {
var (
ready bool
err error
)
for i := 0; i < maxRetryTimesWaitAPIService; i++ {
ready, err := s.isAPIServiceReady()
if err != nil {
log.Warn("failed to check api server ready", errs.ZapError(err))
}
if ready {
ready, err = s.isAPIServiceReady()
if err == nil && ready {
return nil
}
log.Debug("api server is not ready, retrying", errs.ZapError(err), zap.Bool("ready", ready))
select {
case <-s.ctx.Done():
return errors.New("context canceled while waiting api server ready")
case <-time.After(retryIntervalWaitAPIService):
log.Debug("api server is not ready, retrying")
}
}
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)
}

Expand Down

0 comments on commit 7fa24f3

Please sign in to comment.