mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-05 05:18:52 +08:00
b445587e11
Signed-off-by: XuanYang-cn <xuan.yang@zilliz.com>
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package datanode
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/datapb"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
|
|
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
const (
|
|
RPCConnectionTimeout = 30 * time.Second
|
|
Retry = 3
|
|
)
|
|
|
|
type Client struct {
|
|
ctx context.Context
|
|
grpc datapb.DataNodeClient
|
|
conn *grpc.ClientConn
|
|
address string
|
|
}
|
|
|
|
func NewClient(address string) *Client {
|
|
return &Client{
|
|
address: address,
|
|
}
|
|
}
|
|
|
|
func (c *Client) Init() error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), RPCConnectionTimeout)
|
|
defer cancel()
|
|
var err error
|
|
for i := 0; i < Retry; i++ {
|
|
if c.conn, err = grpc.DialContext(ctx, c.address, grpc.WithInsecure(), grpc.WithBlock()); err == nil {
|
|
break
|
|
}
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.grpc = datapb.NewDataNodeClient(c.conn)
|
|
return nil
|
|
}
|
|
|
|
func (c *Client) Start() error {
|
|
return nil
|
|
}
|
|
|
|
func (c *Client) Stop() error {
|
|
return c.conn.Close()
|
|
}
|
|
|
|
func (c *Client) GetComponentStates(empty *commonpb.Empty) (*internalpb2.ComponentStates, error) {
|
|
return c.grpc.GetComponentStates(context.Background(), empty)
|
|
}
|
|
|
|
func (c *Client) WatchDmChannels(in *datapb.WatchDmChannelRequest) (*commonpb.Status, error) {
|
|
return c.grpc.WatchDmChannels(context.Background(), in)
|
|
}
|
|
|
|
func (c *Client) FlushSegments(in *datapb.FlushSegRequest) (*commonpb.Status, error) {
|
|
return c.grpc.FlushSegments(context.Background(), in)
|
|
}
|