From f3d6a2dd37fb27cce7dc917edd7699213c890538 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Mon, 15 Apr 2024 17:40:19 +0800 Subject: [PATCH] code clean for dynamicSleeper (#19499) --- cmd/data-scanner.go | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/cmd/data-scanner.go b/cmd/data-scanner.go index 04501007a..035065711 100644 --- a/cmd/data-scanner.go +++ b/cmd/data-scanner.go @@ -1422,48 +1422,7 @@ func (d *dynamicSleeper) Timer(ctx context.Context) func() { t := time.Now() return func() { doneAt := time.Now() - for { - // Grab current values - d.mu.RLock() - minWait, maxWait := d.minSleep, d.maxSleep - factor := d.factor - cycle := d.cycle - d.mu.RUnlock() - elapsed := doneAt.Sub(t) - // Don't sleep for really small amount of time - wantSleep := time.Duration(float64(elapsed) * factor) - if wantSleep <= minWait { - return - } - if maxWait > 0 && wantSleep > maxWait { - wantSleep = maxWait - } - timer := time.NewTimer(wantSleep) - select { - case <-ctx.Done(): - if !timer.Stop() { - <-timer.C - } - if d.isScanner { - globalScannerMetrics.incTime(scannerMetricYield, wantSleep) - } - return - case <-timer.C: - if d.isScanner { - globalScannerMetrics.incTime(scannerMetricYield, wantSleep) - } - return - case <-cycle: - if !timer.Stop() { - // We expired. - <-timer.C - if d.isScanner { - globalScannerMetrics.incTime(scannerMetricYield, wantSleep) - } - return - } - } - } + d.Sleep(ctx, doneAt.Sub(t)) } }