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: impl slot manager in dispatcher, and check resource before start dispatcher #49195

Merged
merged 15 commits into from
Dec 11, 2023

Conversation

D3Hunter
Copy link
Contributor

@D3Hunter D3Hunter commented Dec 5, 2023

What problem does this PR solve?

Issue Number: close #49100

Problem Summary:

What changed and how does it work?

  • impl slotManager on dispatcher
  • check resource before start disaptcher

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 Dec 5, 2023
Copy link

tiprow bot commented Dec 5, 2023

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

}()
dm.setRunningTask(task, dispatcher)
metrics.UpdateMetricsForRunTask(task)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved from setRunningTask

@ywqzzy
Copy link
Contributor

ywqzzy commented Dec 5, 2023

/cc @ywqzzy

@ti-chi-bot ti-chi-bot bot requested a review from ywqzzy December 5, 2023 10:23
Copy link

codecov bot commented Dec 5, 2023

Codecov Report

Merging #49195 (ddeb124) into master (32cf9b9) will increase coverage by 0.8469%.
Report is 36 commits behind head on master.
The diff coverage is 17.4377%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49195        +/-   ##
================================================
+ Coverage   71.0441%   71.8911%   +0.8469%     
================================================
  Files          1368       1410        +42     
  Lines        402948     418921     +15973     
================================================
+ Hits         286271     301167     +14896     
- Misses        96736      98842      +2106     
+ Partials      19941      18912      -1029     
Flag Coverage Δ
integration 43.6281% <17.4377%> (?)
unit 71.0388% <ø> (-0.0053%) ⬇️

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

Components Coverage Δ
dumpling 53.9663% <ø> (ø)
parser ∅ <ø> (∅)
br 47.8780% <ø> (-5.0906%) ⬇️

Comment on lines +93 to 97
mu struct {
syncutil.RWMutex
taskIDs map[int64]struct{}
dispatchers map[int64]Dispatcher
}
}
Copy link
Member

Choose a reason for hiding this comment

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

How about using sync.Map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's untyped. let's leave it here

Copy link
Member

@okJiang okJiang 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

Comment on lines +197 to +200
if taskCnt >= proto.MaxConcurrentTask {
break
}
for _, task := range tasks {
// This task is running, so no need to reprocess it.
if dm.isRunningTask(task.ID) {
continue
}
metrics.DistTaskGauge.WithLabelValues(task.Type.String(), metrics.DispatchingStatus).Inc()
// we check it before start dispatcher, so no need to check it again.
// see startDispatcher.
// this should not happen normally, unless user modify system table
// directly.
if getDispatcherFactory(task.Type) == nil {
logutil.BgLogger().Warn("unknown task type", zap.Int64("task-id", task.ID),
zap.Stringer("task-type", task.Type))
dm.failTask(task, errors.New("unknown task type"))
continue
}
// the task is not in runningTasks set when:
// owner changed or task is cancelled when status is pending.
if task.State == proto.TaskStateRunning || task.State == proto.TaskStateReverting || task.State == proto.TaskStateCancelling {
metrics.UpdateMetricsForDispatchTask(task)
dm.startDispatcher(task)
cnt++
continue
}
if dm.checkConcurrencyOverflow(cnt) {
break
}
metrics.UpdateMetricsForDispatchTask(task)
dm.startDispatcher(task)
cnt++
reservedExecID, ok := dm.slotMgr.canReserve(task)
Copy link
Member

Choose a reason for hiding this comment

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

why check it twice?

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's checked twice?

Copy link
Member

Choose a reason for hiding this comment

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

It is strange. In fact I commented L197 in vs code.....

I mean L197 and L158

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check in L158, so no need to run any sql

Comment on lines +593 to +598
require.Eventually(t, func() bool {
taskKeys := getRunningTaskKeys()
return err == nil && len(taskKeys) == 4 &&
taskKeys[0] == "key/0" && taskKeys[1] == "key/1" &&
taskKeys[2] == "key/3" && taskKeys[3] == "key/4"
}, time.Second*10, time.Millisecond*100)
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment to explain why there are 4 tasks. I think it is because the MaxDispatcherConcurency

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, limited by max concurrent task. seems quite trivial to comment this

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 8, 2023
Comment on lines +177 to +179
// this should not happen normally, unless user modify system table
// directly.
if getDispatcherFactory(task.Type) == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Which system table affects this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

suppose user change task.Type to some invalid value

Copy link
Contributor

@tangenta tangenta 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

pkg/disttask/framework/dispatcher/slots.go Outdated Show resolved Hide resolved
D3Hunter and others added 2 commits December 11, 2023 19:52
Co-authored-by: tangenta <tangenta@126.com>
Co-authored-by: tangenta <tangenta@126.com>
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 11, 2023
Copy link

ti-chi-bot bot commented Dec 11, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-08 07:20:47.06928148 +0000 UTC m=+1771275.734507687: ☑️ agreed by okJiang.
  • 2023-12-11 12:40:24.102311164 +0000 UTC m=+273515.139538093: ☑️ agreed by tangenta.

Copy link

ti-chi-bot bot commented Dec 11, 2023

@D3Hunter: you cannot LGTM your own PR.

In response to this:

/lgtm

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.

Copy link

ti-chi-bot bot commented Dec 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, okJiang, 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 Dec 11, 2023
Copy link

ti-chi-bot bot commented Dec 11, 2023

@D3Hunter: Please do not delete or edit you lgtm type comment!

In response to this:

/lgtm

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.

@ti-chi-bot ti-chi-bot bot merged commit a7260ff into pingcap:master Dec 11, 2023
16 checks passed
@D3Hunter D3Hunter deleted the dispatcher-slot branch December 11, 2023 13:50
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.

impl slot manager in dispatcher, and control resource before start dispatcher
4 participants