milvus/internal/querynode/scheduler_policy.go
congqixia ac6394d0fd
Fix container/list removal in iteration (#17382)
Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
2022-06-06 16:34:05 +08:00

26 lines
549 B
Go

package querynode
import (
"container/list"
)
type scheduleReadTaskPolicy func(sqTasks *list.List, targetUsage int32) ([]readTask, int32)
func defaultScheduleReadPolicy(sqTasks *list.List, targetUsage int32) ([]readTask, int32) {
var ret []readTask
usage := int32(0)
var next *list.Element
for e := sqTasks.Front(); e != nil; e = next {
next = e.Next()
t, _ := e.Value.(readTask)
tUsage := t.CPUUsage()
if usage+tUsage > targetUsage {
break
}
usage += tUsage
sqTasks.Remove(e)
ret = append(ret, t)
}
return ret, usage
}