2021-01-22 06:28:06 +00:00
|
|
|
package grpcquerynode
|
2021-01-15 07:28:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-01-27 01:50:52 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
2021-01-15 07:28:54 +00:00
|
|
|
"net"
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2021-01-27 01:50:52 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/dataservice"
|
|
|
|
grpcdataserviceclient "github.com/zilliztech/milvus-distributed/internal/distributed/dataservice"
|
|
|
|
grpcindexserviceclient "github.com/zilliztech/milvus-distributed/internal/distributed/indexservice/client"
|
|
|
|
grpcqueryserviceclient "github.com/zilliztech/milvus-distributed/internal/distributed/queryservice/client"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/indexservice"
|
2021-01-15 07:28:54 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
2021-01-22 06:28:06 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/milvuspb"
|
2021-01-15 07:28:54 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/querypb"
|
2021-01-16 02:12:14 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/querynode"
|
2021-01-27 01:50:52 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/queryservice"
|
2021-01-15 07:28:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Server struct {
|
|
|
|
grpcServer *grpc.Server
|
2021-01-22 03:17:18 +00:00
|
|
|
node *querynode.QueryNode
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 01:50:52 +00:00
|
|
|
func NewServer(ctx context.Context) *Server {
|
|
|
|
server := &Server{
|
|
|
|
node: querynode.NewQueryNodeWithoutID(ctx),
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|
2021-01-27 01:50:52 +00:00
|
|
|
|
|
|
|
queryservice.Params.Init()
|
|
|
|
queryClient := grpcqueryserviceclient.NewClient(queryservice.Params.Address)
|
|
|
|
if err := server.node.SetQueryService(queryClient); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
indexservice.Params.Init()
|
|
|
|
indexClient := grpcindexserviceclient.NewClient(indexservice.Params.Address)
|
|
|
|
if err := server.node.SetIndexService(indexClient); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dataservice.Params.Init()
|
|
|
|
log.Println("connect to data service, address =", fmt.Sprint(dataservice.Params.Address, ":", dataservice.Params.Port))
|
|
|
|
dataClient := grpcdataserviceclient.NewClient(fmt.Sprint(dataservice.Params.Address, ":", dataservice.Params.Port))
|
|
|
|
if err := server.node.SetDataService(dataClient); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return server
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) StartGrpcServer() {
|
2021-01-27 01:50:52 +00:00
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", querynode.Params.QueryNodePort))
|
2021-01-15 07:28:54 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.grpcServer = grpc.NewServer()
|
|
|
|
querypb.RegisterQueryNodeServer(s.grpcServer, s)
|
2021-01-27 01:50:52 +00:00
|
|
|
fmt.Println("start query node grpc server...")
|
2021-01-15 07:28:54 +00:00
|
|
|
if err = s.grpcServer.Serve(lis); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 03:17:18 +00:00
|
|
|
func (s *Server) Init() error {
|
2021-01-27 01:50:52 +00:00
|
|
|
return s.node.Init()
|
2021-01-22 03:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) Start() error {
|
2021-01-15 07:28:54 +00:00
|
|
|
go s.StartGrpcServer()
|
2021-01-22 03:17:18 +00:00
|
|
|
return s.node.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) Stop() error {
|
|
|
|
return s.Stop()
|
|
|
|
}
|
|
|
|
|
2021-01-22 06:28:06 +00:00
|
|
|
func (s *Server) GetTimeTickChannel(ctx context.Context, in *commonpb.Empty) (*milvuspb.StringResponse, error) {
|
2021-01-22 03:17:18 +00:00
|
|
|
// ignore ctx and in
|
|
|
|
channel, err := s.node.GetTimeTickChannel()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-22 06:28:06 +00:00
|
|
|
return &milvuspb.StringResponse{
|
2021-01-22 03:17:18 +00:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
},
|
2021-01-22 06:28:06 +00:00
|
|
|
Value: channel,
|
2021-01-22 03:17:18 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-22 06:28:06 +00:00
|
|
|
func (s *Server) GetStatsChannel(ctx context.Context, in *commonpb.Empty) (*milvuspb.StringResponse, error) {
|
2021-01-22 03:17:18 +00:00
|
|
|
// ignore ctx and in
|
|
|
|
channel, err := s.node.GetStatisticsChannel()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-22 06:28:06 +00:00
|
|
|
return &milvuspb.StringResponse{
|
2021-01-22 03:17:18 +00:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
},
|
2021-01-22 06:28:06 +00:00
|
|
|
Value: channel,
|
2021-01-22 03:17:18 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-22 06:28:06 +00:00
|
|
|
func (s *Server) GetComponentStates(ctx context.Context, in *commonpb.Empty) (*querypb.ComponentStatesResponse, error) {
|
2021-01-22 03:17:18 +00:00
|
|
|
// ignore ctx and in
|
|
|
|
componentStates, err := s.node.GetComponentStates()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-22 06:28:06 +00:00
|
|
|
return &querypb.ComponentStatesResponse{
|
2021-01-22 03:17:18 +00:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
},
|
2021-01-22 06:28:06 +00:00
|
|
|
States: componentStates,
|
2021-01-22 03:17:18 +00:00
|
|
|
}, nil
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) AddQueryChannel(ctx context.Context, in *querypb.AddQueryChannelsRequest) (*commonpb.Status, error) {
|
2021-01-16 07:04:32 +00:00
|
|
|
// ignore ctx
|
|
|
|
return s.node.AddQueryChannel(in)
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) RemoveQueryChannel(ctx context.Context, in *querypb.RemoveQueryChannelsRequest) (*commonpb.Status, error) {
|
2021-01-16 07:04:32 +00:00
|
|
|
// ignore ctx
|
|
|
|
return s.node.RemoveQueryChannel(in)
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) WatchDmChannels(ctx context.Context, in *querypb.WatchDmChannelsRequest) (*commonpb.Status, error) {
|
2021-01-16 07:04:32 +00:00
|
|
|
// ignore ctx
|
|
|
|
return s.node.WatchDmChannels(in)
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) LoadSegments(ctx context.Context, in *querypb.LoadSegmentRequest) (*commonpb.Status, error) {
|
2021-01-16 07:04:32 +00:00
|
|
|
// ignore ctx
|
|
|
|
return s.node.LoadSegments(in)
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) ReleaseSegments(ctx context.Context, in *querypb.ReleaseSegmentRequest) (*commonpb.Status, error) {
|
2021-01-16 07:04:32 +00:00
|
|
|
// ignore ctx
|
|
|
|
return s.node.ReleaseSegments(in)
|
2021-01-15 07:28:54 +00:00
|
|
|
}
|