Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc/service: Refactor middleware #8849

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 52 additions & 25 deletions server/gc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,24 @@ import (
"github.com/tikv/pd/pkg/utils/tsoutil"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"
"google.golang.org/grpc"
)

// GetGCSafePointV2 return gc safe point for the given keyspace.
func (s *GrpcServer) GetGCSafePointV2(ctx context.Context, request *pdpb.GetGCSafePointV2Request) (*pdpb.GetGCSafePointV2Response, error) {
fn := func(ctx context.Context, client *grpc.ClientConn) (any, error) {
return pdpb.NewPDClient(client).GetGCSafePointV2(ctx, request)
}
if rsp, err := s.unaryMiddleware(ctx, request, fn); err != nil {
if midResp, err := s.unaryMiddleware(ctx, request, "GetGCSafePointV2"); err != nil {
return nil, err
} else if rsp != nil {
return rsp.(*pdpb.GetGCSafePointV2Response), err
} else if midResp != nil {
if midResp.header != nil {
return &pdpb.GetGCSafePointV2Response{
Header: midResp.header,
}, nil
}
if midResp.deferFunc != nil {
defer midResp.deferFunc()
}
if midResp.resp != nil {
return midResp.resp.(*pdpb.GetGCSafePointV2Response), nil
}
}

safePoint, err := s.safePointV2Manager.LoadGCSafePoint(request.GetKeyspaceId())
Expand All @@ -61,13 +67,20 @@ func (s *GrpcServer) GetGCSafePointV2(ctx context.Context, request *pdpb.GetGCSa

// UpdateGCSafePointV2 update gc safe point for the given keyspace.
func (s *GrpcServer) UpdateGCSafePointV2(ctx context.Context, request *pdpb.UpdateGCSafePointV2Request) (*pdpb.UpdateGCSafePointV2Response, error) {
fn := func(ctx context.Context, client *grpc.ClientConn) (any, error) {
return pdpb.NewPDClient(client).UpdateGCSafePointV2(ctx, request)
}
if rsp, err := s.unaryMiddleware(ctx, request, fn); err != nil {
if midResp, err := s.unaryMiddleware(ctx, request, "UpdateGCSafePointV2"); err != nil {
return nil, err
} else if rsp != nil {
return rsp.(*pdpb.UpdateGCSafePointV2Response), err
} else if midResp != nil {
if midResp.header != nil {
return &pdpb.UpdateGCSafePointV2Response{
Header: midResp.header,
}, nil
}
if midResp.deferFunc != nil {
defer midResp.deferFunc()
}
if midResp.resp != nil {
return midResp.resp.(*pdpb.UpdateGCSafePointV2Response), nil
}
}

newSafePoint := request.GetSafePoint()
Expand Down Expand Up @@ -98,13 +111,20 @@ func (s *GrpcServer) UpdateGCSafePointV2(ctx context.Context, request *pdpb.Upda

// UpdateServiceSafePointV2 update service safe point for the given keyspace.
func (s *GrpcServer) UpdateServiceSafePointV2(ctx context.Context, request *pdpb.UpdateServiceSafePointV2Request) (*pdpb.UpdateServiceSafePointV2Response, error) {
fn := func(ctx context.Context, client *grpc.ClientConn) (any, error) {
return pdpb.NewPDClient(client).UpdateServiceSafePointV2(ctx, request)
}
if rsp, err := s.unaryMiddleware(ctx, request, fn); err != nil {
if midResp, err := s.unaryMiddleware(ctx, request, "UpdateServiceSafePointV2"); err != nil {
return nil, err
} else if rsp != nil {
return rsp.(*pdpb.UpdateServiceSafePointV2Response), err
} else if midResp != nil {
if midResp.header != nil {
return &pdpb.UpdateServiceSafePointV2Response{
Header: midResp.header,
}, nil
}
if midResp.deferFunc != nil {
defer midResp.deferFunc()
}
if midResp.resp != nil {
return midResp.resp.(*pdpb.UpdateServiceSafePointV2Response), nil
}
}

nowTSO, err := s.getGlobalTSO(ctx)
Expand Down Expand Up @@ -195,13 +215,20 @@ func (s *GrpcServer) WatchGCSafePointV2(request *pdpb.WatchGCSafePointV2Request,

// GetAllGCSafePointV2 return all gc safe point v2.
func (s *GrpcServer) GetAllGCSafePointV2(ctx context.Context, request *pdpb.GetAllGCSafePointV2Request) (*pdpb.GetAllGCSafePointV2Response, error) {
fn := func(ctx context.Context, client *grpc.ClientConn) (any, error) {
return pdpb.NewPDClient(client).GetAllGCSafePointV2(ctx, request)
}
if rsp, err := s.unaryMiddleware(ctx, request, fn); err != nil {
if midResp, err := s.unaryMiddleware(ctx, request, "GetAllGCSafePointV2"); err != nil {
return nil, err
} else if rsp != nil {
return rsp.(*pdpb.GetAllGCSafePointV2Response), err
} else if midResp != nil {
if midResp.header != nil {
return &pdpb.GetAllGCSafePointV2Response{
Header: midResp.header,
}, nil
}
if midResp.deferFunc != nil {
defer midResp.deferFunc()
}
if midResp.resp != nil {
return midResp.resp.(*pdpb.GetAllGCSafePointV2Response), nil
}
}

startkey := keypath.GCSafePointV2Prefix()
Expand Down
Loading
Loading