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: only use runningJobs to check job dependency #54003

Merged
merged 22 commits into from
Jun 19, 2024

Conversation

lance6716
Copy link
Contributor

@lance6716 lance6716 commented Jun 13, 2024

What problem does this PR solve?

Issue Number: ref #52795, #53246

Problem Summary:

What changed and how does it work?

assuming there's one DDL owner at any time, we don't need to query persistent data of running DDL jobs. Instead, we can check the memory cache of running DDL jobs.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • 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

Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 13, 2024
Copy link

tiprow bot commented Jun 13, 2024

Hi @lance6716. 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.

pkg/ddl/ddl_api.go Outdated Show resolved Hide resolved
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Copy link

codecov bot commented Jun 13, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 22 lines in your changes missing coverage. Please review.

Project coverage is 56.1069%. Comparing base (2cea994) to head (a9fcd16).
Report is 13 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54003         +/-   ##
=================================================
- Coverage   74.5294%   56.1069%   -18.4226%     
=================================================
  Files          1516       1638        +122     
  Lines        360821     610295     +249474     
=================================================
+ Hits         268918     342418      +73500     
- Misses        72393     244462     +172069     
- Partials      19510      23415       +3905     
Flag Coverage Δ
integration 37.0623% <64.8484%> (?)
unit 71.7640% <86.6666%> (-1.6452%) ⬇️

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

Components Coverage Δ
dumpling 52.9656% <ø> (-2.2339%) ⬇️
parser ∅ <ø> (∅)
br 52.2563% <ø> (+8.2840%) ⬆️

Signed-off-by: lance6716 <lance6716@gmail.com>
@lance6716 lance6716 changed the title [WIP]ddl: only use runningJobs to check job dependency ddl: only use runningJobs to check job dependency Jun 17, 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 Jun 17, 2024
@lance6716
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jun 17, 2024

@lance6716: 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

placement policy and resource group are out of our check currently, we need to make sure 2 jobs of same name doesn't run concurrently

Copy link
Contributor

Choose a reason for hiding this comment

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

we also need to merge InvolvingSchemaInfo which cames from foreign key for multiple schema change

Copy link
Contributor

Choose a reason for hiding this comment

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

create table with foreign key also need it, but i have add it in #54041 for some tests depends on it

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 placement policy and resource group, do you think we can add another field for InvolvingSchemaInfo to record the dependency or other implementation? also cc @tangenta

I'll consider FK in next commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

now placement policy and resource group will set its name to job.Schema, if they have same namespace as database, seems ok to set InvolvingSchemaInfo = xx.*

Copy link
Contributor

Choose a reason for hiding this comment

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

placement policy and resource group related ddl all have a none, none InvolvingSchemaInfo😓

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding another field maybe better. It is weird if a policy job blocks a create-database job..

Copy link
Contributor Author

@lance6716 lance6716 Jun 18, 2024

Choose a reason for hiding this comment

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

I found it's a bit complex and I only want to add a TODO in this PR. Because there're exclusive jobs and shared jobs. Like CreatePlacementPolicy that directly modifies PlacementPolicy, and AlterTablePlacement that referring PlacementPolicy. Two AlterTablePlacement jobs should not have dependency.

And I think CREATE TABLE LIKE and FK are simliar. I want to leave this PR to this situation:

  • When two jobs only referring to an object, in other words, does not modify it, the jobs have no dependency
  • A referring job and a modifying job to the same object have no dependency. (I'll add TODO and improve it in next PR)
  • Two modifying jobs have dependency.

I'll commit soon

Copy link
Contributor

@D3Hunter D3Hunter Jun 18, 2024

Choose a reason for hiding this comment

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

When two jobs only referring to an object, in other words, does not modify it, the jobs have no dependency

we should take them as depends on each other now as when calculate dependency we don't consider skipped jobs now, suppose this

  • job 1: create table a ...foreign key refer test.t
  • job 2: alter table test.t
  • job 3: create table b ...foreign key refer test.t

job 1 can run, but not job 2, when we check job 3, we need consider job 2, not run it directly.

A referring job and a modifying job to the same object have no dependency.

do you mean job 1 create table a foreign key test.t; job 2 alter table test.t have no dependency? i think it does if job 2 modify the referred column

Copy link
Contributor Author

Choose a reason for hiding this comment

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

job 1: create table a ...foreign key refer test.t
job 2: alter table test.t
job 3: create table b ...foreign key refer test.t
job 1 can run, but not job 2, when we check job 3, we need consider job 2, not run it directly.

I think this is the case of fair lock. I'll keep this property in next PR

do you mean job 1 create table a foreign key test.t; job 2 alter table test.t have no dependency? i think it does if job 2 modify the referred column

It should have dependency, but I also want to leave it for next PR. In next PR I'll add exclusive and shared fields to runningJobs and InvolvingSchemaInfo to implement it.

@@ -7949,7 +7969,17 @@ func (d *ddl) CreateForeignKey(ctx sessionctx.Context, ti ast.Ident, fkName mode
BinlogInfo: &model.HistoryInfo{},
Args: []any{fkInfo, fkCheck},
CDCWriteSource: ctx.GetSessionVars().CDCWriteSource,
SQLMode: ctx.GetSessionVars().SQLMode,
InvolvingSchemaInfo: []model.InvolvingSchemaInfo{
Copy link
Contributor

Choose a reason for hiding this comment

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

drop foreign key also need it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see that in the execution code dropForeignKey, it does not check the existence of RefSchema / RefTable, maybe in this way it's more rubust.

@crazycs520 Do you think we should check dependency for the reference table of drop foreign key?

pkg/ddl/ddl_api.go Outdated Show resolved Hide resolved
@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 Jun 18, 2024
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
pkg/parser/model/ddl.go Show resolved Hide resolved
pkg/ddl/ddl_running_jobs.go Show resolved Hide resolved
pkg/ddl/ddl_running_jobs.go Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 18, 2024
@lance6716
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 18, 2024
@@ -2829,31 +2829,16 @@ func (d *ddl) createTableWithInfoJob(
args = append(args, ctx.GetSessionVars().ForeignKeyChecks)
}

involvingSchemaInfo := make([]model.InvolvingSchemaInfo, 0, len(tbInfo.ForeignKeys)+1)
Copy link
Contributor

Choose a reason for hiding this comment

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

why it's removed? and below FK for multi schema change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to allow CREATE TABLE t1 FOREIGN KEY t0.c0 and CREATE TABLE t2 FOREIGN KEY t0.c0 running concurrently in this PR. See below.

#54003 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, CI is failed because of this...

TestTruncateOrDropTableWithForeignKeyReferred2

Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
@lance6716
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jun 18, 2024

@lance6716: 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.

Signed-off-by: lance6716 <lance6716@gmail.com>
@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 Jun 18, 2024
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
@lance6716
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jun 19, 2024

@lance6716: 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.

Signed-off-by: lance6716 <lance6716@gmail.com>
@lance6716
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jun 19, 2024

@lance6716: 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.

Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Copy link

ti-chi-bot bot commented Jun 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, 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 lgtm approved and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 19, 2024
Copy link

ti-chi-bot bot commented Jun 19, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-18 08:13:38.991601459 +0000 UTC m=+102545.477090292: ☑️ agreed by D3Hunter.
  • 2024-06-19 06:08:54.93598283 +0000 UTC m=+181461.421471662: ☑️ agreed by tangenta.

@ti-chi-bot ti-chi-bot bot merged commit 51ccce2 into pingcap:master Jun 19, 2024
23 checks passed
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.

3 participants