query_node.go 15.0 KB
Newer Older
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"
17
	"fmt"
S
sunby 已提交
18
	"math/rand"
X
Xiangyu Wang 已提交
19
	"strings"
C
cai.zhang 已提交
20
	"sync/atomic"
S
sunby 已提交
21
	"time"
22

T
ThreadDao 已提交
23 24
	"github.com/zilliztech/milvus-distributed/internal/types"

S
sunby 已提交
25 26
	"errors"

B
bigsheeper 已提交
27 28 29
	"go.uber.org/zap"

	"github.com/zilliztech/milvus-distributed/internal/log"
G
groot 已提交
30
	"github.com/zilliztech/milvus-distributed/internal/msgstream"
X
Xiangyu Wang 已提交
31
	"github.com/zilliztech/milvus-distributed/internal/msgstream/pulsarms"
G
groot 已提交
32
	"github.com/zilliztech/milvus-distributed/internal/msgstream/rmqms"
33
	"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
C
cai.zhang 已提交
34
	"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
35
	queryPb "github.com/zilliztech/milvus-distributed/internal/proto/querypb"
36
	"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
B
bigsheeper 已提交
37 38 39
)

type QueryNode struct {
40 41
	typeutil.Service

X
XuanYang-cn 已提交
42
	queryNodeLoopCtx    context.Context
43
	queryNodeLoopCancel context.CancelFunc
44

45
	QueryNodeID UniqueID
C
cai.zhang 已提交
46
	stateCode   atomic.Value
B
bigsheeper 已提交
47

48
	replica ReplicaInterface
B
bigsheeper 已提交
49

50
	// internal services
51 52 53 54 55
	dataSyncService *dataSyncService
	metaService     *metaService
	searchService   *searchService
	loadService     *loadService
	statsService    *statsService
56

57
	// clients
T
ThreadDao 已提交
58 59 60 61
	masterService types.MasterService
	queryService  types.QueryService
	indexService  types.IndexService
	dataService   types.DataService
G
groot 已提交
62 63

	msFactory msgstream.Factory
B
bigsheeper 已提交
64
}
65

66
func NewQueryNode(ctx context.Context, queryNodeID UniqueID, factory msgstream.Factory) *QueryNode {
S
sunby 已提交
67
	rand.Seed(time.Now().UnixNano())
X
XuanYang-cn 已提交
68
	ctx1, cancel := context.WithCancel(ctx)
C
cai.zhang 已提交
69
	node := &QueryNode{
70 71 72 73 74 75 76 77
		queryNodeLoopCtx:    ctx1,
		queryNodeLoopCancel: cancel,
		QueryNodeID:         queryNodeID,

		dataSyncService: nil,
		metaService:     nil,
		searchService:   nil,
		statsService:    nil,
G
groot 已提交
78 79

		msFactory: factory,
80 81
	}

82
	node.replica = newCollectionReplica()
D
del-zhenwu 已提交
83
	node.UpdateStateCode(internalpb2.StateCode_Abnormal)
C
cai.zhang 已提交
84 85
	return node
}
G
godchen 已提交
86

G
groot 已提交
87
func NewQueryNodeWithoutID(ctx context.Context, factory msgstream.Factory) *QueryNode {
88 89 90 91 92 93 94 95 96
	ctx1, cancel := context.WithCancel(ctx)
	node := &QueryNode{
		queryNodeLoopCtx:    ctx1,
		queryNodeLoopCancel: cancel,

		dataSyncService: nil,
		metaService:     nil,
		searchService:   nil,
		statsService:    nil,
G
groot 已提交
97 98

		msFactory: factory,
99 100
	}

101
	node.replica = newCollectionReplica()
D
del-zhenwu 已提交
102
	node.UpdateStateCode(internalpb2.StateCode_Abnormal)
103

104
	return node
B
bigsheeper 已提交
105 106
}

