From 505623e475ba1c31ba43972c1a4c1cf196f3f40f Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 8 Feb 2024 11:12:11 +0800 Subject: [PATCH 1/2] wait until api server is ready Signed-off-by: Ryan Leung --- pkg/mcs/utils/constant.go | 2 -- pkg/mcs/utils/util.go | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/pkg/mcs/utils/constant.go b/pkg/mcs/utils/constant.go index 6174852d89f..21b57a3c5c5 100644 --- a/pkg/mcs/utils/constant.go +++ b/pkg/mcs/utils/constant.go @@ -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 diff --git a/pkg/mcs/utils/util.go b/pkg/mcs/utils/util.go index f8e5f5df548..485c6ddaa7f 100644 --- a/pkg/mcs/utils/util.go +++ b/pkg/mcs/utils/util.go @@ -123,7 +123,7 @@ func WaitAPIServiceReady(s server) error { ) ticker := time.NewTicker(RetryIntervalWaitAPIService) defer ticker.Stop() - for i := 0; i < MaxRetryTimesWaitAPIService; i++ { + for { ready, err = isAPIServiceReady(s) if err == nil && ready { return nil @@ -135,10 +135,6 @@ func WaitAPIServiceReady(s server) error { case <-ticker.C: } } - 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) { From bf013b5348aae8fe628b9048cefc9bf119648651 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 8 Feb 2024 15:46:06 +0800 Subject: [PATCH 2/2] address the comment Signed-off-by: Ryan Leung --- pkg/mcs/utils/util.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/mcs/utils/util.go b/pkg/mcs/utils/util.go index 485c6ddaa7f..b6ac2eb37e5 100644 --- a/pkg/mcs/utils/util.go +++ b/pkg/mcs/utils/util.go @@ -123,16 +123,21 @@ func WaitAPIServiceReady(s server) error { ) ticker := time.NewTicker(RetryIntervalWaitAPIService) defer ticker.Stop() + 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 + } } } }