2021-11-17 19:47:36 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-10-07 19:48:54 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-17 19:47:36 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-10-07 19:48:54 +08:00
|
|
|
//
|
2021-11-17 19:47:36 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-10-07 19:48:54 +08:00
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
package querycoord
|
2021-01-26 15:13:20 +08:00
|
|
|
|
|
|
|
import (
|
2021-06-23 09:24:10 +08:00
|
|
|
"context"
|
2021-06-15 12:41:40 +08:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-03-25 04:40:59 +08:00
|
|
|
"sync"
|
2021-02-26 17:44:24 +08:00
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
nodeclient "github.com/milvus-io/milvus/internal/distributed/querynode/client"
|
2021-06-19 11:45:09 +08:00
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-08-02 22:39:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
2021-11-13 08:49:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2021-08-02 22:39:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-09-15 20:40:07 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-11-05 16:00:55 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2021-01-26 15:13:20 +08:00
|
|
|
)
|
|
|
|
|
2021-10-07 19:50:46 +08:00
|
|
|
// Node provides many interfaces to access querynode via grpc
|
2021-08-02 22:39:25 +08:00
|
|
|
type Node interface {
|
|
|
|
start() error
|
|
|
|
stop()
|
2021-11-05 16:00:55 +08:00
|
|
|
getNodeInfo() (Node, error)
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
releaseCollection(ctx context.Context, in *querypb.ReleaseCollectionRequest) error
|
|
|
|
releasePartitions(ctx context.Context, in *querypb.ReleasePartitionsRequest) error
|
|
|
|
|
|
|
|
watchDmChannels(ctx context.Context, in *querypb.WatchDmChannelsRequest) error
|
2021-11-05 14:47:19 +08:00
|
|
|
watchDeltaChannels(ctx context.Context, in *querypb.WatchDeltaChannelsRequest) error
|
2021-09-15 20:40:07 +08:00
|
|
|
//removeDmChannel(collectionID UniqueID, channels []string) error
|
2021-08-02 22:39:25 +08:00
|
|
|
|
2021-11-13 08:49:08 +08:00
|
|
|
hasWatchedDeltaChannel(collectionID UniqueID) bool
|
2021-08-02 22:39:25 +08:00
|
|
|
hasWatchedQueryChannel(collectionID UniqueID) bool
|
2021-09-15 20:40:07 +08:00
|
|
|
//showWatchedQueryChannels() []*querypb.QueryChannelInfo
|
2021-08-02 22:39:25 +08:00
|
|
|
addQueryChannel(ctx context.Context, in *querypb.AddQueryChannelRequest) error
|
|
|
|
removeQueryChannel(ctx context.Context, in *querypb.RemoveQueryChannelRequest) error
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
setState(state nodeState)
|
|
|
|
getState() nodeState
|
|
|
|
isOnline() bool
|
|
|
|
isOffline() bool
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
getSegmentInfo(ctx context.Context, in *querypb.GetSegmentInfoRequest) (*querypb.GetSegmentInfoResponse, error)
|
|
|
|
loadSegments(ctx context.Context, in *querypb.LoadSegmentsRequest) error
|
|
|
|
releaseSegments(ctx context.Context, in *querypb.ReleaseSegmentsRequest) error
|
|
|
|
getComponentInfo(ctx context.Context) *internalpb.ComponentInfo
|
2021-08-17 10:06:11 +08:00
|
|
|
|
|
|
|
getMetrics(ctx context.Context, in *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error)
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
type queryNode struct {
|
2021-07-13 14:16:00 +08:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
2021-06-19 11:45:09 +08:00
|
|
|
id int64
|
|
|
|
address string
|
|
|
|
client types.QueryNode
|
|
|
|
kvClient *etcdkv.EtcdKV
|
2021-03-25 04:40:59 +08:00
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
sync.RWMutex
|
|
|
|
watchedQueryChannels map[UniqueID]*querypb.QueryChannelInfo
|
2021-11-13 08:49:08 +08:00
|
|
|
watchedDeltaChannels map[UniqueID][]*datapb.VchannelInfo
|
2021-09-15 20:40:07 +08:00
|
|
|
state nodeState
|
|
|
|
stateLock sync.RWMutex
|
2021-11-05 16:00:55 +08:00
|
|
|
|
|
|
|
totalMem uint64
|
|
|
|
memUsage uint64
|
|
|
|
memUsageRate float64
|
|
|
|
cpuUsage float64
|
2021-01-26 15:13:20 +08:00
|
|
|
}
|
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
func newQueryNode(ctx context.Context, address string, id UniqueID, kv *etcdkv.EtcdKV) (Node, error) {
|
2021-06-15 12:41:40 +08:00
|
|
|
watchedChannels := make(map[UniqueID]*querypb.QueryChannelInfo)
|
2021-11-13 08:49:08 +08:00
|
|
|
watchedDeltaChannels := make(map[UniqueID][]*datapb.VchannelInfo)
|
2021-07-13 14:16:00 +08:00
|
|
|
childCtx, cancel := context.WithCancel(ctx)
|
2021-08-26 14:17:54 +08:00
|
|
|
client, err := nodeclient.NewClient(childCtx, address)
|
|
|
|
if err != nil {
|
|
|
|
cancel()
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-13 14:16:00 +08:00
|
|
|
node := &queryNode{
|
|
|
|
ctx: childCtx,
|
|
|
|
cancel: cancel,
|
2021-06-19 11:45:09 +08:00
|
|
|
id: id,
|
|
|
|
address: address,
|
2021-08-26 14:17:54 +08:00
|
|
|
client: client,
|
2021-06-19 11:45:09 +08:00
|
|
|
kvClient: kv,
|
2021-06-15 12:41:40 +08:00
|
|
|
watchedQueryChannels: watchedChannels,
|
2021-11-13 08:49:08 +08:00
|
|
|
watchedDeltaChannels: watchedDeltaChannels,
|
2021-09-15 20:40:07 +08:00
|
|
|
state: disConnect,
|
2021-07-13 14:16:00 +08:00
|
|
|
}
|
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
return node, nil
|
2021-07-13 14:16:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) start() error {
|
2021-08-26 14:17:54 +08:00
|
|
|
if err := qn.client.Init(); err != nil {
|
2021-12-06 21:49:53 +08:00
|
|
|
log.Error("start: init queryNode client failed", zap.Int64("nodeID", qn.id), zap.String("error", err.Error()))
|
2021-07-13 14:16:00 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-08-26 14:17:54 +08:00
|
|
|
if err := qn.client.Start(); err != nil {
|
2021-12-06 21:49:53 +08:00
|
|
|
log.Error("start: start queryNode client failed", zap.Int64("nodeID", qn.id), zap.String("error", err.Error()))
|
2021-07-13 14:16:00 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
qn.stateLock.Lock()
|
|
|
|
if qn.state < online {
|
|
|
|
qn.state = online
|
|
|
|
}
|
|
|
|
qn.stateLock.Unlock()
|
2022-04-26 11:29:54 +08:00
|
|
|
log.Info("start: queryNode client start success", zap.Int64("nodeID", qn.id), zap.String("address", qn.address))
|
2021-07-13 14:16:00 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) stop() {
|
2022-01-17 17:37:37 +08:00
|
|
|
//qn.stateLock.Lock()
|
|
|
|
//defer qn.stateLock.Unlock()
|
|
|
|
//qn.state = offline
|
2021-07-13 14:16:00 +08:00
|
|
|
if qn.client != nil {
|
|
|
|
qn.client.Stop()
|
|
|
|
}
|
|
|
|
qn.cancel()
|
2021-01-26 15:13:20 +08:00
|
|
|
}
|
2021-02-04 11:40:14 +08:00
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
func (qn *queryNode) hasWatchedQueryChannel(collectionID UniqueID) bool {
|
|
|
|
qn.RLock()
|
|
|
|
defer qn.RUnlock()
|
|
|
|
|
|
|
|
if _, ok := qn.watchedQueryChannels[collectionID]; ok {
|
|
|
|
return true
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-11-13 08:49:08 +08:00
|
|
|
func (qn *queryNode) hasWatchedDeltaChannel(collectionID UniqueID) bool {
|
|
|
|
qn.RLock()
|
|
|
|
defer qn.RUnlock()
|
|
|
|
|
|
|
|
_, ok := qn.watchedDeltaChannels[collectionID]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
//func (qn *queryNode) showWatchedQueryChannels() []*querypb.QueryChannelInfo {
|
|
|
|
// qn.RLock()
|
|
|
|
// defer qn.RUnlock()
|
|
|
|
//
|
|
|
|
// results := make([]*querypb.QueryChannelInfo, 0)
|
|
|
|
// for _, info := range qn.watchedQueryChannels {
|
|
|
|
// results = append(results, proto.Clone(info).(*querypb.QueryChannelInfo))
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return results
|
|
|
|
//}
|
2021-06-15 12:41:40 +08:00
|
|
|
|
2021-11-13 08:49:08 +08:00
|
|
|
func (qn *queryNode) setDeltaChannelInfo(collectionID int64, infos []*datapb.VchannelInfo) {
|
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
|
|
|
|
qn.watchedDeltaChannels[collectionID] = infos
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) setQueryChannelInfo(info *querypb.QueryChannelInfo) {
|
2021-06-15 12:41:40 +08:00
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
qn.watchedQueryChannels[info.CollectionID] = info
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) removeQueryChannelInfo(collectionID UniqueID) {
|
|
|
|
qn.Lock()
|
|
|
|
defer qn.Unlock()
|
2021-06-19 11:45:09 +08:00
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
delete(qn.watchedQueryChannels, collectionID)
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
func (qn *queryNode) setState(state nodeState) {
|
|
|
|
qn.stateLock.Lock()
|
|
|
|
defer qn.stateLock.Unlock()
|
|
|
|
|
|
|
|
qn.state = state
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) getState() nodeState {
|
|
|
|
qn.stateLock.RLock()
|
|
|
|
defer qn.stateLock.RUnlock()
|
|
|
|
|
|
|
|
return qn.state
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) isOnline() bool {
|
|
|
|
qn.stateLock.RLock()
|
|
|
|
defer qn.stateLock.RUnlock()
|
2021-06-19 11:45:09 +08:00
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
return qn.state == online
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
func (qn *queryNode) isOffline() bool {
|
|
|
|
qn.stateLock.RLock()
|
|
|
|
defer qn.stateLock.RUnlock()
|
2021-06-19 11:45:09 +08:00
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
return qn.state == offline
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
//***********************grpc req*************************//
|
|
|
|
func (qn *queryNode) watchDmChannels(ctx context.Context, in *querypb.WatchDmChannelsRequest) error {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-08-02 22:39:25 +08:00
|
|
|
return errors.New("WatchDmChannels: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
status, err := qn.client.WatchDmChannels(qn.ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
2021-12-21 11:57:39 +08:00
|
|
|
|
|
|
|
return nil
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
|
|
|
|
2021-11-05 14:47:19 +08:00
|
|
|
func (qn *queryNode) watchDeltaChannels(ctx context.Context, in *querypb.WatchDeltaChannelsRequest) error {
|
|
|
|
if !qn.isOnline() {
|
|
|
|
return errors.New("WatchDmChannels: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
status, err := qn.client.WatchDeltaChannels(qn.ctx, in)
|
2021-11-05 14:47:19 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
2021-11-13 08:49:08 +08:00
|
|
|
qn.setDeltaChannelInfo(in.CollectionID, in.Infos)
|
2021-11-05 14:47:19 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) addQueryChannel(ctx context.Context, in *querypb.AddQueryChannelRequest) error {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-08-02 22:39:25 +08:00
|
|
|
return errors.New("AddQueryChannel: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
status, err := qn.client.AddQueryChannel(qn.ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
queryChannelInfo := &querypb.QueryChannelInfo{
|
2021-12-15 16:53:12 +08:00
|
|
|
CollectionID: in.CollectionID,
|
|
|
|
QueryChannel: in.QueryChannel,
|
|
|
|
QueryResultChannel: in.QueryResultChannel,
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
|
|
|
qn.setQueryChannelInfo(queryChannelInfo)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) removeQueryChannel(ctx context.Context, in *querypb.RemoveQueryChannelRequest) error {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
status, err := qn.client.RemoveQueryChannel(qn.ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
qn.removeQueryChannelInfo(in.CollectionID)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) releaseCollection(ctx context.Context, in *querypb.ReleaseCollectionRequest) error {
|
2021-09-18 15:51:51 +08:00
|
|
|
if !qn.isOnline() {
|
2022-04-26 11:29:54 +08:00
|
|
|
log.Warn("ReleaseCollection: the QueryNode has been offline, the release request is no longer needed", zap.Int64("nodeID", qn.id))
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
status, err := qn.client.ReleaseCollection(qn.ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
2021-12-21 11:57:39 +08:00
|
|
|
qn.Lock()
|
|
|
|
delete(qn.watchedDeltaChannels, in.CollectionID)
|
|
|
|
delete(qn.watchedQueryChannels, in.CollectionID)
|
|
|
|
qn.Unlock()
|
2021-08-02 22:39:25 +08:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) releasePartitions(ctx context.Context, in *querypb.ReleasePartitionsRequest) error {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-08-02 22:39:25 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
status, err := qn.client.ReleasePartitions(qn.ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) getSegmentInfo(ctx context.Context, in *querypb.GetSegmentInfoRequest) (*querypb.GetSegmentInfoResponse, error) {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-11-05 16:00:55 +08:00
|
|
|
return nil, fmt.Errorf("getSegmentInfo: queryNode %d is offline", qn.id)
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
res, err := qn.client.GetSegmentInfo(qn.ctx, in)
|
2021-11-05 16:00:55 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if res.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return nil, errors.New(res.Status.Reason)
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
|
|
|
|
2021-11-05 16:00:55 +08:00
|
|
|
return res, nil
|
2021-08-02 22:39:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) getComponentInfo(ctx context.Context) *internalpb.ComponentInfo {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-08-02 22:39:25 +08:00
|
|
|
return &internalpb.ComponentInfo{
|
|
|
|
NodeID: qn.id,
|
|
|
|
StateCode: internalpb.StateCode_Abnormal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
res, err := qn.client.GetComponentStates(qn.ctx)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil || res.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return &internalpb.ComponentInfo{
|
|
|
|
NodeID: qn.id,
|
|
|
|
StateCode: internalpb.StateCode_Abnormal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.State
|
|
|
|
}
|
|
|
|
|
2021-08-17 10:06:11 +08:00
|
|
|
func (qn *queryNode) getMetrics(ctx context.Context, in *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-12-15 22:11:09 +08:00
|
|
|
return nil, fmt.Errorf("getMetrics: queryNode %d is offline", qn.id)
|
2021-08-17 10:06:11 +08:00
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
return qn.client.GetMetrics(qn.ctx, in)
|
2021-08-17 10:06:11 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 22:39:25 +08:00
|
|
|
func (qn *queryNode) loadSegments(ctx context.Context, in *querypb.LoadSegmentsRequest) error {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-08-02 22:39:25 +08:00
|
|
|
return errors.New("LoadSegments: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
status, err := qn.client.LoadSegments(qn.ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qn *queryNode) releaseSegments(ctx context.Context, in *querypb.ReleaseSegmentsRequest) error {
|
2021-09-15 20:40:07 +08:00
|
|
|
if !qn.isOnline() {
|
2021-08-02 22:39:25 +08:00
|
|
|
return errors.New("ReleaseSegments: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
2021-12-03 15:15:32 +08:00
|
|
|
status, err := qn.client.ReleaseSegments(qn.ctx, in)
|
2021-08-02 22:39:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(status.Reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-05 16:00:55 +08:00
|
|
|
func (qn *queryNode) getNodeInfo() (Node, error) {
|
|
|
|
qn.RLock()
|
|
|
|
defer qn.RUnlock()
|
|
|
|
|
|
|
|
if !qn.isOnline() {
|
|
|
|
return nil, errors.New("getNodeInfo: queryNode is offline")
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
resp, err := qn.client.GetMetrics(qn.ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if resp.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return nil, errors.New(resp.Status.Reason)
|
|
|
|
}
|
|
|
|
infos := metricsinfo.QueryNodeInfos{}
|
|
|
|
err = metricsinfo.UnmarshalComponentInfos(resp.Response, &infos)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
qn.cpuUsage = infos.HardwareInfos.CPUCoreUsage
|
|
|
|
qn.totalMem = infos.HardwareInfos.Memory
|
|
|
|
qn.memUsage = infos.HardwareInfos.MemoryUsage
|
|
|
|
qn.memUsageRate = float64(qn.memUsage) / float64(qn.totalMem)
|
|
|
|
return &queryNode{
|
|
|
|
id: qn.id,
|
|
|
|
address: qn.address,
|
|
|
|
state: qn.state,
|
|
|
|
|
|
|
|
totalMem: qn.totalMem,
|
|
|
|
memUsage: qn.memUsage,
|
|
|
|
memUsageRate: qn.memUsageRate,
|
|
|
|
cpuUsage: qn.cpuUsage,
|
|
|
|
}, nil
|
|
|
|
}
|