N
neza2017 已提交
107
func (node *QueryNode) Init() error {
G
godchen 已提交
108
	ctx := context.Background()
X
xige-16 已提交
109
	registerReq := &queryPb.RegisterNodeRequest{
110
		Base: &commonpb.MsgBase{
111
			MsgType:  commonpb.MsgType_None,
112 113
			SourceID: Params.QueryNodeID,
		},
C
cai.zhang 已提交
114 115 116 117 118
		Address: &commonpb.Address{
			Ip:   Params.QueryNodeIP,
			Port: Params.QueryNodePort,
		},
	}
119

T
ThreadDao 已提交
120
	resp, err := node.queryService.RegisterNode(ctx, registerReq)
C
cai.zhang 已提交
121 122 123
	if err != nil {
		panic(err)
	}
Q
quicksilver 已提交
124
	if resp.Status.ErrorCode != commonpb.ErrorCode_ERROR_CODE_SUCCESS {
125 126 127 128 129 130 131 132 133 134 135 136 137 138
		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:
S
sunby 已提交
139
			return fmt.Errorf("Invalid key: %v", kv.Key)
140
		}
C
cai.zhang 已提交
141 142
	}

B
bigsheeper 已提交
143
	log.Debug("", zap.Int64("QueryNodeID", Params.QueryNodeID))
C
cai.zhang 已提交
144

T
ThreadDao 已提交
145
	if node.masterService == nil {
B
bigsheeper 已提交
146
		log.Error("null master service detected")
147 148
	}

T
ThreadDao 已提交
149
	if node.indexService == nil {
B
bigsheeper 已提交
150
		log.Error("null index service detected")
151 152
	}

T
ThreadDao 已提交
153
	if node.dataService == nil {
B
bigsheeper 已提交
154
		log.Error("null data service detected")
155 156
	}

157 158 159 160
	return nil
}

func (node *QueryNode) Start() error {
G
groot 已提交
161 162 163 164 165 166 167 168 169 170
	var err error
	m := map[string]interface{}{
		"PulsarAddress":  Params.PulsarAddress,
		"ReceiveBufSize": 1024,
		"PulsarBufSize":  1024}
	err = node.msFactory.SetParams(m)
	if err != nil {
		return err
	}

X
XuanYang-cn 已提交
171
	// init services and manager
G
groot 已提交
172 173
	node.dataSyncService = newDataSyncService(node.queryNodeLoopCtx, node.replica, node.msFactory)
	node.searchService = newSearchService(node.queryNodeLoopCtx, node.replica, node.msFactory)
B
bigsheeper 已提交
174
	//node.metaService = newMetaService(node.queryNodeLoopCtx, node.replica)
G
groot 已提交
175

T
ThreadDao 已提交
176
	node.loadService = newLoadService(node.queryNodeLoopCtx, node.masterService, node.dataService, node.indexService, node.replica, node.dataSyncService.dmStream)
G
groot 已提交
177
	node.statsService = newStatsService(node.queryNodeLoopCtx, node.replica, node.loadService.segLoader.indexLoader.fieldStatsChan, node.msFactory)
B
bigsheeper 已提交
178

X
XuanYang-cn 已提交
179
	// start services
180
	go node.dataSyncService.start()
N
neza2017 已提交
181
	go node.searchService.start()
B
bigsheeper 已提交
182
	//go node.metaService.start()
183
	go node.loadService.start()
X
XuanYang-cn 已提交
184
	go node.statsService.start()
D
del-zhenwu 已提交
185
	node.UpdateStateCode(internalpb2.StateCode_Healthy)
N
neza2017 已提交
186
	return nil
B
bigsheeper 已提交
187
}
B
bigsheeper 已提交
188

