-
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
Changes from 10 commits
6295f58
eae2e5e
45e4b72
26e6254
66c50ed
bfc0084
6df88d1
908b65c
59db269
ff93eab
b69f291
f54e5d7
8809905
b57efc6
133f34b
e6006d1
0a72a54
4a0ef07
3c1beb9
8cc2e33
c640046
c442754
3781105
6392faf
7d9f45e
2003d2a
a34651f
06422f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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 | ||
|
||
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 | ||
} | ||
|
||
func WrapPriorityQueue(task *Task) *TaskWrapper { | ||
return &TaskWrapper{ | ||
Task: task, | ||
} | ||
} |
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++ | ||
} | ||
} |
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.
upgrade
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.
it is useless, I will remove it