2021-01-26 15:13:20 +08:00
|
|
|
package queryservice
|
|
|
|
|
|
|
|
import (
|
2021-02-26 17:44:24 +08:00
|
|
|
"context"
|
2021-03-25 04:40:59 +08:00
|
|
|
"sync"
|
2021-02-26 17:44:24 +08:00
|
|
|
|
2021-01-26 15:13:20 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
2021-03-12 14:22:09 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
2021-01-26 15:13:20 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/querypb"
|
2021-03-12 14:22:09 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/types"
|
2021-01-26 15:13:20 +08:00
|
|
|
)
|
|
|
|
|
2021-02-02 11:52:41 +08:00
|
|
|
type queryNodeInfo struct {
|
2021-03-25 04:40:59 +08:00
|
|
|
client types.QueryNode
|
|
|
|
|
|
|
|
mu sync.Mutex // guards segments and channels2Col
|
2021-03-22 16:36:10 +08:00
|
|
|
segments map[UniqueID][]UniqueID
|
|
|
|
channels2Col map[UniqueID][]string
|
2021-01-26 15:13:20 +08:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func (qn *queryNodeInfo) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
2021-02-26 17:44:24 +08:00
|
|
|
return qn.client.GetComponentStates(ctx)
|
2021-01-26 15:13:20 +08:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func (qn *queryNodeInfo) LoadSegments(ctx context.Context, in *querypb.LoadSegmentsRequest) (*commonpb.Status, error) {
|
2021-02-26 17:44:24 +08:00
|
|
|
return qn.client.LoadSegments(ctx, in)
|
2021-01-26 15:13:20 +08:00
|
|
|
}
|
2021-02-04 11:40:14 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func (qn *queryNodeInfo) GetSegmentInfo(ctx context.Context, in *querypb.GetSegmentInfoRequest) (*querypb.GetSegmentInfoResponse, error) {
|
2021-02-26 17:44:24 +08:00
|
|
|
return qn.client.GetSegmentInfo(ctx, in)
|
2021-02-04 11:40:14 +08:00
|
|
|
}
|
2021-02-04 17:47:19 +08:00
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
func (qn *queryNodeInfo) WatchDmChannels(ctx context.Context, in *querypb.WatchDmChannelsRequest) (*commonpb.Status, error) {
|
|
|
|
return qn.client.WatchDmChannels(ctx, in)
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
func (qn *queryNodeInfo) AddDmChannels(channels []string, collectionID UniqueID) {
|
2021-03-25 04:40:59 +08:00
|
|
|
qn.mu.Lock()
|
|
|
|
defer qn.mu.Unlock()
|
2021-03-22 16:36:10 +08:00
|
|
|
if _, ok := qn.channels2Col[collectionID]; !ok {
|
|
|
|
chs := make([]string, 0)
|
|
|
|
qn.channels2Col[collectionID] = chs
|
|
|
|
}
|
|
|
|
qn.channels2Col[collectionID] = append(qn.channels2Col[collectionID], channels...)
|
|
|
|
}
|
|
|
|
|
2021-03-26 05:09:16 +08:00
|
|
|
func (qn *queryNodeInfo) getNumChannels() int {
|
2021-03-25 04:40:59 +08:00
|
|
|
qn.mu.Lock()
|
|
|
|
defer qn.mu.Unlock()
|
2021-03-26 05:09:16 +08:00
|
|
|
numChannels := 0
|
|
|
|
for _, chs := range qn.channels2Col {
|
|
|
|
numChannels += len(chs)
|
|
|
|
}
|
|
|
|
return numChannels
|
2021-03-25 04:40:59 +08:00
|
|
|
}
|
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
func (qn *queryNodeInfo) AddSegments(segmentIDs []UniqueID, collectionID UniqueID) {
|
2021-03-25 04:40:59 +08:00
|
|
|
qn.mu.Lock()
|
|
|
|
defer qn.mu.Unlock()
|
2021-03-22 16:36:10 +08:00
|
|
|
if _, ok := qn.segments[collectionID]; !ok {
|
|
|
|
seg := make([]UniqueID, 0)
|
|
|
|
qn.segments[collectionID] = seg
|
|
|
|
}
|
|
|
|
qn.segments[collectionID] = append(qn.segments[collectionID], segmentIDs...)
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-03-26 05:09:16 +08:00
|
|
|
func (qn *queryNodeInfo) getSegmentsLength() int {
|
|
|
|
qn.mu.Lock()
|
|
|
|
defer qn.mu.Unlock()
|
|
|
|
return len(qn.segments)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNodeInfo) getNumSegments() int {
|
|
|
|
qn.mu.Lock()
|
|
|
|
defer qn.mu.Unlock()
|
|
|
|
numSegments := 0
|
|
|
|
for _, ids := range qn.segments {
|
|
|
|
numSegments += len(ids)
|
|
|
|
}
|
|
|
|
return numSegments
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func (qn *queryNodeInfo) AddQueryChannel(ctx context.Context, in *querypb.AddQueryChannelRequest) (*commonpb.Status, error) {
|
2021-02-26 17:44:24 +08:00
|
|
|
return qn.client.AddQueryChannel(ctx, in)
|
2021-02-09 17:09:26 +08:00
|
|
|
}
|
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
func (qn *queryNodeInfo) ReleaseCollection(ctx context.Context, in *querypb.ReleaseCollectionRequest) (*commonpb.Status, error) {
|
2021-03-22 16:36:10 +08:00
|
|
|
status, err := qn.client.ReleaseCollection(ctx, in)
|
2021-03-25 04:40:59 +08:00
|
|
|
qn.mu.Lock()
|
|
|
|
defer qn.mu.Unlock()
|
2021-03-22 16:36:10 +08:00
|
|
|
if err != nil {
|
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
delete(qn.segments, in.CollectionID)
|
|
|
|
delete(qn.channels2Col, in.CollectionID)
|
|
|
|
return status, nil
|
2021-02-24 17:24:51 +08:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func (qn *queryNodeInfo) ReleasePartitions(ctx context.Context, in *querypb.ReleasePartitionsRequest) (*commonpb.Status, error) {
|
2021-02-26 17:44:24 +08:00
|
|
|
return qn.client.ReleasePartitions(ctx, in)
|
2021-02-24 17:24:51 +08:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func newQueryNodeInfo(client types.QueryNode) *queryNodeInfo {
|
2021-03-22 16:36:10 +08:00
|
|
|
segments := make(map[UniqueID][]UniqueID)
|
|
|
|
channels := make(map[UniqueID][]string)
|
2021-02-04 17:47:19 +08:00
|
|
|
return &queryNodeInfo{
|
2021-03-22 16:36:10 +08:00
|
|
|
client: client,
|
|
|
|
segments: segments,
|
|
|
|
channels2Col: channels,
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
}
|