mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-03 12:29:36 +08:00
69252f812d
Related to #16298 #16291 #16154 Co-authored-by: sunby <bingyi.sun@zilliz.com> Co-authored-by: yangxuan <xuan.yang@zilliz.com> Co-authored-by: yah01 <yang.cen@zilliz.com> Co-authored-by: Letian Jiang <letian.jiang@zilliz.com> Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package querycoord
|
|
|
|
import "sort"
|
|
|
|
type balancer interface {
|
|
addNode(nodeID int64) ([]*balancePlan, error)
|
|
removeNode(nodeID int64) []*balancePlan
|
|
rebalance() []*balancePlan
|
|
}
|
|
|
|
type balancePlan struct {
|
|
nodeID int64
|
|
sourceReplica int64
|
|
targetReplica int64
|
|
}
|
|
|
|
type replicaBalancer struct {
|
|
meta Meta
|
|
}
|
|
|
|
func newReplicaBalancer(meta Meta) *replicaBalancer {
|
|
return &replicaBalancer{meta}
|
|
}
|
|
|
|
func (b *replicaBalancer) addNode(nodeID int64) ([]*balancePlan, error) {
|
|
// allocate this node to all collections replicas
|
|
var ret []*balancePlan
|
|
collections := b.meta.showCollections()
|
|
for _, c := range collections {
|
|
replicas, err := b.meta.getReplicasByCollectionID(c.GetCollectionID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(replicas) == 0 {
|
|
continue
|
|
}
|
|
sort.Slice(replicas, func(i, j int) bool {
|
|
return len(replicas[i].GetNodeIds()) < len(replicas[j].GetNodeIds())
|
|
})
|
|
|
|
ret = append(ret, &balancePlan{
|
|
nodeID: nodeID,
|
|
sourceReplica: -1,
|
|
targetReplica: replicas[0].GetReplicaID(),
|
|
})
|
|
}
|
|
return ret, nil
|
|
}
|
|
|
|
func (b *replicaBalancer) removeNode(nodeID int64) []*balancePlan {
|
|
// for this version, querynode does not support move from a replica to another
|
|
return nil
|
|
}
|
|
|
|
func (b *replicaBalancer) rebalance() []*balancePlan {
|
|
return nil
|
|
}
|