2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-08-25 15:45:19 +08:00
|
|
|
|
2020-09-02 10:38:08 +08:00
|
|
|
/*
|
|
|
|
|
2020-10-23 18:01:24 +08:00
|
|
|
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
|
2020-09-02 10:38:08 +08:00
|
|
|
|
2020-10-31 15:11:47 +08:00
|
|
|
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_segcore -Wl,-rpath=${SRCDIR}/../core/output/lib
|
2020-09-02 10:38:08 +08:00
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
#include "segcore/collection_c.h"
|
|
|
|
#include "segcore/segment_c.h"
|
2020-09-02 10:38:08 +08:00
|
|
|
|
|
|
|
*/
|
2020-08-25 15:45:19 +08:00
|
|
|
import "C"
|
2020-09-02 10:38:08 +08:00
|
|
|
|
2020-08-25 15:45:19 +08:00
|
|
|
import (
|
2020-10-15 21:31:50 +08:00
|
|
|
"context"
|
2021-01-11 18:35:54 +08:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
"github.com/uber/jaeger-client-go/config"
|
2021-01-19 09:45:42 +08:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2021-01-15 15:28:54 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
|
|
queryPb "github.com/zilliztech/milvus-distributed/internal/proto/querypb"
|
2020-08-25 15:45:19 +08:00
|
|
|
)
|
|
|
|
|
2021-01-15 15:28:54 +08:00
|
|
|
type Node interface {
|
|
|
|
Start() error
|
|
|
|
Close()
|
|
|
|
|
2021-01-16 15:04:32 +08:00
|
|
|
AddQueryChannel(in *queryPb.AddQueryChannelsRequest) (*commonpb.Status, error)
|
|
|
|
RemoveQueryChannel(in *queryPb.RemoveQueryChannelsRequest) (*commonpb.Status, error)
|
|
|
|
WatchDmChannels(in *queryPb.WatchDmChannelsRequest) (*commonpb.Status, error)
|
|
|
|
LoadSegments(in *queryPb.LoadSegmentRequest) (*commonpb.Status, error)
|
|
|
|
ReleaseSegments(in *queryPb.ReleaseSegmentRequest) (*commonpb.Status, error)
|
|
|
|
GetPartitionState(in *queryPb.PartitionStatesRequest) (*queryPb.PartitionStatesResponse, error)
|
2021-01-15 15:28:54 +08:00
|
|
|
}
|
|
|
|
|
2020-08-25 15:45:19 +08:00
|
|
|
type QueryNode struct {
|
2020-12-08 14:41:04 +08:00
|
|
|
queryNodeLoopCtx context.Context
|
2020-12-10 16:31:09 +08:00
|
|
|
queryNodeLoopCancel context.CancelFunc
|
2020-10-15 21:31:50 +08:00
|
|
|
|
2020-11-05 10:52:50 +08:00
|
|
|
QueryNodeID uint64
|
2021-01-19 09:45:42 +08:00
|
|
|
grpcServer *grpc.Server
|
2020-08-25 15:45:19 +08:00
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
replica collectionReplica
|
2020-08-25 15:45:19 +08:00
|
|
|
|
2021-01-15 15:28:54 +08:00
|
|
|
// internal services
|
2020-12-24 20:55:40 +08:00
|
|
|
dataSyncService *dataSyncService
|
|
|
|
metaService *metaService
|
|
|
|
searchService *searchService
|
|
|
|
loadIndexService *loadIndexService
|
|
|
|
statsService *statsService
|
2021-01-11 18:35:54 +08:00
|
|
|
|
2021-01-18 10:09:17 +08:00
|
|
|
segManager *segmentManager
|
|
|
|
|
2021-01-11 18:35:54 +08:00
|
|
|
//opentracing
|
|
|
|
tracer opentracing.Tracer
|
|
|
|
closer io.Closer
|
2020-11-05 10:52:50 +08:00
|
|
|
}
|
2020-09-07 17:01:46 +08:00
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
func Init() {
|
|
|
|
Params.Init()
|
|
|
|
}
|
|
|
|
|
2021-01-15 15:28:54 +08:00
|
|
|
func NewQueryNode(ctx context.Context, queryNodeID uint64) Node {
|
|
|
|
var node Node = newQueryNode(ctx, queryNodeID)
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
func newQueryNode(ctx context.Context, queryNodeID uint64) *QueryNode {
|
2021-01-19 09:45:42 +08:00
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
2021-01-11 18:35:54 +08:00
|
|
|
q := &QueryNode{
|
|
|
|
queryNodeLoopCtx: ctx1,
|
|
|
|
queryNodeLoopCancel: cancel,
|
|
|
|
QueryNodeID: queryNodeID,
|
|
|
|
|
|
|
|
dataSyncService: nil,
|
|
|
|
metaService: nil,
|
|
|
|
searchService: nil,
|
|
|
|
statsService: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
cfg := &config.Configuration{
|
|
|
|
ServiceName: "query_node",
|
|
|
|
Sampler: &config.SamplerConfig{
|
|
|
|
Type: "const",
|
|
|
|
Param: 1,
|
|
|
|
},
|
|
|
|
}
|
2021-01-15 17:09:41 +08:00
|
|
|
q.tracer, q.closer, err = cfg.NewTracer()
|
2021-01-11 18:35:54 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("ERROR: cannot init Jaeger: %v\n", err))
|
|
|
|
}
|
|
|
|
opentracing.SetGlobalTracer(q.tracer)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2020-11-05 10:52:50 +08:00
|
|
|
segmentsMap := make(map[int64]*Segment)
|
2020-11-09 16:27:11 +08:00
|
|
|
collections := make([]*Collection, 0)
|
2020-09-23 17:38:15 +08:00
|
|
|
|
2020-11-18 16:38:28 +08:00
|
|
|
tSafe := newTSafe()
|
|
|
|
|
2021-01-11 18:35:54 +08:00
|
|
|
q.replica = &collectionReplicaImpl{
|
2020-11-13 17:20:13 +08:00
|
|
|
collections: collections,
|
|
|
|
segments: segmentsMap,
|
2020-11-18 16:38:28 +08:00
|
|
|
|
|
|
|
tSafe: tSafe,
|
2020-11-13 17:20:13 +08:00
|
|
|
}
|
|
|
|
|
2021-01-11 18:35:54 +08:00
|
|
|
return q
|
2020-09-15 15:53:10 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
func (node *QueryNode) Start() error {
|
|
|
|
// todo add connectMaster logic
|
|
|
|
node.dataSyncService = newDataSyncService(node.queryNodeLoopCtx, node.replica)
|
|
|
|
node.searchService = newSearchService(node.queryNodeLoopCtx, node.replica)
|
|
|
|
node.metaService = newMetaService(node.queryNodeLoopCtx, node.replica)
|
2020-12-24 20:55:40 +08:00
|
|
|
node.loadIndexService = newLoadIndexService(node.queryNodeLoopCtx, node.replica)
|
|
|
|
node.statsService = newStatsService(node.queryNodeLoopCtx, node.replica, node.loadIndexService.fieldStatsChan)
|
2020-09-15 15:53:10 +08:00
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
go node.dataSyncService.start()
|
2020-11-19 17:09:22 +08:00
|
|
|
go node.searchService.start()
|
2020-11-05 10:52:50 +08:00
|
|
|
go node.metaService.start()
|
2020-12-24 20:55:40 +08:00
|
|
|
go node.loadIndexService.start()
|
2020-12-08 14:41:04 +08:00
|
|
|
go node.statsService.start()
|
2020-12-10 16:31:09 +08:00
|
|
|
|
|
|
|
<-node.queryNodeLoopCtx.Done()
|
2020-12-08 14:41:04 +08:00
|
|
|
return nil
|
2020-11-05 10:52:50 +08:00
|
|
|
}
|
2020-09-15 15:53:10 +08:00
|
|
|
|
2020-11-05 10:52:50 +08:00
|
|
|
func (node *QueryNode) Close() {
|
2020-12-08 14:41:04 +08:00
|
|
|
node.queryNodeLoopCancel()
|
|
|
|
|
2020-11-24 16:12:39 +08:00
|
|
|
// free collectionReplica
|
2020-12-08 14:41:04 +08:00
|
|
|
node.replica.freeAll()
|
2020-11-24 16:12:39 +08:00
|
|
|
|
|
|
|
// close services
|
|
|
|
if node.dataSyncService != nil {
|
2020-12-08 14:41:04 +08:00
|
|
|
node.dataSyncService.close()
|
2020-11-24 16:12:39 +08:00
|
|
|
}
|
|
|
|
if node.searchService != nil {
|
2020-12-08 14:41:04 +08:00
|
|
|
node.searchService.close()
|
2020-11-24 16:12:39 +08:00
|
|
|
}
|
2021-01-12 18:03:24 +08:00
|
|
|
if node.loadIndexService != nil {
|
|
|
|
node.loadIndexService.close()
|
|
|
|
}
|
2020-11-24 16:12:39 +08:00
|
|
|
if node.statsService != nil {
|
2020-12-08 14:41:04 +08:00
|
|
|
node.statsService.close()
|
2020-11-24 16:12:39 +08:00
|
|
|
}
|
2021-01-11 18:35:54 +08:00
|
|
|
if node.closer != nil {
|
|
|
|
node.closer.Close()
|
|
|
|
}
|
|
|
|
|
2020-09-14 11:26:35 +08:00
|
|
|
}
|