retryOperation attempts up to `count` attempts at running given function, exiting as soon as it returns with non-error.
(operation func() error, notFatalHint ...bool)
| 161 | // retryOperation attempts up to `count` attempts at running given function, |
| 162 | // exiting as soon as it returns with non-error. |
| 163 | func (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 |