N
neza2017 已提交
189
func (node *QueryNode) Stop() error {
D
del-zhenwu 已提交
190
	node.UpdateStateCode(internalpb2.StateCode_Abnormal)
X
XuanYang-cn 已提交
191 192
	node.queryNodeLoopCancel()

B
bigsheeper 已提交
193
	// free collectionReplica
X
XuanYang-cn 已提交
194
	node.replica.freeAll()
B
bigsheeper 已提交
195 196 197

	// close services
	if node.dataSyncService != nil {
X
XuanYang-cn 已提交
198
		node.dataSyncService.close()
B
bigsheeper 已提交
199 200
	}
	if node.searchService != nil {
X
XuanYang-cn 已提交
201
		node.searchService.close()
B
bigsheeper 已提交
202
	}
203 204
	if node.loadService != nil {
		node.loadService.close()
B
bigsheeper 已提交
205
	}
B
bigsheeper 已提交
206
	if node.statsService != nil {
X
XuanYang-cn 已提交
207
		node.statsService.close()
B
bigsheeper 已提交
208
	}
N
neza2017 已提交
209
	return nil
X
XuanYang-cn 已提交
210 211
}

212 213 214 215
func (node *QueryNode) UpdateStateCode(code internalpb2.StateCode) {
	node.stateCode.Store(code)
}

T
ThreadDao 已提交
216
func (node *QueryNode) SetMasterService(master types.MasterService) error {
B
bigsheeper 已提交
217 218 219
	if master == nil {
		return errors.New("null master service interface")
	}
T
ThreadDao 已提交
220
	node.masterService = master
B
bigsheeper 已提交
221 222 223
	return nil
}

T
ThreadDao 已提交
224
func (node *QueryNode) SetQueryService(query types.QueryService) error {
225
	if query == nil {
B
bigsheeper 已提交
226
		return errors.New("null query service interface")
227
	}
T
ThreadDao 已提交
228
	node.queryService = query
229 230 231
	return nil
}

T
ThreadDao 已提交
232
func (node *QueryNode) SetIndexService(index types.IndexService) error {
233 234 235
	if index == nil {
		return errors.New("null index service interface")
	}
T
ThreadDao 已提交
236
	node.indexService = index
237 238 239
	return nil
}

T
ThreadDao 已提交
240
func (node *QueryNode) SetDataService(data types.DataService) error {
241 242 243
	if data == nil {
		return errors.New("null data service interface")
	}
T
ThreadDao 已提交
244
	node.dataService = data
245 246 247
	return nil
}

C
cai.zhang 已提交
248
func (node *QueryNode) GetComponentStates() (*internalpb2.ComponentStates, error) {
249 250
	stats := &internalpb2.ComponentStates{
		Status: &commonpb.Status{
Q
quicksilver 已提交
251
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
252 253
		},
	}
C
cai.zhang 已提交
254 255
	code, ok := node.stateCode.Load().(internalpb2.StateCode)
	if !ok {
256 257
		errMsg := "unexpected error in type assertion"
		stats.Status = &commonpb.Status{
Q
quicksilver 已提交
258
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
259 260 261
			Reason:    errMsg,
		}
		return stats, errors.New(errMsg)
C
cai.zhang 已提交
262 263 264
	}
	info := &internalpb2.ComponentInfo{
		NodeID:    Params.QueryNodeID,
X
XuanYang-cn 已提交
265
		Role:      typeutil.QueryNodeRole,
C
cai.zhang 已提交
266 267
		StateCode: code,
	}
268
	stats.State = info
C
cai.zhang 已提交
269 270 271 272
	return stats, nil
}

func (node *QueryNode) GetTimeTickChannel() (string, error) {
N
neza2017 已提交
273
	return Params.QueryTimeTickChannelName, nil
C
cai.zhang 已提交
274 275 276 277 278 279
}

func (node *QueryNode) GetStatisticsChannel() (string, error) {
	return Params.StatsChannelName, nil
}

