2021-10-22 14:01:21 +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 11:12:56 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-22 14:01:21 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 11:12:56 +08:00
|
|
|
//
|
2021-10-22 14:01:21 +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 11:12:56 +08:00
|
|
|
|
2021-06-18 21:30:08 +08:00
|
|
|
package grpcrootcoord
|
2021-01-19 14:44:03 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
2021-02-27 10:11:52 +08:00
|
|
|
"strconv"
|
2021-01-19 14:44:03 +08:00
|
|
|
"sync"
|
2021-11-29 14:25:17 +08:00
|
|
|
"time"
|
2021-01-19 14:44:03 +08:00
|
|
|
|
2022-08-23 10:44:52 +08:00
|
|
|
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
|
|
|
"github.com/milvus-io/milvus/pkg/tracer"
|
2023-06-21 11:36:46 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/interceptor"
|
2023-09-07 07:25:14 +08:00
|
|
|
"github.com/tikv/client-go/v2/txnkv"
|
2022-04-07 22:05:32 +08:00
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
2023-01-12 16:09:39 +08:00
|
|
|
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
2023-08-20 21:24:19 +08:00
|
|
|
"go.uber.org/atomic"
|
2022-04-07 22:05:32 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/keepalive"
|
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-06-17 17:45:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/proxypb"
|
2021-06-22 16:14:09 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
2021-06-18 21:30:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/rootcoord"
|
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
2023-09-07 07:25:14 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/etcd"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/funcutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/logutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2023-09-07 07:25:14 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/tikv"
|
2021-12-29 14:35:21 +08:00
|
|
|
|
|
|
|
dcc "github.com/milvus-io/milvus/internal/distributed/datacoord/client"
|
|
|
|
qcc "github.com/milvus-io/milvus/internal/distributed/querycoord/client"
|
2021-01-19 14:44:03 +08:00
|
|
|
)
|
|
|
|
|
2021-06-04 16:29:35 +08:00
|
|
|
// Server grpc wrapper
|
2021-02-23 11:40:30 +08:00
|
|
|
type Server struct {
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord types.RootCoordComponent
|
2021-06-17 16:47:57 +08:00
|
|
|
grpcServer *grpc.Server
|
|
|
|
grpcErrChan chan error
|
2021-02-23 11:40:30 +08:00
|
|
|
|
|
|
|
wg sync.WaitGroup
|
2021-01-19 14:44:03 +08:00
|
|
|
|
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
2021-02-23 11:40:30 +08:00
|
|
|
|
2023-08-20 21:24:19 +08:00
|
|
|
serverID atomic.Int64
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
etcdCli *clientv3.Client
|
2023-09-07 07:25:14 +08:00
|
|
|
tikvCli *txnkv.Client
|
2021-06-21 18:22:13 +08:00
|
|
|
dataCoord types.DataCoord
|
2021-06-22 16:44:09 +08:00
|
|
|
queryCoord types.QueryCoord
|
2021-02-23 11:40:30 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
newDataCoordClient func(string, *clientv3.Client) types.DataCoord
|
|
|
|
newQueryCoordClient func(string, *clientv3.Client) types.QueryCoord
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
func (s *Server) CreateDatabase(ctx context.Context, request *milvuspb.CreateDatabaseRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.CreateDatabase(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) DropDatabase(ctx context.Context, request *milvuspb.DropDatabaseRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.DropDatabase(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) ListDatabases(ctx context.Context, request *milvuspb.ListDatabasesRequest) (*milvuspb.ListDatabasesResponse, error) {
|
|
|
|
return s.rootCoord.ListDatabases(ctx, request)
|
|
|
|
}
|
|
|
|
|
2022-10-18 13:39:26 +08:00
|
|
|
func (s *Server) CheckHealth(ctx context.Context, request *milvuspb.CheckHealthRequest) (*milvuspb.CheckHealthResponse, error) {
|
|
|
|
return s.rootCoord.CheckHealth(ctx, request)
|
|
|
|
}
|
|
|
|
|
2021-11-11 21:03:23 +08:00
|
|
|
// CreateAlias creates an alias for specified collection.
|
2021-09-18 11:13:51 +08:00
|
|
|
func (s *Server) CreateAlias(ctx context.Context, request *milvuspb.CreateAliasRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.CreateAlias(ctx, request)
|
|
|
|
}
|
|
|
|
|
2021-11-11 21:05:20 +08:00
|
|
|
// DropAlias drops the specified alias.
|
2021-09-18 11:13:51 +08:00
|
|
|
func (s *Server) DropAlias(ctx context.Context, request *milvuspb.DropAliasRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.DropAlias(ctx, request)
|
|
|
|
}
|
|
|
|
|
2021-11-12 17:57:22 +08:00
|
|
|
// AlterAlias alters the alias for the specified collection.
|
2021-09-18 11:13:51 +08:00
|
|
|
func (s *Server) AlterAlias(ctx context.Context, request *milvuspb.AlterAliasRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.AlterAlias(ctx, request)
|
|
|
|
}
|
|
|
|
|
2021-11-12 17:59:18 +08:00
|
|
|
// NewServer create a new RootCoord grpc server.
|
2022-04-07 22:05:32 +08:00
|
|
|
func NewServer(ctx context.Context, factory dependency.Factory) (*Server, error) {
|
2021-02-23 11:40:30 +08:00
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
|
|
|
s := &Server{
|
2021-05-25 14:03:06 +08:00
|
|
|
ctx: ctx1,
|
|
|
|
cancel: cancel,
|
|
|
|
grpcErrChan: make(chan error),
|
2021-02-23 11:40:30 +08:00
|
|
|
}
|
2021-04-24 17:23:35 +08:00
|
|
|
s.setClient()
|
2021-03-23 01:49:50 +08:00
|
|
|
var err error
|
2021-06-18 21:30:08 +08:00
|
|
|
s.rootCoord, err = rootcoord.NewCore(s.ctx, factory)
|
2021-02-23 11:40:30 +08:00
|
|
|
if err != nil {
|
2021-01-19 14:44:03 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-02-23 11:40:30 +08:00
|
|
|
return s, err
|
|
|
|
}
|
2021-02-08 14:30:54 +08:00
|
|
|
|
2021-04-24 17:23:35 +08:00
|
|
|
func (s *Server) setClient() {
|
2021-12-29 14:35:21 +08:00
|
|
|
s.newDataCoordClient = func(etcdMetaRoot string, etcdCli *clientv3.Client) types.DataCoord {
|
|
|
|
dsClient, err := dcc.NewClient(s.ctx, etcdMetaRoot, etcdCli)
|
2021-06-23 09:24:10 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-05-25 14:03:06 +08:00
|
|
|
return dsClient
|
2021-04-24 17:23:35 +08:00
|
|
|
}
|
2023-01-04 19:37:36 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
s.newQueryCoordClient = func(metaRootPath string, etcdCli *clientv3.Client) types.QueryCoord {
|
|
|
|
qsClient, err := qcc.NewClient(s.ctx, metaRootPath, etcdCli)
|
2021-05-25 14:03:06 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-06-03 19:01:33 +08:00
|
|
|
return qsClient
|
2021-04-24 17:23:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-12 18:01:14 +08:00
|
|
|
// Run initializes and starts RootCoord's grpc service.
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) Run() error {
|
|
|
|
if err := s.init(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-27 17:32:33 +08:00
|
|
|
log.Debug("RootCoord init done ...")
|
|
|
|
|
2021-02-23 11:40:30 +08:00
|
|
|
if err := s.start(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-27 17:32:33 +08:00
|
|
|
log.Debug("RootCoord start done ...")
|
2021-02-23 11:40:30 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-07 07:25:14 +08:00
|
|
|
var getTiKVClient = tikv.GetTiKVClient
|
|
|
|
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) init() error {
|
2023-09-07 07:25:14 +08:00
|
|
|
params := paramtable.Get()
|
|
|
|
etcdConfig := ¶ms.EtcdCfg
|
|
|
|
rpcParams := ¶ms.RootCoordGrpcServerCfg
|
2021-12-29 14:35:21 +08:00
|
|
|
log.Debug("init params done..")
|
2021-03-23 01:49:50 +08:00
|
|
|
|
2022-11-30 18:23:15 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(
|
2022-12-16 15:59:23 +08:00
|
|
|
etcdConfig.UseEmbedEtcd.GetAsBool(),
|
|
|
|
etcdConfig.EtcdUseSSL.GetAsBool(),
|
|
|
|
etcdConfig.Endpoints.GetAsStrings(),
|
|
|
|
etcdConfig.EtcdTLSCert.GetValue(),
|
|
|
|
etcdConfig.EtcdTLSKey.GetValue(),
|
|
|
|
etcdConfig.EtcdTLSCACert.GetValue(),
|
|
|
|
etcdConfig.EtcdTLSMinVersion.GetValue())
|
2021-12-29 14:35:21 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Debug("RootCoord connect to etcd failed", zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
s.etcdCli = etcdCli
|
|
|
|
s.rootCoord.SetEtcdClient(s.etcdCli)
|
2023-09-07 07:25:14 +08:00
|
|
|
s.rootCoord.SetAddress(rpcParams.GetAddress())
|
2021-12-29 14:35:21 +08:00
|
|
|
log.Debug("etcd connect done ...")
|
2021-02-23 11:40:30 +08:00
|
|
|
|
2023-09-07 07:25:14 +08:00
|
|
|
if params.MetaStoreCfg.MetaStoreType.GetValue() == util.MetaStoreTypeTiKV {
|
|
|
|
log.Info("Connecting to tikv metadata storage.")
|
|
|
|
s.tikvCli, err = getTiKVClient(¶mtable.Get().TiKVCfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Debug("RootCoord failed to connect to tikv", zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
s.rootCoord.SetTiKVClient(s.tikvCli)
|
|
|
|
log.Info("Connected to tikv. Using tikv as metadata storage.")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.startGrpc(rpcParams.Port.GetAsInt())
|
2021-05-25 15:06:05 +08:00
|
|
|
if err != nil {
|
2021-02-23 11:40:30 +08:00
|
|
|
return err
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-12-29 14:35:21 +08:00
|
|
|
log.Debug("grpc init done ...")
|
2021-02-23 11:40:30 +08:00
|
|
|
|
2021-06-17 16:47:57 +08:00
|
|
|
if s.newDataCoordClient != nil {
|
2021-06-18 21:30:08 +08:00
|
|
|
log.Debug("RootCoord start to create DataCoord client")
|
2022-11-17 18:59:09 +08:00
|
|
|
dataCoord := s.newDataCoordClient(rootcoord.Params.EtcdCfg.MetaRootPath.GetValue(), s.etcdCli)
|
2023-01-12 19:49:40 +08:00
|
|
|
s.dataCoord = dataCoord
|
|
|
|
if err = s.dataCoord.Init(); err != nil {
|
|
|
|
log.Error("RootCoord DataCoordClient Init failed", zap.Error(err))
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err = s.dataCoord.Start(); err != nil {
|
|
|
|
log.Error("RootCoord DataCoordClient Start failed", zap.Error(err))
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err := s.rootCoord.SetDataCoord(dataCoord); err != nil {
|
2021-02-23 11:40:30 +08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2023-01-04 19:37:36 +08:00
|
|
|
|
2021-06-17 16:47:57 +08:00
|
|
|
if s.newQueryCoordClient != nil {
|
2021-06-18 21:30:08 +08:00
|
|
|
log.Debug("RootCoord start to create QueryCoord client")
|
2022-11-17 18:59:09 +08:00
|
|
|
queryCoord := s.newQueryCoordClient(rootcoord.Params.EtcdCfg.MetaRootPath.GetValue(), s.etcdCli)
|
2023-01-12 19:49:40 +08:00
|
|
|
s.queryCoord = queryCoord
|
|
|
|
if err := s.queryCoord.Init(); err != nil {
|
|
|
|
log.Error("RootCoord QueryCoordClient Init failed", zap.Error(err))
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err := s.queryCoord.Start(); err != nil {
|
|
|
|
log.Error("RootCoord QueryCoordClient Start failed", zap.Error(err))
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-06-18 21:30:08 +08:00
|
|
|
if err := s.rootCoord.SetQueryCoord(queryCoord); err != nil {
|
2021-02-23 11:40:30 +08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2021-05-25 14:03:06 +08:00
|
|
|
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.Init()
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-12-13 21:39:10 +08:00
|
|
|
func (s *Server) startGrpc(port int) error {
|
2021-02-23 11:40:30 +08:00
|
|
|
s.wg.Add(1)
|
2021-12-13 21:39:10 +08:00
|
|
|
go s.startGrpcLoop(port)
|
2021-02-23 11:40:30 +08:00
|
|
|
// wait for grpc server loop start
|
|
|
|
err := <-s.grpcErrChan
|
2021-01-19 14:44:03 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-13 21:39:10 +08:00
|
|
|
func (s *Server) startGrpcLoop(port int) {
|
2021-02-23 11:40:30 +08:00
|
|
|
defer s.wg.Done()
|
2022-12-16 15:59:23 +08:00
|
|
|
Params := ¶mtable.Get().RootCoordGrpcServerCfg
|
2021-11-29 14:25:17 +08:00
|
|
|
var kaep = keepalive.EnforcementPolicy{
|
|
|
|
MinTime: 5 * time.Second, // If a client pings more than once every 5 seconds, terminate the connection
|
|
|
|
PermitWithoutStream: true, // Allow pings even when there are no active streams
|
|
|
|
}
|
2021-02-23 11:40:30 +08:00
|
|
|
|
2021-11-29 14:25:17 +08:00
|
|
|
var kasp = keepalive.ServerParameters{
|
|
|
|
Time: 60 * time.Second, // Ping the client if it is idle for 60 seconds to ensure the connection is still active
|
|
|
|
Timeout: 10 * time.Second, // Wait 10 second for the ping ack before assuming the connection is dead
|
|
|
|
}
|
2021-12-13 21:39:10 +08:00
|
|
|
log.Debug("start grpc ", zap.Int("port", port))
|
|
|
|
lis, err := net.Listen("tcp", ":"+strconv.Itoa(port))
|
2021-02-23 11:40:30 +08:00
|
|
|
if err != nil {
|
2021-02-27 10:11:52 +08:00
|
|
|
log.Error("GrpcServer:failed to listen", zap.String("error", err.Error()))
|
2021-02-23 11:40:30 +08:00
|
|
|
s.grpcErrChan <- err
|
|
|
|
return
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
|
|
|
|
2021-02-23 11:40:30 +08:00
|
|
|
ctx, cancel := context.WithCancel(s.ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
opts := tracer.GetInterceptorOpts()
|
2021-03-08 15:49:42 +08:00
|
|
|
s.grpcServer = grpc.NewServer(
|
2021-11-29 14:25:17 +08:00
|
|
|
grpc.KeepaliveEnforcementPolicy(kaep),
|
|
|
|
grpc.KeepaliveParams(kasp),
|
2022-12-16 15:59:23 +08:00
|
|
|
grpc.MaxRecvMsgSize(Params.ServerMaxRecvSize.GetAsInt()),
|
|
|
|
grpc.MaxSendMsgSize(Params.ServerMaxSendSize.GetAsInt()),
|
2022-08-23 10:44:52 +08:00
|
|
|
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
|
2023-01-12 16:09:39 +08:00
|
|
|
otelgrpc.UnaryServerInterceptor(opts...),
|
2023-06-21 11:36:46 +08:00
|
|
|
logutil.UnaryTraceLoggerInterceptor,
|
|
|
|
interceptor.ClusterValidationUnaryServerInterceptor(),
|
2023-08-20 21:24:19 +08:00
|
|
|
interceptor.ServerIDValidationUnaryServerInterceptor(func() int64 {
|
|
|
|
if s.serverID.Load() == 0 {
|
|
|
|
s.serverID.Store(paramtable.GetNodeID())
|
|
|
|
}
|
|
|
|
return s.serverID.Load()
|
|
|
|
}),
|
2023-06-21 11:36:46 +08:00
|
|
|
)),
|
2022-08-23 10:44:52 +08:00
|
|
|
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
|
2023-01-12 16:09:39 +08:00
|
|
|
otelgrpc.StreamServerInterceptor(opts...),
|
2023-06-21 11:36:46 +08:00
|
|
|
logutil.StreamTraceLoggerInterceptor,
|
|
|
|
interceptor.ClusterValidationStreamServerInterceptor(),
|
2023-08-20 21:24:19 +08:00
|
|
|
interceptor.ServerIDValidationStreamServerInterceptor(func() int64 {
|
|
|
|
if s.serverID.Load() == 0 {
|
|
|
|
s.serverID.Store(paramtable.GetNodeID())
|
|
|
|
}
|
|
|
|
return s.serverID.Load()
|
|
|
|
}),
|
2023-06-21 11:36:46 +08:00
|
|
|
)))
|
2021-06-22 16:14:09 +08:00
|
|
|
rootcoordpb.RegisterRootCoordServer(s.grpcServer, s)
|
2021-02-23 11:40:30 +08:00
|
|
|
|
|
|
|
go funcutil.CheckGrpcReady(ctx, s.grpcErrChan)
|
|
|
|
if err := s.grpcServer.Serve(lis); err != nil {
|
|
|
|
s.grpcErrChan <- err
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) start() error {
|
2023-01-30 11:11:50 +08:00
|
|
|
log.Info("RootCoord Core start ...")
|
2021-12-15 11:47:10 +08:00
|
|
|
if err := s.rootCoord.Register(); err != nil {
|
|
|
|
log.Error("RootCoord registers service failed", zap.Error(err))
|
2021-02-23 11:40:30 +08:00
|
|
|
return err
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
2022-01-18 12:09:37 +08:00
|
|
|
|
2023-01-30 11:11:50 +08:00
|
|
|
if err := s.rootCoord.Start(); err != nil {
|
|
|
|
log.Error("RootCoord start service failed", zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:40:30 +08:00
|
|
|
return nil
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
|
|
|
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) Stop() error {
|
2022-12-16 15:59:23 +08:00
|
|
|
Params := ¶mtable.Get().RootCoordGrpcServerCfg
|
2021-12-17 10:23:15 +08:00
|
|
|
log.Debug("Rootcoord stop", zap.String("Address", Params.GetAddress()))
|
2021-12-29 14:35:21 +08:00
|
|
|
if s.etcdCli != nil {
|
|
|
|
defer s.etcdCli.Close()
|
|
|
|
}
|
2023-09-07 07:25:14 +08:00
|
|
|
if s.tikvCli != nil {
|
|
|
|
defer s.tikvCli.Close()
|
|
|
|
}
|
2021-06-18 21:30:08 +08:00
|
|
|
if s.dataCoord != nil {
|
|
|
|
if err := s.dataCoord.Stop(); err != nil {
|
2021-11-30 10:59:42 +08:00
|
|
|
log.Error("Failed to close dataCoord client", zap.Error(err))
|
2021-03-29 09:50:52 +08:00
|
|
|
}
|
2021-02-23 11:40:30 +08:00
|
|
|
}
|
2021-06-18 21:30:08 +08:00
|
|
|
if s.queryCoord != nil {
|
|
|
|
if err := s.queryCoord.Stop(); err != nil {
|
2021-11-30 10:59:42 +08:00
|
|
|
log.Error("Failed to close queryCoord client", zap.Error(err))
|
2021-03-29 09:50:52 +08:00
|
|
|
}
|
2021-02-23 11:40:30 +08:00
|
|
|
}
|
2021-06-17 16:47:57 +08:00
|
|
|
if s.rootCoord != nil {
|
|
|
|
if err := s.rootCoord.Stop(); err != nil {
|
2021-11-30 10:59:42 +08:00
|
|
|
log.Error("Failed to close close rootCoord", zap.Error(err))
|
2021-03-29 09:50:52 +08:00
|
|
|
}
|
2021-02-23 11:40:30 +08:00
|
|
|
}
|
2021-11-30 10:59:42 +08:00
|
|
|
log.Debug("Rootcoord begin to stop grpc server")
|
2021-02-23 11:40:30 +08:00
|
|
|
s.cancel()
|
|
|
|
if s.grpcServer != nil {
|
2021-12-02 18:13:49 +08:00
|
|
|
log.Debug("Graceful stop grpc server...")
|
2021-02-23 11:40:30 +08:00
|
|
|
s.grpcServer.GracefulStop()
|
2021-02-05 14:09:55 +08:00
|
|
|
}
|
2021-02-23 11:40:30 +08:00
|
|
|
s.wg.Wait()
|
|
|
|
return nil
|
2021-02-05 14:09:55 +08:00
|
|
|
}
|
|
|
|
|
2021-11-16 09:14:00 +08:00
|
|
|
// GetComponentStates gets the component states of RootCoord.
|
2022-10-10 15:55:22 +08:00
|
|
|
func (s *Server) GetComponentStates(ctx context.Context, req *milvuspb.GetComponentStatesRequest) (*milvuspb.ComponentStates, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.GetComponentStates(ctx)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-06-04 16:29:35 +08:00
|
|
|
// GetTimeTickChannel receiver time tick from proxy service, and put it into this channel
|
2021-03-12 14:22:09 +08:00
|
|
|
func (s *Server) GetTimeTickChannel(ctx context.Context, req *internalpb.GetTimeTickChannelRequest) (*milvuspb.StringResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.GetTimeTickChannel(ctx)
|
2021-03-12 14:22:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-04 16:29:35 +08:00
|
|
|
// GetStatisticsChannel just define a channel, not used currently
|
2021-03-12 14:22:09 +08:00
|
|
|
func (s *Server) GetStatisticsChannel(ctx context.Context, req *internalpb.GetStatisticsChannelRequest) (*milvuspb.StringResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.GetStatisticsChannel(ctx)
|
2021-03-12 14:22:09 +08:00
|
|
|
}
|
|
|
|
|
2021-09-22 17:11:54 +08:00
|
|
|
// CreateCollection creates a collection
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) CreateCollection(ctx context.Context, in *milvuspb.CreateCollectionRequest) (*commonpb.Status, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.CreateCollection(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-22 10:05:58 +08:00
|
|
|
// DropCollection drops a collection
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) DropCollection(ctx context.Context, in *milvuspb.DropCollectionRequest) (*commonpb.Status, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.DropCollection(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-18 16:27:51 +08:00
|
|
|
// HasCollection checks whether a collection is created
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) HasCollection(ctx context.Context, in *milvuspb.HasCollectionRequest) (*milvuspb.BoolResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.HasCollection(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-18 16:46:01 +08:00
|
|
|
// DescribeCollection gets meta info of a collection
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) DescribeCollection(ctx context.Context, in *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.DescribeCollection(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 16:37:35 +08:00
|
|
|
// DescribeCollectionInternal gets meta info of a collection
|
|
|
|
func (s *Server) DescribeCollectionInternal(ctx context.Context, in *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) {
|
|
|
|
return s.rootCoord.DescribeCollectionInternal(ctx, in)
|
|
|
|
}
|
|
|
|
|
2021-09-17 11:15:53 +08:00
|
|
|
// ShowCollections gets all collections
|
2021-03-12 14:22:09 +08:00
|
|
|
func (s *Server) ShowCollections(ctx context.Context, in *milvuspb.ShowCollectionsRequest) (*milvuspb.ShowCollectionsResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.ShowCollections(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-17 17:35:53 +08:00
|
|
|
// CreatePartition creates a partition in a collection
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) CreatePartition(ctx context.Context, in *milvuspb.CreatePartitionRequest) (*commonpb.Status, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.CreatePartition(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-11-16 09:16:08 +08:00
|
|
|
// DropPartition drops the specified partition.
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) DropPartition(ctx context.Context, in *milvuspb.DropPartitionRequest) (*commonpb.Status, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.DropPartition(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-11-16 09:18:00 +08:00
|
|
|
// HasPartition checks whether a partition is created.
|
2021-02-23 11:40:30 +08:00
|
|
|
func (s *Server) HasPartition(ctx context.Context, in *milvuspb.HasPartitionRequest) (*milvuspb.BoolResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.HasPartition(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-11-16 21:28:00 +08:00
|
|
|
// ShowPartitions gets all partitions for the specified collection.
|
2021-03-12 14:22:09 +08:00
|
|
|
func (s *Server) ShowPartitions(ctx context.Context, in *milvuspb.ShowPartitionsRequest) (*milvuspb.ShowPartitionsResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.ShowPartitions(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 16:37:35 +08:00
|
|
|
// ShowPartitionsInternal gets all partitions for the specified collection.
|
|
|
|
func (s *Server) ShowPartitionsInternal(ctx context.Context, in *milvuspb.ShowPartitionsRequest) (*milvuspb.ShowPartitionsResponse, error) {
|
|
|
|
return s.rootCoord.ShowPartitionsInternal(ctx, in)
|
|
|
|
}
|
|
|
|
|
2021-06-04 16:29:35 +08:00
|
|
|
// AllocTimestamp global timestamp allocator
|
2021-06-22 16:14:09 +08:00
|
|
|
func (s *Server) AllocTimestamp(ctx context.Context, in *rootcoordpb.AllocTimestampRequest) (*rootcoordpb.AllocTimestampResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.AllocTimestamp(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-11-17 22:07:13 +08:00
|
|
|
// AllocID allocates an ID
|
2021-06-22 16:14:09 +08:00
|
|
|
func (s *Server) AllocID(ctx context.Context, in *rootcoordpb.AllocIDRequest) (*rootcoordpb.AllocIDResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.AllocID(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-05-21 16:08:12 +08:00
|
|
|
// UpdateChannelTimeTick used to handle ChannelTimeTickMsg
|
|
|
|
func (s *Server) UpdateChannelTimeTick(ctx context.Context, in *internalpb.ChannelTimeTickMsg) (*commonpb.Status, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.UpdateChannelTimeTick(ctx, in)
|
2021-05-21 16:08:12 +08:00
|
|
|
}
|
|
|
|
|
2021-11-17 22:05:19 +08:00
|
|
|
// ShowSegments gets all segments
|
2021-03-12 14:22:09 +08:00
|
|
|
func (s *Server) ShowSegments(ctx context.Context, in *milvuspb.ShowSegmentsRequest) (*milvuspb.ShowSegmentsResponse, error) {
|
2021-06-17 16:47:57 +08:00
|
|
|
return s.rootCoord.ShowSegments(ctx, in)
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-06-18 21:30:08 +08:00
|
|
|
|
2022-05-19 10:13:56 +08:00
|
|
|
// InvalidateCollectionMetaCache notifies RootCoord to release the collection cache in Proxies.
|
|
|
|
func (s *Server) InvalidateCollectionMetaCache(ctx context.Context, in *proxypb.InvalidateCollMetaCacheRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.InvalidateCollectionMetaCache(ctx, in)
|
|
|
|
}
|
|
|
|
|
2022-08-12 13:20:39 +08:00
|
|
|
// ShowConfigurations gets specified configurations para of RootCoord
|
|
|
|
func (s *Server) ShowConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) (*internalpb.ShowConfigurationsResponse, error) {
|
|
|
|
return s.rootCoord.ShowConfigurations(ctx, req)
|
|
|
|
}
|
|
|
|
|
2021-11-29 19:27:45 +08:00
|
|
|
// GetMetrics gets the metrics of RootCoord.
|
2021-08-31 11:45:59 +08:00
|
|
|
func (s *Server) GetMetrics(ctx context.Context, in *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
|
|
|
return s.rootCoord.GetMetrics(ctx, in)
|
|
|
|
}
|
2022-03-11 17:13:59 +08:00
|
|
|
|
|
|
|
// Import data files(json, numpy, etc.) on MinIO/S3 storage, read and parse them into sealed segments
|
|
|
|
func (s *Server) Import(ctx context.Context, in *milvuspb.ImportRequest) (*milvuspb.ImportResponse, error) {
|
|
|
|
return s.rootCoord.Import(ctx, in)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check import task state from datanode
|
|
|
|
func (s *Server) GetImportState(ctx context.Context, in *milvuspb.GetImportStateRequest) (*milvuspb.GetImportStateResponse, error) {
|
|
|
|
return s.rootCoord.GetImportState(ctx, in)
|
|
|
|
}
|
|
|
|
|
2022-04-25 17:37:46 +08:00
|
|
|
// Returns id array of all import tasks
|
|
|
|
func (s *Server) ListImportTasks(ctx context.Context, in *milvuspb.ListImportTasksRequest) (*milvuspb.ListImportTasksResponse, error) {
|
|
|
|
return s.rootCoord.ListImportTasks(ctx, in)
|
|
|
|
}
|
|
|
|
|
2022-03-11 17:13:59 +08:00
|
|
|
// Report impot task state to datacoord
|
|
|
|
func (s *Server) ReportImport(ctx context.Context, in *rootcoordpb.ImportResult) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.ReportImport(ctx, in)
|
|
|
|
}
|
2022-04-11 19:49:34 +08:00
|
|
|
|
|
|
|
func (s *Server) CreateCredential(ctx context.Context, request *internalpb.CredentialInfo) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.CreateCredential(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) GetCredential(ctx context.Context, request *rootcoordpb.GetCredentialRequest) (*rootcoordpb.GetCredentialResponse, error) {
|
|
|
|
return s.rootCoord.GetCredential(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) UpdateCredential(ctx context.Context, request *internalpb.CredentialInfo) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.UpdateCredential(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) DeleteCredential(ctx context.Context, request *milvuspb.DeleteCredentialRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.DeleteCredential(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) ListCredUsers(ctx context.Context, request *milvuspb.ListCredUsersRequest) (*milvuspb.ListCredUsersResponse, error) {
|
|
|
|
return s.rootCoord.ListCredUsers(ctx, request)
|
|
|
|
}
|
2022-05-28 00:04:01 +08:00
|
|
|
|
|
|
|
func (s *Server) CreateRole(ctx context.Context, request *milvuspb.CreateRoleRequest) (*commonpb.Status, error) {
|
2022-08-04 11:04:34 +08:00
|
|
|
return s.rootCoord.CreateRole(ctx, request)
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) DropRole(ctx context.Context, request *milvuspb.DropRoleRequest) (*commonpb.Status, error) {
|
2022-08-04 11:04:34 +08:00
|
|
|
return s.rootCoord.DropRole(ctx, request)
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) OperateUserRole(ctx context.Context, request *milvuspb.OperateUserRoleRequest) (*commonpb.Status, error) {
|
2022-08-04 11:04:34 +08:00
|
|
|
return s.rootCoord.OperateUserRole(ctx, request)
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) SelectRole(ctx context.Context, request *milvuspb.SelectRoleRequest) (*milvuspb.SelectRoleResponse, error) {
|
2022-08-04 11:04:34 +08:00
|
|
|
return s.rootCoord.SelectRole(ctx, request)
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) SelectUser(ctx context.Context, request *milvuspb.SelectUserRequest) (*milvuspb.SelectUserResponse, error) {
|
2022-08-04 11:04:34 +08:00
|
|
|
return s.rootCoord.SelectUser(ctx, request)
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (s *Server) OperatePrivilege(ctx context.Context, request *milvuspb.OperatePrivilegeRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.OperatePrivilege(ctx, request)
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) SelectGrant(ctx context.Context, request *milvuspb.SelectGrantRequest) (*milvuspb.SelectGrantResponse, error) {
|
2022-08-04 11:04:34 +08:00
|
|
|
return s.rootCoord.SelectGrant(ctx, request)
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) ListPolicy(ctx context.Context, request *internalpb.ListPolicyRequest) (*internalpb.ListPolicyResponse, error) {
|
2022-08-04 11:04:34 +08:00
|
|
|
return s.rootCoord.ListPolicy(ctx, request)
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
2022-10-10 20:31:22 +08:00
|
|
|
|
|
|
|
func (s *Server) AlterCollection(ctx context.Context, request *milvuspb.AlterCollectionRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.AlterCollection(ctx, request)
|
|
|
|
}
|
2023-01-19 14:13:43 +08:00
|
|
|
|
|
|
|
func (s *Server) RenameCollection(ctx context.Context, request *milvuspb.RenameCollectionRequest) (*commonpb.Status, error) {
|
|
|
|
return s.rootCoord.RenameCollection(ctx, request)
|
|
|
|
}
|