From 3d318bae767d62fd30f94b86fb429f79937ad432 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Wed, 8 Jan 2020 22:36:54 +0100 Subject: [PATCH] init: Use constant time retries (#8769) Exponential backoff does not seem like a good fit for this function since we can expect a few roundtrips on initial startup. This retry loop get slow pretty quickly with initial wait being 1 second and each try being double the wait until 30 seconds is reached. Instead simply try 2 times per second. --- cmd/prepare-storage.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/cmd/prepare-storage.go b/cmd/prepare-storage.go index e74f19b84..a69b3526c 100644 --- a/cmd/prepare-storage.go +++ b/cmd/prepare-storage.go @@ -307,13 +307,6 @@ func waitForFormatXL(firstDisk bool, endpoints Endpoints, setCount, drivesPerSet return nil, err } - // Done channel is used to close any lingering retry routine, as soon - // as this function returns. - doneCh := make(chan struct{}) - - // Indicate to our retry routine to exit cleanly, upon this function return. - defer close(doneCh) - // prepare getElapsedTime() to calculate elapsed time since we started trying formatting disks. // All times are rounded to avoid showing milli, micro and nano seconds formatStartTime := time.Now().Round(time.Second) @@ -321,13 +314,16 @@ func waitForFormatXL(firstDisk bool, endpoints Endpoints, setCount, drivesPerSet return time.Now().Round(time.Second).Sub(formatStartTime).String() } - // Wait on the jitter retry loop. - retryTimerCh := newRetryTimerSimple(doneCh) + // Wait on each try for an update. + ticker := time.NewTicker(500 * time.Millisecond) + defer ticker.Stop() + var tries int for { select { - case retryCount := <-retryTimerCh: - format, err := connectLoadInitFormats(retryCount, firstDisk, endpoints, setCount, drivesPerSet, deploymentID) + case <-ticker.C: + format, err := connectLoadInitFormats(tries, firstDisk, endpoints, setCount, drivesPerSet, deploymentID) if err != nil { + tries++ switch err { case errNotFirstDisk: // Fresh setup, wait for first server to be up.