2021-10-20 11:39:49 +00: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 05:50:12 +00:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-20 11:39:49 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 05:50:12 +00:00
|
|
|
//
|
2021-10-20 11:39:49 +00: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 05:50:12 +00:00
|
|
|
|
2021-01-20 10:26:20 +00:00
|
|
|
package grpcindexnodeclient
|
2021-01-15 06:38:36 +00:00
|
|
|
|
|
|
|
import (
|
2021-01-19 10:32:57 +00:00
|
|
|
"context"
|
2021-05-27 02:30:11 +00:00
|
|
|
"fmt"
|
2021-01-29 09:08:31 +00:00
|
|
|
|
2021-04-22 06:45:57 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-12-03 07:15:32 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/funcutil"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/grpcclient"
|
2021-12-17 02:23:15 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2021-12-03 07:15:32 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
|
|
|
"google.golang.org/grpc"
|
2021-01-15 06:38:36 +00:00
|
|
|
)
|
|
|
|
|
2021-12-20 06:25:25 +00:00
|
|
|
var ClientParams paramtable.GrpcClientConfig
|
2021-12-17 02:23:15 +00:00
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// Client is the grpc client of IndexNode.
|
2021-01-15 06:38:36 +00:00
|
|
|
type Client struct {
|
2021-12-03 07:15:32 +00:00
|
|
|
grpcClient grpcclient.GrpcClient
|
|
|
|
addr string
|
2021-09-17 11:45:42 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// NewClient creates a new IndexNode client.
|
2021-06-24 11:05:06 +00:00
|
|
|
func NewClient(ctx context.Context, addr string) (*Client, error) {
|
2021-06-03 11:01:33 +00:00
|
|
|
if addr == "" {
|
2021-05-27 02:30:11 +00:00
|
|
|
return nil, fmt.Errorf("address is empty")
|
|
|
|
}
|
2021-12-20 06:25:25 +00:00
|
|
|
ClientParams.InitOnce(typeutil.IndexNodeRole)
|
2021-09-27 10:41:58 +00:00
|
|
|
client := &Client{
|
2021-12-03 07:15:32 +00:00
|
|
|
addr: addr,
|
|
|
|
grpcClient: &grpcclient.ClientBase{
|
2021-12-20 06:25:25 +00:00
|
|
|
ClientMaxRecvSize: ClientParams.ClientMaxRecvSize,
|
|
|
|
ClientMaxSendSize: ClientParams.ClientMaxSendSize,
|
2021-12-03 07:15:32 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
client.grpcClient.SetRole(typeutil.IndexNodeRole)
|
|
|
|
client.grpcClient.SetGetAddrFunc(client.getAddr)
|
|
|
|
client.grpcClient.SetNewGrpcClientFunc(client.newGrpcClient)
|
2021-09-27 10:41:58 +00:00
|
|
|
return client, nil
|
2021-03-12 06:22:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// Init initializes IndexNode's grpc client.
|
2021-01-29 09:08:31 +00:00
|
|
|
func (c *Client) Init() error {
|
2021-09-27 10:41:58 +00:00
|
|
|
return nil
|
2021-05-27 02:30:11 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// Start starts IndexNode's client service. But it does nothing here.
|
2021-01-29 09:08:31 +00:00
|
|
|
func (c *Client) Start() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// Stop stops IndexNode's grpc client.
|
2021-01-29 09:08:31 +00:00
|
|
|
func (c *Client) Stop() error {
|
2021-12-03 07:15:32 +00:00
|
|
|
return c.grpcClient.Close()
|
2021-01-29 09:08:31 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 07:06:05 +00:00
|
|
|
// Register dummy
|
|
|
|
func (c *Client) Register() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-03 07:15:32 +00:00
|
|
|
func (c *Client) newGrpcClient(cc *grpc.ClientConn) interface{} {
|
|
|
|
return indexpb.NewIndexNodeClient(cc)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) getAddr() (string, error) {
|
|
|
|
return c.addr, nil
|
|
|
|
}
|
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// GetComponentStates gets the component states of IndexNode.
|
2021-03-12 06:22:09 +00:00
|
|
|
func (c *Client) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
2021-12-03 07:15:32 +00:00
|
|
|
ret, err := c.grpcClient.ReCall(ctx, func(client interface{}) (interface{}, error) {
|
2021-11-18 03:17:12 +00:00
|
|
|
if !funcutil.CheckCtxValid(ctx) {
|
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
2021-12-03 07:15:32 +00:00
|
|
|
return client.(indexpb.IndexNodeClient).GetComponentStates(ctx, &internalpb.GetComponentStatesRequest{})
|
2021-05-27 02:30:11 +00:00
|
|
|
})
|
2021-09-17 11:45:42 +00:00
|
|
|
if err != nil || ret == nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-27 02:30:11 +00:00
|
|
|
return ret.(*internalpb.ComponentStates), err
|
2021-01-26 11:24:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// GetTimeTickChannel gets the time tick channel of IndexNode.
|
2021-02-26 09:44:24 +00:00
|
|
|
func (c *Client) GetTimeTickChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
2021-12-03 07:15:32 +00:00
|
|
|
ret, err := c.grpcClient.ReCall(ctx, func(client interface{}) (interface{}, error) {
|
2021-11-18 03:17:12 +00:00
|
|
|
if !funcutil.CheckCtxValid(ctx) {
|
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
2021-12-03 07:15:32 +00:00
|
|
|
return client.(indexpb.IndexNodeClient).GetTimeTickChannel(ctx, &internalpb.GetTimeTickChannelRequest{})
|
2021-05-27 02:30:11 +00:00
|
|
|
})
|
2021-09-17 11:45:42 +00:00
|
|
|
if err != nil || ret == nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-27 02:30:11 +00:00
|
|
|
return ret.(*milvuspb.StringResponse), err
|
2021-01-26 11:24:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// GetStatisticsChannel gets the statistics channel of IndexNode.
|
2021-02-26 09:44:24 +00:00
|
|
|
func (c *Client) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
2021-12-03 07:15:32 +00:00
|
|
|
ret, err := c.grpcClient.ReCall(ctx, func(client interface{}) (interface{}, error) {
|
2021-11-18 03:17:12 +00:00
|
|
|
if !funcutil.CheckCtxValid(ctx) {
|
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
2021-12-03 07:15:32 +00:00
|
|
|
return client.(indexpb.IndexNodeClient).GetStatisticsChannel(ctx, &internalpb.GetStatisticsChannelRequest{})
|
2021-05-27 02:30:11 +00:00
|
|
|
})
|
2021-09-17 11:45:42 +00:00
|
|
|
if err != nil || ret == nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-27 02:30:11 +00:00
|
|
|
return ret.(*milvuspb.StringResponse), err
|
2021-01-26 11:24:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// CreateIndex sends the build index request to IndexNode.
|
2021-05-27 14:24:29 +00:00
|
|
|
func (c *Client) CreateIndex(ctx context.Context, req *indexpb.CreateIndexRequest) (*commonpb.Status, error) {
|
2021-12-03 07:15:32 +00:00
|
|
|
ret, err := c.grpcClient.ReCall(ctx, func(client interface{}) (interface{}, error) {
|
2021-11-18 03:17:12 +00:00
|
|
|
if !funcutil.CheckCtxValid(ctx) {
|
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
2021-12-03 07:15:32 +00:00
|
|
|
return client.(indexpb.IndexNodeClient).CreateIndex(ctx, req)
|
2021-05-27 02:30:11 +00:00
|
|
|
})
|
2021-09-17 11:45:42 +00:00
|
|
|
if err != nil || ret == nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-27 02:30:11 +00:00
|
|
|
return ret.(*commonpb.Status), err
|
2021-02-23 03:57:18 +00:00
|
|
|
}
|
2021-08-19 02:28:10 +00:00
|
|
|
|
2021-10-03 02:24:01 +00:00
|
|
|
// GetMetrics gets the metrics info of IndexNode.
|
2021-08-19 02:28:10 +00:00
|
|
|
func (c *Client) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
2021-12-03 07:15:32 +00:00
|
|
|
ret, err := c.grpcClient.ReCall(ctx, func(client interface{}) (interface{}, error) {
|
2021-11-18 03:17:12 +00:00
|
|
|
if !funcutil.CheckCtxValid(ctx) {
|
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
2021-12-03 07:15:32 +00:00
|
|
|
return client.(indexpb.IndexNodeClient).GetMetrics(ctx, req)
|
2021-08-19 02:28:10 +00:00
|
|
|
})
|
2021-09-17 11:45:42 +00:00
|
|
|
if err != nil || ret == nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-19 02:28:10 +00:00
|
|
|
return ret.(*milvuspb.GetMetricsResponse), err
|
|
|
|
}
|