mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 01:28:27 +08:00
83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package grpcdatanodeclient
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
otgrpc "github.com/opentracing-contrib/go-grpc"
|
|
"github.com/opentracing/opentracing-go"
|
|
"github.com/zilliztech/milvus-distributed/internal/log"
|
|
"github.com/zilliztech/milvus-distributed/internal/util/retry"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/datapb"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/milvuspb"
|
|
|
|
"go.uber.org/zap"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type Client struct {
|
|
ctx context.Context
|
|
grpc datapb.DataNodeClient
|
|
conn *grpc.ClientConn
|
|
address string
|
|
}
|
|
|
|
func NewClient(address string) *Client {
|
|
return &Client{
|
|
address: address,
|
|
ctx: context.Background(),
|
|
}
|
|
}
|
|
|
|
func (c *Client) Init() error {
|
|
tracer := opentracing.GlobalTracer()
|
|
connectGrpcFunc := func() error {
|
|
log.Debug("DataNode connect czs::", zap.String("address", c.address))
|
|
conn, err := grpc.DialContext(c.ctx, c.address, grpc.WithInsecure(), grpc.WithBlock(),
|
|
grpc.WithUnaryInterceptor(
|
|
otgrpc.OpenTracingClientInterceptor(tracer)),
|
|
grpc.WithStreamInterceptor(
|
|
otgrpc.OpenTracingStreamClientInterceptor(tracer)))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.conn = conn
|
|
return nil
|
|
}
|
|
|
|
err := retry.Retry(100, time.Millisecond*200, connectGrpcFunc)
|
|
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(ctx context.Context) (*internalpb2.ComponentStates, error) {
|
|
return c.grpc.GetComponentStates(ctx, &commonpb.Empty{})
|
|
}
|
|
|
|
func (c *Client) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
//TODO: implement grpc GetStatisticsChannel interface
|
|
panic("implement me")
|
|
}
|
|
|
|
func (c *Client) WatchDmChannels(ctx context.Context, in *datapb.WatchDmChannelRequest) (*commonpb.Status, error) {
|
|
return c.grpc.WatchDmChannels(ctx, in)
|
|
}
|
|
|
|
func (c *Client) FlushSegments(ctx context.Context, in *datapb.FlushSegRequest) (*commonpb.Status, error) {
|
|
return c.grpc.FlushSegments(ctx, in)
|
|
}
|