-
Notifications
You must be signed in to change notification settings - Fork 6k
disttask: task executor slot manager #49136
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
Merged
ti-chi-bot
merged 28 commits into
pingcap:master
from
okJiang:disttask-rc/scheduler-slot-manager
Dec 20, 2023
Merged
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6295f58
rename
okJiang eae2e5e
save work
okJiang 45e4b72
Merge branch 'master' of https://github.com/pingcap/tidb into disttas…
okJiang 26e6254
Merge branch 'master' of https://github.com/pingcap/tidb into disttas…
okJiang 66c50ed
rename GetSubtasksByStepAndStates
okJiang bfc0084
implement priority quere for task and slotManager
okJiang 6df88d1
add ut
okJiang 908b65c
fix ut
okJiang 59db269
Merge branch 'master' of https://github.com/pingcap/tidb into disttas…
okJiang ff93eab
fix bazel
okJiang b69f291
add comment, fix bazel
okJiang f54e5d7
fix comment
okJiang 8809905
add ut
okJiang b57efc6
fix comment
okJiang 133f34b
add comment
okJiang e6006d1
Merge branch 'master' of https://github.com/pingcap/tidb into disttas…
okJiang 0a72a54
delete priority queue
okJiang 4a0ef07
remove useless convert
okJiang 3c1beb9
fix bazel
okJiang 8cc2e33
fix ut
okJiang c640046
Refactor slot management in task executor
okJiang c442754
Update pkg/disttask/framework/taskexecutor/slot.go
okJiang 3781105
fix comment
okJiang 6392faf
fix comment
okJiang 7d9f45e
Merge branch 'master' of https://github.com/pingcap/tidb into disttas…
okJiang 2003d2a
fix comment: refactor ut
okJiang a34651f
fix comment
okJiang 06422f4
fix comment
okJiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,7 +266,8 @@ tools/bin/vfsgendev: | |
tools/bin/gotestsum: | ||
GOBIN=$(shell pwd)/tools/bin $(GO) install gotest.tools/[email protected] | ||
|
||
tools/bin/mockgen: | ||
# [email protected] is imcompatible with v0.3.0, so install it always. | ||
mockgen: | ||
GOBIN=$(shell pwd)/tools/bin $(GO) install go.uber.org/mock/[email protected] | ||
|
||
# Usage: | ||
|
@@ -374,17 +375,17 @@ br_compatibility_test_prepare: | |
br_compatibility_test: | ||
@cd br && tests/run_compatible.sh run | ||
|
||
mock_s3iface: tools/bin/mockgen | ||
mock_s3iface: mockgen | ||
tools/bin/mockgen -package mock github.com/aws/aws-sdk-go/service/s3/s3iface S3API > br/pkg/mock/s3iface.go | ||
|
||
# mock interface for lightning and IMPORT INTO | ||
mock_lightning: tools/bin/mockgen | ||
mock_lightning: mockgen | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/br/pkg/lightning/backend Backend,EngineWriter,TargetInfoGetter,ChunkFlushStatus > br/pkg/mock/backend.go | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/br/pkg/lightning/backend/encode Encoder,EncodingBuilder,Rows,Row > br/pkg/mock/encode.go | ||
tools/bin/mockgen -package mocklocal github.com/pingcap/tidb/br/pkg/lightning/backend/local DiskUsage,TiKVModeSwitcher > br/pkg/mock/mocklocal/local.go | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/br/pkg/utils TaskRegister > br/pkg/mock/task_register.go | ||
|
||
gen_mock: tools/bin/mockgen | ||
gen_mock: mockgen | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/pkg/disttask/framework/taskexecutor TaskTable,Pool,TaskExecutor,Extension > pkg/disttask/framework/mock/task_executor_mock.go | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/pkg/disttask/framework/dispatcher Dispatcher,CleanUpRoutine,TaskManager > pkg/disttask/framework/mock/dispatcher_mock.go | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/pkg/disttask/framework/dispatcher Extension > pkg/disttask/framework/dispatcher/mock/dispatcher_mock.go | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package proto | ||
|
||
// TaskWrapper wraps a task and adds some extra information for the priority queue. | ||
type TaskWrapper struct { | ||
*Task | ||
|
||
IndexInPriorityQueue int // Index of the task in the priority queue | ||
} | ||
|
||
// TaskPriorityQueue represents a priority queue of tasks. | ||
type TaskPriorityQueue []*TaskWrapper | ||
|
||
// TaskPriorityQueue implementation for heap.Interface | ||
func (pq TaskPriorityQueue) Len() int { return len(pq) } | ||
|
||
// Less returns true if the task at index i has higher priority than the task at index j. | ||
func (pq TaskPriorityQueue) Less(i, j int) bool { | ||
// We want Pop to give us the highest priority, so we use greater than here. | ||
return pq[i].Priority > pq[j].Priority || | ||
(pq[i].Priority == pq[j].Priority && pq[i].CreateTime.Before(pq[j].CreateTime)) || | ||
(pq[i].Priority == pq[j].Priority && pq[i].CreateTime.Equal(pq[j].CreateTime) && pq[i].ID < pq[j].ID) | ||
} | ||
|
||
// Swap swaps the tasks at the given indices. | ||
func (pq TaskPriorityQueue) Swap(i, j int) { | ||
pq[i], pq[j] = pq[j], pq[i] | ||
pq[i].IndexInPriorityQueue = i | ||
pq[j].IndexInPriorityQueue = j | ||
} | ||
|
||
// Push adds x as element Len(). | ||
func (pq *TaskPriorityQueue) Push(x interface{}) { | ||
task := x.(*TaskWrapper) | ||
task.IndexInPriorityQueue = len(*pq) | ||
*pq = append(*pq, task) | ||
} | ||
|
||
// Pop removes and returns element Len() - 1. | ||
func (pq *TaskPriorityQueue) Pop() interface{} { | ||
old := *pq | ||
n := len(old) | ||
task := old[n-1] | ||
task.IndexInPriorityQueue = -1 // for safety | ||
*pq = old[0 : n-1] | ||
return task | ||
} | ||
|
||
// WrapPriorityQueue wraps a task into a TaskWrapper. | ||
func WrapPriorityQueue(task *Task) *TaskWrapper { | ||
return &TaskWrapper{ | ||
Task: task, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package proto | ||
|
||
import ( | ||
"container/heap" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTaskPriorityQueue(t *testing.T) { | ||
priorityQueue := make(TaskPriorityQueue, 0) | ||
heap.Init(&priorityQueue) | ||
|
||
task1 := &TaskWrapper{Task: &Task{ID: 1, Priority: 1, CreateTime: time.Now()}} | ||
task2 := &TaskWrapper{Task: &Task{ID: 2, Priority: 1, CreateTime: time.Now()}} | ||
task3 := &TaskWrapper{Task: &Task{ID: 3, Priority: 1, CreateTime: time.Now().Add(-2 * time.Second)}} | ||
task4 := &TaskWrapper{Task: &Task{ID: 4, Priority: 2, CreateTime: time.Now().Add(2 * time.Second)}} | ||
|
||
heap.Push(&priorityQueue, task1) | ||
heap.Push(&priorityQueue, task2) | ||
heap.Push(&priorityQueue, task3) | ||
heap.Push(&priorityQueue, task4) | ||
|
||
expected := []int64{4, 3, 1, 2} | ||
|
||
i := 0 | ||
// Pop tasks in priority order | ||
for priorityQueue.Len() > 0 { | ||
task := heap.Pop(&priorityQueue).(*TaskWrapper) | ||
require.Equal(t, expected[i], task.ID) | ||
i++ | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using this after it merged https://github.com/pingcap/tidb/pull/49195/files#diff-9cbb4aa7310f95ed10a52e14e392efa29e0356b179e85efec38db8fde5dca9f3R165
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