pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.27k stars 5.84k forks source link

refine the context and context-like struct usage in DDL #56398

Open lance6716 opened 1 month ago

lance6716 commented 1 month ago

Enhancement

Currently the context usage is a bit of messy. One problem is https://github.com/pingcap/tidb/issues/56017 and I think a better context usage and cancellation will solve it. After a simple review of current DDL code, I think there should to 2 types of context:

  1. the context of a DDL job. All job execution logic should use this context. And another goroutine polling the job state should cancel the context if it's not JobStateRunning.
  2. the context of DDL module. Job rollingback, canceling, cleanup, scheduling, execution and other module-level action should use this context. It's canceled when the parent context is canceled which means domain is closing.
lance6716 commented 1 month ago

@D3Hunter please help link this issue to #54436 in a proper task

D3Hunter commented 1 month ago

And another goroutine polling the job state should cancel the context if it's not JobStateRunning.

some general jobs like create-table go directly from queuing -> done