queryCoord的balancer分析
milvus版本:v2.3.2
涉及到一个参数设置:
queryCoord.balancer = ScoreBasedBalancer
milvus内置的balancer有3种:
代码位置:internal\querycoordv2\balance\balance.go
var (
RoundRobinBalancerName = "RoundRobinBalancer"
RowCountBasedBalancerName = "RowCountBasedBalancer"
ScoreBasedBalancerName = "ScoreBasedBalancer"
)
Balance接口:
type Balance interface {
AssignSegment(collectionID int64, segments []*meta.Segment, nodes []int64) []SegmentAssignPlan
AssignChannel(channels []*meta.DmChannel, nodes []int64) []ChannelAssignPlan
BalanceReplica(replica *meta.Replica) ([]SegmentAssignPlan, []ChannelAssignPlan)
}
这个接口有3个实现。
ScoreBasedBalancer、RoundRobinBalancer、RowCountBasedBalancer。
func (controller *CheckerController) check(ctx context.Context, checkerType string) {
checker := controller.checkers[checkerType]
tasks := checker.Check(ctx)
for _, task := range tasks {
err := controller.scheduler.Add(task)
if err != nil {
task.Cancel(err)
continue
}
}
}
checker.Check()有4个实现,会调用AssignSegment、AssignChannel、BalanceReplica方法。