2021-04-19 13:50:12 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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-01-15 14:38:36 +08:00
|
|
|
package indexnode
|
2020-12-10 17:55:55 +08:00
|
|
|
|
2021-09-22 16:05:59 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
|
|
|
|
|
|
|
|
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_indexbuilder -Wl,-rpath=${SRCDIR}/../core/output/lib
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "indexbuilder/init_c.h"
|
|
|
|
|
|
|
|
*/
|
|
|
|
import "C"
|
2020-12-10 17:55:55 +08:00
|
|
|
import (
|
|
|
|
"context"
|
2021-09-09 10:06:29 +08:00
|
|
|
"errors"
|
2021-02-25 17:35:36 +08:00
|
|
|
"io"
|
2021-03-08 15:25:55 +08:00
|
|
|
"math/rand"
|
2021-05-21 19:28:52 +08:00
|
|
|
"strconv"
|
2021-09-23 21:27:54 +08:00
|
|
|
"sync"
|
2021-06-04 16:29:35 +08:00
|
|
|
"sync/atomic"
|
2020-12-10 17:55:55 +08:00
|
|
|
"time"
|
2021-09-22 16:05:59 +08:00
|
|
|
"unsafe"
|
2020-12-10 17:55:55 +08:00
|
|
|
|
2021-10-04 17:24:38 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-08-19 10:28:10 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
|
|
|
|
2021-03-10 09:56:09 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/kv"
|
2021-05-27 22:24:29 +08:00
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
2021-04-22 14:45:57 +08:00
|
|
|
miniokv "github.com/milvus-io/milvus/internal/kv/minio"
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2021-07-22 11:40:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/retry"
|
2021-05-21 19:28:52 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2021-07-22 11:40:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/trace"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-01-26 09:38:40 +08:00
|
|
|
)
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// UniqueID is an alias of int64, is used as a unique identifier for the request.
|
2020-12-10 17:55:55 +08:00
|
|
|
type UniqueID = typeutil.UniqueID
|
|
|
|
|
2021-10-04 17:24:38 +08:00
|
|
|
// make sure IndexNode implements types.IndexNode
|
|
|
|
var _ types.IndexNode = (*IndexNode)(nil)
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// IndexNode is a component that executes the task of building indexes.
|
2021-03-05 16:52:45 +08:00
|
|
|
type IndexNode struct {
|
2021-06-04 16:29:35 +08:00
|
|
|
stateCode atomic.Value
|
2021-01-26 19:24:09 +08:00
|
|
|
|
2021-01-19 18:32:57 +08:00
|
|
|
loopCtx context.Context
|
|
|
|
loopCancel func()
|
|
|
|
|
2021-01-26 09:38:40 +08:00
|
|
|
sched *TaskScheduler
|
2021-01-19 18:32:57 +08:00
|
|
|
|
2021-09-24 20:37:56 +08:00
|
|
|
once sync.Once
|
|
|
|
|
2021-05-21 19:28:52 +08:00
|
|
|
kv kv.BaseKV
|
|
|
|
session *sessionutil.Session
|
2021-01-19 18:32:57 +08:00
|
|
|
|
2020-12-10 17:55:55 +08:00
|
|
|
// Add callback functions at different stages
|
|
|
|
startCallbacks []func()
|
|
|
|
closeCallbacks []func()
|
2021-02-25 17:35:36 +08:00
|
|
|
|
2021-05-27 22:24:29 +08:00
|
|
|
etcdKV *etcdkv.EtcdKV
|
|
|
|
finishedTasks map[UniqueID]commonpb.IndexState
|
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
closer io.Closer
|
2021-09-23 21:27:54 +08:00
|
|
|
|
|
|
|
initOnce sync.Once
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// NewIndexNode creates a new IndexNode component.
|
2021-03-05 16:52:45 +08:00
|
|
|
func NewIndexNode(ctx context.Context) (*IndexNode, error) {
|
2021-06-06 09:41:35 +08:00
|
|
|
log.Debug("New IndexNode ...")
|
2021-03-08 15:25:55 +08:00
|
|
|
rand.Seed(time.Now().UnixNano())
|
2020-12-10 17:55:55 +08:00
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
2021-03-05 16:52:45 +08:00
|
|
|
b := &IndexNode{
|
2020-12-10 17:55:55 +08:00
|
|
|
loopCtx: ctx1,
|
|
|
|
loopCancel: cancel,
|
|
|
|
}
|
2021-06-11 09:50:34 +08:00
|
|
|
b.UpdateStateCode(internalpb.StateCode_Abnormal)
|
2021-09-23 19:14:01 +08:00
|
|
|
sc, err := NewTaskScheduler(b.loopCtx, b.kv)
|
2021-01-29 17:08:31 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-09-23 19:14:01 +08:00
|
|
|
|
|
|
|
b.sched = sc
|
2021-01-29 17:08:31 +08:00
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// Register register index node at etcd.
|
2021-05-25 15:06:05 +08:00
|
|
|
func (i *IndexNode) Register() error {
|
2021-06-11 22:04:41 +08:00
|
|
|
i.session = sessionutil.NewSession(i.loopCtx, Params.MetaRootPath, Params.EtcdEndpoints)
|
2021-09-09 10:06:29 +08:00
|
|
|
if i.session == nil {
|
|
|
|
return errors.New("failed to initialize session")
|
|
|
|
}
|
2021-10-14 16:40:35 +08:00
|
|
|
i.session.Init(typeutil.IndexNodeRole, Params.IP+":"+strconv.Itoa(Params.Port), false)
|
2021-05-25 15:06:05 +08:00
|
|
|
Params.NodeID = i.session.ServerID
|
2021-10-01 08:52:50 +08:00
|
|
|
Params.SetLogger(Params.NodeID)
|
2021-05-25 15:06:05 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-22 16:05:59 +08:00
|
|
|
func (i *IndexNode) initKnowhere() {
|
|
|
|
C.IndexBuilderInit()
|
|
|
|
|
2021-09-29 20:50:19 +08:00
|
|
|
// override index builder SIMD type
|
2021-09-22 16:05:59 +08:00
|
|
|
cSimdType := C.CString(Params.SimdType)
|
2021-09-29 20:50:19 +08:00
|
|
|
cRealSimdType := C.IndexBuilderSetSimdType(cSimdType)
|
|
|
|
Params.SimdType = C.GoString(cRealSimdType)
|
|
|
|
C.free(unsafe.Pointer(cRealSimdType))
|
2021-09-22 16:05:59 +08:00
|
|
|
C.free(unsafe.Pointer(cSimdType))
|
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// Init initializes the IndexNode component.
|
2021-03-05 16:52:45 +08:00
|
|
|
func (i *IndexNode) Init() error {
|
2021-09-23 21:27:54 +08:00
|
|
|
var initErr error = nil
|
|
|
|
i.initOnce.Do(func() {
|
|
|
|
Params.Init()
|
|
|
|
i.UpdateStateCode(internalpb.StateCode_Initializing)
|
2021-10-01 11:51:41 +08:00
|
|
|
log.Debug("IndexNode init", zap.Any("State", internalpb.StateCode_Initializing))
|
2021-09-23 21:27:54 +08:00
|
|
|
connectEtcdFn := func() error {
|
|
|
|
etcdKV, err := etcdkv.NewEtcdKV(Params.EtcdEndpoints, Params.MetaRootPath)
|
|
|
|
i.etcdKV = etcdKV
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err := retry.Do(i.loopCtx, connectEtcdFn, retry.Attempts(300))
|
|
|
|
if err != nil {
|
2021-10-13 10:54:33 +08:00
|
|
|
log.Error("IndexNode failed to connect to etcd", zap.Error(err))
|
2021-09-23 21:27:54 +08:00
|
|
|
initErr = err
|
|
|
|
return
|
|
|
|
}
|
2021-10-13 10:54:33 +08:00
|
|
|
log.Debug("IndexNode connected to etcd successfully")
|
2021-09-23 21:27:54 +08:00
|
|
|
|
|
|
|
option := &miniokv.Option{
|
|
|
|
Address: Params.MinIOAddress,
|
|
|
|
AccessKeyID: Params.MinIOAccessKeyID,
|
|
|
|
SecretAccessKeyID: Params.MinIOSecretAccessKey,
|
|
|
|
UseSSL: Params.MinIOUseSSL,
|
|
|
|
BucketName: Params.MinioBucketName,
|
|
|
|
CreateBucket: true,
|
|
|
|
}
|
2021-09-28 18:22:16 +08:00
|
|
|
kv, err := miniokv.NewMinIOKV(i.loopCtx, option)
|
2021-09-23 21:27:54 +08:00
|
|
|
if err != nil {
|
2021-09-26 21:22:04 +08:00
|
|
|
log.Error("IndexNode NewMinIOKV failed", zap.Error(err))
|
2021-09-23 21:27:54 +08:00
|
|
|
initErr = err
|
|
|
|
return
|
|
|
|
}
|
2021-09-28 18:22:16 +08:00
|
|
|
|
|
|
|
i.kv = kv
|
|
|
|
|
2021-10-13 10:54:33 +08:00
|
|
|
log.Debug("IndexNode NewMinIOKV succeeded")
|
2021-09-23 21:27:54 +08:00
|
|
|
i.closer = trace.InitTracing("index_node")
|
|
|
|
|
|
|
|
i.initKnowhere()
|
|
|
|
})
|
2021-09-22 16:05:59 +08:00
|
|
|
|
2021-09-23 21:27:54 +08:00
|
|
|
log.Debug("Init IndexNode finished", zap.Error(initErr))
|
2021-09-22 16:05:59 +08:00
|
|
|
|
2021-09-23 21:27:54 +08:00
|
|
|
return initErr
|
2021-01-26 09:38:40 +08:00
|
|
|
}
|
2020-12-10 17:55:55 +08:00
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// Start starts the IndexNode component.
|
2021-03-05 16:52:45 +08:00
|
|
|
func (i *IndexNode) Start() error {
|
2021-09-24 20:37:56 +08:00
|
|
|
var startErr error = nil
|
|
|
|
i.once.Do(func() {
|
|
|
|
startErr = i.sched.Start()
|
2020-12-10 17:55:55 +08:00
|
|
|
|
2021-09-26 17:56:08 +08:00
|
|
|
Params.CreatedTime = time.Now()
|
|
|
|
Params.UpdatedTime = time.Now()
|
|
|
|
|
2021-09-24 20:37:56 +08:00
|
|
|
//start liveness check
|
2021-10-14 16:40:35 +08:00
|
|
|
go i.session.LivenessCheck(i.loopCtx, func() {
|
2021-09-24 20:37:56 +08:00
|
|
|
i.Stop()
|
|
|
|
})
|
2021-09-23 18:29:55 +08:00
|
|
|
|
2021-09-24 20:37:56 +08:00
|
|
|
i.UpdateStateCode(internalpb.StateCode_Healthy)
|
|
|
|
log.Debug("IndexNode", zap.Any("State", i.stateCode.Load()))
|
|
|
|
})
|
2020-12-10 17:55:55 +08:00
|
|
|
// Start callbacks
|
2021-01-26 09:38:40 +08:00
|
|
|
for _, cb := range i.startCallbacks {
|
2020-12-10 17:55:55 +08:00
|
|
|
cb()
|
|
|
|
}
|
2021-09-24 20:37:56 +08:00
|
|
|
|
|
|
|
log.Debug("IndexNode start finished", zap.Error(startErr))
|
|
|
|
return startErr
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// Stop closes the server.
|
2021-03-05 16:52:45 +08:00
|
|
|
func (i *IndexNode) Stop() error {
|
2021-01-29 17:08:31 +08:00
|
|
|
i.loopCancel()
|
|
|
|
if i.sched != nil {
|
|
|
|
i.sched.Close()
|
|
|
|
}
|
2021-01-26 09:38:40 +08:00
|
|
|
for _, cb := range i.closeCallbacks {
|
|
|
|
cb()
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
2021-10-01 11:51:41 +08:00
|
|
|
log.Debug("Index node stopped.")
|
2021-01-26 09:38:40 +08:00
|
|
|
return nil
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// UpdateStateCode updates the component state of IndexNode.
|
2021-03-12 14:22:09 +08:00
|
|
|
func (i *IndexNode) UpdateStateCode(code internalpb.StateCode) {
|
2021-06-04 16:29:35 +08:00
|
|
|
i.stateCode.Store(code)
|
2021-01-29 17:08:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-19 10:28:10 +08:00
|
|
|
func (i *IndexNode) isHealthy() bool {
|
|
|
|
code := i.stateCode.Load().(internalpb.StateCode)
|
|
|
|
return code == internalpb.StateCode_Healthy
|
|
|
|
}
|
|
|
|
|
2021-09-18 00:01:51 +08:00
|
|
|
// CreateIndex receives request from IndexCoordinator to build an index.
|
|
|
|
// Index building is asynchronous, so when an index building request comes, IndexNode records the task and returns.
|
2021-05-27 22:24:29 +08:00
|
|
|
func (i *IndexNode) CreateIndex(ctx context.Context, request *indexpb.CreateIndexRequest) (*commonpb.Status, error) {
|
2021-06-24 14:36:08 +08:00
|
|
|
if i.stateCode.Load().(internalpb.StateCode) != internalpb.StateCode_Healthy {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "state code is not healthy",
|
|
|
|
}, nil
|
|
|
|
}
|
2021-10-01 11:51:41 +08:00
|
|
|
log.Info("IndexNode building index ...",
|
2021-03-26 10:01:08 +08:00
|
|
|
zap.Int64("IndexBuildID", request.IndexBuildID),
|
2021-06-06 09:41:35 +08:00
|
|
|
zap.String("IndexName", request.IndexName),
|
2021-03-26 10:01:08 +08:00
|
|
|
zap.Int64("IndexID", request.IndexID),
|
2021-05-27 22:24:29 +08:00
|
|
|
zap.Int64("Version", request.Version),
|
|
|
|
zap.String("MetaPath", request.MetaPath),
|
2021-03-26 10:01:08 +08:00
|
|
|
zap.Strings("DataPaths", request.DataPaths),
|
|
|
|
zap.Any("TypeParams", request.TypeParams),
|
|
|
|
zap.Any("IndexParams", request.IndexParams))
|
|
|
|
|
2021-09-16 10:07:48 +08:00
|
|
|
sp, ctx := trace.StartSpanFromContextWithOperationName(ctx, "IndexNode-CreateIndex")
|
2021-07-22 11:40:11 +08:00
|
|
|
defer sp.Finish()
|
2021-09-16 10:07:48 +08:00
|
|
|
sp.SetTag("IndexBuildID", strconv.FormatInt(request.IndexBuildID, 10))
|
2021-07-22 11:40:11 +08:00
|
|
|
|
2021-02-23 09:58:06 +08:00
|
|
|
t := &IndexBuildTask{
|
|
|
|
BaseTask: BaseTask{
|
|
|
|
ctx: ctx,
|
2021-02-27 10:45:03 +08:00
|
|
|
done: make(chan error),
|
2021-02-23 09:58:06 +08:00
|
|
|
},
|
2021-06-15 10:19:38 +08:00
|
|
|
req: request,
|
|
|
|
kv: i.kv,
|
|
|
|
etcdKV: i.etcdKV,
|
|
|
|
nodeID: Params.NodeID,
|
2021-02-23 09:58:06 +08:00
|
|
|
}
|
2020-12-13 06:48:05 +08:00
|
|
|
|
2021-01-26 09:38:40 +08:00
|
|
|
ret := &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
|
|
|
|
2021-02-27 10:45:03 +08:00
|
|
|
err := i.sched.IndexBuildQueue.Enqueue(t)
|
2021-01-26 09:38:40 +08:00
|
|
|
if err != nil {
|
2021-10-01 11:51:41 +08:00
|
|
|
log.Warn("IndexNode failed to schedule", zap.Int64("indexBuildID", request.IndexBuildID), zap.Error(err))
|
2021-03-10 22:06:22 +08:00
|
|
|
ret.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-01-26 09:38:40 +08:00
|
|
|
ret.Reason = err.Error()
|
|
|
|
return ret, nil
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
2021-10-13 10:54:33 +08:00
|
|
|
log.Info("IndexNode successfully scheduled", zap.Int64("indexBuildID", request.IndexBuildID))
|
2021-01-26 19:24:09 +08:00
|
|
|
|
2021-05-27 22:24:29 +08:00
|
|
|
return ret, nil
|
2021-02-23 11:57:18 +08:00
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// GetComponentStates gets the component states of IndexNode.
|
2021-03-12 14:22:09 +08:00
|
|
|
func (i *IndexNode) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
2021-06-04 16:29:35 +08:00
|
|
|
log.Debug("get IndexNode components states ...")
|
2021-03-12 14:22:09 +08:00
|
|
|
stateInfo := &internalpb.ComponentInfo{
|
2021-01-26 19:24:09 +08:00
|
|
|
NodeID: Params.NodeID,
|
2021-01-29 17:08:31 +08:00
|
|
|
Role: "NodeImpl",
|
2021-06-04 16:29:35 +08:00
|
|
|
StateCode: i.stateCode.Load().(internalpb.StateCode),
|
2021-01-26 19:24:09 +08:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
ret := &internalpb.ComponentStates{
|
2021-01-26 19:24:09 +08:00
|
|
|
State: stateInfo,
|
|
|
|
SubcomponentStates: nil, // todo add subcomponents states
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-26 19:24:09 +08:00
|
|
|
},
|
|
|
|
}
|
2021-03-26 10:01:08 +08:00
|
|
|
|
2021-06-06 09:41:35 +08:00
|
|
|
log.Debug("IndexNode Component states",
|
2021-03-26 10:01:08 +08:00
|
|
|
zap.Any("State", ret.State),
|
|
|
|
zap.Any("Status", ret.Status),
|
|
|
|
zap.Any("SubcomponentStates", ret.SubcomponentStates))
|
2021-01-26 19:24:09 +08:00
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// GetTimeTickChannel gets the time tick channel of IndexNode.
|
2021-03-05 16:52:45 +08:00
|
|
|
func (i *IndexNode) GetTimeTickChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
2021-06-06 09:41:35 +08:00
|
|
|
log.Debug("get IndexNode time tick channel ...")
|
2021-03-26 10:01:08 +08:00
|
|
|
|
2021-02-04 19:34:35 +08:00
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-04 19:34:35 +08:00
|
|
|
},
|
|
|
|
}, nil
|
2021-01-26 19:24:09 +08:00
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// GetStatisticsChannel gets the statistics channel of IndexNode.
|
2021-03-05 16:52:45 +08:00
|
|
|
func (i *IndexNode) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
2021-06-06 09:41:35 +08:00
|
|
|
log.Debug("get IndexNode statistics channel ...")
|
2021-02-04 19:34:35 +08:00
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-04 19:34:35 +08:00
|
|
|
},
|
|
|
|
}, nil
|
2021-01-26 19:24:09 +08:00
|
|
|
}
|
2021-08-19 10:28:10 +08:00
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// GetMetrics gets the metrics info of IndexNode.
|
2021-08-19 10:28:10 +08:00
|
|
|
// TODO(dragondriver): cache the Metrics and set a retention to the cache
|
|
|
|
func (i *IndexNode) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
|
|
|
log.Debug("IndexNode.GetMetrics",
|
|
|
|
zap.Int64("node_id", Params.NodeID),
|
|
|
|
zap.String("req", req.Request))
|
|
|
|
|
|
|
|
if !i.isHealthy() {
|
|
|
|
log.Warn("IndexNode.GetMetrics failed",
|
|
|
|
zap.Int64("node_id", Params.NodeID),
|
|
|
|
zap.String("req", req.Request),
|
|
|
|
zap.Error(errIndexNodeIsUnhealthy(Params.NodeID)))
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: msgIndexNodeIsUnhealthy(Params.NodeID),
|
|
|
|
},
|
|
|
|
Response: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
metricType, err := metricsinfo.ParseMetricType(req.Request)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("IndexNode.GetMetrics failed to parse metric type",
|
|
|
|
zap.Int64("node_id", Params.NodeID),
|
|
|
|
zap.String("req", req.Request),
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: err.Error(),
|
|
|
|
},
|
|
|
|
Response: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if metricType == metricsinfo.SystemInfoMetrics {
|
|
|
|
metrics, err := getSystemInfoMetrics(ctx, req, i)
|
|
|
|
|
|
|
|
log.Debug("IndexNode.GetMetrics",
|
|
|
|
zap.Int64("node_id", Params.NodeID),
|
|
|
|
zap.String("req", req.Request),
|
|
|
|
zap.String("metric_type", metricType),
|
|
|
|
zap.Any("metrics", metrics), // TODO(dragondriver): necessary? may be very large
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
return metrics, err
|
|
|
|
}
|
|
|
|
|
2021-10-01 11:51:41 +08:00
|
|
|
log.Warn("IndexNode.GetMetrics failed, request metric type is not implemented yet",
|
2021-08-19 10:28:10 +08:00
|
|
|
zap.Int64("node_id", Params.NodeID),
|
|
|
|
zap.String("req", req.Request),
|
|
|
|
zap.String("metric_type", metricType))
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: metricsinfo.MsgUnimplementedMetric,
|
|
|
|
},
|
|
|
|
Response: "",
|
|
|
|
}, nil
|
|
|
|
}
|