X
XuanYang-cn 已提交
280 281 282 283
func (node *QueryNode) AddQueryChannel(in *queryPb.AddQueryChannelsRequest) (*commonpb.Status, error) {
	if node.searchService == nil || node.searchService.searchMsgStream == nil {
		errMsg := "null search service or null search message stream"
		status := &commonpb.Status{
Q
quicksilver 已提交
284
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
X
XuanYang-cn 已提交
285 286 287 288 289 290 291 292 293
			Reason:    errMsg,
		}

		return status, errors.New(errMsg)
	}

	// add request channel
	consumeChannels := []string{in.RequestChannelID}
	consumeSubName := Params.MsgChannelSubName
X
xige-16 已提交
294
	node.searchService.searchMsgStream.AsConsumer(consumeChannels, consumeSubName)
X
Xiangyu Wang 已提交
295
	log.Debug("querynode AsConsumer: " + strings.Join(consumeChannels, ", ") + " : " + consumeSubName)
X
XuanYang-cn 已提交
296 297 298

	// add result channel
	producerChannels := []string{in.ResultChannelID}
X
xige-16 已提交
299
	node.searchService.searchResultMsgStream.AsProducer(producerChannels)
X
Xiangyu Wang 已提交
300
	log.Debug("querynode AsProducer: " + strings.Join(producerChannels, ", "))
X
XuanYang-cn 已提交
301 302

	status := &commonpb.Status{
Q
quicksilver 已提交
303
		ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
X
XuanYang-cn 已提交
304 305 306 307 308 309 310 311
	}
	return status, nil
}

func (node *QueryNode) RemoveQueryChannel(in *queryPb.RemoveQueryChannelsRequest) (*commonpb.Status, error) {
	if node.searchService == nil || node.searchService.searchMsgStream == nil {
		errMsg := "null search service or null search result message stream"
		status := &commonpb.Status{
Q
quicksilver 已提交
312
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
X
XuanYang-cn 已提交
313 314 315 316 317 318
			Reason:    errMsg,
		}

		return status, errors.New(errMsg)
	}

X
Xiangyu Wang 已提交
319
	searchStream, ok := node.searchService.searchMsgStream.(*pulsarms.PulsarMsgStream)
X
XuanYang-cn 已提交
320 321 322
	if !ok {
		errMsg := "type assertion failed for search message stream"
		status := &commonpb.Status{
Q
quicksilver 已提交
323
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
X
XuanYang-cn 已提交
324 325 326 327 328 329
			Reason:    errMsg,
		}

		return status, errors.New(errMsg)
	}

X
Xiangyu Wang 已提交
330
	resultStream, ok := node.searchService.searchResultMsgStream.(*pulsarms.PulsarMsgStream)
X
XuanYang-cn 已提交
331 332 333
	if !ok {
		errMsg := "type assertion failed for search result message stream"
		status := &commonpb.Status{
Q
quicksilver 已提交
334
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
X
XuanYang-cn 已提交
335 336 337 338 339 340 341 342 343 344
			Reason:    errMsg,
		}

		return status, errors.New(errMsg)
	}

	// remove request channel
	consumeChannels := []string{in.RequestChannelID}
	consumeSubName := Params.MsgChannelSubName
	// TODO: searchStream.RemovePulsarConsumers(producerChannels)
Z
zhenshan.cao 已提交
345
	searchStream.AsConsumer(consumeChannels, consumeSubName)
X
XuanYang-cn 已提交
346 347 348 349

	// remove result channel
	producerChannels := []string{in.ResultChannelID}
	// TODO: resultStream.RemovePulsarProducer(producerChannels)
Z
zhenshan.cao 已提交
350
	resultStream.AsProducer(producerChannels)
X
XuanYang-cn 已提交
351 352

	status := &commonpb.Status{
Q
quicksilver 已提交
353
		ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
X
XuanYang-cn 已提交
354 355 356 357 358 359 360 361
	}
	return status, nil
}

