Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tso: use less interval when waiting api service #6451

Merged
merged 4 commits into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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