2021-11-01 22:48:06 +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-04-19 13:50:12 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-01 22:48:06 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:50:12 +08:00
|
|
|
//
|
2021-11-01 22:48:06 +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-04-19 13:50:12 +08:00
|
|
|
|
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
|
|
|
/*
|
2022-06-24 21:12:15 +08:00
|
|
|
#cgo pkg-config: milvus_indexbuilder
|
2021-09-22 16:05:59 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2022-04-13 14:39:34 +08:00
|
|
|
#include <stdint.h>
|
2021-09-22 16:05:59 +08:00
|
|
|
#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"
|
2022-03-17 17:17:22 +08:00
|
|
|
"os"
|
2022-05-03 08:39:49 +08:00
|
|
|
"path"
|
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"
|
2021-11-22 16:23:17 +08:00
|
|
|
"syscall"
|
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
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
|
|
"go.uber.org/zap"
|
2022-03-02 20:49:56 +08:00
|
|
|
|
2021-11-19 13:57:12 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2021-12-23 18:39:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2022-08-25 15:48:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2021-12-23 18:39:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
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
|
|
|
)
|
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
// TODO add comments
|
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-12-29 14:35:21 +08:00
|
|
|
// make sure IndexNode implements types.IndexNodeComponent
|
|
|
|
var _ types.IndexNodeComponent = (*IndexNode)(nil)
|
|
|
|
|
2022-01-04 10:45:31 +08:00
|
|
|
// Params is a GlobalParamTable singleton of indexnode
|
2022-02-08 20:57:47 +08:00
|
|
|
var Params paramtable.ComponentParam
|
2021-12-23 18:39:11 +08:00
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
type taskKey struct {
|
|
|
|
ClusterID UniqueID
|
|
|
|
BuildID UniqueID
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
factory dependency.Factory
|
|
|
|
storageFactory StorageFactory
|
|
|
|
session *sessionutil.Session
|
2021-02-25 17:35:36 +08:00
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
etcdCli *clientv3.Client
|
2021-05-27 22:24:29 +08:00
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
closer io.Closer
|
2021-09-23 21:27:54 +08:00
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
initOnce sync.Once
|
|
|
|
stateLock sync.Mutex
|
|
|
|
tasks map[taskKey]*taskInfo
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
|
|
|
|
2021-10-03 10:19:57 +08:00
|
|
|
// NewIndexNode creates a new IndexNode component.
|
2022-04-07 22:05:32 +08:00
|
|
|
func NewIndexNode(ctx context.Context, factory dependency.Factory) (*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{
|
2022-08-25 15:48:54 +08:00
|
|
|
loopCtx: ctx1,
|
|
|
|
loopCancel: cancel,
|
|
|
|
factory: factory,
|
|
|
|
storageFactory: &chunkMgr{},
|
|
|
|
tasks: map[taskKey]*taskInfo{},
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
2021-06-11 09:50:34 +08:00
|
|
|
b.UpdateStateCode(internalpb.StateCode_Abnormal)
|
2022-08-25 15:48:54 +08:00
|
|
|
sc, err := NewTaskScheduler(b.loopCtx)
|
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-12-15 11:47:10 +08:00
|
|
|
i.session.Register()
|
|
|
|
|
|
|
|
//start liveness check
|
|
|
|
go i.session.LivenessCheck(i.loopCtx, func() {
|
|
|
|
log.Error("Index Node disconnected from etcd, process will exit", zap.Int64("Server Id", i.session.ServerID))
|
|
|
|
if err := i.Stop(); err != nil {
|
|
|
|
log.Fatal("failed to stop server", zap.Error(err))
|
|
|
|
}
|
|
|
|
// manually send signal to starter goroutine
|
2021-12-29 14:35:21 +08:00
|
|
|
if i.session.TriggerKill {
|
2022-03-17 17:17:22 +08:00
|
|
|
if p, err := os.FindProcess(os.Getpid()); err == nil {
|
|
|
|
p.Signal(syscall.SIGINT)
|
|
|
|
}
|
2021-12-29 14:35:21 +08:00
|
|
|
}
|
2021-12-15 11:47:10 +08:00
|
|
|
})
|
2021-05-25 15:06:05 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-22 16:05:59 +08:00
|
|
|
func (i *IndexNode) initKnowhere() {
|
2022-05-03 08:39:49 +08:00
|
|
|
cEasyloggingYaml := C.CString(path.Join(Params.BaseTable.GetConfigDir(), paramtable.DefaultEasyloggingYaml))
|
|
|
|
C.IndexBuilderInit(cEasyloggingYaml)
|
|
|
|
C.free(unsafe.Pointer(cEasyloggingYaml))
|
2021-09-22 16:05:59 +08:00
|
|
|
|
2021-09-29 20:50:19 +08:00
|
|
|
// override index builder SIMD type
|
2022-03-04 11:17:56 +08:00
|
|
|
cSimdType := C.CString(Params.CommonCfg.SimdType)
|
2021-09-29 20:50:19 +08:00
|
|
|
cRealSimdType := C.IndexBuilderSetSimdType(cSimdType)
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.SimdType = C.GoString(cRealSimdType)
|
2021-09-29 20:50:19 +08:00
|
|
|
C.free(unsafe.Pointer(cRealSimdType))
|
2021-09-22 16:05:59 +08:00
|
|
|
C.free(unsafe.Pointer(cSimdType))
|
2022-04-08 20:29:33 +08:00
|
|
|
|
|
|
|
// override segcore index slice size
|
|
|
|
cIndexSliceSize := C.int64_t(Params.CommonCfg.IndexSliceSize)
|
|
|
|
C.IndexBuilderSetIndexSliceSize(cIndexSliceSize)
|
2021-09-22 16:05:59 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 11:47:10 +08:00
|
|
|
func (i *IndexNode) initSession() error {
|
2022-02-07 10:09:45 +08:00
|
|
|
i.session = sessionutil.NewSession(i.loopCtx, Params.EtcdCfg.MetaRootPath, i.etcdCli)
|
2021-12-15 11:47:10 +08:00
|
|
|
if i.session == nil {
|
|
|
|
return errors.New("failed to initialize session")
|
|
|
|
}
|
2021-12-29 14:35:21 +08:00
|
|
|
i.session.Init(typeutil.IndexNodeRole, Params.IndexNodeCfg.IP+":"+strconv.Itoa(Params.IndexNodeCfg.Port), false, true)
|
2022-04-24 22:03:44 +08:00
|
|
|
Params.IndexNodeCfg.SetNodeID(i.session.ServerID)
|
|
|
|
Params.SetLogger(i.session.ServerID)
|
2021-12-15 11:47:10 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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()
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2021-09-23 21:27:54 +08:00
|
|
|
i.UpdateStateCode(internalpb.StateCode_Initializing)
|
2021-12-15 11:47:10 +08:00
|
|
|
log.Debug("IndexNode init", zap.Any("State", i.stateCode.Load().(internalpb.StateCode)))
|
|
|
|
err := i.initSession()
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
initErr = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Debug("IndexNode init session successful", zap.Int64("serverID", i.session.ServerID))
|
|
|
|
|
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
|
|
|
|
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-12-23 18:39:11 +08:00
|
|
|
Params.IndexNodeCfg.CreatedTime = time.Now()
|
|
|
|
Params.IndexNodeCfg.UpdatedTime = time.Now()
|
2021-09-26 17:56:08 +08:00
|
|
|
|
2021-09-24 20:37:56 +08:00
|
|
|
i.UpdateStateCode(internalpb.StateCode_Healthy)
|
|
|
|
log.Debug("IndexNode", zap.Any("State", i.stateCode.Load()))
|
|
|
|
})
|
|
|
|
|
|
|
|
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-12-06 10:39:36 +08:00
|
|
|
// https://github.com/milvus-io/milvus/issues/12282
|
|
|
|
i.UpdateStateCode(internalpb.StateCode_Abnormal)
|
2022-08-25 15:48:54 +08:00
|
|
|
// cleanup all running tasks
|
|
|
|
deletedTasks := i.deleteAllTasks()
|
|
|
|
for _, task := range deletedTasks {
|
|
|
|
if task.cancel != nil {
|
|
|
|
task.cancel()
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 17:08:31 +08:00
|
|
|
i.loopCancel()
|
|
|
|
if i.sched != nil {
|
|
|
|
i.sched.Close()
|
|
|
|
}
|
2021-11-16 22:31:14 +08:00
|
|
|
i.session.Revoke(time.Second)
|
2021-11-26 11:39:16 +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-12-29 14:35:21 +08:00
|
|
|
// SetEtcdClient assigns parameter client to its member etcdCli
|
2022-07-07 14:44:21 +08:00
|
|
|
func (i *IndexNode) SetEtcdClient(client *clientv3.Client) {
|
|
|
|
i.etcdCli = client
|
2021-12-29 14:35:21 +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
|
|
|
|
}
|
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
//// BuildIndex 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.
|
|
|
|
//func (i *IndexNode) BuildIndex(ctx context.Context, request *indexpb.BuildIndexRequest) (*commonpb.Status, error) {
|
|
|
|
// if i.stateCode.Load().(internalpb.StateCode) != internalpb.StateCode_Healthy {
|
|
|
|
// return &commonpb.Status{
|
|
|
|
// ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
// Reason: "state code is not healthy",
|
|
|
|
// }, nil
|
|
|
|
// }
|
|
|
|
// log.Info("IndexNode building index ...",
|
|
|
|
// zap.Int64("clusterID", request.ClusterID),
|
|
|
|
// zap.Int64("IndexBuildID", request.IndexBuildID),
|
|
|
|
// zap.Int64("Version", request.IndexVersion),
|
|
|
|
// zap.Int("binlog paths num", len(request.DataPaths)),
|
|
|
|
// zap.Any("TypeParams", request.TypeParams),
|
|
|
|
// zap.Any("IndexParams", request.IndexParams))
|
|
|
|
//
|
|
|
|
// sp, ctx2 := trace.StartSpanFromContextWithOperationName(i.loopCtx, "IndexNode-CreateIndex")
|
|
|
|
// defer sp.Finish()
|
|
|
|
// sp.SetTag("IndexBuildID", strconv.FormatInt(request.IndexBuildID, 10))
|
|
|
|
// metrics.IndexNodeBuildIndexTaskCounter.WithLabelValues(strconv.FormatInt(Params.IndexNodeCfg.GetNodeID(), 10), metrics.TotalLabel).Inc()
|
|
|
|
//
|
|
|
|
// t := &IndexBuildTask{
|
|
|
|
// BaseTask: BaseTask{
|
|
|
|
// ctx: ctx2,
|
|
|
|
// done: make(chan error),
|
|
|
|
// },
|
|
|
|
// req: request,
|
|
|
|
// cm: i.chunkManager,
|
|
|
|
// etcdKV: i.etcdKV,
|
|
|
|
// nodeID: Params.IndexNodeCfg.GetNodeID(),
|
|
|
|
// serializedSize: 0,
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ret := &commonpb.Status{
|
|
|
|
// ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// err := i.sched.IndexBuildQueue.Enqueue(t)
|
|
|
|
// if err != nil {
|
|
|
|
// log.Warn("IndexNode failed to schedule", zap.Int64("indexBuildID", request.IndexBuildID), zap.Error(err))
|
|
|
|
// ret.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
// ret.Reason = err.Error()
|
|
|
|
// metrics.IndexNodeBuildIndexTaskCounter.WithLabelValues(strconv.FormatInt(Params.IndexNodeCfg.GetNodeID(), 10), metrics.FailLabel).Inc()
|
|
|
|
// return ret, nil
|
|
|
|
// }
|
|
|
|
// log.Info("IndexNode successfully scheduled", zap.Int64("indexBuildID", request.IndexBuildID))
|
|
|
|
//
|
|
|
|
// metrics.IndexNodeBuildIndexTaskCounter.WithLabelValues(strconv.FormatInt(Params.IndexNodeCfg.GetNodeID(), 10), metrics.SuccessLabel).Inc()
|
|
|
|
// return ret, nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//// GetTaskSlots gets how many task the IndexNode can still perform.
|
|
|
|
//func (i *IndexNode) GetTaskSlots(ctx context.Context, req *indexpb.GetTaskSlotsRequest) (*indexpb.GetTaskSlotsResponse, error) {
|
|
|
|
// if i.stateCode.Load().(internalpb.StateCode) != internalpb.StateCode_Healthy {
|
|
|
|
// return &indexpb.GetTaskSlotsResponse{
|
|
|
|
// Status: &commonpb.Status{
|
|
|
|
// ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
// Reason: "state code is not healthy",
|
|
|
|
// },
|
|
|
|
// }, nil
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// log.Info("IndexNode GetTaskSlots received")
|
|
|
|
// ret := &indexpb.GetTaskSlotsResponse{
|
|
|
|
// Status: &commonpb.Status{
|
|
|
|
// ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ret.Slots = int64(i.sched.GetTaskSlots())
|
|
|
|
// log.Info("IndexNode GetTaskSlots success", zap.Int64("slots", ret.Slots))
|
|
|
|
// return ret, nil
|
|
|
|
//}
|
2022-07-07 14:44:21 +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-11-19 13:57:12 +08:00
|
|
|
nodeID := common.NotRegisteredID
|
|
|
|
if i.session != nil && i.session.Registered() {
|
|
|
|
nodeID = i.session.ServerID
|
|
|
|
}
|
2021-03-12 14:22:09 +08:00
|
|
|
stateInfo := &internalpb.ComponentInfo{
|
2021-11-19 13:57:12 +08:00
|
|
|
// NodeID: Params.NodeID, // will race with i.Register()
|
|
|
|
NodeID: nodeID,
|
2022-08-25 15:48:54 +08:00
|
|
|
Role: typeutil.IndexNodeRole,
|
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
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
func (i *IndexNode) GetNodeID() int64 {
|
|
|
|
return Params.IndexNodeCfg.GetNodeID()
|
|
|
|
}
|
|
|
|
|
2022-08-12 13:20:39 +08:00
|
|
|
//ShowConfigurations returns the configurations of indexNode matching req.Pattern
|
|
|
|
func (i *IndexNode) ShowConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) (*internalpb.ShowConfigurationsResponse, error) {
|
|
|
|
if !i.isHealthy() {
|
|
|
|
log.Warn("IndexNode.ShowConfigurations failed",
|
|
|
|
zap.Int64("nodeId", Params.IndexNodeCfg.GetNodeID()),
|
|
|
|
zap.String("req", req.Pattern),
|
|
|
|
zap.Error(errIndexNodeIsUnhealthy(Params.IndexNodeCfg.GetNodeID())))
|
|
|
|
|
|
|
|
return &internalpb.ShowConfigurationsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: msgIndexNodeIsUnhealthy(Params.IndexNodeCfg.GetNodeID()),
|
|
|
|
},
|
|
|
|
Configuations: nil,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return getComponentConfigurations(ctx, req), nil
|
|
|
|
}
|
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
//// GetMetrics gets the metrics info of IndexNode.
|
|
|
|
//// 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) {
|
|
|
|
// if !i.isHealthy() {
|
|
|
|
// log.Warn("IndexNode.GetMetrics failed",
|
|
|
|
// zap.Int64("node_id", Params.IndexNodeCfg.GetNodeID()),
|
|
|
|
// zap.String("req", req.Request),
|
|
|
|
// zap.Error(errIndexNodeIsUnhealthy(Params.IndexNodeCfg.GetNodeID())))
|
|
|
|
//
|
|
|
|
// return &milvuspb.GetMetricsResponse{
|
|
|
|
// Status: &commonpb.Status{
|
|
|
|
// ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
// Reason: msgIndexNodeIsUnhealthy(Params.IndexNodeCfg.GetNodeID()),
|
|
|
|
// },
|
|
|
|
// 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.IndexNodeCfg.GetNodeID()),
|
|
|
|
// 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.IndexNodeCfg.GetNodeID()),
|
|
|
|
// zap.String("req", req.Request),
|
|
|
|
// zap.String("metric_type", metricType),
|
|
|
|
// zap.Error(err))
|
|
|
|
//
|
|
|
|
// return metrics, nil
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// log.Warn("IndexNode.GetMetrics failed, request metric type is not implemented yet",
|
|
|
|
// zap.Int64("node_id", Params.IndexNodeCfg.GetNodeID()),
|
|
|
|
// 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
|
|
|
|
//}
|