8000 resource_group: replace LoadResourceGroups with GetResourceGroupsMeta… by disksing · Pull Request #9273 · tikv/pd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

resource_group: replace LoadResourceGroups with GetResourceGroupsMeta… #9273

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/prometheus/client_golang v1.20.5
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c h1:xpW9bvK+HuuTm
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d h1:52qhTQG8G8V/pHo/w7F4d2Tw98KMk2C+gAe3U8SWRAg=
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e h1:RQFa6zpLAOIuOliTEq1+79DIbQaY+FvkbN6MhViaBzk=
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
10 changes: 6 additions & 4 deletions client/meta_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ func (c *innerClient) Get(ctx context.Context, key []byte, opts ...opt.MetaStora

ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
req := &meta_storagepb.GetRequest{
Key: key,
RangeEnd: options.RangeEnd,
Limit: options.Limit,
Revision: options.Revision,
Key: key,
RangeEnd: options.RangeEnd,
Limit: options.Limit,
Revision: options.Revision,
KeysOnly: options.KeysOnly,
CountOnly: options.CountOnly,
}
ctx = grpcutil.BuildForwardContext(ctx, c.serviceDiscovery.GetServingURL())
cli := c.metaStorageClient()
Expand Down
16 changes: 16 additions & 0 deletions client/opt/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@
Lease int64
Limit int64
IsOptsWithPrefix bool
KeysOnly bool
CountOnly bool
}

// MetaStorageOption configures MetaStorageOp.
Expand Down Expand Up @@ -349,3 +351,17 @@
op.IsOptsWithPrefix = true
}
}

// WithKeysOnly specifies that only keys should be returned.
func WithKeysOnly() MetaStorageOption {
return func(op *MetaStorageOp) {
op.KeysOnly = true
}

Check warning on line 359 in client/opt/option.go

View check run for this annotation

Codecov / codecov/patch

client/opt/option.go#L356-L359

Added lines #L356 - L359 were not covered by tests
}

// WithCountOnly specifies that only the count of keys should be returned.
func WithCountOnly() MetaStorageOption {
return func(op *MetaStorageOp) {
op.CountOnly = true
}
}
4 changes: 2 additions & 2 deletions client/resource_group/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type ResourceGroupProvider interface {
ModifyResourceGroup(ctx context.Context, metaGroup *rmpb.ResourceGroup) (string, error)
DeleteResourceGroup(ctx context.Context, resourceGroupName string) (string, error)
AcquireTokenBuckets(ctx context.Context, request *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error)
LoadResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, int64, error)
GetResourceGroupsMetaRevision(ctx context.Context) (int64, error)

metastorage.Client
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
stateUpdateTicker.Reset(time.Millisecond * 100)
})

_, metaRevision, err := c.provider.LoadResourceGroups(ctx)
metaRevision, err := c.provider.GetResourceGroupsMetaRevision(ctx)
if err != nil {
log.Warn("load resource group revision failed", zap.Error(err))
}
Expand Down
6 changes: 3 additions & 3 deletions client/resource_group/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type MockResourceGroupProvider struct {
func newMockResourceGroupProvider() *MockResourceGroupProvider {
mockProvider := &MockResourceGroupProvider{}
mockProvider.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(&meta_storagepb.GetResponse{}, nil)
mockProvider.On("LoadResourceGroups", mock.Anything).Return([]*rmpb.ResourceGroup{}, int64(0), nil)
mockProvider.On("GetResourceGroupsMetaRevision", mock.Anything).Return(int64(0), nil)
mockProvider.On("Watch", mock.Anything, mock.Anything, mock.Anything).Return(make(chan []*meta_storagepb.Event), nil)
return mockProvider
}
Expand Down Expand Up @@ -220,9 +220,9 @@ func (m *MockResourceGroupProvider) AcquireTokenBuckets(ctx context.Context, req
return args.Get(0).([]*rmpb.TokenBucketResponse), args.Error(1)
}

func (m *MockResourceGroupProvider) LoadResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, int64, error) {
func (m *MockResourceGroupProvider) GetResourceGroupsMetaRevision(ctx context.Context) (int64, error) {
args := m.Called(ctx)
return args.Get(0).([]*rmpb.ResourceGroup), args.Get(1).(int64), args.Error(2)
return args.Get(0).(int64), args.Error(1)
}

func (m *MockResourceGroupProvider) Watch(ctx context.Context, key []byte, opts ...opt.MetaStorageOption) (chan []*meta_storagepb.Event, error) {
Expand Down
23 changes: 7 additions & 16 deletions client/resource_manager_client.go
< F438 td class="blob-code blob-code-addition js-file-line"> return 0, err
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"context"
"time"

"github.com/gogo/protobuf/proto"
"go.uber.org/zap"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -53,7 +52,7 @@
AddResourceGroup(ctx context.Context, metaGroup *rmpb.ResourceGroup) (string, error)
ModifyResourceGroup(ctx context.Context, metaGroup *rmpb.ResourceGroup) (string, error)
DeleteResourceGroup(ctx context.Context, resourceGroupName string) (string, error)
LoadResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, int64, error)
GetResourceGroupsMetaRevision(ctx context.Context) (int64, error)
AcquireTokenBuckets(ctx context.Context, request *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error)
Watch(ctx context.Context, key []byte, opts ...opt.MetaStorageOption) (chan []*meta_storagepb.Event, error)
}
Expand Down Expand Up @@ -188,24 +187,16 @@
return resp.GetBody(), nil
}

