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