2021-11-17 19:39:17 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-06-15 12:41:40 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-17 19:39:17 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-06-15 12:41:40 +08:00
|
|
|
//
|
2021-11-17 19:39:17 +08:00
|
|
|
// 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.
|
2021-06-15 12:41:40 +08:00
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
package querycoord
|
2021-06-15 12:41:40 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-06-19 11:45:09 +08:00
|
|
|
"encoding/json"
|
2021-06-15 12:41:40 +08:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-06-19 11:45:09 +08:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2021-06-15 12:41:40 +08:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-11-17 09:47:12 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/kv"
|
2021-06-19 11:45:09 +08:00
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
2021-11-17 09:47:12 +08:00
|
|
|
minioKV "github.com/milvus-io/milvus/internal/kv/minio"
|
2021-06-15 12:41:40 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-11-12 18:49:10 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
2021-06-15 12:41:40 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-08-26 14:17:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2021-06-15 12:41:40 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-06-19 11:45:09 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2021-09-15 20:40:07 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-06-19 11:45:09 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-06-22 16:44:09 +08:00
|
|
|
queryNodeInfoPrefix = "queryCoord-queryNodeInfo"
|
2021-06-15 12:41:40 +08:00
|
|
|
)
|
|
|
|
|
2021-09-27 10:47:57 +08:00
|
|
|
// Cluster manages all query node connections and grpc requests
|
2021-08-02 22:39:25 +08:00
|
|
|
type Cluster interface {
|
|
|
|
reloadFromKV() error
|
2021-12-21 11:57:39 +08:00
|
|
|
getComponentInfos(ctx context.Context) []*internalpb.ComponentInfo
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
loadSegments(ctx context.Context, nodeID int64, in *querypb.LoadSegmentsRequest) error
|
|
|
|
releaseSegments(ctx context.Context, nodeID int64, in *querypb.ReleaseSegmentsRequest) error
|
|
|
|
|
|
|
|
watchDmChannels(ctx context.Context, nodeID int64, in *querypb.WatchDmChannelsRequest) error
|
2021-11-05 14:47:19 +08:00
|
|
|
watchDeltaChannels(ctx context.Context, nodeID int64, in *querypb.WatchDeltaChannelsRequest) error
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
hasWatchedQueryChannel(ctx context.Context, nodeID int64, collectionID UniqueID) bool
|
2021-11-13 08:49:08 +08:00
|
|
|
hasWatchedDeltaChannel(ctx context.Context, nodeID int64, collectionID UniqueID) bool
|
2021-08-02 22:39:25 +08:00
|
|
|
addQueryChannel(ctx context.Context, nodeID int64, in *querypb.AddQueryChannelRequest) error
|
|
|
|
removeQueryChannel(ctx context.Context, nodeID int64, in *querypb.RemoveQueryChannelRequest) error
|
|
|
|
releaseCollection(ctx context.Context, nodeID int64, in *querypb.ReleaseCollectionRequest) error
|
|
|
|
releasePartitions(ctx context.Context, nodeID int64, in *querypb.ReleasePartitionsRequest) error
|
|
|
|
getSegmentInfo(ctx context.Context, in *querypb.GetSegmentInfoRequest) ([]*querypb.SegmentInfo, error)
|
2021-11-05 16:00:55 +08:00
|
|
|
getSegmentInfoByNode(ctx context.Context, nodeID int64, in *querypb.GetSegmentInfoRequest) ([]*querypb.SegmentInfo, error)
|
2021-11-12 18:49:10 +08:00
|
|
|
getSegmentInfoByID(ctx context.Context, segmentID UniqueID) (*querypb.SegmentInfo, error)
|
2021-08-02 22:39:25 +08:00
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
registerNode(ctx context.Context, session *sessionutil.Session, id UniqueID, state nodeState) error
|
2021-11-05 16:00:55 +08:00
|
|
|
getNodeInfoByID(nodeID int64) (Node, error)
|
2021-08-02 22:39:25 +08:00
|
|
|
removeNodeInfo(nodeID int64) error
|
|
|
|
stopNode(nodeID int64)
|
2021-12-21 11:57:39 +08:00
|
|
|
onlineNodeIDs() []int64
|
2021-09-15 20:40:07 +08:00
|
|
|
isOnline(nodeID int64) (bool, error)
|
2021-12-21 11:57:39 +08:00
|
|
|
offlineNodeIDs() []int64
|
2021-11-05 16:00:55 +08:00
|
|
|
hasNode(nodeID int64) bool
|
2021-08-02 22:39:25 +08:00
|
|
|
|
2021-11-12 18:49:10 +08:00
|
|
|
allocateSegmentsToQueryNode(ctx context.Context, reqs []*querypb.LoadSegmentsRequest, wait bool, excludeNodeIDs []int64, includeNodeIDs []int64) error
|
2021-11-11 12:56:42 +08:00
|
|
|
allocateChannelsToQueryNode(ctx context.Context, reqs []*querypb.WatchDmChannelsRequest, wait bool, excludeNodeIDs []int64) error
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
getSessionVersion() int64
|
|
|
|
|
|
|
|
getMetrics(ctx context.Context, in *milvuspb.GetMetricsRequest) []queryNodeGetMetricsResponse
|
2021-11-17 09:47:12 +08:00
|
|
|
estimateSegmentsSize(segments *querypb.LoadSegmentsRequest) (int64, error)
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
type newQueryNodeFn func(ctx context.Context, address string, id UniqueID, kv *etcdkv.EtcdKV) (Node, error)
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
type nodeState int
|
|
|
|
|
|
|
|
const (
|
|
|
|
disConnect nodeState = 0
|
|
|
|
online nodeState = 1
|
|
|
|
offline nodeState = 2
|
|
|
|
)
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
type queryNodeCluster struct {
|
2021-09-15 20:40:07 +08:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
2021-06-19 11:45:09 +08:00
|
|
|
client *etcdkv.EtcdKV
|
2021-11-17 09:47:12 +08:00
|
|
|
dataKV kv.DataKV
|
2021-06-19 11:45:09 +08:00
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
session *sessionutil.Session
|
|
|
|
sessionVersion int64
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
sync.RWMutex
|
2021-11-11 12:56:42 +08:00
|
|
|
clusterMeta Meta
|
|
|
|
nodes map[int64]Node
|
|
|
|
newNodeFn newQueryNodeFn
|
|
|
|
segmentAllocator SegmentAllocatePolicy
|
|
|
|
channelAllocator ChannelAllocatePolicy
|
2021-11-17 09:47:12 +08:00
|
|
|
segSizeEstimator func(request *querypb.LoadSegmentsRequest, dataKV kv.DataKV) (int64, error)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-11-05 16:00:55 +08:00
|
|
|
func newQueryNodeCluster(ctx context.Context, clusterMeta Meta, kv *etcdkv.EtcdKV, newNodeFn newQueryNodeFn, session *sessionutil.Session) (Cluster, error) {
|
2021-09-15 20:40:07 +08:00
|
|
|
childCtx, cancel := context.WithCancel(ctx)
|
2021-08-02 22:39:25 +08:00
|
|
|
nodes := make(map[int64]Node)
|
2021-06-19 11:45:09 +08:00
|
|
|
c := &queryNodeCluster{
|
2021-11-11 12:56:42 +08:00
|
|
|
ctx: childCtx,
|
|
|
|
cancel: cancel,
|
|
|
|
client: kv,
|
|
|
|
session: session,
|
|
|
|
clusterMeta: clusterMeta,
|
|
|
|
nodes: nodes,
|
|
|
|
newNodeFn: newNodeFn,
|
|
|
|
segmentAllocator: defaultSegAllocatePolicy(),
|
|
|
|
channelAllocator: defaultChannelAllocatePolicy(),
|
2021-11-17 09:47:12 +08:00
|
|
|
segSizeEstimator: defaultSegEstimatePolicy(),
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-06-19 11:45:09 +08:00
|
|
|
err := c.reloadFromKV()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-11-17 09:47:12 +08:00
|
|
|
option := &minioKV.Option{
|
2021-12-23 18:39:11 +08:00
|
|
|
Address: Params.QueryCoordCfg.MinioEndPoint,
|
|
|
|
AccessKeyID: Params.QueryCoordCfg.MinioAccessKeyID,
|
|
|
|
SecretAccessKeyID: Params.QueryCoordCfg.MinioSecretAccessKey,
|
|
|
|
UseSSL: Params.QueryCoordCfg.MinioUseSSLStr,
|
2021-11-17 09:47:12 +08:00
|
|
|
CreateBucket: true,
|
2021-12-23 18:39:11 +08:00
|
|
|
BucketName: Params.QueryCoordCfg.MinioBucketName,
|
2021-11-17 09:47:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c.dataKV, err = minioKV.NewMinIOKV(ctx, option)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 21:03:55 +08:00
|
|
|
// Reload trigger task, trigger task states, internal task, internal task state from etcd
|
|
|
|
// Assign the internal task to the corresponding trigger task as a child task
|
2021-06-19 11:45:09 +08:00
|
|
|
func (c *queryNodeCluster) reloadFromKV() error {
|
2021-09-15 20:40:07 +08:00
|
|
|
toLoadMetaNodeIDs := make([]int64, 0)
|
|
|
|
// get current online session
|
|
|
|
onlineNodeSessions, version, _ := c.session.GetSessions(typeutil.QueryNodeRole)
|
|
|
|
onlineSessionMap := make(map[int64]*sessionutil.Session)
|
|
|
|
for _, session := range onlineNodeSessions {
|
|
|
|
nodeID := session.ServerID
|
|
|
|
onlineSessionMap[nodeID] = session
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-09-15 20:40:07 +08:00
|
|
|
for nodeID, session := range onlineSessionMap {
|
2021-12-06 10:05:41 +08:00
|
|
|
log.Debug("reloadFromKV: register a queryNode to cluster", zap.Any("nodeID", nodeID))
|
2021-09-15 20:40:07 +08:00
|
|
|
err := c.registerNode(c.ctx, session, nodeID, disConnect)
|
2021-06-19 11:45:09 +08:00
|
|
|
if err != nil {
|
2021-12-21 21:23:19 +08:00
|
|
|
log.Error("QueryNode failed to register", zap.Int64("nodeID", nodeID), zap.String("error info", err.Error()))
|
2021-06-19 11:45:09 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-09-15 20:40:07 +08:00
|
|
|
toLoadMetaNodeIDs = append(toLoadMetaNodeIDs, nodeID)
|
|
|
|
}
|
|
|
|
c.sessionVersion = version
|
2021-06-26 22:28:10 +08:00
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
// load node information before power off from etcd
|
|
|
|
oldStringNodeIDs, oldNodeSessions, err := c.client.LoadWithPrefix(queryNodeInfoPrefix)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("reloadFromKV: get previous node info from etcd error", zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for index := range oldStringNodeIDs {
|
|
|
|
nodeID, err := strconv.ParseInt(filepath.Base(oldStringNodeIDs[index]), 10, 64)
|
2021-06-19 11:45:09 +08:00
|
|
|
if err != nil {
|
2021-12-06 10:05:41 +08:00
|
|
|
log.Error("watchNodeLoop: parse nodeID error", zap.Error(err))
|
2021-06-19 11:45:09 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-09-15 20:40:07 +08:00
|
|
|
if _, ok := onlineSessionMap[nodeID]; !ok {
|
|
|
|
session := &sessionutil.Session{}
|
|
|
|
err = json.Unmarshal([]byte(oldNodeSessions[index]), session)
|
|
|
|
if err != nil {
|
2021-12-06 10:05:41 +08:00
|
|
|
log.Error("watchNodeLoop: unmarshal session error", zap.Error(err))
|
2021-09-15 20:40:07 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = c.registerNode(context.Background(), session, nodeID, offline)
|
|
|
|
if err != nil {
|
2021-12-06 10:05:41 +08:00
|
|
|
log.Debug("reloadFromKV: failed to add queryNode to cluster", zap.Int64("nodeID", nodeID), zap.String("error info", err.Error()))
|
2021-09-15 20:40:07 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
toLoadMetaNodeIDs = append(toLoadMetaNodeIDs, nodeID)
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
}
|
2021-09-15 20:40:07 +08:00
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
func (c *queryNodeCluster) getSessionVersion() int64 {
|
|
|
|
return c.sessionVersion
|
|
|
|
}
|
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
func (c *queryNodeCluster) getComponentInfos(ctx context.Context) []*internalpb.ComponentInfo {
|
2021-06-15 12:41:40 +08:00
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
2021-12-21 11:57:39 +08:00
|
|
|
var subComponentInfos []*internalpb.ComponentInfo
|
|
|
|
for _, node := range c.nodes {
|
2021-08-02 22:39:25 +08:00
|
|
|
componentState := node.getComponentInfo(ctx)
|
|
|
|
subComponentInfos = append(subComponentInfos, componentState)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
return subComponentInfos
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (c *queryNodeCluster) loadSegments(ctx context.Context, nodeID int64, in *querypb.LoadSegmentsRequest) error {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
var targetNode Node
|
2021-06-15 12:41:40 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-11-17 23:37:11 +08:00
|
|
|
targetNode = node
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
if targetNode != nil {
|
|
|
|
err := targetNode.loadSegments(ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
2021-11-16 09:31:24 +08:00
|
|
|
log.Debug("loadSegments: queryNode load segments error", zap.Int64("nodeID", nodeID), zap.String("error info", err.Error()))
|
2021-08-02 22:39:25 +08:00
|
|
|
return err
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-10-22 19:07:15 +08:00
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-12-17 22:32:42 +08:00
|
|
|
return fmt.Errorf("loadSegments: can't find QueryNode by nodeID, nodeID = %d", nodeID)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (c *queryNodeCluster) releaseSegments(ctx context.Context, nodeID int64, in *querypb.ReleaseSegmentsRequest) error {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
var targetNode Node
|
2021-06-15 12:41:40 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-11-17 23:37:11 +08:00
|
|
|
targetNode = node
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
if targetNode != nil {
|
|
|
|
if !targetNode.isOnline() {
|
2021-08-02 22:39:25 +08:00
|
|
|
return errors.New("node offline")
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
|
2021-11-17 23:37:11 +08:00
|
|
|
err := targetNode.releaseSegments(ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
2021-11-16 09:33:20 +08:00
|
|
|
log.Debug("releaseSegments: queryNode release segments error", zap.Int64("nodeID", nodeID), zap.String("error info", err.Error()))
|
2021-08-02 22:39:25 +08:00
|
|
|
return err
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-12-21 21:25:15 +08:00
|
|
|
return fmt.Errorf("releaseSegments: can't find QueryNode by nodeID, nodeID = %d", nodeID)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (c *queryNodeCluster) watchDmChannels(ctx context.Context, nodeID int64, in *querypb.WatchDmChannelsRequest) error {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
var targetNode Node
|
2021-06-15 12:41:40 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-11-17 23:37:11 +08:00
|
|
|
targetNode = node
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
if targetNode != nil {
|
|
|
|
err := targetNode.watchDmChannels(ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
2021-11-16 09:35:14 +08:00
|
|
|
log.Debug("watchDmChannels: queryNode watch dm channel error", zap.String("error", err.Error()))
|
2021-08-02 22:39:25 +08:00
|
|
|
return err
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-12-21 11:57:39 +08:00
|
|
|
dmChannelWatchInfo := make([]*querypb.DmChannelWatchInfo, len(in.Infos))
|
|
|
|
for index, info := range in.Infos {
|
|
|
|
dmChannelWatchInfo[index] = &querypb.DmChannelWatchInfo{
|
|
|
|
CollectionID: info.CollectionID,
|
|
|
|
DmChannel: info.ChannelName,
|
|
|
|
NodeIDLoaded: nodeID,
|
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-06-19 11:45:09 +08:00
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
err = c.clusterMeta.setDmChannelInfos(dmChannelWatchInfo)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
2021-12-21 11:57:39 +08:00
|
|
|
log.Debug("watchDmChannels: update dmChannelWatchInfos to meta failed", zap.String("error", err.Error()))
|
2021-08-02 22:39:25 +08:00
|
|
|
return err
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-12-24 19:39:03 +08:00
|
|
|
return fmt.Errorf("watchDmChannels: can't find QueryNode by nodeID, nodeID = %d", nodeID)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-11-05 14:47:19 +08:00
|
|
|
func (c *queryNodeCluster) watchDeltaChannels(ctx context.Context, nodeID int64, in *querypb.WatchDeltaChannelsRequest) error {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
var targetNode Node
|
2021-11-05 14:47:19 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-11-17 23:37:11 +08:00
|
|
|
targetNode = node
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
if targetNode != nil {
|
|
|
|
err := targetNode.watchDeltaChannels(ctx, in)
|
2021-11-05 14:47:19 +08:00
|
|
|
if err != nil {
|
2021-11-17 23:37:11 +08:00
|
|
|
log.Debug("watchDeltaChannels: queryNode watch delta channel error", zap.String("error", err.Error()))
|
2021-11-05 14:47:19 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-11-13 08:49:08 +08:00
|
|
|
|
2021-11-05 14:47:19 +08:00
|
|
|
return nil
|
|
|
|
}
|
2021-11-17 23:37:11 +08:00
|
|
|
|
2021-12-21 21:27:09 +08:00
|
|
|
return fmt.Errorf("watchDeltaChannels: can't find QueryNode by nodeID, nodeID = %d", nodeID)
|
2021-11-05 14:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-11-13 08:49:08 +08:00
|
|
|
func (c *queryNodeCluster) hasWatchedDeltaChannel(ctx context.Context, nodeID int64, collectionID UniqueID) bool {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
2021-11-13 08:49:08 +08:00
|
|
|
|
|
|
|
return c.nodes[nodeID].hasWatchedDeltaChannel(collectionID)
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
func (c *queryNodeCluster) hasWatchedQueryChannel(ctx context.Context, nodeID int64, collectionID UniqueID) bool {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
2021-06-15 12:41:40 +08:00
|
|
|
|
|
|
|
return c.nodes[nodeID].hasWatchedQueryChannel(collectionID)
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (c *queryNodeCluster) addQueryChannel(ctx context.Context, nodeID int64, in *querypb.AddQueryChannelRequest) error {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
var targetNode Node
|
2021-06-15 12:41:40 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-11-17 23:37:11 +08:00
|
|
|
targetNode = node
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
if targetNode != nil {
|
2021-12-21 13:50:54 +08:00
|
|
|
emptyChangeInfo := &querypb.SealedSegmentsChangeInfo{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_SealedSegmentsChangeInfo,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msgPosition, err := c.clusterMeta.sendSealedSegmentChangeInfos(in.CollectionID, in.QueryChannel, emptyChangeInfo)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("addQueryChannel: get latest messageID of query channel error", zap.String("queryChannel", in.QueryChannel), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// update watch position to latest
|
|
|
|
in.SeekPosition = msgPosition
|
|
|
|
err = targetNode.addQueryChannel(ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
2021-12-21 13:50:54 +08:00
|
|
|
log.Error("addQueryChannel: queryNode add query channel error", zap.String("queryChannel", in.QueryChannel), zap.Error(err))
|
2021-08-02 22:39:25 +08:00
|
|
|
return err
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 21:46:45 +08:00
|
|
|
return fmt.Errorf("addQueryChannel: can't find QueryNode by nodeID, nodeID = %d", nodeID)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
func (c *queryNodeCluster) removeQueryChannel(ctx context.Context, nodeID int64, in *querypb.RemoveQueryChannelRequest) error {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
var targetNode Node
|
2021-06-15 12:41:40 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-11-17 23:37:11 +08:00
|
|
|
targetNode = node
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
if targetNode != nil {
|
|
|
|
err := targetNode.removeQueryChannel(ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
2021-11-16 21:53:13 +08:00
|
|
|
log.Debug("removeQueryChannel: queryNode remove query channel error", zap.String("error", err.Error()))
|
2021-08-02 22:39:25 +08:00
|
|
|
return err
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-12-22 21:01:19 +08:00
|
|
|
return fmt.Errorf("removeQueryChannel: can't find QueryNode by nodeID, nodeID = %d", nodeID)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (c *queryNodeCluster) releaseCollection(ctx context.Context, nodeID int64, in *querypb.ReleaseCollectionRequest) error {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
var targetNode Node
|
2021-06-15 12:41:40 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-11-17 23:37:11 +08:00
|
|
|
targetNode = node
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
if targetNode != nil {
|
|
|
|
err := targetNode.releaseCollection(ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
2021-11-29 21:15:49 +08:00
|
|
|
log.Debug("releaseCollection: queryNode release collection error", zap.String("error", err.Error()))
|
2021-08-02 22:39:25 +08:00
|
|
|
return err
|
2021-07-13 14:16:00 +08:00
|
|
|
}
|
2021-12-21 11:57:39 +08:00
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-12-23 21:56:22 +08:00
|
|
|
return fmt.Errorf("releaseCollection: can't find QueryNode by nodeID, nodeID = %d", nodeID)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (c *queryNodeCluster) releasePartitions(ctx context.Context, nodeID int64, in *querypb.ReleasePartitionsRequest) error {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
var targetNode Node
|
2021-06-15 12:41:40 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-11-17 23:37:11 +08:00
|
|
|
targetNode = node
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
if targetNode != nil {
|
|
|
|
err := targetNode.releasePartitions(ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
2021-11-29 21:17:46 +08:00
|
|
|
log.Debug("releasePartitions: queryNode release partitions error", zap.String("error", err.Error()))
|
2021-08-02 22:39:25 +08:00
|
|
|
return err
|
2021-07-13 14:16:00 +08:00
|
|
|
}
|
2021-10-11 09:54:37 +08:00
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-11-29 21:17:46 +08:00
|
|
|
return fmt.Errorf("releasePartitions: can't find query node by nodeID, nodeID = %d", nodeID)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-11-12 18:49:10 +08:00
|
|
|
func (c *queryNodeCluster) getSegmentInfoByID(ctx context.Context, segmentID UniqueID) (*querypb.SegmentInfo, error) {
|
2021-12-13 21:51:10 +08:00
|
|
|
segmentInfo, err := c.clusterMeta.getSegmentInfoByID(segmentID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-11-12 18:49:10 +08:00
|
|
|
c.RLock()
|
2021-12-13 21:51:10 +08:00
|
|
|
targetNode, ok := c.nodes[segmentInfo.NodeID]
|
|
|
|
c.RUnlock()
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("updateSegmentInfo: can't find query node by nodeID, nodeID = %d", segmentInfo.NodeID)
|
|
|
|
}
|
2021-11-12 18:49:10 +08:00
|
|
|
|
2021-12-13 21:51:10 +08:00
|
|
|
res, err := targetNode.getSegmentInfo(ctx, &querypb.GetSegmentInfoRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_SegmentInfo,
|
|
|
|
},
|
|
|
|
CollectionID: segmentInfo.CollectionID,
|
|
|
|
})
|
2021-11-12 18:49:10 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-12-13 21:51:10 +08:00
|
|
|
|
|
|
|
// protobuf convention, it's ok to call GetXXX on nil
|
|
|
|
for _, info := range res.GetInfos() {
|
|
|
|
if info.GetSegmentID() == segmentID {
|
|
|
|
return info, nil
|
2021-11-12 18:49:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-23 21:58:14 +08:00
|
|
|
return nil, fmt.Errorf("updateSegmentInfo: can't find segment %d on QueryNode %d", segmentID, segmentInfo.NodeID)
|
2021-11-12 18:49:10 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
func (c *queryNodeCluster) getSegmentInfo(ctx context.Context, in *querypb.GetSegmentInfoRequest) ([]*querypb.SegmentInfo, error) {
|
2021-12-13 21:51:10 +08:00
|
|
|
|
|
|
|
type respTuple struct {
|
|
|
|
res *querypb.GetSegmentInfoResponse
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2021-07-13 14:16:00 +08:00
|
|
|
c.RLock()
|
2021-12-13 21:51:10 +08:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
cnt := len(c.nodes)
|
|
|
|
resChan := make(chan respTuple, cnt)
|
|
|
|
wg.Add(cnt)
|
2021-06-15 12:41:40 +08:00
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
for _, node := range c.nodes {
|
2021-12-13 21:51:10 +08:00
|
|
|
go func(node Node) {
|
|
|
|
defer wg.Done()
|
|
|
|
res, err := node.getSegmentInfo(ctx, in)
|
|
|
|
resChan <- respTuple{
|
|
|
|
res: res,
|
|
|
|
err: err,
|
|
|
|
}
|
|
|
|
}(node)
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
wg.Wait()
|
|
|
|
close(resChan)
|
|
|
|
var segmentInfos []*querypb.SegmentInfo
|
|
|
|
|
|
|
|
for tuple := range resChan {
|
|
|
|
if tuple.err != nil {
|
|
|
|
return nil, tuple.err
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
2021-12-13 21:51:10 +08:00
|
|
|
segmentInfos = append(segmentInfos, tuple.res.GetInfos()...)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
//TODO::update meta
|
2021-06-15 12:41:40 +08:00
|
|
|
return segmentInfos, nil
|
|
|
|
}
|
|
|
|
|
2021-11-05 16:00:55 +08:00
|
|
|
func (c *queryNodeCluster) getSegmentInfoByNode(ctx context.Context, nodeID int64, in *querypb.GetSegmentInfoRequest) ([]*querypb.SegmentInfo, error) {
|
|
|
|
c.RLock()
|
2021-12-13 21:51:10 +08:00
|
|
|
node, ok := c.nodes[nodeID]
|
|
|
|
c.RUnlock()
|
2021-11-05 16:00:55 +08:00
|
|
|
|
2021-12-13 21:51:10 +08:00
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("getSegmentInfoByNode: can't find query node by nodeID, nodeID = %d", nodeID)
|
2021-11-05 16:00:55 +08:00
|
|
|
}
|
2021-12-13 21:51:10 +08:00
|
|
|
res, err := node.getSegmentInfo(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return res.GetInfos(), nil
|
2021-11-05 16:00:55 +08:00
|
|
|
}
|
|
|
|
|
2021-08-17 10:06:11 +08:00
|
|
|
type queryNodeGetMetricsResponse struct {
|
|
|
|
resp *milvuspb.GetMetricsResponse
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *queryNodeCluster) getMetrics(ctx context.Context, in *milvuspb.GetMetricsRequest) []queryNodeGetMetricsResponse {
|
|
|
|
c.RLock()
|
2021-12-13 21:51:10 +08:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
cnt := len(c.nodes)
|
|
|
|
wg.Add(cnt)
|
|
|
|
respChan := make(chan queryNodeGetMetricsResponse, cnt)
|
2021-08-17 10:06:11 +08:00
|
|
|
for _, node := range c.nodes {
|
2021-12-13 21:51:10 +08:00
|
|
|
go func(node Node) {
|
|
|
|
defer wg.Done()
|
|
|
|
resp, err := node.getMetrics(ctx, in)
|
|
|
|
respChan <- queryNodeGetMetricsResponse{
|
|
|
|
resp: resp,
|
|
|
|
err: err,
|
|
|
|
}
|
|
|
|
}(node)
|
|
|
|
}
|
|
|
|
c.RUnlock()
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
close(respChan)
|
|
|
|
|
|
|
|
ret := make([]queryNodeGetMetricsResponse, 0, cnt)
|
|
|
|
for res := range respChan {
|
|
|
|
ret = append(ret, res)
|
2021-08-17 10:06:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
func (c *queryNodeCluster) registerNode(ctx context.Context, session *sessionutil.Session, id UniqueID, state nodeState) error {
|
2021-06-19 11:45:09 +08:00
|
|
|
c.Lock()
|
|
|
|
defer c.Unlock()
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
if _, ok := c.nodes[id]; !ok {
|
2021-07-13 14:16:00 +08:00
|
|
|
sessionJSON, err := json.Marshal(session)
|
|
|
|
if err != nil {
|
2021-11-30 21:21:39 +08:00
|
|
|
log.Debug("registerNode: marshal session error", zap.Int64("nodeID", id), zap.Any("address", session))
|
2021-07-13 14:16:00 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
key := fmt.Sprintf("%s/%d", queryNodeInfoPrefix, id)
|
|
|
|
err = c.client.Save(key, string(sessionJSON))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-09-15 20:40:07 +08:00
|
|
|
node, err := c.newNodeFn(ctx, session.Address, id, c.client)
|
2021-08-26 14:17:54 +08:00
|
|
|
if err != nil {
|
2021-11-30 21:21:39 +08:00
|
|
|
log.Debug("registerNode: create a new query node failed", zap.Int64("nodeID", id), zap.Error(err))
|
2021-08-26 14:17:54 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-09-15 20:40:07 +08:00
|
|
|
node.setState(state)
|
|
|
|
if state < online {
|
|
|
|
go node.start()
|
|
|
|
}
|
|
|
|
c.nodes[id] = node
|
2021-12-17 21:30:42 +08:00
|
|
|
log.Debug("registerNode: create a new query node", zap.Int64("nodeID", id), zap.String("address", session.Address), zap.Any("state", state))
|
2021-06-15 12:41:40 +08:00
|
|
|
return nil
|
|
|
|
}
|
2021-11-30 21:21:39 +08:00
|
|
|
return fmt.Errorf("registerNode: node %d alredy exists in cluster", id)
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
2021-06-19 11:45:09 +08:00
|
|
|
|
2021-11-05 16:00:55 +08:00
|
|
|
func (c *queryNodeCluster) getNodeInfoByID(nodeID int64) (Node, error) {
|
2021-06-30 17:48:19 +08:00
|
|
|
c.RLock()
|
2021-12-13 21:51:10 +08:00
|
|
|
node, ok := c.nodes[nodeID]
|
|
|
|
c.RUnlock()
|
|
|
|
if !ok {
|
2021-12-23 22:02:07 +08:00
|
|
|
return nil, fmt.Errorf("getNodeInfoByID: QueryNode %d not exist", nodeID)
|
2021-06-30 17:48:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-13 21:51:10 +08:00
|
|
|
nodeInfo, err := node.getNodeInfo()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return nodeInfo, nil
|
2021-06-30 17:48:19 +08:00
|
|
|
}
|
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
func (c *queryNodeCluster) removeNodeInfo(nodeID int64) error {
|
2021-06-22 14:10:09 +08:00
|
|
|
c.Lock()
|
|
|
|
defer c.Unlock()
|
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
key := fmt.Sprintf("%s/%d", queryNodeInfoPrefix, nodeID)
|
2021-06-22 14:10:09 +08:00
|
|
|
err := c.client.Remove(key)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
delete(c.nodes, nodeID)
|
|
|
|
log.Debug("removeNodeInfo: delete nodeInfo in cluster MetaReplica", zap.Int64("nodeID", nodeID))
|
2021-06-22 14:10:09 +08:00
|
|
|
|
|
|
|
return nil
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-07-13 14:16:00 +08:00
|
|
|
func (c *queryNodeCluster) stopNode(nodeID int64) {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
2021-08-26 14:17:54 +08:00
|
|
|
|
2021-07-13 14:16:00 +08:00
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
|
|
|
node.stop()
|
2021-12-01 22:01:33 +08:00
|
|
|
log.Debug("stopNode: queryNode offline", zap.Int64("nodeID", nodeID))
|
2021-07-13 14:16:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
func (c *queryNodeCluster) onlineNodeIDs() []int64 {
|
2021-06-30 17:48:19 +08:00
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
2021-06-19 11:45:09 +08:00
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
var onlineNodeIDs []int64
|
2021-06-19 11:45:09 +08:00
|
|
|
for nodeID, node := range c.nodes {
|
2021-09-15 20:40:07 +08:00
|
|
|
if node.isOnline() {
|
2021-12-21 11:57:39 +08:00
|
|
|
onlineNodeIDs = append(onlineNodeIDs, nodeID)
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
return onlineNodeIDs
|
2021-06-30 17:48:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
func (c *queryNodeCluster) offlineNodeIDs() []int64 {
|
2021-09-15 20:40:07 +08:00
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
var offlineNodeIDs []int64
|
|
|
|
for nodeID, node := range c.nodes {
|
|
|
|
if node.isOffline() {
|
|
|
|
offlineNodeIDs = append(offlineNodeIDs, nodeID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offlineNodeIDs
|
2021-09-15 20:40:07 +08:00
|
|
|
}
|
|
|
|
|
2021-11-05 16:00:55 +08:00
|
|
|
func (c *queryNodeCluster) hasNode(nodeID int64) bool {
|
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
|
|
|
|
|
|
|
if _, ok := c.nodes[nodeID]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
func (c *queryNodeCluster) isOnline(nodeID int64) (bool, error) {
|
2021-11-17 23:37:11 +08:00
|
|
|
c.RLock()
|
|
|
|
defer c.RUnlock()
|
2021-06-30 17:48:19 +08:00
|
|
|
|
|
|
|
if node, ok := c.nodes[nodeID]; ok {
|
2021-09-15 20:40:07 +08:00
|
|
|
return node.isOnline(), nil
|
2021-06-30 17:48:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-24 19:37:12 +08:00
|
|
|
return false, fmt.Errorf("isOnline: QueryNode %d not exist", nodeID)
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
//func (c *queryNodeCluster) printMeta() {
|
|
|
|
// c.RLock()
|
|
|
|
// defer c.RUnlock()
|
|
|
|
//
|
|
|
|
// for id, node := range c.nodes {
|
|
|
|
// if node.isOnline() {
|
|
|
|
// collectionInfos := node.showCollections()
|
|
|
|
// for _, info := range collectionInfos {
|
|
|
|
// log.Debug("PrintMeta: query coordinator cluster info: collectionInfo", zap.Int64("nodeID", id), zap.Int64("collectionID", info.CollectionID), zap.Any("info", info))
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// queryChannelInfos := node.showWatchedQueryChannels()
|
|
|
|
// for _, info := range queryChannelInfos {
|
|
|
|
// log.Debug("PrintMeta: query coordinator cluster info: watchedQueryChannelInfo", zap.Int64("nodeID", id), zap.Int64("collectionID", info.CollectionID), zap.Any("info", info))
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
2021-08-02 22:39:25 +08:00
|
|
|
|
2021-11-12 18:49:10 +08:00
|
|
|
func (c *queryNodeCluster) allocateSegmentsToQueryNode(ctx context.Context, reqs []*querypb.LoadSegmentsRequest, wait bool, excludeNodeIDs []int64, includeNodeIDs []int64) error {
|
2021-12-21 11:57:39 +08:00
|
|
|
return c.segmentAllocator(ctx, reqs, c, c.clusterMeta, wait, excludeNodeIDs, includeNodeIDs)
|
2021-11-11 12:56:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *queryNodeCluster) allocateChannelsToQueryNode(ctx context.Context, reqs []*querypb.WatchDmChannelsRequest, wait bool, excludeNodeIDs []int64) error {
|
2021-12-21 11:57:39 +08:00
|
|
|
return c.channelAllocator(ctx, reqs, c, c.clusterMeta, wait, excludeNodeIDs)
|
2021-11-11 12:56:42 +08:00
|
|
|
}
|
2021-11-17 09:47:12 +08:00
|
|
|
|
|
|
|
func (c *queryNodeCluster) estimateSegmentsSize(segments *querypb.LoadSegmentsRequest) (int64, error) {
|
|
|
|
return c.segSizeEstimator(segments, c.dataKV)
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultSegEstimatePolicy() segEstimatePolicy {
|
|
|
|
return estimateSegmentsSize
|
|
|
|
}
|
|
|
|
|
|
|
|
type segEstimatePolicy func(request *querypb.LoadSegmentsRequest, dataKv kv.DataKV) (int64, error)
|
|
|
|
|
|
|
|
func estimateSegmentsSize(segments *querypb.LoadSegmentsRequest, kvClient kv.DataKV) (int64, error) {
|
|
|
|
segmentSize := int64(0)
|
|
|
|
|
|
|
|
//TODO:: collection has multi vector field
|
|
|
|
//vecFields := make([]int64, 0)
|
|
|
|
//for _, field := range segments.Schema.Fields {
|
|
|
|
// if field.DataType == schemapb.DataType_BinaryVector || field.DataType == schemapb.DataType_FloatVector {
|
|
|
|
// vecFields = append(vecFields, field.FieldID)
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
// get fields data size, if len(indexFieldIDs) == 0, vector field would be involved in fieldBinLogs
|
|
|
|
for _, loadInfo := range segments.Infos {
|
|
|
|
// get index size
|
|
|
|
if loadInfo.EnableIndex {
|
|
|
|
for _, pathInfo := range loadInfo.IndexPathInfos {
|
2021-12-22 20:27:34 +08:00
|
|
|
segmentSize += int64(pathInfo.GetSerializedSize())
|
2021-11-17 09:47:12 +08:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// get binlog size
|
|
|
|
for _, binlogPath := range loadInfo.BinlogPaths {
|
2021-12-21 20:01:03 +08:00
|
|
|
for _, binlog := range binlogPath.Binlogs {
|
|
|
|
segmentSize += binlog.GetLogSize()
|
2021-11-17 09:47:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return segmentSize, nil
|
|
|
|
}
|