From 93d853f70f2784687d1d3cc18bc4f9206421e160 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Mon, 6 Jan 2025 11:26:58 +0800 Subject: [PATCH] server: advance ServerStart check (#8951) (#8972) close tikv/pd#8950 Signed-off-by: okJiang <819421878@qq.com> Co-authored-by: okJiang <819421878@qq.com> --- server/grpc_service.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 {