Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: handle context done after sending DDL jobs #57945

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions pkg/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ func (d *ddl) close() {

startTime := time.Now()
d.cancel()
failpoint.InjectCall("afterDDLCloseCancel")
d.wg.Wait()
// when run with real-tikv, the lifecycle of ownerManager is managed by globalOwnerManager,
// when run with uni-store BreakCampaignLoop is same as Close.
Expand Down
11 changes: 9 additions & 2 deletions pkg/ddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6587,8 +6587,15 @@ func (e *executor) DoDDLJobWrapper(ctx sessionctx.Context, jobW *JobWrapper) (re
}
})

// worker should restart to continue handling tasks in limitJobCh, and send back through jobW.err
result := <-jobW.ResultCh[0]
var result jobSubmitResult
select {
case <-e.ctx.Done():
logutil.DDLLogger().Info("DoDDLJob will quit because context done")
return context.Canceled
tangenta marked this conversation as resolved.
Show resolved Hide resolved
case res := <-jobW.ResultCh[0]:
// worker should restart to continue handling tasks in limitJobCh, and send back through jobW.err
result = res
}
// job.ID must be allocated after previous channel receive returns nil.
jobID, err := result.jobID, result.err
defer e.delJobDoneCh(jobID)
Expand Down
14 changes: 14 additions & 0 deletions pkg/ddl/job_submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,17 @@ func TestGenGIDAndInsertJobsWithRetryOnErr(t *testing.T) {
require.True(t, ok)
require.Equal(t, newGID-1, jobs[0].TableID)
}

func TestSubmitJobAfterDDLIsClosed(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
tk := testkit.NewTestKit(t, store)

var ddlErr error
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/afterDDLCloseCancel", func() {
ddlErr = tk.ExecToErr("create database test2;")
})
err := dom.DDL().Stop()
require.NoError(t, err)
require.Error(t, ddlErr)
require.Equal(t, "context canceled", ddlErr.Error())
}