Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/ddl/backfilling_dist_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package ddl
import (
"context"
"encoding/json"
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/pkg/ddl/ingest"
Expand Down Expand Up @@ -224,6 +225,12 @@ func (*backfillDistExecutor) IsIdempotent(*proto.Subtask) bool {
}

func isRetryableError(err error) bool {
errMsg := err.Error()
for _, m := range dbterror.ReorgRetryableErrMsgs {
if strings.Contains(errMsg, m) {
return true
}
}
originErr := errors.Cause(err)
if tErr, ok := originErr.(*terror.Error); ok {
sqlErr := terror.ToSQLError(tErr)
Expand Down
6 changes: 6 additions & 0 deletions pkg/ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,12 @@ func errorIsRetryable(err error, job *model.Job) bool {
if job.ErrorCount+1 >= variable.GetDDLErrorCountLimit() {
return false
}
errMsg := err.Error()
for _, m := range dbterror.ReorgRetryableErrMsgs {
if strings.Contains(errMsg, m) {
return true
}
}
originErr := errors.Cause(err)
if tErr, ok := originErr.(*terror.Error); ok {
sqlErr := terror.ToSQLError(tErr)
Expand Down
5 changes: 5 additions & 0 deletions pkg/owner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ func AcquireDistributedLock(
}
return false, nil
})
failpoint.Inject("mockAcquireDistLockFailed", func(val failpoint.Value) {
if ok := val.(bool); ok {
err = errors.Errorf("requested lease not found")
}
})
if err != nil {
err1 := se.Close()
if err1 != nil {
Expand Down
8 changes: 7 additions & 1 deletion pkg/util/dbterror/ddl_terror.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ var (
ErrWarnGlobalIndexNeedManuallyAnalyze = ClassDDL.NewStd(mysql.ErrWarnGlobalIndexNeedManuallyAnalyze)
)

// ReorgRetryableErrCodes is the error codes that are retryable for reorganization.
// ReorgRetryableErrCodes are the error codes that are retryable for reorganization.
var ReorgRetryableErrCodes = map[uint16]struct{}{
mysql.ErrPDServerTimeout: {},
mysql.ErrTiKVServerTimeout: {},
Expand All @@ -526,3 +526,9 @@ var ReorgRetryableErrCodes = map[uint16]struct{}{
// Temporary network partitioning may cause pk commit failure.
uint16(terror.CodeResultUndetermined): {},
}

// ReorgRetryableErrMsgs are the error messages that are retryable for reorganization.
var ReorgRetryableErrMsgs = []string{
"context deadline exceeded",
"requested lease not found",
}
14 changes: 14 additions & 0 deletions tests/realtikvtest/addindextest1/disttask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,17 @@ func TestAddUKErrorMessage(t *testing.T) {
err := tk.ExecToErr("alter table t add unique index uk(b);")
require.ErrorContains(t, err, "Duplicate entry '1' for key 't.uk'")
}

func TestAddIndexDistLockAcquireFailed(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set global tidb_enable_dist_task = on;")
t.Cleanup(func() {
tk.MustExec("set global tidb_enable_dist_task = off;")
})
tk.MustExec("create table t (a int, b int);")
tk.MustExec("insert into t values (1, 1);")
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/owner/mockAcquireDistLockFailed", "1*return(true)")
tk.MustExec("alter table t add index idx(b);")
}