diff --git a/cmd/dataservice/main.go b/cmd/dataservice/main.go index a555504882..095bf92ac8 100644 --- a/cmd/dataservice/main.go +++ b/cmd/dataservice/main.go @@ -9,12 +9,13 @@ import ( "syscall" "time" + ms "github.com/zilliztech/milvus-distributed/internal/distributed/masterservice" + + "github.com/zilliztech/milvus-distributed/internal/masterservice" + "github.com/zilliztech/milvus-distributed/internal/distributed/dataservice" "github.com/zilliztech/milvus-distributed/internal/proto/internalpb2" - - "github.com/zilliztech/milvus-distributed/internal/distributed/masterservice" - "github.com/zilliztech/milvus-distributed/internal/master" ) func main() { @@ -22,8 +23,8 @@ func main() { service := dataservice.NewGrpcService(ctx) - master.Params.Init() - client, err := masterservice.NewGrpcClient(fmt.Sprintf("%s:%d", master.Params.Address, master.Params.Port), 30*time.Second) + masterservice.Params.Init() + client, err := ms.NewGrpcClient(fmt.Sprintf("%s:%d", masterservice.Params.Address, masterservice.Params.Port), 30*time.Second) if err != nil { panic(err) } diff --git a/internal/distributed/dataservice/grpc_service.go b/internal/distributed/dataservice/grpc_service.go index cf3019dffb..330291a4fd 100644 --- a/internal/distributed/dataservice/grpc_service.go +++ b/internal/distributed/dataservice/grpc_service.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net" + "time" "github.com/zilliztech/milvus-distributed/internal/distributed/masterservice" @@ -43,6 +44,7 @@ func (s *Service) SetMasterClient(masterClient dataservice.MasterClient) { } func (s *Service) Init() error { + var err error s.grpcServer = grpc.NewServer() datapb.RegisterDataServiceServer(s.grpcServer, s) lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", dataservice.Params.Address, dataservice.Params.Port)) @@ -50,9 +52,20 @@ func (s *Service) Init() error { log.Fatal(err.Error()) return nil } - if err = s.grpcServer.Serve(lis); err != nil { - log.Fatal(err.Error()) - return nil + c := make(chan struct{}) + go func() { + if err2 := s.grpcServer.Serve(lis); err2 != nil { + log.Println(err.Error()) + close(c) + err = err2 + } + }() + timer := time.NewTimer(1 * time.Second) + select { + case <-timer.C: + break + case <-c: + return err } return s.server.Init() }