2021-12-03 19:25:45 +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-04-19 13:47:10 +08:00
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
|
//
|
2021-12-03 19:25:45 +08:00
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
|
//
|
2021-12-03 19:25:45 +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-04-19 13:47:10 +08:00
|
|
|
|
|
2021-04-12 09:18:43 +08:00
|
|
|
|
package querynode
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2021-06-15 12:41:40 +08:00
|
|
|
|
"fmt"
|
2021-04-12 09:18:43 +08:00
|
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
2021-11-25 15:03:16 +08:00
|
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2021-04-22 14:45:57 +08:00
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2022-05-27 14:12:01 +08:00
|
|
|
|
"github.com/milvus-io/milvus/internal/metrics"
|
2021-04-22 14:45:57 +08:00
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2022-04-27 10:41:46 +08:00
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-04-22 14:45:57 +08:00
|
|
|
|
queryPb "github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-11-05 16:00:55 +08:00
|
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2022-05-27 14:12:01 +08:00
|
|
|
|
"github.com/milvus-io/milvus/internal/util/timerecord"
|
2021-04-22 14:45:57 +08:00
|
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-04-12 09:18:43 +08:00
|
|
|
|
)
|
|
|
|
|
|
2021-12-24 13:26:30 +08:00
|
|
|
|
// GetComponentStates returns information about whether the node is healthy
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
|
|
|
|
stats := &internalpb.ComponentStates{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
},
|
|
|
|
|
}
|
2021-11-25 15:03:16 +08:00
|
|
|
|
code, ok := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
if !ok {
|
|
|
|
|
errMsg := "unexpected error in type assertion"
|
2021-04-12 09:18:43 +08:00
|
|
|
|
stats.Status = &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-11-25 15:03:16 +08:00
|
|
|
|
Reason: errMsg,
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return stats, nil
|
2021-11-25 15:03:16 +08:00
|
|
|
|
}
|
|
|
|
|
nodeID := common.NotRegisteredID
|
|
|
|
|
if node.session != nil && node.session.Registered() {
|
|
|
|
|
nodeID = node.session.ServerID
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
info := &internalpb.ComponentInfo{
|
2021-11-25 15:03:16 +08:00
|
|
|
|
NodeID: nodeID,
|
2021-04-12 09:18:43 +08:00
|
|
|
|
Role: typeutil.QueryNodeRole,
|
|
|
|
|
StateCode: code,
|
|
|
|
|
}
|
|
|
|
|
stats.State = info
|
2021-12-06 15:25:35 +08:00
|
|
|
|
log.Debug("Get QueryNode component state done", zap.Any("stateCode", info.StateCode))
|
2021-04-12 09:18:43 +08:00
|
|
|
|
return stats, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 20:10:43 +08:00
|
|
|
|
// GetTimeTickChannel returns the time tick channel
|
|
|
|
|
// TimeTickChannel contains many time tick messages, which will be sent by query nodes
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) GetTimeTickChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
Reason: "",
|
|
|
|
|
},
|
2022-03-04 11:17:56 +08:00
|
|
|
|
Value: Params.CommonCfg.QueryCoordTimeTick,
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-24 13:26:30 +08:00
|
|
|
|
// GetStatisticsChannel returns the statistics channel
|
2021-10-30 19:00:52 +08:00
|
|
|
|
// Statistics channel contains statistics infos of query nodes, such as segment infos, memory infos
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
Reason: "",
|
|
|
|
|
},
|
2022-03-04 11:17:56 +08:00
|
|
|
|
Value: Params.CommonCfg.QueryNodeStats,
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-24 17:28:20 +08:00
|
|
|
|
// WatchDmChannels create consumers on dmChannels to receive Incremental data,which is the important part of real-time query
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) WatchDmChannels(ctx context.Context, in *queryPb.WatchDmChannelsRequest) (*commonpb.Status, error) {
|
2021-07-13 14:16:00 +08:00
|
|
|
|
code := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
if code != internalpb.StateCode_Healthy {
|
2022-04-24 22:03:44 +08:00
|
|
|
|
err := fmt.Errorf("query node %d is not ready", Params.QueryNodeCfg.GetNodeID())
|
2021-07-13 14:16:00 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-07-13 14:16:00 +08:00
|
|
|
|
}
|
2021-04-16 14:40:33 +08:00
|
|
|
|
dct := &watchDmChannelsTask{
|
|
|
|
|
baseTask: baseTask{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
done: make(chan error),
|
|
|
|
|
},
|
|
|
|
|
req: in,
|
|
|
|
|
node: node,
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-16 14:40:33 +08:00
|
|
|
|
err := node.scheduler.queue.Enqueue(dct)
|
|
|
|
|
if err != nil {
|
2021-04-12 09:18:43 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-04-16 14:40:33 +08:00
|
|
|
|
Reason: err.Error(),
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Info("watchDmChannelsTask Enqueue done", zap.Int64("collectionID", in.CollectionID), zap.Int64("nodeID", Params.QueryNodeCfg.GetNodeID()), zap.Int64("replicaID", in.GetReplicaID()))
|
2021-08-03 22:01:27 +08:00
|
|
|
|
waitFunc := func() (*commonpb.Status, error) {
|
2021-04-16 14:40:33 +08:00
|
|
|
|
err = dct.WaitToFinish()
|
2021-04-12 09:18:43 +08:00
|
|
|
|
if err != nil {
|
2021-08-03 22:01:27 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Info("watchDmChannelsTask WaitToFinish done", zap.Int64("collectionID", in.CollectionID), zap.Int64("nodeID", Params.QueryNodeCfg.GetNodeID()))
|
2021-08-03 22:01:27 +08:00
|
|
|
|
return &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
}, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2021-08-03 22:01:27 +08:00
|
|
|
|
|
|
|
|
|
return waitFunc()
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-24 17:16:41 +08:00
|
|
|
|
// WatchDeltaChannels create consumers on dmChannels to receive Incremental data,which is the important part of real-time query
|
2021-11-05 14:47:19 +08:00
|
|
|
|
func (node *QueryNode) WatchDeltaChannels(ctx context.Context, in *queryPb.WatchDeltaChannelsRequest) (*commonpb.Status, error) {
|
2021-11-09 09:27:04 +08:00
|
|
|
|
code := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
if code != internalpb.StateCode_Healthy {
|
2022-04-24 22:03:44 +08:00
|
|
|
|
err := fmt.Errorf("query node %d is not ready", Params.QueryNodeCfg.GetNodeID())
|
2021-11-09 09:27:04 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-11-09 09:27:04 +08:00
|
|
|
|
}
|
|
|
|
|
dct := &watchDeltaChannelsTask{
|
|
|
|
|
baseTask: baseTask{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
done: make(chan error),
|
|
|
|
|
},
|
|
|
|
|
req: in,
|
|
|
|
|
node: node,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := node.scheduler.queue.Enqueue(dct)
|
|
|
|
|
if err != nil {
|
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-11-09 09:27:04 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
|
|
|
|
|
log.Info("watchDeltaChannelsTask Enqueue done", zap.Int64("collectionID", in.CollectionID), zap.Int64("nodeID", Params.QueryNodeCfg.GetNodeID()))
|
2021-11-09 09:27:04 +08:00
|
|
|
|
|
|
|
|
|
waitFunc := func() (*commonpb.Status, error) {
|
|
|
|
|
err = dct.WaitToFinish()
|
|
|
|
|
if err != nil {
|
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-11-09 09:27:04 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
|
|
|
|
|
log.Info("watchDeltaChannelsTask WaitToFinish done", zap.Int64("collectionID", in.CollectionID), zap.Int64("nodeID", Params.QueryNodeCfg.GetNodeID()))
|
2021-11-09 09:27:04 +08:00
|
|
|
|
return &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return waitFunc()
|
2021-11-05 14:47:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-02 21:58:22 +08:00
|
|
|
|
// LoadSegments load historical data into query node, historical data can be vector data or index
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) LoadSegments(ctx context.Context, in *queryPb.LoadSegmentsRequest) (*commonpb.Status, error) {
|
2021-07-13 14:16:00 +08:00
|
|
|
|
code := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
if code != internalpb.StateCode_Healthy {
|
2022-04-24 22:03:44 +08:00
|
|
|
|
err := fmt.Errorf("query node %d is not ready", Params.QueryNodeCfg.GetNodeID())
|
2021-07-13 14:16:00 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-07-13 14:16:00 +08:00
|
|
|
|
}
|
2021-04-12 09:18:43 +08:00
|
|
|
|
dct := &loadSegmentsTask{
|
|
|
|
|
baseTask: baseTask{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
done: make(chan error),
|
|
|
|
|
},
|
|
|
|
|
req: in,
|
|
|
|
|
node: node,
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 12:52:03 +08:00
|
|
|
|
segmentIDs := make([]UniqueID, 0, len(in.GetInfos()))
|
|
|
|
|
for _, info := range in.Infos {
|
|
|
|
|
segmentIDs = append(segmentIDs, info.SegmentID)
|
|
|
|
|
}
|
2021-04-12 09:18:43 +08:00
|
|
|
|
err := node.scheduler.queue.Enqueue(dct)
|
|
|
|
|
if err != nil {
|
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-06-02 12:52:03 +08:00
|
|
|
|
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Info("loadSegmentsTask Enqueue done", zap.Int64("collectionID", in.CollectionID), zap.Int64s("segmentIDs", segmentIDs), zap.Int64("nodeID", Params.QueryNodeCfg.GetNodeID()))
|
2021-04-12 09:18:43 +08:00
|
|
|
|
|
2021-08-03 22:01:27 +08:00
|
|
|
|
waitFunc := func() (*commonpb.Status, error) {
|
2021-04-16 14:40:33 +08:00
|
|
|
|
err = dct.WaitToFinish()
|
|
|
|
|
if err != nil {
|
2021-08-03 22:01:27 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Info("loadSegmentsTask WaitToFinish done", zap.Int64("collectionID", in.CollectionID), zap.Int64s("segmentIDs", segmentIDs), zap.Int64("nodeID", Params.QueryNodeCfg.GetNodeID()))
|
2021-08-03 22:01:27 +08:00
|
|
|
|
return &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
}, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2021-08-03 22:01:27 +08:00
|
|
|
|
|
|
|
|
|
return waitFunc()
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-24 17:14:52 +08:00
|
|
|
|
// ReleaseCollection clears all data related to this collection on the querynode
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) ReleaseCollection(ctx context.Context, in *queryPb.ReleaseCollectionRequest) (*commonpb.Status, error) {
|
2021-07-13 14:16:00 +08:00
|
|
|
|
code := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
if code != internalpb.StateCode_Healthy {
|
2022-04-24 22:03:44 +08:00
|
|
|
|
err := fmt.Errorf("query node %d is not ready", Params.QueryNodeCfg.GetNodeID())
|
2021-07-13 14:16:00 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-07-13 14:16:00 +08:00
|
|
|
|
}
|
2021-04-12 09:18:43 +08:00
|
|
|
|
dct := &releaseCollectionTask{
|
|
|
|
|
baseTask: baseTask{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
done: make(chan error),
|
|
|
|
|
},
|
|
|
|
|
req: in,
|
|
|
|
|
node: node,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := node.scheduler.queue.Enqueue(dct)
|
|
|
|
|
if err != nil {
|
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Info("releaseCollectionTask Enqueue done", zap.Int64("collectionID", in.CollectionID))
|
2021-04-12 09:18:43 +08:00
|
|
|
|
|
2021-04-16 17:37:50 +08:00
|
|
|
|
func() {
|
2021-04-16 14:40:33 +08:00
|
|
|
|
err = dct.WaitToFinish()
|
|
|
|
|
if err != nil {
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-04-16 14:40:33 +08:00
|
|
|
|
return
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Info("releaseCollectionTask WaitToFinish done", zap.Int64("collectionID", in.CollectionID))
|
2021-04-16 14:40:33 +08:00
|
|
|
|
}()
|
2021-04-12 09:18:43 +08:00
|
|
|
|
|
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
}
|
|
|
|
|
return status, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 22:58:53 +08:00
|
|
|
|
// ReleasePartitions clears all data related to this partition on the querynode
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) ReleasePartitions(ctx context.Context, in *queryPb.ReleasePartitionsRequest) (*commonpb.Status, error) {
|
2021-07-13 14:16:00 +08:00
|
|
|
|
code := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
if code != internalpb.StateCode_Healthy {
|
2022-04-24 22:03:44 +08:00
|
|
|
|
err := fmt.Errorf("query node %d is not ready", Params.QueryNodeCfg.GetNodeID())
|
2021-07-13 14:16:00 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-07-13 14:16:00 +08:00
|
|
|
|
}
|
2021-04-12 09:18:43 +08:00
|
|
|
|
dct := &releasePartitionsTask{
|
|
|
|
|
baseTask: baseTask{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
done: make(chan error),
|
|
|
|
|
},
|
|
|
|
|
req: in,
|
|
|
|
|
node: node,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := node.scheduler.queue.Enqueue(dct)
|
|
|
|
|
if err != nil {
|
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Info("releasePartitionsTask Enqueue done", zap.Int64("collectionID", in.CollectionID), zap.Int64s("partitionIDs", in.PartitionIDs))
|
2021-04-12 09:18:43 +08:00
|
|
|
|
|
2021-04-16 17:37:50 +08:00
|
|
|
|
func() {
|
2021-04-16 14:40:33 +08:00
|
|
|
|
err = dct.WaitToFinish()
|
|
|
|
|
if err != nil {
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Warn(err.Error())
|
2021-04-16 14:40:33 +08:00
|
|
|
|
return
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-05-07 10:27:51 +08:00
|
|
|
|
log.Info("releasePartitionsTask WaitToFinish done", zap.Int64("collectionID", in.CollectionID), zap.Int64s("partitionIDs", in.PartitionIDs))
|
2021-04-16 14:40:33 +08:00
|
|
|
|
}()
|
2021-04-12 09:18:43 +08:00
|
|
|
|
|
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
}
|
|
|
|
|
return status, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 23:13:26 +08:00
|
|
|
|
// ReleaseSegments remove the specified segments from query node according segmentIDs, partitionIDs, and collectionID
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) ReleaseSegments(ctx context.Context, in *queryPb.ReleaseSegmentsRequest) (*commonpb.Status, error) {
|
2021-07-13 14:16:00 +08:00
|
|
|
|
code := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
if code != internalpb.StateCode_Healthy {
|
2022-04-24 22:03:44 +08:00
|
|
|
|
err := fmt.Errorf("query node %d is not ready", Params.QueryNodeCfg.GetNodeID())
|
2021-07-13 14:16:00 +08:00
|
|
|
|
status := &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return status, nil
|
2021-07-13 14:16:00 +08:00
|
|
|
|
}
|
2022-06-01 13:18:02 +08:00
|
|
|
|
|
2022-05-16 18:23:55 +08:00
|
|
|
|
// collection lock is not needed since we guarantee not query/search will be dispatch from leader
|
2021-04-12 09:18:43 +08:00
|
|
|
|
for _, id := range in.SegmentIDs {
|
2022-06-17 17:38:12 +08:00
|
|
|
|
switch in.GetScope() {
|
|
|
|
|
case queryPb.DataScope_Streaming:
|
|
|
|
|
node.metaReplica.removeSegment(id, segmentTypeGrowing)
|
|
|
|
|
case queryPb.DataScope_Historical:
|
|
|
|
|
node.metaReplica.removeSegment(id, segmentTypeSealed)
|
|
|
|
|
case queryPb.DataScope_All:
|
|
|
|
|
node.metaReplica.removeSegment(id, segmentTypeSealed)
|
|
|
|
|
node.metaReplica.removeSegment(id, segmentTypeGrowing)
|
|
|
|
|
}
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
2022-01-05 21:15:20 +08:00
|
|
|
|
|
2022-06-17 17:38:12 +08:00
|
|
|
|
log.Info("release segments done", zap.Int64("collectionID", in.CollectionID), zap.Int64s("segmentIDs", in.SegmentIDs), zap.String("Scope", in.GetScope().String()))
|
2022-06-01 13:18:02 +08:00
|
|
|
|
return &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
}, nil
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-02 21:56:34 +08:00
|
|
|
|
// GetSegmentInfo returns segment information of the collection on the queryNode, and the information includes memSize, numRow, indexName, indexID ...
|
2021-04-12 09:18:43 +08:00
|
|
|
|
func (node *QueryNode) GetSegmentInfo(ctx context.Context, in *queryPb.GetSegmentInfoRequest) (*queryPb.GetSegmentInfoResponse, error) {
|
2021-07-13 14:16:00 +08:00
|
|
|
|
code := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
if code != internalpb.StateCode_Healthy {
|
2022-04-24 22:03:44 +08:00
|
|
|
|
err := fmt.Errorf("query node %d is not ready", Params.QueryNodeCfg.GetNodeID())
|
2021-07-13 14:16:00 +08:00
|
|
|
|
res := &queryPb.GetSegmentInfoResponse{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
},
|
|
|
|
|
}
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return res, nil
|
2021-07-13 14:16:00 +08:00
|
|
|
|
}
|
2022-02-07 15:35:44 +08:00
|
|
|
|
var segmentInfos []*queryPb.SegmentInfo
|
|
|
|
|
|
|
|
|
|
segmentIDs := make(map[int64]struct{})
|
|
|
|
|
for _, segmentID := range in.GetSegmentIDs() {
|
|
|
|
|
segmentIDs[segmentID] = struct{}{}
|
|
|
|
|
}
|
2021-11-05 16:00:55 +08:00
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
|
infos := node.metaReplica.getSegmentInfosByColID(in.CollectionID)
|
|
|
|
|
segmentInfos = append(segmentInfos, filterSegmentInfo(infos, segmentIDs)...)
|
2021-11-06 15:22:56 +08:00
|
|
|
|
|
2021-04-12 09:18:43 +08:00
|
|
|
|
return &queryPb.GetSegmentInfoResponse{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
|
},
|
2022-02-07 15:35:44 +08:00
|
|
|
|
Infos: segmentInfos,
|
2021-04-12 09:18:43 +08:00
|
|
|
|
}, nil
|
|
|
|
|
}
|
2021-08-17 10:06:11 +08:00
|
|
|
|
|
2022-02-07 15:35:44 +08:00
|
|
|
|
// filterSegmentInfo returns segment info which segment id in segmentIDs map
|
|
|
|
|
func filterSegmentInfo(segmentInfos []*queryPb.SegmentInfo, segmentIDs map[int64]struct{}) []*queryPb.SegmentInfo {
|
|
|
|
|
if len(segmentIDs) == 0 {
|
|
|
|
|
return segmentInfos
|
|
|
|
|
}
|
|
|
|
|
filtered := make([]*queryPb.SegmentInfo, 0, len(segmentIDs))
|
|
|
|
|
for _, info := range segmentInfos {
|
|
|
|
|
_, ok := segmentIDs[info.GetSegmentID()]
|
|
|
|
|
if !ok {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
filtered = append(filtered, info)
|
|
|
|
|
}
|
|
|
|
|
return filtered
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 17:37:25 +08:00
|
|
|
|
// isHealthy checks if QueryNode is healthy
|
2021-08-17 10:06:11 +08:00
|
|
|
|
func (node *QueryNode) isHealthy() bool {
|
|
|
|
|
code := node.stateCode.Load().(internalpb.StateCode)
|
|
|
|
|
return code == internalpb.StateCode_Healthy
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 12:03:27 +08:00
|
|
|
|
// Search performs replica search tasks.
|
2022-04-02 14:15:31 +08:00
|
|
|
|
func (node *QueryNode) Search(ctx context.Context, req *queryPb.SearchRequest) (*internalpb.SearchResults, error) {
|
2022-05-27 14:12:01 +08:00
|
|
|
|
metrics.QueryNodeSQCount.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.SearchLabel, metrics.TotalLabel).Inc()
|
2022-05-23 16:41:58 +08:00
|
|
|
|
failRet := &internalpb.SearchResults{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
},
|
|
|
|
|
}
|
2022-05-27 14:12:01 +08:00
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
if failRet.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
|
metrics.QueryNodeSQCount.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.QueryLabel, metrics.FailLabel).Inc()
|
|
|
|
|
}
|
|
|
|
|
}()
|
2022-04-20 16:15:41 +08:00
|
|
|
|
if !node.isHealthy() {
|
2022-05-23 16:41:58 +08:00
|
|
|
|
failRet.Status.Reason = msgQueryNodeIsUnhealthy(Params.QueryNodeCfg.GetNodeID())
|
|
|
|
|
return failRet, nil
|
2022-04-20 16:15:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-13 11:42:09 +08:00
|
|
|
|
msgID := req.GetReq().GetBase().GetMsgID()
|
2022-05-30 17:18:03 +08:00
|
|
|
|
log.Debug("Received SearchRequest",
|
2022-06-13 11:42:09 +08:00
|
|
|
|
zap.Int64("msgID", msgID),
|
|
|
|
|
zap.Bool("fromShardLeader", req.GetFromShardLeader()),
|
2022-05-30 17:18:03 +08:00
|
|
|
|
zap.String("vChannel", req.GetDmlChannel()),
|
|
|
|
|
zap.Int64s("segmentIDs", req.GetSegmentIDs()),
|
|
|
|
|
zap.Uint64("guaranteeTimestamp", req.GetReq().GetGuaranteeTimestamp()),
|
|
|
|
|
zap.Uint64("timeTravel", req.GetReq().GetTravelTimestamp()))
|
2022-04-20 16:15:41 +08:00
|
|
|
|
|
|
|
|
|
if node.queryShardService == nil {
|
2022-05-23 16:41:58 +08:00
|
|
|
|
failRet.Status.Reason = "queryShardService is nil"
|
|
|
|
|
return failRet, nil
|
2022-04-20 16:15:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qs, err := node.queryShardService.getQueryShard(req.GetDmlChannel())
|
|
|
|
|
if err != nil {
|
2022-06-13 11:42:09 +08:00
|
|
|
|
log.Warn("Search failed, failed to get query shard",
|
|
|
|
|
zap.Int64("msgID", msgID),
|
|
|
|
|
zap.String("dml channel", req.GetDmlChannel()),
|
|
|
|
|
zap.Error(err))
|
2022-05-23 16:41:58 +08:00
|
|
|
|
failRet.Status.ErrorCode = commonpb.ErrorCode_NotShardLeader
|
|
|
|
|
failRet.Status.Reason = err.Error()
|
|
|
|
|
return failRet, nil
|
2022-04-20 16:15:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 20:48:10 +08:00
|
|
|
|
log.Debug("start do search",
|
|
|
|
|
zap.Int64("msgID", msgID),
|
|
|
|
|
zap.Bool("fromShardLeader", req.GetFromShardLeader()),
|
|
|
|
|
zap.String("vChannel", req.GetDmlChannel()),
|
|
|
|
|
zap.Int64s("segmentIDs", req.GetSegmentIDs()))
|
|
|
|
|
tr := timerecord.NewTimeRecorder("")
|
2022-05-27 14:12:01 +08:00
|
|
|
|
|
2022-05-23 16:41:58 +08:00
|
|
|
|
if req.FromShardLeader {
|
|
|
|
|
historicalTask, err2 := newSearchTask(ctx, req)
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
failRet.Status.Reason = err2.Error()
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
|
|
|
|
historicalTask.QS = qs
|
|
|
|
|
historicalTask.DataScope = querypb.DataScope_Historical
|
|
|
|
|
err2 = node.scheduler.AddReadTask(ctx, historicalTask)
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
failRet.Status.Reason = err2.Error()
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err2 = historicalTask.WaitToFinish()
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
failRet.Status.Reason = err2.Error()
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
2022-05-27 14:12:01 +08:00
|
|
|
|
|
2022-06-13 11:42:09 +08:00
|
|
|
|
tr.Elapse(fmt.Sprintf("do search done, msgID = %d, fromSharedLeader = %t, vChannel = %s, segmentIDs = %v",
|
|
|
|
|
msgID, req.GetFromShardLeader(), req.GetDmlChannel(), req.GetSegmentIDs()))
|
|
|
|
|
|
2022-05-27 14:12:01 +08:00
|
|
|
|
failRet.Status.ErrorCode = commonpb.ErrorCode_Success
|
|
|
|
|
metrics.QueryNodeSQLatencyInQueue.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
metrics.SearchLabel).Observe(float64(historicalTask.queueDur.Milliseconds()))
|
|
|
|
|
metrics.QueryNodeReduceLatency.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
metrics.SearchLabel).Observe(float64(historicalTask.reduceDur.Milliseconds()))
|
|
|
|
|
latency := tr.ElapseSpan()
|
|
|
|
|
metrics.QueryNodeSQReqLatency.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.SearchLabel).Observe(float64(latency.Milliseconds()))
|
|
|
|
|
metrics.QueryNodeSQCount.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.SearchLabel, metrics.SuccessLabel).Inc()
|
2022-05-23 16:41:58 +08:00
|
|
|
|
return historicalTask.Ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//from Proxy
|
|
|
|
|
cluster, ok := qs.clusterService.getShardCluster(req.GetDmlChannel())
|
|
|
|
|
if !ok {
|
|
|
|
|
failRet.Status.Reason = fmt.Sprintf("channel %s leader is not here", req.GetDmlChannel())
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchCtx, cancel := context.WithCancel(ctx)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
var results []*internalpb.SearchResults
|
|
|
|
|
var streamingResult *internalpb.SearchResults
|
|
|
|
|
var errCluster error
|
|
|
|
|
|
2022-06-17 17:38:12 +08:00
|
|
|
|
withStreaming := func(ctx context.Context) error {
|
|
|
|
|
streamingTask, err := newSearchTask(searchCtx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2022-05-23 16:41:58 +08:00
|
|
|
|
}
|
|
|
|
|
streamingTask.QS = qs
|
|
|
|
|
streamingTask.DataScope = querypb.DataScope_Streaming
|
2022-06-17 17:38:12 +08:00
|
|
|
|
err = node.scheduler.AddReadTask(searchCtx, streamingTask)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2022-05-23 16:41:58 +08:00
|
|
|
|
}
|
2022-06-17 17:38:12 +08:00
|
|
|
|
err = streamingTask.WaitToFinish()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2022-05-23 16:41:58 +08:00
|
|
|
|
}
|
2022-05-27 14:12:01 +08:00
|
|
|
|
metrics.QueryNodeSQLatencyInQueue.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
metrics.SearchLabel).Observe(float64(streamingTask.queueDur.Milliseconds()))
|
|
|
|
|
metrics.QueryNodeReduceLatency.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
metrics.SearchLabel).Observe(float64(streamingTask.reduceDur.Milliseconds()))
|
2022-05-23 16:41:58 +08:00
|
|
|
|
streamingResult = streamingTask.Ret
|
2022-06-17 17:38:12 +08:00
|
|
|
|
return nil
|
2022-04-20 16:15:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 17:38:12 +08:00
|
|
|
|
// shard leader dispatches request to its shard cluster
|
|
|
|
|
results, errCluster = cluster.Search(searchCtx, req, withStreaming)
|
|
|
|
|
if errCluster != nil {
|
|
|
|
|
log.Warn("search cluster failed", zap.Int64("msgID", msgID), zap.Int64("collectionID", req.Req.GetCollectionID()), zap.Error(errCluster))
|
|
|
|
|
failRet.Status.Reason = errCluster.Error()
|
2022-05-23 16:41:58 +08:00
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
2022-06-13 11:42:09 +08:00
|
|
|
|
|
|
|
|
|
tr.Elapse(fmt.Sprintf("start reduce search result, msgID = %d, fromSharedLeader = %t, vChannel = %s, segmentIDs = %v",
|
|
|
|
|
msgID, req.GetFromShardLeader(), req.GetDmlChannel(), req.GetSegmentIDs()))
|
|
|
|
|
|
2022-05-23 16:41:58 +08:00
|
|
|
|
results = append(results, streamingResult)
|
|
|
|
|
ret, err2 := reduceSearchResults(results, req.Req.GetNq(), req.Req.GetTopk(), req.Req.GetMetricType())
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
failRet.Status.Reason = err2.Error()
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
2022-05-27 14:12:01 +08:00
|
|
|
|
|
2022-06-13 11:42:09 +08:00
|
|
|
|
tr.Elapse(fmt.Sprintf("do search done, msgID = %d, fromSharedLeader = %t, vChannel = %s, segmentIDs = %v",
|
|
|
|
|
msgID, req.GetFromShardLeader(), req.GetDmlChannel(), req.GetSegmentIDs()))
|
|
|
|
|
|
2022-05-27 14:12:01 +08:00
|
|
|
|
failRet.Status.ErrorCode = commonpb.ErrorCode_Success
|
|
|
|
|
latency := tr.ElapseSpan()
|
|
|
|
|
metrics.QueryNodeSQReqLatency.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.SearchLabel).Observe(float64(latency.Milliseconds()))
|
|
|
|
|
metrics.QueryNodeSQCount.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.SearchLabel, metrics.SuccessLabel).Inc()
|
2022-06-02 16:06:03 +08:00
|
|
|
|
metrics.QueryNodeSearchNQ.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID())).Observe(float64(req.Req.GetNq()))
|
|
|
|
|
metrics.QueryNodeSearchTopK.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID())).Observe(float64(req.Req.GetTopk()))
|
2022-05-23 16:41:58 +08:00
|
|
|
|
return ret, nil
|
2022-03-30 12:03:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Query performs replica query tasks.
|
2022-04-02 14:15:31 +08:00
|
|
|
|
func (node *QueryNode) Query(ctx context.Context, req *queryPb.QueryRequest) (*internalpb.RetrieveResults, error) {
|
2022-05-27 14:12:01 +08:00
|
|
|
|
metrics.QueryNodeSQCount.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.QueryLabel, metrics.TotalLabel).Inc()
|
2022-05-23 16:41:58 +08:00
|
|
|
|
failRet := &internalpb.RetrieveResults{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
},
|
|
|
|
|
}
|
2022-05-27 14:12:01 +08:00
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
if failRet.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
|
metrics.QueryNodeSQCount.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.SearchLabel, metrics.FailLabel).Inc()
|
|
|
|
|
}
|
|
|
|
|
}()
|
2022-04-20 16:15:41 +08:00
|
|
|
|
if !node.isHealthy() {
|
2022-05-23 16:41:58 +08:00
|
|
|
|
failRet.Status.Reason = msgQueryNodeIsUnhealthy(Params.QueryNodeCfg.GetNodeID())
|
|
|
|
|
return failRet, nil
|
2022-04-20 16:15:41 +08:00
|
|
|
|
}
|
2022-05-30 17:18:03 +08:00
|
|
|
|
|
2022-06-13 11:42:09 +08:00
|
|
|
|
msgID := req.GetReq().GetBase().GetMsgID()
|
2022-05-30 17:18:03 +08:00
|
|
|
|
log.Debug("Received QueryRequest",
|
2022-06-13 11:42:09 +08:00
|
|
|
|
zap.Int64("msgID", msgID),
|
|
|
|
|
zap.Bool("fromShardLeader", req.GetFromShardLeader()),
|
2022-05-30 17:18:03 +08:00
|
|
|
|
zap.String("vChannel", req.GetDmlChannel()),
|
|
|
|
|
zap.Int64s("segmentIDs", req.GetSegmentIDs()),
|
|
|
|
|
zap.Uint64("guaranteeTimestamp", req.GetReq().GetGuaranteeTimestamp()),
|
|
|
|
|
zap.Uint64("timeTravel", req.GetReq().GetTravelTimestamp()))
|
2022-04-20 16:15:41 +08:00
|
|
|
|
|
|
|
|
|
if node.queryShardService == nil {
|
2022-05-23 16:41:58 +08:00
|
|
|
|
failRet.Status.Reason = "queryShardService is nil"
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 16:15:41 +08:00
|
|
|
|
qs, err := node.queryShardService.getQueryShard(req.GetDmlChannel())
|
|
|
|
|
if err != nil {
|
2022-06-13 11:42:09 +08:00
|
|
|
|
log.Warn("Query failed, failed to get query shard", zap.Int64("msgID", msgID), zap.String("dml channel", req.GetDmlChannel()), zap.Error(err))
|
2022-05-23 16:41:58 +08:00
|
|
|
|
failRet.Status.Reason = err.Error()
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 20:48:10 +08:00
|
|
|
|
log.Debug("start do query",
|
|
|
|
|
zap.Int64("msgID", msgID),
|
|
|
|
|
zap.Bool("fromShardLeader", req.GetFromShardLeader()),
|
|
|
|
|
zap.String("vChannel", req.GetDmlChannel()),
|
|
|
|
|
zap.Int64s("segmentIDs", req.GetSegmentIDs()))
|
|
|
|
|
tr := timerecord.NewTimeRecorder("")
|
2022-06-13 11:42:09 +08:00
|
|
|
|
|
2022-05-23 16:41:58 +08:00
|
|
|
|
if req.FromShardLeader {
|
|
|
|
|
// construct a queryTask
|
|
|
|
|
queryTask := newQueryTask(ctx, req)
|
|
|
|
|
queryTask.QS = qs
|
|
|
|
|
queryTask.DataScope = querypb.DataScope_Historical
|
|
|
|
|
err2 := node.scheduler.AddReadTask(ctx, queryTask)
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
failRet.Status.Reason = err2.Error()
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err2 = queryTask.WaitToFinish()
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
failRet.Status.Reason = err2.Error()
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
2022-06-13 11:42:09 +08:00
|
|
|
|
|
|
|
|
|
tr.Elapse(fmt.Sprintf("do query done, msgID = %d, fromSharedLeader = %t, vChannel = %s, segmentIDs = %v",
|
|
|
|
|
msgID, req.GetFromShardLeader(), req.GetDmlChannel(), req.GetSegmentIDs()))
|
|
|
|
|
|
2022-05-27 14:12:01 +08:00
|
|
|
|
failRet.Status.ErrorCode = commonpb.ErrorCode_Success
|
|
|
|
|
metrics.QueryNodeSQLatencyInQueue.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
metrics.QueryLabel).Observe(float64(queryTask.queueDur.Milliseconds()))
|
|
|
|
|
metrics.QueryNodeReduceLatency.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
metrics.QueryLabel).Observe(float64(queryTask.reduceDur.Milliseconds()))
|
|
|
|
|
latency := tr.ElapseSpan()
|
|
|
|
|
metrics.QueryNodeSQReqLatency.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.QueryLabel).Observe(float64(latency.Milliseconds()))
|
|
|
|
|
metrics.QueryNodeSQCount.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.QueryLabel, metrics.SuccessLabel).Inc()
|
2022-05-23 16:41:58 +08:00
|
|
|
|
return queryTask.Ret, nil
|
2022-04-20 16:15:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 16:41:58 +08:00
|
|
|
|
cluster, ok := qs.clusterService.getShardCluster(req.GetDmlChannel())
|
|
|
|
|
if !ok {
|
|
|
|
|
failRet.Status.Reason = fmt.Sprintf("channel %s leader is not here", req.GetDmlChannel())
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add cancel when error occurs
|
|
|
|
|
queryCtx, cancel := context.WithCancel(ctx)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
var results []*internalpb.RetrieveResults
|
|
|
|
|
var streamingResult *internalpb.RetrieveResults
|
|
|
|
|
|
2022-06-17 17:38:12 +08:00
|
|
|
|
withStreaming := func(ctx context.Context) error {
|
2022-05-23 16:41:58 +08:00
|
|
|
|
streamingTask := newQueryTask(queryCtx, req)
|
|
|
|
|
streamingTask.DataScope = querypb.DataScope_Streaming
|
|
|
|
|
streamingTask.QS = qs
|
2022-06-17 17:38:12 +08:00
|
|
|
|
err := node.scheduler.AddReadTask(queryCtx, streamingTask)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2022-05-23 16:41:58 +08:00
|
|
|
|
}
|
2022-06-17 17:38:12 +08:00
|
|
|
|
err = streamingTask.WaitToFinish()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2022-05-23 16:41:58 +08:00
|
|
|
|
}
|
2022-05-27 14:12:01 +08:00
|
|
|
|
metrics.QueryNodeSQLatencyInQueue.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
metrics.QueryLabel).Observe(float64(streamingTask.queueDur.Milliseconds()))
|
|
|
|
|
metrics.QueryNodeReduceLatency.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
metrics.QueryLabel).Observe(float64(streamingTask.reduceDur.Milliseconds()))
|
2022-05-23 16:41:58 +08:00
|
|
|
|
streamingResult = streamingTask.Ret
|
2022-06-17 17:38:12 +08:00
|
|
|
|
return nil
|
2022-04-20 16:15:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 17:38:12 +08:00
|
|
|
|
var errCluster error
|
|
|
|
|
// shard leader dispatches request to its shard cluster
|
|
|
|
|
results, errCluster = cluster.Query(queryCtx, req, withStreaming)
|
|
|
|
|
if errCluster != nil {
|
|
|
|
|
log.Warn("failed to query cluster", zap.Int64("msgID", msgID), zap.Int64("collectionID", req.Req.GetCollectionID()), zap.Error(errCluster))
|
|
|
|
|
failRet.Status.Reason = errCluster.Error()
|
2022-05-23 16:41:58 +08:00
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
2022-06-13 11:42:09 +08:00
|
|
|
|
|
|
|
|
|
tr.Elapse(fmt.Sprintf("start reduce query result, msgID = %d, fromSharedLeader = %t, vChannel = %s, segmentIDs = %v",
|
|
|
|
|
msgID, req.GetFromShardLeader(), req.GetDmlChannel(), req.GetSegmentIDs()))
|
|
|
|
|
|
2022-05-23 16:41:58 +08:00
|
|
|
|
results = append(results, streamingResult)
|
|
|
|
|
ret, err2 := mergeInternalRetrieveResults(results)
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
failRet.Status.Reason = err2.Error()
|
|
|
|
|
return failRet, nil
|
|
|
|
|
}
|
2022-06-13 11:42:09 +08:00
|
|
|
|
|
|
|
|
|
tr.Elapse(fmt.Sprintf("do query done, msgID = %d, fromSharedLeader = %t, vChannel = %s, segmentIDs = %v",
|
|
|
|
|
msgID, req.GetFromShardLeader(), req.GetDmlChannel(), req.GetSegmentIDs()))
|
|
|
|
|
|
2022-05-27 14:12:01 +08:00
|
|
|
|
failRet.Status.ErrorCode = commonpb.ErrorCode_Success
|
|
|
|
|
latency := tr.ElapseSpan()
|
|
|
|
|
metrics.QueryNodeSQReqLatency.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.QueryLabel).Observe(float64(latency.Milliseconds()))
|
|
|
|
|
metrics.QueryNodeSQCount.WithLabelValues(fmt.Sprint(Params.QueryNodeCfg.GetNodeID()), metrics.QueryLabel, metrics.SuccessLabel).Inc()
|
2022-05-23 16:41:58 +08:00
|
|
|
|
return ret, nil
|
2022-03-30 12:03:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-27 10:41:46 +08:00
|
|
|
|
// SyncReplicaSegments syncs replica node & segments states
|
|
|
|
|
func (node *QueryNode) SyncReplicaSegments(ctx context.Context, req *querypb.SyncReplicaSegmentsRequest) (*commonpb.Status, error) {
|
|
|
|
|
if !node.isHealthy() {
|
|
|
|
|
return &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: msgQueryNodeIsUnhealthy(Params.QueryNodeCfg.GetNodeID()),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Debug("Received SyncReplicaSegments request", zap.String("vchannelName", req.GetVchannelName()))
|
|
|
|
|
|
|
|
|
|
err := node.ShardClusterService.SyncReplicaSegments(req.GetVchannelName(), req.GetReplicaSegments())
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warn("failed to sync replica semgents,", zap.String("vchannel", req.GetVchannelName()), zap.Error(err))
|
|
|
|
|
return &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Debug("SyncReplicaSegments Done", zap.String("vchannel", req.GetVchannelName()))
|
|
|
|
|
|
|
|
|
|
return &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-24 17:13:10 +08:00
|
|
|
|
// GetMetrics return system infos of the query node, such as total memory, memory usage, cpu usage ...
|
2021-11-10 23:56:10 +08:00
|
|
|
|
// TODO(dragondriver): cache the Metrics and set a retention to the cache
|
2021-08-17 10:06:11 +08:00
|
|
|
|
func (node *QueryNode) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
|
|
|
|
if !node.isHealthy() {
|
|
|
|
|
log.Warn("QueryNode.GetMetrics failed",
|
2022-04-24 22:03:44 +08:00
|
|
|
|
zap.Int64("node_id", Params.QueryNodeCfg.GetNodeID()),
|
2021-08-17 10:06:11 +08:00
|
|
|
|
zap.String("req", req.Request),
|
2022-04-24 22:03:44 +08:00
|
|
|
|
zap.Error(errQueryNodeIsUnhealthy(Params.QueryNodeCfg.GetNodeID())))
|
2021-08-17 10:06:11 +08:00
|
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2022-04-24 22:03:44 +08:00
|
|
|
|
Reason: msgQueryNodeIsUnhealthy(Params.QueryNodeCfg.GetNodeID()),
|
2021-08-17 10:06:11 +08:00
|
|
|
|
},
|
|
|
|
|
Response: "",
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
metricType, err := metricsinfo.ParseMetricType(req.Request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warn("QueryNode.GetMetrics failed to parse metric type",
|
2022-04-24 22:03:44 +08:00
|
|
|
|
zap.Int64("node_id", Params.QueryNodeCfg.GetNodeID()),
|
2021-08-17 10:06:11 +08:00
|
|
|
|
zap.String("req", req.Request),
|
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: err.Error(),
|
|
|
|
|
},
|
|
|
|
|
Response: "",
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if metricType == metricsinfo.SystemInfoMetrics {
|
|
|
|
|
metrics, err := getSystemInfoMetrics(ctx, req, node)
|
2022-01-14 23:55:34 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warn("QueryNode.GetMetrics failed",
|
2022-04-24 22:03:44 +08:00
|
|
|
|
zap.Int64("node_id", Params.QueryNodeCfg.GetNodeID()),
|
2022-01-14 23:55:34 +08:00
|
|
|
|
zap.String("req", req.Request),
|
|
|
|
|
zap.String("metric_type", metricType),
|
|
|
|
|
zap.Error(err))
|
|
|
|
|
}
|
2021-08-17 10:06:11 +08:00
|
|
|
|
|
2021-12-01 22:13:37 +08:00
|
|
|
|
return metrics, nil
|
2021-08-17 10:06:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Debug("QueryNode.GetMetrics failed, request metric type is not implemented yet",
|
2022-04-24 22:03:44 +08:00
|
|
|
|
zap.Int64("node_id", Params.QueryNodeCfg.GetNodeID()),
|
2021-08-17 10:06:11 +08:00
|
|
|
|
zap.String("req", req.Request),
|
|
|
|
|
zap.String("metric_type", metricType))
|
|
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
|
Reason: metricsinfo.MsgUnimplementedMetric,
|
|
|
|
|
},
|
|
|
|
|
Response: "",
|
|
|
|
|
}, nil
|
|
|
|
|
}
|