2021-06-15 12:41:40 +08:00
|
|
|
//// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
////
|
|
|
|
//// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
//// with the License. You may obtain a copy of the License at
|
|
|
|
////
|
|
|
|
//// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
////
|
|
|
|
//// 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-04-19 13:47:10 +08:00
|
|
|
//
|
2021-06-22 16:44:09 +08:00
|
|
|
package querycoord
|
2021-01-26 15:13:20 +08:00
|
|
|
|
|
|
|
import (
|
2021-06-23 09:24:10 +08:00
|
|
|
"context"
|
2021-06-15 12:41:40 +08:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-03-25 04:40:59 +08:00
|
|
|
"sync"
|
2021-02-26 17:44:24 +08:00
|
|
|
|
2021-08-17 10:06:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
nodeclient "github.com/milvus-io/milvus/internal/distributed/querynode/client"
|
2021-06-19 11:45:09 +08:00
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-08-02 22:39:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-06-15 12:41:40 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-01-26 15:13:20 +08:00
|
|
|
)
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
type Node interface {
|
|
|
|
start() error
|
|
|
|
stop()
|
|
|
|
clearNodeInfo() error
|
|
|
|
|
|
|
|
addCollection(collectionID UniqueID, schema *schemapb.CollectionSchema) error
|
|
|
|
setCollectionInfo(info *querypb.CollectionInfo) error
|
|
|
|
showCollections() []*querypb.CollectionInfo
|
|
|
|
releaseCollection(ctx context.Context, in *querypb.ReleaseCollectionRequest) error
|
|
|
|
|
|
|
|
addPartition(collectionID UniqueID, partitionID UniqueID) error
|
|
|
|
releasePartitions(ctx context.Context, in *querypb.ReleasePartitionsRequest) error
|
|
|
|
|
|
|
|
watchDmChannels(ctx context.Context, in *querypb.WatchDmChannelsRequest) error
|
|
|
|
removeDmChannel(collectionID UniqueID, channels []string) error
|
|
|
|
|
|
|
|
hasWatchedQueryChannel(collectionID UniqueID) bool
|
|
|
|
showWatchedQueryChannels() []*querypb.QueryChannelInfo
|
|
|
|
addQueryChannel(ctx context.Context, in *querypb.AddQueryChannelRequest) error
|
|
|
|
removeQueryChannel(ctx context.Context, in *querypb.RemoveQueryChannelRequest) error
|
|
|
|
|
|
|
|
setNodeState(onService bool)
|
|
|
|
isOnService() bool
|
|
|
|
|
|
|
|
getSegmentInfo(ctx context.Context, in *querypb.GetSegmentInfoRequest) (*querypb.GetSegmentInfoResponse, error)
|
|
|
|
loadSegments(ctx context.Context, in *querypb.LoadSegmentsRequest) error
|
|
|
|
releaseSegments(ctx context.Context, in *querypb.ReleaseSegmentsRequest) error
|
|
|
|
getComponentInfo(ctx context.Context) *internalpb.ComponentInfo
|
2021-08-17 10:06:11 +08:00
|
|
|
|
|
|
|
getMetrics(ctx context.Context, in *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error)
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
type queryNode struct {
|
2021-07-13 14:16:00 +08:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
2021-06-19 11:45:09 +08:00
|
|
|
id int64
|
|
|
|
address string
|
|
|
|
client types.QueryNode
|
|
|
|
kvClient *etcdkv.EtcdKV
|
2021-03-25 04:40:59 +08:00
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
sync.RWMutex
|
|
|
|
collectionInfos map[UniqueID]*querypb.CollectionInfo
|
|
|
|
watchedQueryChannels map[UniqueID]*querypb.QueryChannelInfo
|
2021-06-19 11:45:09 +08:00
|
|
|
onService bool
|
2021-08-02 22:39:25 +08:00
|
|
|
serviceLock sync.RWMutex
|
2021-01-26 15:13:20 +08:00
|
|
|
}
|
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
func newQueryNode(ctx context.Context, address string, id UniqueID, kv *etcdkv.EtcdKV) (Node, error) {
|
2021-06-15 12:41:40 +08:00
|
|
|
collectionInfo := make(map[UniqueID]*querypb.CollectionInfo)
|
|
|
|
watchedChannels := make(map[UniqueID]*querypb.QueryChannelInfo)
|
2021-07-13 14:16:00 +08:00
|
|
|
childCtx, cancel := context.WithCancel(ctx)
|
2021-08-26 14:17:54 +08:00
|
|
|
client, err := nodeclient.NewClient(childCtx, address)
|
|
|
|
if err != nil {
|
|
|
|
cancel()
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-13 14:16:00 +08:00
|
|
|
node := &queryNode{
|
|
|
|
ctx: childCtx,
|
|
|
|
cancel: cancel,
|
2021-06-19 11:45:09 +08:00
|
|
|
id: id,
|
|
|
|
address: address,
|
2021-08-26 14:17:54 +08:00
|
|
|
client: client,
|
2021-06-19 11:45:09 +08:00
|
|
|
kvClient: kv,
|
2021-06-15 12:41:40 +08:00
|
|
|
collectionInfos: collectionInfo,
|
|
|
|
watchedQueryChannels: watchedChannels,
|
2021-07-13 14:16:00 +08:00
|
|
|
onService: false,
|
|
|
|
}
|
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
return node, nil
|
2021-07-13 14:16:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) start() error {
|
2021-08-26 14:17:54 +08:00
|
|
|
if err := qn.client.Init(); err != nil {
|
2021-07-13 14:16:00 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-08-26 14:17:54 +08:00
|
|
|
if err := qn.client.Start(); err != nil {
|
2021-07-13 14:16:00 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-16 10:21:55 +08:00
|
|
|
qn.serviceLock.Lock()
|
2021-07-13 14:16:00 +08:00
|
|
|
qn.onService = true
|
2021-07-16 10:21:55 +08:00
|
|
|
qn.serviceLock.Unlock()
|
2021-08-02 22:39:25 +08:00
|
|
|
log.Debug("Start: queryNode client start success", zap.Int64("nodeID", qn.id), zap.String("address", qn.address))
|
2021-07-13 14:16:00 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) stop() {
|
2021-07-16 10:21:55 +08:00
|
|
|
qn.serviceLock.Lock()
|
|
|
|
defer qn.serviceLock.Unlock()
|
2021-07-13 14:16:00 +08:00
|
|
|
qn.onService = false
|
|
|
|
if qn.client != nil {
|
|
|
|
qn.client.Stop()
|
|
|
|
}
|
|
|
|
qn.cancel()
|
2021-01-26 15:13:20 +08:00
|
|
|
}
|
2021-02-04 11:40:14 +08:00
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
func (qn *queryNode) addCollection(collectionID UniqueID, schema *schemapb.CollectionSchema) error {
|
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
|
|
|
|
if _, ok := qn.collectionInfos[collectionID]; !ok {
|
|
|
|
partitions := make([]UniqueID, 0)
|
|
|
|
channels := make([]*querypb.DmChannelInfo, 0)
|
|
|
|
newCollection := &querypb.CollectionInfo{
|
|
|
|
CollectionID: collectionID,
|
|
|
|
PartitionIDs: partitions,
|
|
|
|
ChannelInfos: channels,
|
|
|
|
Schema: schema,
|
|
|
|
}
|
|
|
|
qn.collectionInfos[collectionID] = newCollection
|
2021-08-02 22:39:25 +08:00
|
|
|
err := saveNodeCollectionInfo(collectionID, newCollection, qn.id, qn.kvClient)
|
2021-06-19 11:45:09 +08:00
|
|
|
if err != nil {
|
2021-08-02 22:39:25 +08:00
|
|
|
log.Error("AddCollection: save collectionInfo error", zap.Any("error", err.Error()), zap.Int64("collectionID", collectionID))
|
|
|
|
return err
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-03-26 05:09:16 +08:00
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) setCollectionInfo(info *querypb.CollectionInfo) error {
|
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
|
|
|
|
qn.collectionInfos[info.CollectionID] = info
|
|
|
|
err := saveNodeCollectionInfo(info.CollectionID, info, qn.id, qn.kvClient)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("SetCollectionInfo: save collectionInfo error", zap.Any("error", err.Error()), zap.Int64("collectionID", info.CollectionID))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2021-03-25 04:40:59 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) showCollections() []*querypb.CollectionInfo {
|
|
|
|
qn.RLock()
|
|
|
|
defer qn.RUnlock()
|
|
|
|
|
|
|
|
results := make([]*querypb.CollectionInfo, 0)
|
|
|
|
for _, info := range qn.collectionInfos {
|
|
|
|
results = append(results, proto.Clone(info).(*querypb.CollectionInfo))
|
|
|
|
}
|
|
|
|
|
|
|
|
return results
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
func (qn *queryNode) addPartition(collectionID UniqueID, partitionID UniqueID) error {
|
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
if col, ok := qn.collectionInfos[collectionID]; ok {
|
|
|
|
for _, id := range col.PartitionIDs {
|
|
|
|
if id == partitionID {
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
col.PartitionIDs = append(col.PartitionIDs, partitionID)
|
2021-08-02 22:39:25 +08:00
|
|
|
err := saveNodeCollectionInfo(collectionID, col, qn.id, qn.kvClient)
|
2021-06-19 11:45:09 +08:00
|
|
|
if err != nil {
|
2021-08-02 22:39:25 +08:00
|
|
|
log.Error("AddPartition: save collectionInfo error", zap.Any("error", err.Error()), zap.Int64("collectionID", collectionID))
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
return nil
|
2021-03-22 16:36:10 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
return errors.New("AddPartition: can't find collection when add partition")
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) releaseCollectionInfo(collectionID UniqueID) error {
|
2021-06-15 12:41:40 +08:00
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
2021-06-19 11:45:09 +08:00
|
|
|
if _, ok := qn.collectionInfos[collectionID]; ok {
|
2021-08-02 22:39:25 +08:00
|
|
|
err := removeNodeCollectionInfo(collectionID, qn.id, qn.kvClient)
|
2021-06-19 11:45:09 +08:00
|
|
|
if err != nil {
|
2021-08-02 22:39:25 +08:00
|
|
|
log.Error("ReleaseCollectionInfo: remove collectionInfo error", zap.Any("error", err.Error()), zap.Int64("collectionID", collectionID))
|
|
|
|
return err
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
delete(qn.collectionInfos, collectionID)
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
delete(qn.watchedQueryChannels, collectionID)
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
2021-03-26 05:09:16 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) releasePartitionsInfo(collectionID UniqueID, partitionIDs []UniqueID) error {
|
2021-06-15 12:41:40 +08:00
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
|
|
|
|
if info, ok := qn.collectionInfos[collectionID]; ok {
|
|
|
|
newPartitionIDs := make([]UniqueID, 0)
|
|
|
|
for _, id := range info.PartitionIDs {
|
2021-08-02 22:39:25 +08:00
|
|
|
match := false
|
|
|
|
for _, partitionID := range partitionIDs {
|
|
|
|
if id == partitionID {
|
|
|
|
match = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !match {
|
2021-06-15 12:41:40 +08:00
|
|
|
newPartitionIDs = append(newPartitionIDs, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
info.PartitionIDs = newPartitionIDs
|
2021-08-02 22:39:25 +08:00
|
|
|
err := removeNodeCollectionInfo(collectionID, qn.id, qn.kvClient)
|
2021-06-19 11:45:09 +08:00
|
|
|
if err != nil {
|
2021-08-02 22:39:25 +08:00
|
|
|
log.Error("ReleasePartitionsInfo: remove collectionInfo error", zap.Any("error", err.Error()), zap.Int64("collectionID", collectionID))
|
|
|
|
return err
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-03-26 05:09:16 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
return nil
|
2021-03-26 05:09:16 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
func (qn *queryNode) addDmChannel(collectionID UniqueID, channels []string) error {
|
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
//before add channel, should ensure toAddedChannels not in MetaReplica
|
2021-06-15 12:41:40 +08:00
|
|
|
if info, ok := qn.collectionInfos[collectionID]; ok {
|
|
|
|
findNodeID := false
|
|
|
|
for _, channelInfo := range info.ChannelInfos {
|
|
|
|
if channelInfo.NodeIDLoaded == qn.id {
|
|
|
|
findNodeID = true
|
|
|
|
channelInfo.ChannelIDs = append(channelInfo.ChannelIDs, channels...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !findNodeID {
|
|
|
|
newChannelInfo := &querypb.DmChannelInfo{
|
|
|
|
NodeIDLoaded: qn.id,
|
|
|
|
ChannelIDs: channels,
|
|
|
|
}
|
|
|
|
info.ChannelInfos = append(info.ChannelInfos, newChannelInfo)
|
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
err := saveNodeCollectionInfo(collectionID, info, qn.id, qn.kvClient)
|
2021-06-19 11:45:09 +08:00
|
|
|
if err != nil {
|
2021-08-02 22:39:25 +08:00
|
|
|
log.Error("AddDmChannel: save collectionInfo error", zap.Any("error", err.Error()), zap.Int64("collectionID", collectionID))
|
|
|
|
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-08-02 22:39:25 +08:00
|
|
|
return errors.New("AddDmChannels: can't find collection in watchedQueryChannel")
|
2021-02-24 17:24:51 +08:00
|
|
|
}
|
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
func (qn *queryNode) removeDmChannel(collectionID UniqueID, channels []string) error {
|
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
|
|
|
|
if info, ok := qn.collectionInfos[collectionID]; ok {
|
|
|
|
for _, channelInfo := range info.ChannelInfos {
|
|
|
|
if channelInfo.NodeIDLoaded == qn.id {
|
|
|
|
newChannelIDs := make([]string, 0)
|
|
|
|
for _, channelID := range channelInfo.ChannelIDs {
|
|
|
|
findChannel := false
|
|
|
|
for _, channel := range channels {
|
|
|
|
if channelID == channel {
|
|
|
|
findChannel = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !findChannel {
|
|
|
|
newChannelIDs = append(newChannelIDs, channelID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
channelInfo.ChannelIDs = newChannelIDs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
err := saveNodeCollectionInfo(collectionID, info, qn.id, qn.kvClient)
|
2021-06-19 11:45:09 +08:00
|
|
|
if err != nil {
|
2021-08-02 22:39:25 +08:00
|
|
|
log.Error("RemoveDmChannel: save collectionInfo error", zap.Any("error", err.Error()), zap.Int64("collectionID", collectionID))
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
return errors.New("RemoveDmChannel: can't find collection in watchedQueryChannel")
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
|
|
|
|
func (qn *queryNode) hasWatchedQueryChannel(collectionID UniqueID) bool {
|
|
|
|
qn.RLock()
|
|
|
|
defer qn.RUnlock()
|
|
|
|
|
|
|
|
if _, ok := qn.watchedQueryChannels[collectionID]; ok {
|
|
|
|
return true
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) showWatchedQueryChannels() []*querypb.QueryChannelInfo {
|
|
|
|
qn.RLock()
|
|
|
|
defer qn.RUnlock()
|
|
|
|
|
|
|
|
results := make([]*querypb.QueryChannelInfo, 0)
|
|
|
|
for _, info := range qn.watchedQueryChannels {
|
|
|
|
results = append(results, proto.Clone(info).(*querypb.QueryChannelInfo))
|
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
return results
|
2021-06-15 12:41:40 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) setQueryChannelInfo(info *querypb.QueryChannelInfo) {
|
2021-06-15 12:41:40 +08:00
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
qn.watchedQueryChannels[info.CollectionID] = info
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) removeQueryChannelInfo(collectionID UniqueID) {
|
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
2021-06-19 11:45:09 +08:00
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
delete(qn.watchedQueryChannels, collectionID)
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 14:10:09 +08:00
|
|
|
func (qn *queryNode) clearNodeInfo() error {
|
2021-08-02 22:39:25 +08:00
|
|
|
qn.RLock()
|
|
|
|
defer qn.RUnlock()
|
2021-06-22 14:10:09 +08:00
|
|
|
for collectionID := range qn.collectionInfos {
|
2021-08-02 22:39:25 +08:00
|
|
|
err := removeNodeCollectionInfo(collectionID, qn.id, qn.kvClient)
|
2021-06-22 14:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
func (qn *queryNode) setNodeState(onService bool) {
|
2021-07-16 10:21:55 +08:00
|
|
|
qn.serviceLock.Lock()
|
|
|
|
defer qn.serviceLock.Unlock()
|
2021-06-19 11:45:09 +08:00
|
|
|
|
|
|
|
qn.onService = onService
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) isOnService() bool {
|
2021-08-02 22:39:25 +08:00
|
|
|
qn.serviceLock.RLock()
|
|
|
|
defer qn.serviceLock.RUnlock()
|
2021-06-19 11:45:09 +08:00
|
|
|
|
|
|
|
return qn.onService
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
//***********************grpc req*************************//
|
|
|
|
func (qn *queryNode) watchDmChannels(ctx context.Context, in *querypb.WatchDmChannelsRequest) error {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
onService := qn.onService
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
if !onService {
|
|
|
|
return errors.New("WatchDmChannels: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := qn.client.WatchDmChannels(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
channels := make([]string, 0)
|
|
|
|
for _, info := range in.Infos {
|
|
|
|
channels = append(channels, info.ChannelName)
|
|
|
|
}
|
|
|
|
err = qn.addCollection(in.CollectionID, in.Schema)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = qn.addDmChannel(in.CollectionID, channels)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) addQueryChannel(ctx context.Context, in *querypb.AddQueryChannelRequest) error {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
onService := qn.onService
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
if !onService {
|
|
|
|
return errors.New("AddQueryChannel: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := qn.client.AddQueryChannel(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
queryChannelInfo := &querypb.QueryChannelInfo{
|
|
|
|
CollectionID: in.CollectionID,
|
|
|
|
QueryChannelID: in.RequestChannelID,
|
|
|
|
QueryResultChannelID: in.ResultChannelID,
|
|
|
|
}
|
|
|
|
qn.setQueryChannelInfo(queryChannelInfo)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) removeQueryChannel(ctx context.Context, in *querypb.RemoveQueryChannelRequest) error {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
onService := qn.onService
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
if !onService {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := qn.client.RemoveQueryChannel(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
qn.removeQueryChannelInfo(in.CollectionID)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) releaseCollection(ctx context.Context, in *querypb.ReleaseCollectionRequest) error {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
onService := qn.onService
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
if !onService {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := qn.client.ReleaseCollection(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = qn.releaseCollectionInfo(in.CollectionID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) releasePartitions(ctx context.Context, in *querypb.ReleasePartitionsRequest) error {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
onService := qn.onService
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
if !onService {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := qn.client.ReleasePartitions(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
err = qn.releasePartitionsInfo(in.CollectionID, in.PartitionIDs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) getSegmentInfo(ctx context.Context, in *querypb.GetSegmentInfoRequest) (*querypb.GetSegmentInfoResponse, error) {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
if !qn.onService {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
|
|
|
|
res, err := qn.client.GetSegmentInfo(ctx, in)
|
|
|
|
if err == nil && res.Status.ErrorCode == commonpb.ErrorCode_Success {
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) getComponentInfo(ctx context.Context) *internalpb.ComponentInfo {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
if !qn.onService {
|
|
|
|
return &internalpb.ComponentInfo{
|
|
|
|
NodeID: qn.id,
|
|
|
|
StateCode: internalpb.StateCode_Abnormal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
|
|
|
|
res, err := qn.client.GetComponentStates(ctx)
|
|
|
|
if err != nil || res.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return &internalpb.ComponentInfo{
|
|
|
|
NodeID: qn.id,
|
|
|
|
StateCode: internalpb.StateCode_Abnormal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.State
|
|
|
|
}
|
|
|
|
|
2021-08-17 10:06:11 +08:00
|
|
|
func (qn *queryNode) getMetrics(ctx context.Context, in *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
if !qn.onService {
|
|
|
|
return nil, errQueryNodeIsNotOnService(qn.id)
|
|
|
|
}
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
|
|
|
|
return qn.client.GetMetrics(ctx, in)
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) loadSegments(ctx context.Context, in *querypb.LoadSegmentsRequest) error {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
onService := qn.onService
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
if !onService {
|
|
|
|
return errors.New("LoadSegments: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := qn.client.LoadSegments(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, info := range in.Infos {
|
|
|
|
err = qn.addCollection(info.CollectionID, in.Schema)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = qn.addPartition(info.CollectionID, info.PartitionID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) releaseSegments(ctx context.Context, in *querypb.ReleaseSegmentsRequest) error {
|
|
|
|
qn.serviceLock.RLock()
|
|
|
|
onService := qn.onService
|
|
|
|
qn.serviceLock.RUnlock()
|
|
|
|
if !onService {
|
|
|
|
return errors.New("ReleaseSegments: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := qn.client.ReleaseSegments(ctx, in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//****************************************************//
|
|
|
|
|
|
|
|
func saveNodeCollectionInfo(collectionID UniqueID, info *querypb.CollectionInfo, nodeID int64, kv *etcdkv.EtcdKV) error {
|
|
|
|
infoBytes := proto.MarshalTextString(info)
|
|
|
|
|
|
|
|
key := fmt.Sprintf("%s/%d/%d", queryNodeMetaPrefix, nodeID, collectionID)
|
|
|
|
return kv.Save(key, infoBytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeNodeCollectionInfo(collectionID UniqueID, nodeID int64, kv *etcdkv.EtcdKV) error {
|
|
|
|
key := fmt.Sprintf("%s/%d/%d", queryNodeMetaPrefix, nodeID, collectionID)
|
|
|
|
return kv.Remove(key)
|
|
|
|
}
|