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: refine dispatcher #45460

Merged
merged 24 commits into from
Aug 1, 2023
Merged

disttask: refine dispatcher #45460

merged 24 commits into from
Aug 1, 2023

Conversation

ywqzzy
Copy link
Contributor

@ywqzzy ywqzzy commented Jul 19, 2023

What problem does this PR solve?

Issue Number: ref #41495

Problem Summary:

Currently, the dispatcher use 2 for loop to dispatch and monitor tasks.

There is no abstraction for dispatcher and dispatcherManager.

  1. dispatcher only handles one task.
  2. dispatcherManager manages a bunch of dispatchers and transfer submitted tasks to different dispatchers.

What is changed and how it works?

  1. remove DetectTaskLoop.
  2. Don't call processFlow in DispatchTaskLoop, make it as light weight as possible.
  3. add monitorTask which monitor the task status.
  4. add scheduleTask which will call schedule one task with a for loop.
  5. add executeTask interface which will trigger one goroutine to call scheduleTask.

Abstract dispatcher struct which only schedule and execute one task.

dispatcher will provide interface like:

  1. scheduleTask: schedules the execution of subtasks.
  2. monitorTask: check if the step is finished.
  3. GenerateDistPlan: generate the task plan.

The dispatcher do the following job step by step:

  1. Generate distributed plan which have multiple steps.
  2. dispatch first step's subtasks.
  3. monitor first step's subtasks status and decide if going to next step. If next step, go to 2. If all steps subtasks finished, mark task finished.

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 release-note-none Denotes a PR that doesn't merit a release note. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 19, 2023
@tiprow
Copy link

tiprow bot commented Jul 19, 2023

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

@ywqzzy ywqzzy changed the title disttask: change dispatcher to dispatcher_pool. [WIP]disttask: change dispatcher to dispatcher_pool. Jul 19, 2023
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 19, 2023
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 19, 2023
@ywqzzy ywqzzy changed the title [WIP]disttask: change dispatcher to dispatcher_pool. disttask: change dispatcher to dispatcher_pool. Jul 19, 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 Jul 19, 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 Jul 19, 2023
@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #45460 (61a4fe6) into master (a53fd2d) will increase coverage by 0.0190%.
Report is 7 commits behind head on master.
The diff coverage is 87.3303%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #45460        +/-   ##
================================================
+ Coverage   73.1995%   73.2185%   +0.0190%     
================================================
  Files          1265       1270         +5     
  Lines        390142     391401      +1259     
================================================
+ Hits         285582     286578       +996     
- Misses        86243      86434       +191     
- Partials      18317      18389        +72     
Flag Coverage Δ
integration 78.1388% <ø> (?)
unit 73.2099% <87.3303%> (+0.0104%) ⬆️

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

Components Coverage Δ
dumpling 54.0444% <ø> (ø)
parser 85.0467% <ø> (+0.0108%) ⬆️
br 51.9865% <ø> (-0.0042%) ⬇️

domain/domain.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 19, 2023
domain/domain.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 20, 2023
@ywqzzy
Copy link
Contributor Author

ywqzzy commented Jul 20, 2023

/retest

@ywqzzy ywqzzy requested a review from zimulala July 20, 2023 06:19
}

func (d *dispatcher) Inited() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use this function. Could we remove 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 think Inited is better for checking of the dispatcher is started.

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 27, 2023
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 1, 2023
cancel context.CancelFunc
taskMgr *storage.TaskManager
wg tidbutil.WaitGroupWrapper
gPool *spool.Pool
Copy link
Contributor

Choose a reason for hiding this comment

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

What does gpool do now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does gpool do now?

Fixed

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

// ExecuteTask start to schedule a task
func (d *dispatcher) ExecuteTask() {
// Using the pool with block, so it wouldn't return an error.
_ = d.gPool.Run(func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about move to dispatcher manager?

func (dm *DispatcherManager) StartDispathcer(){
      dm.gPool.Run(func() {
             d := newDispatcher()
             d.ExecuteTask()
             d.delRunningTask()
      })
} 

Then we no need finished channel.

@ti-chi-bot ti-chi-bot bot added the lgtm label Aug 1, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 1, 2023

[APPROVALNOTIFIER] This PR is APPROVED

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

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 and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 1, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 1, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-07-20 01:57:47.182885524 +0000 UTC m=+1161158.953224223: ☑️ agreed by Benjamin2037.
  • 2023-08-01 08:07:05.464021032 +0000 UTC m=+172709.406369562: ☑️ agreed by GMHDBJD.

@ti-chi-bot ti-chi-bot bot merged commit e5e507a into pingcap:master Aug 1, 2023
6 of 9 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants