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: manage job lifecycle in worker #53747

Merged
merged 15 commits into from
Jun 7, 2024
Merged

Conversation

D3Hunter
Copy link
Contributor

@D3Hunter D3Hunter commented Jun 3, 2024

What problem does this PR solve?

Issue Number: ref #53246

Problem Summary:

What changed and how does it work?

  • manage job life cycle inside worker
  • move some methods for querying DDL related system tables to a separate pkg
  • replace some background contexts to DDL worker ctx
  • add context param to begin/commit, rollback is not changed as it doesn't return err and the main usages of ctx is to extract value

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

@ti-chi-bot ti-chi-bot bot added 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. labels Jun 3, 2024
Copy link

tiprow bot commented Jun 3, 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.

Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

14 / 24 files viewed

pkg/ddl/internal/session/session.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jun 3, 2024

Codecov Report

Attention: Patch coverage is 86.82927% with 27 lines in your changes missing coverage. Please review.

Project coverage is 55.4905%. Comparing base (44c9096) to head (1e89963).
Report is 28 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #53747         +/-   ##
=================================================
- Coverage   70.8894%   55.4905%   -15.3989%     
=================================================
  Files          1506       1629        +123     
  Lines        412726     607029     +194303     
=================================================
+ Hits         292579     336844      +44265     
- Misses       100750     246794     +146044     
- Partials      19397      23391       +3994     
Flag Coverage Δ
integration 22.4763% <68.9839%> (?)

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

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

if err != nil {
logutil.DDLLogger().Warn("unexpected error when clean mdl info", zap.Int64("job ID", job.ID), zap.Error(err))
return
}
if cleanETCD && ec != nil {
// TODO do we need clean it for JobStateRollbackDone?
Copy link
Contributor

@tangenta tangenta Jun 3, 2024

Choose a reason for hiding this comment

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

JobStateRollbackDone does trigger schema version changes for some DDLs, if we don't clean keys here, there may be a leak? I can have a test later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, that's why i want to add a JobStateRollbackSynced, so we can check it easily

j.updateInternalRunningJobIDs()

if job.IsFinished() || job.IsSynced() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reorg jobs will check whether there are jobs of same table-id are in-processing in getReorgJob, so for a table-id there shouldn't be 2 jobs running concurrently, so it's ok to delete those unfinishedXXX all the time

Copy link
Contributor

Choose a reason for hiding this comment

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

@D3Hunter Is it not necessary to distinguish processingIDs from unfinishedIDs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

like what we have discussed, runningJobs.remove will only called when the job is in final state like synced/paused/cancelled or it's done by another owner, before that another job operating the same table-id or name should be blocked

@D3Hunter
Copy link
Contributor Author

D3Hunter commented Jun 3, 2024

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 3, 2024
@@ -1776,14 +1777,14 @@ func TestMDLViewIDConflict(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
ddlTK1.MustExec("ALTER TABLE t ADD COLUMN b INT;")
ddlTK1.MustExec("ALTER TABLE t ADD index(a);")
Copy link
Contributor Author

@D3Hunter D3Hunter Jun 4, 2024

Choose a reason for hiding this comment

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

now the routine will hold worker until it exist, so 2 general ddl cannot be run at same time now while it's possible when they have no dependency previously, so we change to reorg job to make this test work

@D3Hunter
Copy link
Contributor Author

D3Hunter commented Jun 4, 2024

/retest

Copy link

tiprow bot commented Jun 4, 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 Jun 5, 2024

/retest

Copy link

tiprow bot commented Jun 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 Jun 5, 2024

/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 5, 2024
@D3Hunter
Copy link
Contributor Author

D3Hunter commented Jun 5, 2024

@lance6716 @tangenta test pass, ptal

@@ -892,13 +893,13 @@ func (r *reorgInfo) UpdateReorgMeta(startKey kv.Key, pool *sess.Pool) (err error
defer pool.Put(sctx)

se := sess.NewSession(sctx)
err = se.Begin()
err = se.Begin(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use r.d.ctx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's no much difference with background, it's only cancelled at shutdown. we should refactor to use job worker ctx or disttask ctx later

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 6, 2024
@D3Hunter D3Hunter mentioned this pull request Jun 6, 2024
18 tasks
pkg/ddl/job_table.go Outdated Show resolved Hide resolved
Copy link

ti-chi-bot bot commented Jun 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

ti-chi-bot bot commented Jun 7, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-06 05:55:41.154558546 +0000 UTC m=+12095.207870470: ☑️ agreed by lance6716.
  • 2024-06-07 07:52:03.339309767 +0000 UTC m=+105477.392621687: ☑️ agreed by tangenta.

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