Skip to content

Commit

Permalink
ddl, parser, planner: admin Pause/Resume on DDL jobs (pingcap#43081)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhysum committed May 10, 2023
1 parent 43e0b25 commit cc005bd
Show file tree
Hide file tree
Showing 11 changed files with 5,614 additions and 5,469 deletions.
20 changes: 10 additions & 10 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ def go_deps():
name = "com_github_cznic_strutil",
build_file_proto_mode = "disable_global",
importpath = "github.com/cznic/strutil",
sum = "h1:0rkFMAbn5KBKNpJyHQ6Prb95vIKanmAe62KxsrN+sqA=",
version = "v0.0.0-20171016134553-529a34b1c186",
sum = "h1:MZRmHqDBd0vxNwenEbKSQqRVT24d3C05ft8kduSwlqM=",
version = "v0.0.0-20181122101858-275e90344537",
)
go_repository(
name = "com_github_daixiang0_gci",
Expand Down Expand Up @@ -6076,8 +6076,8 @@ def go_deps():
name = "org_modernc_golex",
build_file_proto_mode = "disable_global",
importpath = "modernc.org/golex",
sum = "h1:EYKY1a3wStt0RzHaH8mdSRNg78Ub0OHxYfCRWw35YtM=",
version = "v1.0.1",
sum = "h1:IaPGsXg0FX9vkth++hQ/YIHjj0v4eZGJwoMrejWR1Ts=",
version = "v1.0.4",
)
go_repository(
name = "org_modernc_lex",
Expand All @@ -6097,8 +6097,8 @@ def go_deps():
name = "org_modernc_mathutil",
build_file_proto_mode = "disable_global",
importpath = "modernc.org/mathutil",
sum = "h1:ij3fYGe8zBF4Vu+g0oT7mB06r8sqGWKuJu1yXeR4by8=",
version = "v1.4.1",
sum = "h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=",
version = "v1.5.0",
)
go_repository(
name = "org_modernc_parser",
Expand All @@ -6118,15 +6118,15 @@ def go_deps():
name = "org_modernc_sortutil",
build_file_proto_mode = "disable_global",
importpath = "modernc.org/sortutil",
sum = "h1:SUTM1sCR0Ldpv7dbB/KCPC2zHHsZ1KrSkhmGmmV22CQ=",
version = "v1.0.0",
sum = "h1:VQGxbQGcHaQeB/BX9TQjrHFmOA0bounO1X/jvOfRo6Q=",
version = "v1.1.1",
)
go_repository(
name = "org_modernc_strutil",
build_file_proto_mode = "disable_global",
importpath = "modernc.org/strutil",
sum = "h1:+1/yCzZxY2pZwwrsbH+4T7BQMoLQ9QiBshRC9eicYsc=",
version = "v1.1.0",
sum = "h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=",
version = "v1.1.3",
)
go_repository(
name = "org_modernc_y",
Expand Down
8 changes: 8 additions & 0 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,8 @@ const (
AdminCheckTable
AdminShowDDLJobs
AdminCancelDDLJobs
AdminPauseDDLJobs
AdminResumeDDLJobs
AdminCheckIndex
AdminRecoverIndex
AdminCleanupIndex
Expand Down Expand Up @@ -2440,6 +2442,12 @@ func (n *AdminStmt) Restore(ctx *format.RestoreCtx) error {
case AdminCancelDDLJobs:
ctx.WriteKeyWord("CANCEL DDL JOBS ")
restoreJobIDs()
case AdminPauseDDLJobs:
ctx.WriteKeyWord("PAUSE DDL JOBS ")
restoreJobIDs()
case AdminResumeDDLJobs:
ctx.WriteKeyWord("RESUME DDL JOBS ")
restoreJobIDs()
case AdminShowDDLJobQueries:
ctx.WriteKeyWord("SHOW DDL JOB QUERIES ")
restoreJobIDs()
Expand Down
10 changes: 5 additions & 5 deletions parser/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/pingcap/tidb/parser
require (
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548
github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8
github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186
github.com/cznic/strutil v0.0.0-20181122101858-275e90344537
github.com/go-sql-driver/mysql v1.7.0
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7
Expand All @@ -25,10 +25,10 @@ require (
go.uber.org/multierr v1.6.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/golex v1.0.1 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/sortutil v1.0.0 // indirect
modernc.org/strutil v1.1.0 // indirect
modernc.org/golex v1.0.4 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/sortutil v1.1.1 // indirect
modernc.org/strutil v1.1.3 // indirect
)

go 1.18
16 changes: 10 additions & 6 deletions parser/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1v
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8 h1:LpMLYGyy67BoAFGda1NeOBQwqlv7nUXpm+rIVHGxZZ4=
github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8/go.mod h1:q2w6Bg5jeox1B+QkJ6Wp/+Vn0G/bo3f1uY7Fn3vivIQ=
github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186 h1:0rkFMAbn5KBKNpJyHQ6Prb95vIKanmAe62KxsrN+sqA=
github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186/go.mod h1:AHHPPPXTw0h6pVabbcbyGRK1DckRn7r/STdZEeIDzZc=
github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 h1:MZRmHqDBd0vxNwenEbKSQqRVT24d3C05ft8kduSwlqM=
github.com/cznic/strutil v0.0.0-20181122101858-275e90344537/go.mod h1:AHHPPPXTw0h6pVabbcbyGRK1DckRn7r/STdZEeIDzZc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -96,21 +96,25 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
modernc.org/fileutil v1.0.0/go.mod h1:JHsWpkrk/CnVV1H/eGlFf85BEpfkrp56ro8nojIq9Q8=
modernc.org/golex v1.0.1 h1:EYKY1a3wStt0RzHaH8mdSRNg78Ub0OHxYfCRWw35YtM=
modernc.org/golex v1.0.1/go.mod h1:QCA53QtsT1NdGkaZZkF5ezFwk4IXh4BGNafAARTC254=
modernc.org/golex v1.0.4 h1:IaPGsXg0FX9vkth++hQ/YIHjj0v4eZGJwoMrejWR1Ts=
modernc.org/golex v1.0.4/go.mod h1:pTY7KKjdvZbv2ROjfp6FFX5BXMM9QWZEnmCsl60aCfI=
modernc.org/lex v1.0.0/go.mod h1:G6rxMTy3cH2iA0iXL/HRRv4Znu8MK4higxph/lE7ypk=
modernc.org/lexer v1.0.0/go.mod h1:F/Dld0YKYdZCLQ7bD0USbWL4YKCyTDRDHiDTOs0q0vk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
modernc.org/mathutil v1.4.1 h1:ij3fYGe8zBF4Vu+g0oT7mB06r8sqGWKuJu1yXeR4by8=
modernc.org/mathutil v1.4.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/parser v1.0.0/go.mod h1:H20AntYJ2cHHL6MHthJ8LZzXCdDCHMWt1KZXtIMjejA=
modernc.org/parser v1.0.2 h1:/qHLDn1ezrcRk9/XbErYp84bPPM4+w0kIDuvMdRk6Vc=
modernc.org/parser v1.0.2/go.mod h1:TXNq3HABP3HMaqLK7brD1fLA/LfN0KS6JxZn71QdDqs=
modernc.org/scanner v1.0.1/go.mod h1:OIzD2ZtjYk6yTuyqZr57FmifbM9fIH74SumloSsajuE=
modernc.org/sortutil v1.0.0 h1:SUTM1sCR0Ldpv7dbB/KCPC2zHHsZ1KrSkhmGmmV22CQ=
modernc.org/sortutil v1.0.0/go.mod h1:1QO0q8IlIlmjBIwm6t/7sof874+xCfZouyqZMLIAtxM=
modernc.org/sortutil v1.1.1 h1:VQGxbQGcHaQeB/BX9TQjrHFmOA0bounO1X/jvOfRo6Q=
modernc.org/sortutil v1.1.1/go.mod h1:DTj/8BqjEBLZFVPYvEGDfFFg94SsfPxQ70R+SQJ98qA=
modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs=
modernc.org/strutil v1.1.0 h1:+1/yCzZxY2pZwwrsbH+4T7BQMoLQ9QiBshRC9eicYsc=
modernc.org/strutil v1.1.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs=
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
modernc.org/y v1.0.1 h1:+QT+MtLkwkvLkh3fYQq+YD5vw2s5paVE73jdl5R/Py8=
modernc.org/y v1.0.1/go.mod h1:Ho86I+LVHEI+LYXoUKlmOMAM1JTXOCfj8qi1T8PsClE=
54 changes: 53 additions & 1 deletion parser/model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func (sub *SubJob) ToProxyJob(parentJob *Job) Job {
SeqNum: parentJob.SeqNum,
Charset: parentJob.Charset,
Collate: parentJob.Collate,
AdminOperator: parentJob.AdminOperator,
}
}

Expand Down Expand Up @@ -430,6 +431,10 @@ type Job struct {
Charset string `json:"charset"`
// Collate is the collation the DDL Job is created.
Collate string `json:"collate"`

// AdminOperator indicates where the Admin command comes, by the TiDB
// itself (AdminCommandBySystem) or by user (AdminCommandByEndUser).
AdminOperator AdminCommandOperator `json:"admin_operator"`
}

// FinishTableJob is called when a job is finished.
Expand Down Expand Up @@ -737,6 +742,26 @@ func (job *Job) IsCancelling() bool {
return job.State == JobStateCancelling
}

// IsPaused returns whether the job is paused.
func (job *Job) IsPaused() bool {
return job.State == JobStatePaused
}

// IsPausing indicates whether the job is pausing.
func (job *Job) IsPausing() bool {
return job.State == JobStatePausing
}

// IsPausable checks whether we can pause the job.
func (job *Job) IsPausable() bool {
return (job.NotStarted() || job.IsRunning()) && job.IsRollbackable()
}

// IsResumable checks whether the job can be rollback.
func (job *Job) IsResumable() bool {
return job.IsPaused()
}

// IsSynced returns whether the DDL modification is synced among all TiDB servers.
func (job *Job) IsSynced() bool {
return job.State == JobStateSynced
Expand Down Expand Up @@ -823,7 +848,7 @@ func (job *Job) IsRollbackable() bool {
}

// JobState is for job state.
type JobState byte
type JobState int32

// List job states.
const (
Expand All @@ -843,6 +868,9 @@ const (
JobStateCancelling JobState = 7
// JobStateQueueing means the job has not yet been started.
JobStateQueueing JobState = 8

JobStatePaused JobState = 9
JobStatePausing JobState = 10
)

// String implements fmt.Stringer interface.
Expand All @@ -864,6 +892,10 @@ func (s JobState) String() string {
return "synced"
case JobStateQueueing:
return "queueing"
case JobStatePaused:
return "paused"
case JobStatePausing:
return "pausing"
default:
return "none"
}
Expand All @@ -888,11 +920,31 @@ func StrToJobState(s string) JobState {
return JobStateSynced
case "queueing":
return JobStateQueueing
case "paused":
return JobStatePaused
case "pausing":
return JobStatePausing
default:
return JobStateNone
}
}

// AdminCommandOperator indicates where the Cancel/Pause/Resume command on DDL
// jobs comes from.
type AdminCommandOperator int

const (
// AdminCommandByNotKnown indicates that unknow calling of the
// Cancel/Pause/Resume on DDL job.
AdminCommandByNotKnown AdminCommandOperator = iota
// AdminCommandByEndUser indicates that the Cancel/Pause/Resume command on
// DDL job is issued by the end user.
AdminCommandByEndUser
// AdminCommandBySystem indicates that the Cancel/Pause/Resume command on
// DDL job is issued by TiDB itself, such as Upgrade(bootstrap).
AdminCommandBySystem
)

// SchemaDiff contains the schema modification at a particular schema version.
// It is used to reduce schema reload cost.
type SchemaDiff struct {
Expand Down
2 changes: 1 addition & 1 deletion parser/model/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestJobSize(t *testing.T) {
- SubJob.ToProxyJob()
`
job := model.Job{}
require.Equal(t, 320, int(unsafe.Sizeof(job)), msg)
require.Equal(t, 328, int(unsafe.Sizeof(job)), msg)
}

func TestBackfillMetaCodec(t *testing.T) {
Expand Down
Loading

0 comments on commit cc005bd

Please sign in to comment.