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

pkg/schedule: put merge operators together #8050

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/schedule/operator/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,16 @@ func (oc *Controller) AddWaitingOperator(ops ...*Operator) int {
}
continue
}
oc.wop.PutOperator(op)

if isMerge {
// count two merge operators as one, so wopStatus.ops[desc] should
// not be updated here
// TODO: call checkAddOperator ...
oc.wop.PutMergeOperators([]*Operator{op, ops[i+1]})
i++
added++
oc.wop.PutOperator(ops[i])
} else {
oc.wop.PutOperator(op)
}
operatorCounter.WithLabelValues(desc, "put").Inc()
oc.wopStatus.incCount(desc)
Expand Down
16 changes: 16 additions & 0 deletions pkg/schedule/operator/waiting_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var priorityWeight = []float64{1.0, 4.0, 9.0, 16.0}
// WaitingOperator is an interface of waiting operators.
type WaitingOperator interface {
PutOperator(op *Operator)
PutMergeOperators(op []*Operator)
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:

Suggested change
PutMergeOperators(op []*Operator)
PutOperators(op []*Operator)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it is only used for merge, and the common name is easy to misunderstand.

GetOperator() []*Operator
ListOperator() []*Operator
}
Expand Down Expand Up @@ -66,6 +67,21 @@ func (b *randBuckets) PutOperator(op *Operator) {
bucket.ops = append(bucket.ops, op)
}

// PutMergeOperators puts two operators into the random buckets.
func (b *randBuckets) PutMergeOperators(ops []*Operator) {
b.mu.Lock()
defer b.mu.Unlock()
if len(ops) != 2 && (ops[0].Kind()&OpMerge == 0 || ops[1].Kind()&OpMerge == 0) {
return
}
priority := ops[0].GetPriorityLevel()
bucket := b.buckets[priority]
if len(bucket.ops) == 0 {
b.totalWeight += bucket.weight
}
bucket.ops = append(bucket.ops, ops...)
}

// ListOperator lists all operator in the random buckets.
func (b *randBuckets) ListOperator() []*Operator {
b.mu.Lock()
Expand Down
Loading