diff --git a/server/grpc_service.go b/server/grpc_service.go index b1fd840e6f7..7c587ac18b8 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -203,6 +203,10 @@ func (s *GrpcServer) Tso(stream pdpb.PD_TsoServer) error { return errors.WithStack(err) } + // TSO uses leader lease to determine validity. No need to check leader here. + if s.IsClosed() { + return ErrNotStarted + } if forwardedHost, err := s.getForwardedHost(ctx, stream.Context()); err != nil { return err } else if len(forwardedHost) > 0 { @@ -230,10 +234,6 @@ func (s *GrpcServer) Tso(stream pdpb.PD_TsoServer) error { } start := time.Now() - // TSO uses leader lease to determine validity. No need to check leader here. - if s.IsClosed() { - return status.Errorf(codes.Unknown, "server not started") - } if request.GetHeader().GetClusterId() != s.clusterID { return status.Errorf(codes.FailedPrecondition, "mismatch cluster id, need %d but got %d", s.clusterID, request.GetHeader().GetClusterId()) } @@ -345,6 +345,9 @@ func (s *GrpcServer) AllocID(ctx context.Context, request *pdpb.AllocIDRequest) // IsSnapshotRecovering implements gRPC PDServer. func (s *GrpcServer) IsSnapshotRecovering(ctx context.Context, request *pdpb.IsSnapshotRecoveringRequest) (*pdpb.IsSnapshotRecoveringResponse, error) { + if s.IsClosed() { + return nil, ErrNotStarted + } // recovering mark is stored in etcd directly, there's no need to forward. marked, err := s.Server.IsSnapshotRecovering(ctx) if err != nil {