2021-01-16 02:12:14 +00:00
|
|
|
package querynode
|
2020-08-25 07:45:19 +00:00
|
|
|
|
2020-09-02 02:38:08 +00:00
|
|
|
/*
|
|
|
|
|
2020-10-23 10:01:24 +00:00
|
|
|
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
|
2020-09-02 02:38:08 +00:00
|
|
|
|
2020-10-31 07:11:47 +00:00
|
|
|
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_segcore -Wl,-rpath=${SRCDIR}/../core/output/lib
|
2020-09-02 02:38:08 +00:00
|
|
|
|
2020-11-25 02:31:51 +00:00
|
|
|
#include "segcore/collection_c.h"
|
|
|
|
#include "segcore/segment_c.h"
|
2020-09-02 02:38:08 +00:00
|
|
|
|
|
|
|
*/
|
2020-08-25 07:45:19 +00:00
|
|
|
import "C"
|
2020-09-02 02:38:08 +00:00
|
|
|
|
2020-08-25 07:45:19 +00:00
|
|
|
import (
|
2020-10-15 13:31:50 +00:00
|
|
|
"context"
|
2021-01-11 10:35:54 +00:00
|
|
|
"fmt"
|
2021-03-12 06:22:09 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/milvuspb"
|
2021-03-08 07:25:55 +00:00
|
|
|
"math/rand"
|
2021-03-05 10:16:50 +00:00
|
|
|
"strings"
|
2021-01-21 07:20:23 +00:00
|
|
|
"sync/atomic"
|
2021-03-08 07:25:55 +00:00
|
|
|
"time"
|
2021-01-11 10:35:54 +00:00
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/types"
|
|
|
|
|
2021-03-05 02:15:27 +00:00
|
|
|
"errors"
|
|
|
|
|
2021-03-05 01:21:35 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/log"
|
2021-02-09 07:57:10 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream"
|
2021-01-20 02:02:59 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream/pulsarms"
|
2021-02-09 07:57:10 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream/rmqms"
|
2021-01-15 07:28:54 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
2021-03-12 06:22:09 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
2021-01-15 07:28:54 +00:00
|
|
|
queryPb "github.com/zilliztech/milvus-distributed/internal/proto/querypb"
|
2021-01-22 03:17:18 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
|
2020-08-25 07:45:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type QueryNode struct {
|
2020-12-08 06:41:04 +00:00
|
|
|
queryNodeLoopCtx context.Context
|
2020-12-10 08:31:09 +00:00
|
|
|
queryNodeLoopCancel context.CancelFunc
|
2020-10-15 13:31:50 +00:00
|
|
|
|
2021-02-23 03:40:30 +00:00
|
|
|
QueryNodeID UniqueID
|
2021-01-21 07:20:23 +00:00
|
|
|
stateCode atomic.Value
|
2020-08-25 07:45:19 +00:00
|
|
|
|
2021-03-05 08:52:45 +00:00
|
|
|
replica ReplicaInterface
|
2020-08-25 07:45:19 +00:00
|
|
|
|
2021-01-15 07:28:54 +00:00
|
|
|
// internal services
|
2021-01-30 08:02:10 +00:00
|
|
|
dataSyncService *dataSyncService
|
|
|
|
metaService *metaService
|
|
|
|
searchService *searchService
|
|
|
|
loadService *loadService
|
|
|
|
statsService *statsService
|
2021-01-18 02:09:17 +00:00
|
|
|
|
2021-01-26 05:41:41 +00:00
|
|
|
// clients
|
2021-03-08 02:09:48 +00:00
|
|
|
masterService types.MasterService
|
|
|
|
queryService types.QueryService
|
|
|
|
indexService types.IndexService
|
|
|
|
dataService types.DataService
|
2021-02-08 06:30:54 +00:00
|
|
|
|
|
|
|
msFactory msgstream.Factory
|
2020-11-05 02:52:50 +00:00
|
|
|
}
|
2020-09-07 09:01:46 +00:00
|
|
|
|
2021-02-23 03:40:30 +00:00
|
|
|
func NewQueryNode(ctx context.Context, queryNodeID UniqueID, factory msgstream.Factory) *QueryNode {
|
2021-03-08 07:25:55 +00:00
|
|
|
rand.Seed(time.Now().UnixNano())
|
2020-12-08 06:41:04 +00:00
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
2021-01-21 07:20:23 +00:00
|
|
|
node := &QueryNode{
|
2021-01-11 10:35:54 +00:00
|
|
|
queryNodeLoopCtx: ctx1,
|
|
|
|
queryNodeLoopCancel: cancel,
|
|
|
|
QueryNodeID: queryNodeID,
|
|
|
|
|
|
|
|
dataSyncService: nil,
|
|
|
|
metaService: nil,
|
|
|
|
searchService: nil,
|
|
|
|
statsService: nil,
|
2021-02-08 06:30:54 +00:00
|
|
|
|
|
|
|
msFactory: factory,
|
2021-01-11 10:35:54 +00:00
|
|
|
}
|
|
|
|
|
2021-03-05 08:52:45 +00:00
|
|
|
node.replica = newCollectionReplica()
|
2021-03-12 06:22:09 +00:00
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
2021-01-21 07:20:23 +00:00
|
|
|
return node
|
|
|
|
}
|
2020-11-13 09:20:13 +00:00
|
|
|
|
2021-02-08 06:30:54 +00:00
|
|
|
func NewQueryNodeWithoutID(ctx context.Context, factory msgstream.Factory) *QueryNode {
|
2021-01-27 01:50:52 +00:00
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
|
|
|
node := &QueryNode{
|
|
|
|
queryNodeLoopCtx: ctx1,
|
|
|
|
queryNodeLoopCancel: cancel,
|
|
|
|
|
|
|
|
dataSyncService: nil,
|
|
|
|
metaService: nil,
|
|
|
|
searchService: nil,
|
|
|
|
statsService: nil,
|
2021-02-08 06:30:54 +00:00
|
|
|
|
|
|
|
msFactory: factory,
|
2021-01-27 01:50:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-05 08:52:45 +00:00
|
|
|
node.replica = newCollectionReplica()
|
2021-03-12 06:22:09 +00:00
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
2021-01-27 01:50:52 +00:00
|
|
|
|
2021-02-23 03:40:30 +00:00
|
|
|
return node
|
2020-09-15 07:53:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 02:01:29 +00:00
|
|
|
func (node *QueryNode) Init() error {
|
2021-02-26 09:44:24 +00:00
|
|
|
ctx := context.Background()
|
2021-01-22 06:28:06 +00:00
|
|
|
registerReq := &queryPb.RegisterNodeRequest{
|
2021-02-18 08:26:02 +00:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
SourceID: Params.QueryNodeID,
|
|
|
|
},
|
2021-01-21 07:20:23 +00:00
|
|
|
Address: &commonpb.Address{
|
|
|
|
Ip: Params.QueryNodeIP,
|
|
|
|
Port: Params.QueryNodePort,
|
|
|
|
},
|
|
|
|
}
|
2021-01-27 01:50:52 +00:00
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
resp, err := node.queryService.RegisterNode(ctx, registerReq)
|
2021-01-21 07:20:23 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-03-10 14:06:22 +00:00
|
|
|
if resp.Status.ErrorCode != commonpb.ErrorCode_Success {
|
2021-02-18 08:26:02 +00:00
|
|
|
panic(resp.Status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, kv := range resp.InitParams.StartParams {
|
|
|
|
switch kv.Key {
|
|
|
|
case "StatsChannelName":
|
|
|
|
Params.StatsChannelName = kv.Value
|
|
|
|
case "TimeTickChannelName":
|
|
|
|
Params.QueryTimeTickChannelName = kv.Value
|
|
|
|
case "QueryChannelName":
|
|
|
|
Params.SearchChannelNames = append(Params.SearchChannelNames, kv.Value)
|
|
|
|
case "QueryResultChannelName":
|
|
|
|
Params.SearchResultChannelNames = append(Params.SearchResultChannelNames, kv.Value)
|
|
|
|
default:
|
2021-03-05 02:15:27 +00:00
|
|
|
return fmt.Errorf("Invalid key: %v", kv.Key)
|
2021-02-18 08:26:02 +00:00
|
|
|
}
|
2021-01-21 07:20:23 +00:00
|
|
|
}
|
|
|
|
|
2021-03-05 01:21:35 +00:00
|
|
|
log.Debug("", zap.Int64("QueryNodeID", Params.QueryNodeID))
|
2021-01-21 07:20:23 +00:00
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
if node.masterService == nil {
|
2021-03-05 01:21:35 +00:00
|
|
|
log.Error("null master service detected")
|
2021-01-30 08:02:10 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
if node.indexService == nil {
|
2021-03-05 01:21:35 +00:00
|
|
|
log.Error("null index service detected")
|
2021-01-26 05:41:41 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
if node.dataService == nil {
|
2021-03-05 01:21:35 +00:00
|
|
|
log.Error("null data service detected")
|
2021-01-26 05:41:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 08:02:10 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *QueryNode) Start() error {
|
2021-02-08 06:30:54 +00:00
|
|
|
var err error
|
|
|
|
m := map[string]interface{}{
|
|
|
|
"PulsarAddress": Params.PulsarAddress,
|
|
|
|
"ReceiveBufSize": 1024,
|
|
|
|
"PulsarBufSize": 1024}
|
|
|
|
err = node.msFactory.SetParams(m)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-01-19 03:37:16 +00:00
|
|
|
// init services and manager
|
2021-02-08 06:30:54 +00:00
|
|
|
node.dataSyncService = newDataSyncService(node.queryNodeLoopCtx, node.replica, node.msFactory)
|
|
|
|
node.searchService = newSearchService(node.queryNodeLoopCtx, node.replica, node.msFactory)
|
2021-02-07 02:29:58 +00:00
|
|
|
//node.metaService = newMetaService(node.queryNodeLoopCtx, node.replica)
|
2021-02-08 06:30:54 +00:00
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
node.loadService = newLoadService(node.queryNodeLoopCtx, node.masterService, node.dataService, node.indexService, node.replica, node.dataSyncService.dmStream)
|
2021-02-08 06:30:54 +00:00
|
|
|
node.statsService = newStatsService(node.queryNodeLoopCtx, node.replica, node.loadService.segLoader.indexLoader.fieldStatsChan, node.msFactory)
|
2020-09-15 07:53:10 +00:00
|
|
|
|
2021-01-19 03:37:16 +00:00
|
|
|
// start services
|
2020-11-09 08:27:11 +00:00
|
|
|
go node.dataSyncService.start()
|
2020-11-19 09:09:22 +00:00
|
|
|
go node.searchService.start()
|
2021-02-07 02:29:58 +00:00
|
|
|
//go node.metaService.start()
|
2021-01-30 08:02:10 +00:00
|
|
|
go node.loadService.start()
|
2020-12-08 06:41:04 +00:00
|
|
|
go node.statsService.start()
|
2021-03-12 06:22:09 +00:00
|
|
|
node.UpdateStateCode(internalpb.StateCode_Healthy)
|
2021-01-21 02:01:29 +00:00
|
|
|
return nil
|
2020-11-05 02:52:50 +00:00
|
|
|
}
|
2020-09-15 07:53:10 +00:00
|
|
|
|
2021-01-21 02:01:29 +00:00
|
|
|
func (node *QueryNode) Stop() error {
|
2021-03-12 06:22:09 +00:00
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
2020-12-08 06:41:04 +00:00
|
|
|
node.queryNodeLoopCancel()
|
|
|
|
|
2020-11-24 08:12:39 +00:00
|
|
|
// free collectionReplica
|
2020-12-08 06:41:04 +00:00
|
|
|
node.replica.freeAll()
|
2020-11-24 08:12:39 +00:00
|
|
|
|
|
|
|
// close services
|
|
|
|
if node.dataSyncService != nil {
|
2020-12-08 06:41:04 +00:00
|
|
|
node.dataSyncService.close()
|
2020-11-24 08:12:39 +00:00
|
|
|
}
|
|
|
|
if node.searchService != nil {
|
2020-12-08 06:41:04 +00:00
|
|
|
node.searchService.close()
|
2020-11-24 08:12:39 +00:00
|
|
|
}
|
2021-01-30 08:02:10 +00:00
|
|
|
if node.loadService != nil {
|
|
|
|
node.loadService.close()
|
2021-01-12 10:03:24 +00:00
|
|
|
}
|
2020-11-24 08:12:39 +00:00
|
|
|
if node.statsService != nil {
|
2020-12-08 06:41:04 +00:00
|
|
|
node.statsService.close()
|
2020-11-24 08:12:39 +00:00
|
|
|
}
|
2021-01-21 02:01:29 +00:00
|
|
|
return nil
|
2021-01-19 03:37:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) UpdateStateCode(code internalpb.StateCode) {
|
2021-02-23 03:40:30 +00:00
|
|
|
node.stateCode.Store(code)
|
|
|
|
}
|
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
func (node *QueryNode) SetMasterService(master types.MasterService) error {
|
2021-01-27 06:41:56 +00:00
|
|
|
if master == nil {
|
|
|
|
return errors.New("null master service interface")
|
|
|
|
}
|
2021-03-08 02:09:48 +00:00
|
|
|
node.masterService = master
|
2021-01-27 06:41:56 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
func (node *QueryNode) SetQueryService(query types.QueryService) error {
|
2021-01-27 01:50:52 +00:00
|
|
|
if query == nil {
|
2021-01-27 06:41:56 +00:00
|
|
|
return errors.New("null query service interface")
|
2021-01-27 01:50:52 +00:00
|
|
|
}
|
2021-03-08 02:09:48 +00:00
|
|
|
node.queryService = query
|
2021-01-27 01:50:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
func (node *QueryNode) SetIndexService(index types.IndexService) error {
|
2021-01-26 05:41:41 +00:00
|
|
|
if index == nil {
|
|
|
|
return errors.New("null index service interface")
|
|
|
|
}
|
2021-03-08 02:09:48 +00:00
|
|
|
node.indexService = index
|
2021-01-26 05:41:41 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-08 02:09:48 +00:00
|
|
|
func (node *QueryNode) SetDataService(data types.DataService) error {
|
2021-01-26 05:41:41 +00:00
|
|
|
if data == nil {
|
|
|
|
return errors.New("null data service interface")
|
|
|
|
}
|
2021-03-08 02:09:48 +00:00
|
|
|
node.dataService = data
|
2021-01-26 05:41:41 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
|
|
|
stats := &internalpb.ComponentStates{
|
2021-02-26 07:26:21 +00:00
|
|
|
Status: &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-26 07:26:21 +00:00
|
|
|
},
|
|
|
|
}
|
2021-03-12 06:22:09 +00:00
|
|
|
code, ok := node.stateCode.Load().(internalpb.StateCode)
|
2021-01-21 07:20:23 +00:00
|
|
|
if !ok {
|
2021-02-26 07:26:21 +00:00
|
|
|
errMsg := "unexpected error in type assertion"
|
|
|
|
stats.Status = &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-02-26 07:26:21 +00:00
|
|
|
Reason: errMsg,
|
|
|
|
}
|
|
|
|
return stats, errors.New(errMsg)
|
2021-01-21 07:20:23 +00:00
|
|
|
}
|
2021-03-12 06:22:09 +00:00
|
|
|
info := &internalpb.ComponentInfo{
|
2021-01-21 07:20:23 +00:00
|
|
|
NodeID: Params.QueryNodeID,
|
2021-01-23 10:56:08 +00:00
|
|
|
Role: typeutil.QueryNodeRole,
|
2021-01-21 07:20:23 +00:00
|
|
|
StateCode: code,
|
|
|
|
}
|
2021-02-26 07:26:21 +00:00
|
|
|
stats.State = info
|
2021-01-21 07:20:23 +00:00
|
|
|
return stats, nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) GetTimeTickChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
Value: Params.QueryTimeTickChannelName,
|
|
|
|
}, nil
|
2021-01-21 07:20:23 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
Value: Params.StatsChannelName,
|
|
|
|
}, nil
|
2021-01-21 07:20:23 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) AddQueryChannel(ctx context.Context, in *queryPb.AddQueryChannelRequest) (*commonpb.Status, error) {
|
2021-01-19 03:37:16 +00:00
|
|
|
if node.searchService == nil || node.searchService.searchMsgStream == nil {
|
|
|
|
errMsg := "null search service or null search message stream"
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-01-19 03:37:16 +00:00
|
|
|
Reason: errMsg,
|
|
|
|
}
|
|
|
|
|
|
|
|
return status, errors.New(errMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// add request channel
|
|
|
|
consumeChannels := []string{in.RequestChannelID}
|
|
|
|
consumeSubName := Params.MsgChannelSubName
|
2021-02-09 09:09:26 +00:00
|
|
|
node.searchService.searchMsgStream.AsConsumer(consumeChannels, consumeSubName)
|
2021-03-05 10:16:50 +00:00
|
|
|
log.Debug("querynode AsConsumer: " + strings.Join(consumeChannels, ", ") + " : " + consumeSubName)
|
2021-01-19 03:37:16 +00:00
|
|
|
|
|
|
|
// add result channel
|
|
|
|
producerChannels := []string{in.ResultChannelID}
|
2021-02-09 09:09:26 +00:00
|
|
|
node.searchService.searchResultMsgStream.AsProducer(producerChannels)
|
2021-03-05 10:16:50 +00:00
|
|
|
log.Debug("querynode AsProducer: " + strings.Join(producerChannels, ", "))
|
2021-01-19 03:37:16 +00:00
|
|
|
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-19 03:37:16 +00:00
|
|
|
}
|
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) RemoveQueryChannel(ctx context.Context, in *queryPb.RemoveQueryChannelRequest) (*commonpb.Status, error) {
|
2021-01-19 03:37:16 +00:00
|
|
|
if node.searchService == nil || node.searchService.searchMsgStream == nil {
|
|
|
|
errMsg := "null search service or null search result message stream"
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-01-19 03:37:16 +00:00
|
|
|
Reason: errMsg,
|
|
|
|
}
|
|
|
|
|
|
|
|
return status, errors.New(errMsg)
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:02:59 +00:00
|
|
|
searchStream, ok := node.searchService.searchMsgStream.(*pulsarms.PulsarMsgStream)
|
2021-01-19 03:37:16 +00:00
|
|
|
if !ok {
|
|
|
|
errMsg := "type assertion failed for search message stream"
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-01-19 03:37:16 +00:00
|
|
|
Reason: errMsg,
|
|
|
|
}
|
|
|
|
|
|
|
|
return status, errors.New(errMsg)
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:02:59 +00:00
|
|
|
resultStream, ok := node.searchService.searchResultMsgStream.(*pulsarms.PulsarMsgStream)
|
2021-01-19 03:37:16 +00:00
|
|
|
if !ok {
|
|
|
|
errMsg := "type assertion failed for search result message stream"
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-01-19 03:37:16 +00:00
|
|
|
Reason: errMsg,
|
|
|
|
}
|
|
|
|
|
|
|
|
return status, errors.New(errMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove request channel
|
|
|
|
consumeChannels := []string{in.RequestChannelID}
|
|
|
|
consumeSubName := Params.MsgChannelSubName
|
|
|
|
// TODO: searchStream.RemovePulsarConsumers(producerChannels)
|
2021-02-04 06:37:12 +00:00
|
|
|
searchStream.AsConsumer(consumeChannels, consumeSubName)
|
2021-01-19 03:37:16 +00:00
|
|
|
|
|
|
|
// remove result channel
|
|
|
|
producerChannels := []string{in.ResultChannelID}
|
|
|
|
// TODO: resultStream.RemovePulsarProducer(producerChannels)
|
2021-02-04 06:37:12 +00:00
|
|
|
resultStream.AsProducer(producerChannels)
|
2021-01-19 03:37:16 +00:00
|
|
|
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-19 03:37:16 +00:00
|
|
|
}
|
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) WatchDmChannels(ctx context.Context, in *queryPb.WatchDmChannelsRequest) (*commonpb.Status, error) {
|
2021-01-19 03:37:16 +00:00
|
|
|
if node.dataSyncService == nil || node.dataSyncService.dmStream == nil {
|
|
|
|
errMsg := "null data sync service or null data manipulation stream"
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-01-19 03:37:16 +00:00
|
|
|
Reason: errMsg,
|
|
|
|
}
|
|
|
|
|
|
|
|
return status, errors.New(errMsg)
|
|
|
|
}
|
|
|
|
|
2021-02-09 07:57:10 +00:00
|
|
|
switch t := node.dataSyncService.dmStream.(type) {
|
|
|
|
case *pulsarms.PulsarTtMsgStream:
|
|
|
|
case *rmqms.RmqTtMsgStream:
|
|
|
|
default:
|
|
|
|
_ = t
|
2021-01-19 03:37:16 +00:00
|
|
|
errMsg := "type assertion failed for dm message stream"
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-01-19 03:37:16 +00:00
|
|
|
Reason: errMsg,
|
|
|
|
}
|
|
|
|
|
|
|
|
return status, errors.New(errMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// add request channel
|
|
|
|
consumeChannels := in.ChannelIDs
|
|
|
|
consumeSubName := Params.MsgChannelSubName
|
2021-02-09 07:57:10 +00:00
|
|
|
node.dataSyncService.dmStream.AsConsumer(consumeChannels, consumeSubName)
|
2021-03-05 10:16:50 +00:00
|
|
|
log.Debug("querynode AsConsumer: " + strings.Join(consumeChannels, ", ") + " : " + consumeSubName)
|
2021-01-19 03:37:16 +00:00
|
|
|
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-19 03:37:16 +00:00
|
|
|
}
|
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) LoadSegments(ctx context.Context, in *queryPb.LoadSegmentsRequest) (*commonpb.Status, error) {
|
2021-01-19 03:37:16 +00:00
|
|
|
// TODO: support db
|
2021-01-20 01:36:50 +00:00
|
|
|
collectionID := in.CollectionID
|
2021-01-21 07:20:23 +00:00
|
|
|
partitionID := in.PartitionID
|
|
|
|
segmentIDs := in.SegmentIDs
|
2021-01-19 03:37:16 +00:00
|
|
|
fieldIDs := in.FieldIDs
|
2021-02-07 01:30:48 +00:00
|
|
|
schema := in.Schema
|
2021-01-24 10:02:08 +00:00
|
|
|
|
2021-03-05 01:21:35 +00:00
|
|
|
log.Debug("query node load segment", zap.String("loadSegmentRequest", fmt.Sprintln(in)))
|
2021-03-04 06:49:51 +00:00
|
|
|
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-03-04 06:49:51 +00:00
|
|
|
}
|
2021-02-07 01:30:48 +00:00
|
|
|
hasCollection := node.replica.hasCollection(collectionID)
|
|
|
|
hasPartition := node.replica.hasPartition(partitionID)
|
|
|
|
if !hasCollection {
|
|
|
|
err := node.replica.addCollection(collectionID, schema)
|
|
|
|
if err != nil {
|
2021-03-10 14:06:22 +00:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-03-04 06:49:51 +00:00
|
|
|
status.Reason = err.Error()
|
2021-02-07 01:30:48 +00:00
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !hasPartition {
|
|
|
|
err := node.replica.addPartition(collectionID, partitionID)
|
|
|
|
if err != nil {
|
2021-03-10 14:06:22 +00:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-03-04 06:49:51 +00:00
|
|
|
status.Reason = err.Error()
|
2021-02-07 01:30:48 +00:00
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
}
|
2021-02-06 03:35:35 +00:00
|
|
|
err := node.replica.enablePartition(partitionID)
|
2021-01-26 01:38:40 +00:00
|
|
|
if err != nil {
|
2021-03-10 14:06:22 +00:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-03-04 06:49:51 +00:00
|
|
|
status.Reason = err.Error()
|
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(segmentIDs) == 0 {
|
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(in.SegmentIDs) != len(in.SegmentStates) {
|
|
|
|
err := errors.New("len(segmentIDs) should equal to len(segmentStates)")
|
2021-03-10 14:06:22 +00:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-03-04 06:49:51 +00:00
|
|
|
status.Reason = err.Error()
|
2021-01-26 01:38:40 +00:00
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
|
2021-01-24 10:02:08 +00:00
|
|
|
// segments are ordered before LoadSegments calling
|
2021-03-12 06:22:09 +00:00
|
|
|
//var position *internalpb.MsgPosition = nil
|
2021-02-04 09:47:19 +00:00
|
|
|
for i, state := range in.SegmentStates {
|
2021-03-11 02:21:24 +00:00
|
|
|
//thisPosition := state.StartPosition
|
2021-03-11 06:14:29 +00:00
|
|
|
if state.State <= commonpb.SegmentState_Growing {
|
2021-03-11 02:21:24 +00:00
|
|
|
//if position == nil {
|
|
|
|
// position = &internalpb2.MsgPosition{
|
|
|
|
// ChannelName: thisPosition.ChannelName,
|
|
|
|
// }
|
|
|
|
//}
|
2021-02-04 09:47:19 +00:00
|
|
|
segmentIDs = segmentIDs[:i]
|
|
|
|
break
|
2021-01-26 01:38:40 +00:00
|
|
|
}
|
2021-03-11 02:21:24 +00:00
|
|
|
//position = state.StartPosition
|
2021-01-24 10:02:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:21:24 +00:00
|
|
|
//err = node.dataSyncService.seekSegment(position)
|
|
|
|
//if err != nil {
|
|
|
|
// status := &commonpb.Status{
|
|
|
|
// ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
// Reason: err.Error(),
|
|
|
|
// }
|
|
|
|
// return status, err
|
|
|
|
//}
|
2021-03-04 06:49:51 +00:00
|
|
|
|
|
|
|
err = node.loadService.loadSegment(collectionID, partitionID, segmentIDs, fieldIDs)
|
|
|
|
if err != nil {
|
2021-03-10 14:06:22 +00:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-03-04 06:49:51 +00:00
|
|
|
status.Reason = err.Error()
|
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
return status, nil
|
2021-01-21 07:20:23 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) ReleaseCollection(ctx context.Context, in *queryPb.ReleaseCollectionRequest) (*commonpb.Status, error) {
|
2021-02-24 09:24:51 +00:00
|
|
|
err := node.replica.removeCollection(in.CollectionID)
|
|
|
|
if err != nil {
|
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-02-24 09:24:51 +00:00
|
|
|
Reason: err.Error(),
|
|
|
|
}
|
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-24 09:24:51 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) ReleasePartitions(ctx context.Context, in *queryPb.ReleasePartitionsRequest) (*commonpb.Status, error) {
|
2021-02-24 09:24:51 +00:00
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-24 09:24:51 +00:00
|
|
|
}
|
2021-01-26 01:38:40 +00:00
|
|
|
for _, id := range in.PartitionIDs {
|
2021-02-24 09:24:51 +00:00
|
|
|
err := node.loadService.segLoader.replica.removePartition(id)
|
2021-01-26 01:38:40 +00:00
|
|
|
if err != nil {
|
2021-02-24 09:24:51 +00:00
|
|
|
// not return, try to release all partitions
|
2021-03-10 14:06:22 +00:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-02-24 09:24:51 +00:00
|
|
|
status.Reason = err.Error()
|
2021-01-26 01:38:40 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 09:24:51 +00:00
|
|
|
return status, nil
|
|
|
|
}
|
2021-01-26 01:38:40 +00:00
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) ReleaseSegments(ctx context.Context, in *queryPb.ReleaseSegmentsRequest) (*commonpb.Status, error) {
|
2021-02-24 09:24:51 +00:00
|
|
|
status := &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-24 09:24:51 +00:00
|
|
|
}
|
2021-01-21 07:20:23 +00:00
|
|
|
for _, id := range in.SegmentIDs {
|
2021-02-24 09:24:51 +00:00
|
|
|
err2 := node.loadService.segLoader.replica.removeSegment(id)
|
|
|
|
if err2 != nil {
|
|
|
|
// not return, try to release all segments
|
2021-03-10 14:06:22 +00:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-02-24 09:24:51 +00:00
|
|
|
status.Reason = err2.Error()
|
2021-01-19 03:37:16 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 09:24:51 +00:00
|
|
|
return status, nil
|
2021-01-19 03:37:16 +00:00
|
|
|
}
|
2021-02-04 03:40:14 +00:00
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
func (node *QueryNode) GetSegmentInfo(ctx context.Context, in *queryPb.GetSegmentInfoRequest) (*queryPb.GetSegmentInfoResponse, error) {
|
2021-02-04 03:40:14 +00:00
|
|
|
infos := make([]*queryPb.SegmentInfo, 0)
|
|
|
|
for _, id := range in.SegmentIDs {
|
|
|
|
segment, err := node.replica.getSegmentByID(id)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
info := &queryPb.SegmentInfo{
|
|
|
|
SegmentID: segment.ID(),
|
|
|
|
CollectionID: segment.collectionID,
|
|
|
|
PartitionID: segment.partitionID,
|
|
|
|
MemSize: segment.getMemSize(),
|
|
|
|
NumRows: segment.getRowCount(),
|
|
|
|
IndexName: segment.getIndexName(),
|
|
|
|
IndexID: segment.getIndexID(),
|
|
|
|
}
|
|
|
|
infos = append(infos, info)
|
|
|
|
}
|
2021-03-12 06:22:09 +00:00
|
|
|
return &queryPb.GetSegmentInfoResponse{
|
2021-02-04 03:40:14 +00:00
|
|
|
Status: &commonpb.Status{
|
2021-03-10 14:06:22 +00:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-04 03:40:14 +00:00
|
|
|
},
|
|
|
|
Infos: infos,
|
|
|
|
}, nil
|
|
|
|
}
|