mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-29 10:28:41 +08:00
enhance: add retry termination log (#37894)
/kind improvement Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
parent
bc131a911c
commit
cef55eb093
@ -47,19 +47,34 @@ func Do(ctx context.Context, fn func() error, opts ...Option) error {
|
||||
}
|
||||
|
||||
if !IsRecoverable(err) {
|
||||
if errors.IsAny(err, context.Canceled, context.DeadlineExceeded) && lastErr != nil {
|
||||
isContextErr := errors.IsAny(err, context.Canceled, context.DeadlineExceeded)
|
||||
log.Warn("retry func failed, not be recoverable",
|
||||
zap.Uint("retried", i),
|
||||
zap.Uint("attempt", c.attempts),
|
||||
zap.Bool("isContextErr", isContextErr),
|
||||
)
|
||||
if isContextErr && lastErr != nil {
|
||||
return lastErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
if c.isRetryErr != nil && !c.isRetryErr(err) {
|
||||
log.Warn("retry func failed, not be retryable",
|
||||
zap.Uint("retried", i),
|
||||
zap.Uint("attempt", c.attempts),
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
deadline, ok := ctx.Deadline()
|
||||
if ok && time.Until(deadline) < c.sleep {
|
||||
// to avoid sleep until ctx done
|
||||
if errors.IsAny(err, context.Canceled, context.DeadlineExceeded) && lastErr != nil {
|
||||
isContextErr := errors.IsAny(err, context.Canceled, context.DeadlineExceeded)
|
||||
log.Warn("retry func failed, deadline",
|
||||
zap.Uint("retried", i),
|
||||
zap.Uint("attempt", c.attempts),
|
||||
zap.Bool("isContextErr", isContextErr),
|
||||
)
|
||||
if isContextErr && lastErr != nil {
|
||||
return lastErr
|
||||
}
|
||||
return err
|
||||
@ -70,6 +85,10 @@ func Do(ctx context.Context, fn func() error, opts ...Option) error {
|
||||
select {
|
||||
case <-time.After(c.sleep):
|
||||
case <-ctx.Done():
|
||||
log.Warn("retry func failed, ctx done",
|
||||
zap.Uint("retried", i),
|
||||
zap.Uint("attempt", c.attempts),
|
||||
)
|
||||
return lastErr
|
||||
}
|
||||
|
||||
@ -81,6 +100,11 @@ func Do(ctx context.Context, fn func() error, opts ...Option) error {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if lastErr != nil {
|
||||
log.Warn("retry func failed, reach max retry",
|
||||
zap.Uint("attempt", c.attempts),
|
||||
)
|
||||
}
|
||||
return lastErr
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user