Skip to content

Commit

Permalink
ddl: fix ingest job panic when reset engine failed (#53754)
Browse files Browse the repository at this point in the history
close #53679
  • Loading branch information
tangenta authored Jun 4, 2024
1 parent 625516b commit b23ac8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/ddl/ingest/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ func (bc *litBackendCtx) unsafeImportAndReset(ei *engineInfo) error {
}

err := resetFn(bc.ctx, ei.uuid)
failpoint.Inject("mockResetEngineFailed", func() {
err = fmt.Errorf("mock reset engine failed")
})
if err != nil {
logutil.Logger(bc.ctx).Error(LitErrResetEngineFail, zap.Int64("index ID", ei.indexID))
err1 := ei.closedEngine.Cleanup(bc.ctx)
err1 := closedEngine.Cleanup(bc.ctx)
if err1 != nil {
logutil.Logger(ei.ctx).Error(LitErrCleanEngineErr, zap.Error(err1),
zap.Int64("job ID", ei.jobID), zap.Int64("index ID", ei.indexID))
Expand Down
11 changes: 10 additions & 1 deletion tests/realtikvtest/addindextest4/ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func TestAddIndexBackfillLostUpdate(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionStateBeforeImport"))
}

func TestAddIndexPreCheckFailed(t *testing.T) {
func TestAddIndexIngestFailures(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists addindexlit;")
Expand All @@ -485,9 +485,18 @@ func TestAddIndexPreCheckFailed(t *testing.T) {

tk.MustExec("create table t(id int primary key, b int, k int);")
tk.MustExec("insert into t values (1, 1, 1);")

// Test precheck failed.
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/ingest/mockIngestCheckEnvFailed", "return"))
tk.MustGetErrMsg("alter table t add index idx(b);", "[ddl:8256]Check ingest environment failed: mock error")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/ingest/mockIngestCheckEnvFailed"))

tk.MustExec(`set global tidb_enable_dist_task=on;`)
// Test reset engine failed.
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/ingest/mockResetEngineFailed", "return"))
tk.MustGetErrMsg("alter table t add index idx(b);", "[0]mock reset engine failed")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/ingest/mockResetEngineFailed"))
tk.MustExec(`set global tidb_enable_dist_task=off;`)
}

func TestAddIndexImportFailed(t *testing.T) {
Expand Down

0 comments on commit b23ac8e

Please sign in to comment.