func (node *QueryNode) WatchDmChannels(in *queryPb.WatchDmChannelsRequest) (*commonpb.Status, error) {
	if node.dataSyncService == nil || node.dataSyncService.dmStream == nil {
		errMsg := "null data sync service or null data manipulation stream"
		status := &commonpb.Status{
Q
quicksilver 已提交
362
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
X
XuanYang-cn 已提交
363 364 365 366 367 368
			Reason:    errMsg,
		}

		return status, errors.New(errMsg)
	}

G
groot 已提交
369 370 371 372 373
	switch t := node.dataSyncService.dmStream.(type) {
	case *pulsarms.PulsarTtMsgStream:
	case *rmqms.RmqTtMsgStream:
	default:
		_ = t
X
XuanYang-cn 已提交
374 375
		errMsg := "type assertion failed for dm message stream"
		status := &commonpb.Status{
Q
quicksilver 已提交
376
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
X
XuanYang-cn 已提交
377 378 379 380 381 382 383 384 385
			Reason:    errMsg,
		}

		return status, errors.New(errMsg)
	}

	// add request channel
	consumeChannels := in.ChannelIDs
	consumeSubName := Params.MsgChannelSubName
G
groot 已提交
386
	node.dataSyncService.dmStream.AsConsumer(consumeChannels, consumeSubName)
X
Xiangyu Wang 已提交
387
	log.Debug("querynode AsConsumer: " + strings.Join(consumeChannels, ", ") + " : " + consumeSubName)
X
XuanYang-cn 已提交
388 389

	status := &commonpb.Status{
Q
quicksilver 已提交
390
		ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
X
XuanYang-cn 已提交
391 392 393 394 395 396
	}
	return status, nil
}

func (node *QueryNode) LoadSegments(in *queryPb.LoadSegmentRequest) (*commonpb.Status, error) {
	// TODO: support db
Z
zhenshan.cao 已提交
397
	collectionID := in.CollectionID
C
cai.zhang 已提交
398 399
	partitionID := in.PartitionID
	segmentIDs := in.SegmentIDs
X
XuanYang-cn 已提交
400
	fieldIDs := in.FieldIDs
401
	schema := in.Schema
402

B
bigsheeper 已提交
403
	log.Debug("query node load segment", zap.String("loadSegmentRequest", fmt.Sprintln(in)))
X
xige-16 已提交
404 405

	status := &commonpb.Status{
Q
quicksilver 已提交
406
		ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
X
xige-16 已提交
407
	}
408 409 410 411 412
	hasCollection := node.replica.hasCollection(collectionID)
	hasPartition := node.replica.hasPartition(partitionID)
	if !hasCollection {
		err := node.replica.addCollection(collectionID, schema)
		if err != nil {
Q
quicksilver 已提交
413
			status.ErrorCode = commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR
X
xige-16 已提交
414
			status.Reason = err.Error()
415 416 417 418 419 420
			return status, err
		}
	}
	if !hasPartition {
		err := node.replica.addPartition(collectionID, partitionID)
		if err != nil {
Q
quicksilver 已提交
421
			status.ErrorCode = commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR
X
xige-16 已提交
422
			status.Reason = err.Error()
423 424 425
			return status, err
		}
	}
426
	err := node.replica.enablePartition(partitionID)
C
cai.zhang 已提交
427
	if err != nil {
Q
quicksilver 已提交
428
		status.ErrorCode = commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR
X
xige-16 已提交
429 430 431 432 433 434 435 436 437 438
		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)")
Q
quicksilver 已提交
439
		status.ErrorCode = commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR
X
xige-16 已提交
440
		status.Reason = err.Error()
C
cai.zhang 已提交
441 442 443
		return status, err
	}

444
	// segments are ordered before LoadSegments calling
X
xige-16 已提交
445
	var position *internalpb2.MsgPosition = nil
446
	for i, state := range in.SegmentStates {
X
xige-16 已提交
447 448 449 450 451
		thisPosition := state.StartPosition
		if state.State <= commonpb.SegmentState_SegmentGrowing {
			if position == nil {
				position = &internalpb2.MsgPosition{
					ChannelName: thisPosition.ChannelName,
452
				}
C
cai.zhang 已提交
453
			}
454 455
			segmentIDs = segmentIDs[:i]
			break
C
cai.zhang 已提交
456
		}
X
xige-16 已提交
457
		position = state.StartPosition
458 459
	}

