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

mcs: wait until API server is ready #7814

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
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
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))
}
Comment on lines -138 to -140
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about print warn log every 60 seconds or another better time?
I'm worried that all are debug logs won't be easy to find root case such as when the wrong api addr is set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense

return errors.Errorf("failed to wait api server ready after retrying %d times", MaxRetryTimesWaitAPIService)
}

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