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

disttask, ddl: move backend ctx register code to scheduler #46952

Merged
merged 10 commits into from
Sep 14, 2023

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Sep 13, 2023

What problem does this PR solve?

Issue Number: ref #46258

Problem Summary:

Previously, backendCtx is registered & unregistered every time the subtasks enter the next step. This is quite unefficient because construction & destruction take times.

The previous implementation also has the following drawbacks:

  • It is easy to forget unregistering after a stage complete, causing resource leakage.
  • The context that should be reused accross multiple stages maybe unexpectedly canceled.

What is changed and how it works?

  • Move register code to initialization of Scheduler.
  • Add Close() method to Scheduler, and unregister backendCtx in it.
  • Code refactoring.

Check List

Tests

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

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/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 13, 2023
@tiprow
Copy link

tiprow bot commented Sep 13, 2023

Hi @tangenta. 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/test-infra repository.

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #46952 (88b9d5f) into master (a7e3176) will decrease coverage by 0.6305%.
Report is 14 commits behind head on master.
The diff coverage is 31.7757%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #46952        +/-   ##
================================================
- Coverage   73.2988%   72.6684%   -0.6305%     
================================================
  Files          1331       1353        +22     
  Lines        397485     404404      +6919     
================================================
+ Hits         291352     293874      +2522     
- Misses        87533      91875      +4342     
- Partials      18600      18655        +55     
Flag Coverage Δ
integration 28.8527% <0.0000%> (?)
unit 73.3098% <31.7757%> (+0.0109%) ⬆️

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

Components Coverage Δ
dumpling 53.9263% <ø> (-0.1181%) ⬇️
parser 85.0019% <ø> (ø)
br 48.5715% <ø> (-4.3588%) ⬇️

@tangenta tangenta changed the title [WIP] disttask, ddl: move backend ctx register code to scheduler disttask, ddl: move backend ctx register code to scheduler Sep 13, 2023
@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 13, 2023
ddl/stage_scheduler.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ywqzzy ywqzzy left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 13, 2023
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 13, 2023
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 13, 2023
Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

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

rest lgtm

d: d,
}
s.BaseScheduler.Extension = s

wrapErr := func(err error) scheduler.Scheduler {
s.BaseScheduler.Extension = &failedExtension{err: err}
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add a Init which returns error to scheduler and move below part into it?

it's hacky to do it using this way.

Comment on lines +148 to +150
if s.backendCtx != nil {
ingest.LitBackCtxMgr.Unregister(s.jobID)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

call Close of base scheduler

@@ -44,6 +44,15 @@ func (m *SyncMap[K, V]) Load(key K) (V, bool) {
return val, exist
}

// LoadAndDelete loads and deletes a key value atomically.
func (m *SyncMap[K, V]) LoadAndDelete(key K) (V, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

extend Delete to return previous value and existed?

Copy link
Contributor

@GMHDBJD GMHDBJD left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: GMHDBJD, ywqzzy

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 Sep 13, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 13, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-09-13 11:14:52.224901446 +0000 UTC m=+84058.192489495: ☑️ agreed by ywqzzy.
  • 2023-09-13 15:29:00.327309551 +0000 UTC m=+99306.294897600: ☑️ agreed by GMHDBJD.

@D3Hunter
Copy link
Contributor

/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 Sep 13, 2023
@D3Hunter
Copy link
Contributor

/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 Sep 14, 2023
@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Sep 14, 2023
@tangenta
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit d2e39d7 into pingcap:master Sep 14, 2023
12 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants