2020-11-26 08:01:31 +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"
|
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
|
|
|
|
2020-11-05 02:52:50 +00:00
|
|
|
QueryNodeID uint64
|
2020-08-25 07:45:19 +00:00
|
|
|
|
2020-12-08 06:41:04 +00:00
|
|
|
replica collectionReplica
|
2020-08-25 07:45:19 +00:00
|
|
|
|
2020-12-24 08:19:42 +00:00
|
|
|
dataSyncService *dataSyncService
|
|
|
|
metaService *metaService
|
|
|
|
searchService *searchService
|
|
|
|
statsService *statsService
|
2020-11-05 02:52:50 +00:00
|
|
|
}
|
2020-09-07 09:01:46 +00:00
|
|
|
|
2020-12-08 06:41:04 +00:00
|
|
|
func Init() {
|
|
|
|
Params.Init()
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:00:23 +00:00
|
|
|
func NewQueryNode(ctx context.Context, queryNodeID uint64) *QueryNode {
|
2020-12-08 06:41:04 +00:00
|
|
|
|
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
|
|
|
|
2020-11-05 02:52:50 +00:00
|
|
|
segmentsMap := make(map[int64]*Segment)
|
2020-11-09 08:27:11 +00:00
|
|
|
collections := make([]*Collection, 0)
|
2020-09-23 09:38:15 +00:00
|
|
|
|
2020-11-18 08:38:28 +00:00
|
|
|
tSafe := newTSafe()
|
|
|
|
|
2020-11-17 12:00:23 +00:00
|
|
|
var replica collectionReplica = &collectionReplicaImpl{
|
2020-11-13 09:20:13 +00:00
|
|
|
collections: collections,
|
|
|
|
segments: segmentsMap,
|
2020-11-18 08:38:28 +00:00
|
|
|
|
|
|
|
tSafe: tSafe,
|
2020-11-13 09:20:13 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 09:41:05 +00:00
|
|
|
return &QueryNode{
|
2020-12-08 06:41:04 +00:00
|
|
|
queryNodeLoopCtx: ctx1,
|
|
|
|
queryNodeLoopCancel: cancel,
|
|
|
|
QueryNodeID: queryNodeID,
|
2020-09-15 09:41:05 +00:00
|
|
|
|
2020-12-08 06:41:04 +00:00
|
|
|
replica: replica,
|
2020-09-15 09:41:05 +00:00
|
|
|
|
2020-11-09 08:27:11 +00:00
|
|
|
dataSyncService: nil,
|
|
|
|
metaService: nil,
|
|
|
|
searchService: nil,
|
|
|
|
statsService: nil,
|
2020-09-15 07:53:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 06:41:04 +00: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 08:19:42 +00:00
|
|
|
node.statsService = newStatsService(node.queryNodeLoopCtx, node.replica)
|
2020-09-15 07:53:10 +00:00
|
|
|
|
2020-11-09 08:27:11 +00:00
|
|
|
go node.dataSyncService.start()
|
2020-11-19 09:09:22 +00:00
|
|
|
go node.searchService.start()
|
2020-11-05 02:52:50 +00:00
|
|
|
go node.metaService.start()
|
2020-12-08 06:41:04 +00:00
|
|
|
go node.statsService.start()
|
2020-12-10 08:31:09 +00:00
|
|
|
|
|
|
|
<-node.queryNodeLoopCtx.Done()
|
2020-12-08 06:41:04 +00:00
|
|
|
return nil
|
2020-11-05 02:52:50 +00:00
|
|
|
}
|
2020-09-15 07:53:10 +00:00
|
|
|
|
2020-11-05 02:52:50 +00:00
|
|
|
func (node *QueryNode) Close() {
|
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
|
|
|
}
|
|
|
|
if node.statsService != nil {
|
2020-12-08 06:41:04 +00:00
|
|
|
node.statsService.close()
|
2020-11-24 08:12:39 +00:00
|
|
|
}
|
2020-09-14 03:26:35 +00:00
|
|
|
}
|