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: add job version 2 and use typed args for truncate table #55854

Merged
merged 12 commits into from
Sep 9, 2024

Conversation

D3Hunter
Copy link
Contributor

@D3Hunter D3Hunter commented Sep 4, 2024

What problem does this PR solve?

Issue Number: ref #53930

Problem Summary:

What changed and how does it work?

  • add DDL job version 2 to use typed struct to replace old un-typed args slice
  • add new typed args for TruncateTable
  • currently we choose job version for new jobs randomly in test, see ddl.Start. Note: this only works for truncate-table for now.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

manually run TruncateTable tests using job version 2, success

  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 4, 2024
Copy link

tiprow bot commented Sep 4, 2024

Hi @D3Hunter. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@@ -289,14 +329,14 @@ type Job struct {
Query string `json:"query"`
BinlogInfo *HistoryInfo `json:"binlog"`

// Version indicates the DDL job version. For old jobs, it will be 0.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since version v1.0.0, the job version is already 1, so there shouldn't be jobs of version 0 now. see https://github.com/pingcap/tidb/pull/3993/files#diff-a185df836b8926c4afe351d4def1b56d1e282c65aabe6677c2fa2c54590cc4b2R44-R45

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 81.43460% with 44 lines in your changes missing coverage. Please review.

Project coverage is 57.1298%. Comparing base (e9124dd) to head (c0530a1).
Report is 24 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #55854         +/-   ##
=================================================
- Coverage   72.8514%   57.1298%   -15.7217%     
=================================================
  Files          1601       1756        +155     
  Lines        445302     633207     +187905     
=================================================
+ Hits         324409     361750      +37341     
- Misses       100894     246610     +145716     
- Partials      19999      24847       +4848     
Flag Coverage Δ
integration 39.6920% <69.1983%> (?)
unit 72.1897% <81.4346%> (+0.2285%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9567% <ø> (ø)
parser ∅ <ø> (∅)
br 62.9537% <ø> (+17.1771%) ⬆️

@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 5, 2024
@D3Hunter D3Hunter changed the title [WIP]ddl: add job version 2 and use typed args for truncate table ddl: add job version 2 and use typed args for truncate table Sep 5, 2024
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 5, 2024
@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 5, 2024

/retest

Copy link

tiprow bot commented Sep 5, 2024

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 5, 2024

/retest

Copy link

tiprow bot commented Sep 5, 2024

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@D3Hunter D3Hunter requested a review from joccau September 6, 2024 03:21
@joccau
Copy link
Member

joccau commented Sep 6, 2024

Maybe we could abstract some function, like this:

func setArgsForTruncateTable(job *model.job,  actualArgs *model.TruncateTableArgs, v version) {
    if v == 0 {
        // set args with the actualArgs.
        job.Args[0] = actualArg.NewTableID            
        job.Args[1] = ...
    } else {
       // set argsV2 with actualArgs.
        job.ArgsV2 = &model.TruncateTableArgs{
			NewTableID: 2,
		}
    }
}

func getArgsForTruncateTable(job *model.job, actualArgs *model.TruncateTableArgs, v version){
    if v == 0 {
        // set actualArgs with job.args
        newTableID = job.Args[0].(int64)
    } else {
       // set actualArgs with job.argsV2
       newTableID = job.ArgsV2.(*model.TruncateTableArgs).NewTableID
    }
}

func getIDCountForTruncateTable(job *model.job, v version) int  {
	if jobW.Version == model.JobVersion1 {
		partCount := jobW.Args[3].(int)
		count += 1 + partCount
	} else {
		count += 1 + len(jobW.ArgsV2.(*model.TruncateTableArgs).OldPartitionIDs)
	}
        return count.
}

And we can call this function in DDL jobSubmit and ddl jobScheduler and ...., put together functions that modify related parameters for different DDL type.

@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 6, 2024

/retest

Copy link

tiprow bot commented Sep 6, 2024

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@@ -6426,7 +6429,12 @@ func (e *executor) DoDDLJobWrapper(ctx sessionctx.Context, jobW *JobWrapper) (re
func HandleLockTablesOnSuccessSubmit(ctx sessionctx.Context, jobW *JobWrapper) {
if jobW.Type == model.ActionTruncateTable {
if ok, lockTp := ctx.CheckTableLocked(jobW.TableID); ok {
newTableID := jobW.Args[0].(int64)
var newTableID int64
if jobW.Version == model.JobVersion1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like GetTruncateTableArgsBeforeRun, this part can also be encapsulated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -6437,7 +6445,12 @@ func HandleLockTablesOnSuccessSubmit(ctx sessionctx.Context, jobW *JobWrapper) {
func HandleLockTablesOnFinish(ctx sessionctx.Context, jobW *JobWrapper, ddlErr error) {
if jobW.Type == model.ActionTruncateTable {
if ddlErr != nil {
newTableID := jobW.Args[0].(int64)
var newTableID int64
if jobW.Version == model.JobVersion1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -723,7 +723,13 @@ func job2UniqueIDs(job *model.Job, schema bool) string {
if schema {
return strconv.FormatInt(job.SchemaID, 10)
}
return strconv.FormatInt(job.TableID, 10) + "," + strconv.FormatInt(job.Args[0].(int64), 10)
var newTableID int64
if job.Version == model.JobVersion1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

pkg/ddl/job_submitter.go Show resolved Hide resolved
@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 6, 2024

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 6, 2024
@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 6, 2024

/retest

Copy link

tiprow bot commented Sep 6, 2024

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

partIDs := make([]int64, partCount)
for i := range partIDs {
partIDs[i] = alloc.next()
if jobW.Version == model.JobVersion1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for these getter logic, I prefer we always use a function to convert all version representations to TruncateTableArgs, then caller use TruncateTableArgs.

like

if !jobW.IDAllocated {
  arg := getTruncateTableArgs(job)
  arg.NewTableID = alloc.next()
  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for new jobs, i plan put JobArgs into JobWrapper, and fill to job on insert, so we can use it directly here.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 9, 2024
Copy link

ti-chi-bot bot commented Sep 9, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-09-06 10:29:53.410210012 +0000 UTC m=+6663.150633946: ☑️ agreed by joccau.
  • 2024-09-09 01:54:01.385231471 +0000 UTC m=+234911.125655403: ☑️ agreed by lance6716.

Copy link

ti-chi-bot bot commented Sep 9, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joccau, lance6716, tangenta

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Sep 9, 2024
@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 9, 2024

/retest

Copy link

tiprow bot commented Sep 9, 2024

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 9, 2024

/retest

Copy link

tiprow bot commented Sep 9, 2024

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 9, 2024

/retest

Copy link

tiprow bot commented Sep 9, 2024

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@D3Hunter
Copy link
Contributor Author

D3Hunter commented Sep 9, 2024

/retest

Copy link

tiprow bot commented Sep 9, 2024

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot merged commit 72c1580 into pingcap:master Sep 9, 2024
25 checks passed
@D3Hunter D3Hunter deleted the typed-job-args-rename branch September 9, 2024 11:24
@D3Hunter D3Hunter mentioned this pull request Sep 14, 2024
54 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants