Skip to content

Commit

Permalink
*: fix member race problem (tikv#6070) (tikv#6091)
Browse files Browse the repository at this point in the history
ref tikv#5310, ref tikv#6069, ref tikv#6070

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
ti-chi-bot and rleungx authored Mar 6, 2023
1 parent 5a6f460 commit 51f382c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 11 additions & 1 deletion server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,17 @@ func (s *GrpcServer) wrapErrorToHeader(errorType pdpb.ErrorType, message string)
func (s *GrpcServer) GetMembers(context.Context, *pdpb.GetMembersRequest) (*pdpb.GetMembersResponse, error) {
// Here we purposely do not check the cluster ID because the client does not know the correct cluster ID
// at startup and needs to get the cluster ID with the first request (i.e. GetMembers).
members, err := s.Server.GetMembers()
if s.IsClosed() {
return &pdpb.GetMembersResponse{
Header: &pdpb.ResponseHeader{
Error: &pdpb.Error{
Type: pdpb.ErrorType_UNKNOWN,
Message: errs.ErrServerNotStarted.FastGenByArgs().Error(),
},
},
}, nil
}
members, err := cluster.GetMembers(s.GetClient())
if err != nil {
return &pdpb.GetMembersResponse{
Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, err.Error()),
Expand Down
3 changes: 1 addition & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,7 @@ func (s *Server) GetMembers() ([]*pdpb.Member, error) {
if s.IsClosed() {
return nil, errs.ErrServerNotStarted.FastGenByArgs()
}
members, err := cluster.GetMembers(s.GetClient())
return members, err
return cluster.GetMembers(s.GetClient())
}

// GetServiceMiddlewareConfig gets the service middleware config information.
Expand Down

0 comments on commit 51f382c

Please sign in to comment.