MCPcopy
hub / github.com/github/gh-ost / retryOperation

Method retryOperation

go/logic/migrator.go:163–192  ·  view source on GitHub ↗

retryOperation attempts up to `count` attempts at running given function, exiting as soon as it returns with non-error.

(operation func() error, notFatalHint ...bool)

Source from the content-addressed store, hash-verified

161// retryOperation attempts up to `count` attempts at running given function,
162// exiting as soon as it returns with non-error.
163func (mgtr *Migrator) retryOperation(operation func() error, notFatalHint ...bool) (err error) {
164 maxRetries := int(mgtr.migrationContext.MaxRetries())
165 for i := 0; i < maxRetries; i++ {
166 if i != 0 {
167 // sleep after previous iteration
168 RetrySleepFn(1 * time.Second)
169 }
170 // Check for abort/context cancellation before each retry
171 if abortErr := mgtr.checkAbort(); abortErr != nil {
172 return abortErr
173 }
174 err = operation()
175 if err == nil {
176 return nil
177 }
178 // Check if this is an unrecoverable error (data consistency issues won't resolve on retry)
179 if strings.Contains(err.Error(), "warnings detected") {
180 if len(notFatalHint) == 0 {
181 _ = base.SendWithContext(mgtr.migrationContext.GetContext(), mgtr.migrationContext.PanicAbort, err)
182 }
183 return err
184 }
185 // there's an error. Let's try again.
186 }
187 if len(notFatalHint) == 0 {
188 // Use helper to prevent deadlock if listenOnPanicAbort already exited
189 _ = base.SendWithContext(mgtr.migrationContext.GetContext(), mgtr.migrationContext.PanicAbort, err)
190 }
191 return err
192}
193
194// `retryOperationWithExponentialBackoff` attempts running given function, waiting 2^(n-1)
195// seconds between each attempt, where `n` is the running number of attempts. Exits

Callers 11

TestMigratorRetryFunction · 0.95
handleCutOverResultMethod · 0.95
cutOverMethod · 0.95
cutOverTwoStepMethod · 0.95
atomicCutOverMethod · 0.95
onApplyEventStructMethod · 0.95
finalCleanupMethod · 0.95

Calls 5

checkAbortMethod · 0.95
SendWithContextFunction · 0.92
MaxRetriesMethod · 0.80
GetContextMethod · 0.80
ErrorMethod · 0.65