query_node.go 1.7 KB
Newer Older
N
neza2017 已提交
1
package querynode
B
bigsheeper 已提交
2

3 4
/*

5
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
6

G
GuoRentong 已提交
7
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_segcore -Wl,-rpath=${SRCDIR}/../core/output/lib
8

F
FluorineDog 已提交
9 10
#include "segcore/collection_c.h"
#include "segcore/segment_c.h"
11 12

*/
B
bigsheeper 已提交
13
import "C"
14

B
bigsheeper 已提交
15
import (
16
	"context"
B
bigsheeper 已提交
17 18 19
)

type QueryNode struct {
Z
zhenshan.cao 已提交
20
	ctx context.Context
21

B
bigsheeper 已提交
22
	QueryNodeID uint64
B
bigsheeper 已提交
23

Z
zhenshan.cao 已提交
24
	replica *collectionReplica
B
bigsheeper 已提交
25

26 27 28 29
	dataSyncService *dataSyncService
	metaService     *metaService
	searchService   *searchService
	statsService    *statsService
B
bigsheeper 已提交
30
}
31

D
dragondriver 已提交
32
func NewQueryNode(ctx context.Context, queryNodeID uint64) *QueryNode {
B
bigsheeper 已提交
33
	segmentsMap := make(map[int64]*Segment)
34
	collections := make([]*Collection, 0)
B
bigsheeper 已提交
35

36 37
	tSafe := newTSafe()

D
dragondriver 已提交
38
	var replica collectionReplica = &collectionReplicaImpl{
G
godchen 已提交
39 40
		collections: collections,
		segments:    segmentsMap,
41 42

		tSafe: tSafe,
G
godchen 已提交
43 44
	}

45
	return &QueryNode{
Z
zhenshan.cao 已提交
46 47 48
		ctx: ctx,

		QueryNodeID: queryNodeID,
49

Z
zhenshan.cao 已提交
50
		replica: &replica,
51

52 53 54 55
		dataSyncService: nil,
		metaService:     nil,
		searchService:   nil,
		statsService:    nil,
B
bigsheeper 已提交
56 57 58
	}
}

Z
zhenshan.cao 已提交
59 60 61 62 63
func (node *QueryNode) Start() {
	node.dataSyncService = newDataSyncService(node.ctx, node.replica)
	node.searchService = newSearchService(node.ctx, node.replica)
	node.metaService = newMetaService(node.ctx, node.replica)
	node.statsService = newStatsService(node.ctx, node.replica)
B
bigsheeper 已提交
64

65
	go node.dataSyncService.start()
N
neza2017 已提交
66
	go node.searchService.start()
B
bigsheeper 已提交
67
	go node.metaService.start()
Z
zhenshan.cao 已提交
68
	node.statsService.start()
B
bigsheeper 已提交
69
}
B
bigsheeper 已提交
70

B
bigsheeper 已提交
71
func (node *QueryNode) Close() {
Z
zhenshan.cao 已提交
72
	<-node.ctx.Done()
B
bigsheeper 已提交
73
	// free collectionReplica
Z
zhenshan.cao 已提交
74
	(*node.replica).freeAll()
B
bigsheeper 已提交
75 76 77

	// close services
	if node.dataSyncService != nil {
Z
zhenshan.cao 已提交
78
		(*node.dataSyncService).close()
B
bigsheeper 已提交
79 80
	}
	if node.searchService != nil {
Z
zhenshan.cao 已提交
81
		(*node.searchService).close()
B
bigsheeper 已提交
82 83
	}
	if node.statsService != nil {
Z
zhenshan.cao 已提交
84
		(*node.statsService).close()
B
bigsheeper 已提交
85
	}
R
rain 已提交
86
}