X
xige-16 已提交
460
	err = node.dataSyncService.seekSegment(position)
C
cai.zhang 已提交
461 462
	if err != nil {
		status := &commonpb.Status{
Q
quicksilver 已提交
463
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
C
cai.zhang 已提交
464
			Reason:    err.Error(),
Z
zhenshan.cao 已提交
465
		}
C
cai.zhang 已提交
466
		return status, err
Z
zhenshan.cao 已提交
467
	}
X
xige-16 已提交
468 469 470

	err = node.loadService.loadSegment(collectionID, partitionID, segmentIDs, fieldIDs)
	if err != nil {
Q
quicksilver 已提交
471
		status.ErrorCode = commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR
X
xige-16 已提交
472 473 474 475
		status.Reason = err.Error()
		return status, err
	}
	return status, nil
C
cai.zhang 已提交
476 477
}

B
bigsheeper 已提交
478 479 480 481
func (node *QueryNode) ReleaseCollection(in *queryPb.ReleaseCollectionRequest) (*commonpb.Status, error) {
	err := node.replica.removeCollection(in.CollectionID)
	if err != nil {
		status := &commonpb.Status{
Q
quicksilver 已提交
482
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR,
B
bigsheeper 已提交
483 484 485 486 487 488
			Reason:    err.Error(),
		}
		return status, err
	}

	return &commonpb.Status{
Q
quicksilver 已提交
489
		ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
B
bigsheeper 已提交
490 491 492 493 494
	}, nil
}

func (node *QueryNode) ReleasePartitions(in *queryPb.ReleasePartitionRequest) (*commonpb.Status, error) {
	status := &commonpb.Status{
Q
quicksilver 已提交
495
		ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
B
bigsheeper 已提交
496
	}
C
cai.zhang 已提交
497
	for _, id := range in.PartitionIDs {
B
bigsheeper 已提交
498
		err := node.loadService.segLoader.replica.removePartition(id)
C
cai.zhang 已提交
499
		if err != nil {
B
bigsheeper 已提交
500
			// not return, try to release all partitions
Q
quicksilver 已提交
501
			status.ErrorCode = commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR
B
bigsheeper 已提交
502
			status.Reason = err.Error()
C
cai.zhang 已提交
503 504
		}
	}
B
bigsheeper 已提交
505 506
	return status, nil
}
C
cai.zhang 已提交
507

B
bigsheeper 已提交
508 509
func (node *QueryNode) ReleaseSegments(in *queryPb.ReleaseSegmentRequest) (*commonpb.Status, error) {
	status := &commonpb.Status{
Q
quicksilver 已提交
510
		ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
B
bigsheeper 已提交
511
	}
C
cai.zhang 已提交
512
	for _, id := range in.SegmentIDs {
B
bigsheeper 已提交
513 514 515
		err2 := node.loadService.segLoader.replica.removeSegment(id)
		if err2 != nil {
			// not return, try to release all segments
Q
quicksilver 已提交
516
			status.ErrorCode = commonpb.ErrorCode_ERROR_CODE_UNEXPECTED_ERROR
B
bigsheeper 已提交
517
			status.Reason = err2.Error()
X
XuanYang-cn 已提交
518 519
		}
	}
B
bigsheeper 已提交
520
	return status, nil
X
XuanYang-cn 已提交
521
}
B
bigsheeper 已提交
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542

func (node *QueryNode) GetSegmentInfo(in *queryPb.SegmentInfoRequest) (*queryPb.SegmentInfoResponse, error) {
	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)
	}
	return &queryPb.SegmentInfoResponse{
		Status: &commonpb.Status{
Q
quicksilver 已提交
543
			ErrorCode: commonpb.ErrorCode_ERROR_CODE_SUCCESS,
B
bigsheeper 已提交
544 545 546 547
		},
		Infos: infos,
	}, nil
}