// LoadResourceGroups implements the ResourceManagerClient interface.
func (c *client) LoadResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, int64, error) {
resp, err := c.Get(ctx, GroupSettingsPathPrefixBytes, opt.WithPrefix())
// GetResourceGroupsMetaRevision implements the ResourceManagerClient interface.
func (c *client) GetResourceGroupsMetaRevision(ctx context.Context) (int64, error) {
resp, err := c.Get(ctx, GroupSettingsPathPrefixBytes, opt.WithPrefix(), opt.WithCountOnly())
if err != nil {
return nil, 0, err

Check warning on line 194 in client/resource_manager_client.go

View check run for this annotation

Codecov / codecov/patch

client/resource_manager_client.go#L194

Added line #L194 was not covered by tests
}
if resp.Header.Error != nil {
return nil, resp.Header.Revision, errors.New(resp.Header.Error.Message)
return resp.Header.Revision, errors.New(resp.Header.Error.Message)

Check warning on line 197 in client/resource_manager_client.go

View check run for this annotation

Codecov / codecov/patch

client/resource_manager_client.go#L197

Added line #L197 was not covered by tests
}
groups := make([]*rmpb.ResourceGroup, 0, len(resp.Kvs))
for _, item := range resp.Kvs {
group := &rmpb.ResourceGroup{}
if err := proto.Unmarshal(item.Value, group); err != nil {
continue
}
groups = append(groups, group)
}
return groups, resp.Header.Revision, nil
return resp.Header.Revision, nil
}

// AcquireTokenBuckets implements the ResourceManagerClient interface.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/pingcap/errcode v0.3.0
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21
github.com/pingcap/tidb-dashboard v0.0.0-20250219061340-d62018124ae2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ue
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d h1:52qhTQG8G8V/pHo/w7F4d2Tw98KMk2C+gAe3U8SWRAg=
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e h1:RQFa6zpLAOIuOliTEq1+79DIbQaY+FvkbN6MhViaBzk=
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
Expand Down
6 changes: 6 additions & 0 deletions pkg/mcs/metastorage/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@
if limit := req.GetLimit(); limit != 0 {
options = append(options, clientv3.WithLimit(limit))
}
if req.GetKeysOnly() {
options = append(options, clientv3.WithKeysOnly())
}

Check warning on line 176 in pkg/mcs/metastorage/server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/metastorage/server/grpc_service.go#L175-L176

Added lines #L175 - L176 were not covered by tests
if req.GetCountOnly() {
options = append(options, clientv3.WithCountOnly())
}
cli := s.manager.GetClient()
res, err := cli.Get(ctx, key, options...)
var revision int64
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/go-sql-driver/mysql v1.7.0
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/client_model v0.6.1
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ue
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d h1:52qhTQG8G8V/pHo/w7F4d2Tw98KMk2C+gAe3U8SWRAg=
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e h1:RQFa6zpLAOIuOliTEq1+79DIbQaY+FvkbN6MhViaBzk=
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
Expand Down
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/mattn/go-shellwords v1.0.12
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.20.5
Expand Down
4 changes: 2 additions & 2 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ue
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d h1:52qhTQG8G8V/pHo/w7F4d2Tw98KMk2C+gAe3U8SWRAg=
github.com/pingcap/kvproto v0.0.0-20250224053625-b6a98c6bf02d/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e h1:RQFa6zpLAOIuOliTEq1+79DIbQaY+FvkbN6MhViaBzk=
github.com/pingcap/kvproto v0.0.0-20250428035325-7d4850b2393e/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
Expand Down
0