diff --git a/client/go.mod b/client/go.mod index 1af05ed37b4c..5099d589a742 100644 --- a/client/go.mod +++ b/client/go.mod @@ -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 diff --git a/client/go.sum b/client/go.sum index 6e46e09e98a0..9c521bcf29eb 100644 --- a/client/go.sum +++ b/client/go.sum @@ -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= diff --git a/go.mod b/go.mod index 1137e66fd024..121c2fc4443e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index cbe02f0ea160..0e08260d982b 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/mcs/scheduling/server/grpc_service.go b/pkg/mcs/scheduling/server/grpc_service.go index 663a0387b460..9ae5b8c98954 100644 --- a/pkg/mcs/scheduling/server/grpc_service.go +++ b/pkg/mcs/scheduling/server/grpc_service.go @@ -227,6 +227,33 @@ func (s *Service) ScatterRegions(ctx context.Context, request *schedulingpb.Scat }, nil } +// 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 + } + + 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 + } + + return &schedulingpb.GetOperatorResponse{ + Header: s.header(), + RegionId: requestID, + Desc: []byte(r.Desc()), + Kind: []byte(r.Kind().String()), + Status: r.Status, + }, nil +} + // RegisterGRPCService registers the service to gRPC server. func (s *Service) RegisterGRPCService(g *grpc.Server) { schedulingpb.RegisterSchedulingServer(g, s) diff --git a/server/grpc_service.go b/server/grpc_service.go index 8ad81b454724..ebb257362406 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -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(), + } + resp, err := s.schedulingClient.Load().(*schedulingClient).getClient().GetOperator(ctx, req) + if err != nil { + // reset to let it be updated in the next request + s.schedulingClient.Store(&schedulingClient{}) + return s.convertOperatorResponse(resp), err + } + return s.convertOperatorResponse(resp), nil + } + } fn := func(ctx context.Context, client *grpc.ClientConn) (interface{}, error) { return pdpb.NewPDClient(client).GetOperator(ctx, request) } @@ -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(), + } +} + // Only used for the TestLocalAllocatorLeaderChange. var mockLocalAllocatorLeaderChangeFlag = false diff --git a/tests/integrations/client/go.mod b/tests/integrations/client/go.mod index 4fdbfe3e6c9c..63729d514202 100644 --- a/tests/integrations/client/go.mod +++ b/tests/integrations/client/go.mod @@ -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 diff --git a/tests/integrations/client/go.sum b/tests/integrations/client/go.sum index d995af975303..808675fe2b95 100644 --- a/tests/integrations/client/go.sum +++ b/tests/integrations/client/go.sum @@ -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= diff --git a/tests/integrations/mcs/go.mod b/tests/integrations/mcs/go.mod index 239bba3f3824..917d344da912 100644 --- a/tests/integrations/mcs/go.mod +++ b/tests/integrations/mcs/go.mod @@ -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 diff --git a/tests/integrations/mcs/go.sum b/tests/integrations/mcs/go.sum index a831ed22b6ba..c3743728c403 100644 --- a/tests/integrations/mcs/go.sum +++ b/tests/integrations/mcs/go.sum @@ -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= diff --git a/tests/integrations/tso/go.mod b/tests/integrations/tso/go.mod index 145e4692fca6..6733b8934b06 100644 --- a/tests/integrations/tso/go.mod +++ b/tests/integrations/tso/go.mod @@ -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 diff --git a/tests/integrations/tso/go.sum b/tests/integrations/tso/go.sum index 8ab1c482bb5a..12e63afa7e5f 100644 --- a/tests/integrations/tso/go.sum +++ b/tests/integrations/tso/go.sum @@ -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=