Skip to content

Commit

Permalink
disttask: add more retryable error (#48033) (#48045)
Browse files Browse the repository at this point in the history
ref #46258, close #48034
  • Loading branch information
ti-chi-bot authored Oct 30, 2023
1 parent bcd76f1 commit 3f2c2a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/disttask/framework/scheduler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ go_library(
"//pkg/disttask/framework/storage",
"//pkg/domain/infosync",
"//pkg/metrics",
"//pkg/parser/terror",
"//pkg/resourcemanager/pool/spool",
"//pkg/resourcemanager/util",
"//pkg/util",
"//pkg/util/backoff",
"//pkg/util/dbterror",
"//pkg/util/logutil",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
Expand Down
16 changes: 15 additions & 1 deletion pkg/disttask/framework/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
"github.com/pingcap/tidb/pkg/disttask/framework/storage"
"github.com/pingcap/tidb/pkg/domain/infosync"
"github.com/pingcap/tidb/pkg/metrics"
"github.com/pingcap/tidb/pkg/parser/terror"
"github.com/pingcap/tidb/pkg/util/backoff"
"github.com/pingcap/tidb/pkg/util/dbterror"
"github.com/pingcap/tidb/pkg/util/logutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -575,6 +577,18 @@ func (s *BaseScheduler) finishSubtaskAndUpdateState(ctx context.Context, subtask
metrics.IncDistTaskSubTaskCnt(subtask)
}

// TODO: abstract interface for each business to implement it.
func isRetryableError(err error) bool {
originErr := errors.Cause(err)
if tErr, ok := originErr.(*terror.Error); ok {
sqlErr := terror.ToSQLError(tErr)
_, ok := dbterror.ReorgRetryableErrCodes[sqlErr.Code]
return ok
}
// can't retry Unknown err
return false
}

// markSubTaskCanceledOrFailed check the error type and decide the subtasks' state.
// 1. Only cancel subtasks when meet ErrCancelSubtask.
// 2. Only fail subtasks when meet non retryable error.
Expand All @@ -584,7 +598,7 @@ func (s *BaseScheduler) markSubTaskCanceledOrFailed(ctx context.Context, subtask
if ctx.Err() != nil && context.Cause(ctx) == ErrCancelSubtask {
logutil.Logger(s.logCtx).Warn("subtask canceled", zap.Error(err))
s.updateSubtaskStateAndError(subtask, proto.TaskStateCanceled, nil)
} else if common.IsRetryableError(err) {
} else if common.IsRetryableError(err) || isRetryableError(err) {
logutil.Logger(s.logCtx).Warn("met retryable error", zap.Error(err))
} else if errors.Cause(err) != context.Canceled {
logutil.Logger(s.logCtx).Warn("subtask failed", zap.Error(err))
Expand Down

0 comments on commit 3f2c2a2

Please sign in to comment.