Skip to content

Commit

Permalink
add get operator rpc
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Oct 12, 2023
1 parent e574f67 commit 58fa4dd
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65
replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0
4 changes: 2 additions & 2 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65 h1:llpjsWxqkXEIFnTFKLO82Yyg3reRH+ZDwYk2Bnfxueo=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0 h1:BYUE6ye4O8is1k/OijCJdtWYb/pTfcIRa6lxA3ZsRVs=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ replace google.golang.org/grpc v1.54.0 => google.golang.org/grpc v1.26.0
// After the PR to kvproto is merged, remember to comment this out and run `go mod tidy`.
// replace github.com/pingcap/kvproto => github.com/$YourPrivateRepo $YourPrivateBranch

replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65
replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65 h1:llpjsWxqkXEIFnTFKLO82Yyg3reRH+ZDwYk2Bnfxueo=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0 h1:BYUE6ye4O8is1k/OijCJdtWYb/pTfcIRa6lxA3ZsRVs=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
27 changes: 27 additions & 0 deletions pkg/mcs/scheduling/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,33 @@ func (s *Service) ScatterRegions(ctx context.Context, request *schedulingpb.Scat
}, nil

Check warning on line 227 in pkg/mcs/scheduling/server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/scheduling/server/grpc_service.go#L224-L227

Added lines #L224 - L227 were not covered by tests
}

// GetOperator gets information about the operator belonging to the specify region.
func (s *Service) GetOperator(ctx context.Context, request *schedulingpb.GetOperatorRequest) (*schedulingpb.GetOperatorResponse, error) {
c := s.GetCluster()
if c == nil {
return &schedulingpb.GetOperatorResponse{Header: s.notBootstrappedHeader()}, nil

Check warning on line 234 in pkg/mcs/scheduling/server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/scheduling/server/grpc_service.go#L232-L234

Added lines #L232 - L234 were not covered by tests
}

opController := c.GetCoordinator().GetOperatorController()
requestID := request.GetRegionId()
r := opController.GetOperatorStatus(requestID)
if r == nil {
header := s.errorHeader(&schedulingpb.Error{
Type: schedulingpb.ErrorType_UNKNOWN,
Message: "Not Found",
})
return &schedulingpb.GetOperatorResponse{Header: header}, nil

Check warning on line 245 in pkg/mcs/scheduling/server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/scheduling/server/grpc_service.go#L237-L245

Added lines #L237 - L245 were not covered by tests
}

return &schedulingpb.GetOperatorResponse{
Header: s.header(),
RegionId: requestID,
Desc: []byte(r.Desc()),
Kind: []byte(r.Kind().String()),
Status: r.Status,
}, nil

Check warning on line 254 in pkg/mcs/scheduling/server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/scheduling/server/grpc_service.go#L248-L254

Added lines #L248 - L254 were not covered by tests
}

// RegisterGRPCService registers the service to gRPC server.
func (s *Service) RegisterGRPCService(g *grpc.Server) {
schedulingpb.RegisterSchedulingServer(g, s)
Expand Down
29 changes: 29 additions & 0 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,25 @@ func (s *GrpcServer) UpdateServiceGCSafePoint(ctx context.Context, request *pdpb

// GetOperator gets information about the operator belonging to the specify region.
func (s *GrpcServer) GetOperator(ctx context.Context, request *pdpb.GetOperatorRequest) (*pdpb.GetOperatorResponse, error) {
if s.IsAPIServiceMode() {
s.updateSchedulingClient(ctx)
if s.schedulingClient.Load() != nil {
req := &schedulingpb.GetOperatorRequest{
Header: &schedulingpb.RequestHeader{
ClusterId: request.GetHeader().GetClusterId(),
SenderId: request.GetHeader().GetSenderId(),
},
RegionId: request.GetRegionId(),

Check warning on line 2000 in server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

server/grpc_service.go#L1993-L2000

Added lines #L1993 - L2000 were not covered by tests
}
resp, err := s.schedulingClient.Load().(*schedulingClient).getClient().GetOperator(ctx, req)
if err != nil {

Check warning on line 2003 in server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

server/grpc_service.go#L2002-L2003

Added lines #L2002 - L2003 were not covered by tests
// reset to let it be updated in the next request
s.schedulingClient.Store(&schedulingClient{})
return s.convertOperatorResponse(resp), err

Check warning on line 2006 in server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

server/grpc_service.go#L2005-L2006

Added lines #L2005 - L2006 were not covered by tests
}
return s.convertOperatorResponse(resp), nil

Check warning on line 2008 in server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

server/grpc_service.go#L2008

Added line #L2008 was not covered by tests
}
}
fn := func(ctx context.Context, client *grpc.ClientConn) (interface{}, error) {
return pdpb.NewPDClient(client).GetOperator(ctx, request)
}
Expand Down Expand Up @@ -2107,6 +2126,16 @@ func (s *GrpcServer) convertScatterResponse(resp *schedulingpb.ScatterRegionsRes
}
}

func (s *GrpcServer) convertOperatorResponse(resp *schedulingpb.GetOperatorResponse) *pdpb.GetOperatorResponse {
return &pdpb.GetOperatorResponse{
Header: s.convertHeader(resp.GetHeader()),
RegionId: resp.GetRegionId(),
Desc: resp.GetDesc(),
Kind: resp.GetKind(),
Status: resp.GetStatus(),

Check warning on line 2135 in server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

server/grpc_service.go#L2130-L2135

Added lines #L2130 - L2135 were not covered by tests
}
}

// Only used for the TestLocalAllocatorLeaderChange.
var mockLocalAllocatorLeaderChangeFlag = false

Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65
replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0
4 changes: 2 additions & 2 deletions tests/integrations/client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65 h1:llpjsWxqkXEIFnTFKLO82Yyg3reRH+ZDwYk2Bnfxueo=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0 h1:BYUE6ye4O8is1k/OijCJdtWYb/pTfcIRa6lxA3ZsRVs=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65
replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0
4 changes: 2 additions & 2 deletions tests/integrations/mcs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65 h1:llpjsWxqkXEIFnTFKLO82Yyg3reRH+ZDwYk2Bnfxueo=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0 h1:BYUE6ye4O8is1k/OijCJdtWYb/pTfcIRa6lxA3ZsRVs=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/tso/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65
replace github.com/pingcap/kvproto => github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0
4 changes: 2 additions & 2 deletions tests/integrations/tso/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65 h1:llpjsWxqkXEIFnTFKLO82Yyg3reRH+ZDwYk2Bnfxueo=
github.com/rleungx/kvproto v0.0.0-20231011054944-00d14c9e3b65/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0 h1:BYUE6ye4O8is1k/OijCJdtWYb/pTfcIRa6lxA3ZsRVs=
github.com/rleungx/kvproto v0.0.0-20231012072424-affe11d9e2e0/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down

0 comments on commit 58fa4dd

Please sign in to comment.