Skip to content

Commit

Permalink
better error message when Restore failed
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <[email protected]>
  • Loading branch information
ekexium committed May 7, 2022
1 parent 5d5c7ce commit 3a99388
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions session/nontransactional.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func splitDeleteWorker(ctx context.Context, jobs []job, stmt *ast.NonTransaction

// if the first job failed, there is a large chance that all jobs will fail. So return early.
if i == 0 && jobs[i].err != nil {
return nil, errors.Wrap(jobs[i].err, "Early return: error occurred in the first job. All jobs are canceled")
return nil, errors.Annotate(jobs[i].err, "Early return: error occurred in the first job. All jobs are canceled")
}
}
return splitStmts, nil
Expand Down Expand Up @@ -271,7 +271,7 @@ func doOneJob(ctx context.Context, job *job, totalJobCount int, options statemen
format.RestoreBracketAroundBinaryOperation|
format.RestoreStringWithoutCharset, &sb))
if err != nil {
job.err = err
job.err = errors.Annotate(err, "Failed to restore delete statement")
return ""
}
deleteSQL := sb.String()
Expand Down Expand Up @@ -436,7 +436,7 @@ func buildSelectSQL(stmt *ast.NonTransactionalDeleteStmt, se Session) (*ast.Tabl
format.RestoreBracketAroundBinaryOperation|
format.RestoreStringWithoutCharset, &sb))
if err != nil {
return nil, "", nil, errors.Trace(err)
return nil, "", nil, errors.Annotate(err, "Failed to restore where clause in non-transactional delete")
}
} else {
sb.WriteString("TRUE")
Expand Down
19 changes: 19 additions & 0 deletions session/nontransactional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,22 @@ func TestNonTransactionalDeleteAlias(t *testing.T) {
tk.MustQuery("select count(*) from test.t").Check(testkit.Rows("5"))
}
}

func TestNonTransactionalDeleteShardOnUnsupportedTypes(t *testing.T) {
// When some day the test fail because such types are supported, we can update related docs and consider remove the test.
store, clean := createStorage(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a set('e0', 'e1', 'e2'), b int, key(a))")
tk.MustExec("insert into t values ('e2,e0', 3)")
err := tk.ExecToErr("split on a limit 1 delete from t")
require.Error(t, err)
tk.MustQuery("select count(*) from t").Check(testkit.Rows("1"))

tk.MustExec("create table t2(a enum('e0', 'e1', 'e2'), b int, key(a))")
tk.MustExec("insert into t2 values ('e0', 1)")
err = tk.ExecToErr("split on a limit 1 delete from t2")
require.Error(t, err)
tk.MustQuery("select count(*) from t2").Check(testkit.Rows("1"))
}

0 comments on commit 3a99388

Please sign in to comment.