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

meta: fix remove resource group #40968

Merged
merged 8 commits into from
Feb 6, 2023
Merged
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
5 changes: 1 addition & 4 deletions meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,7 @@ func (m *Meta) UpdateResourceGroup(group *model.ResourceGroupInfo) error {
func (m *Meta) DropResourceGroup(groupID int64) error {
// Check if group exists.
groupKey := m.resourceGroupKey(groupID)
if err := m.txn.HClear(groupKey); err != nil {
return errors.Trace(err)
}
if err := m.txn.HDel(mPolicies, groupKey); err != nil {
if err := m.txn.HDel(mResourceGroups, groupKey); err != nil {
return errors.Trace(err)
}
return nil
Expand Down
39 changes: 39 additions & 0 deletions meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,45 @@ func TestPlacementPolicy(t *testing.T) {
require.NoError(t, err)
}

func TestResourceGroup(t *testing.T) {
store, err := mockstore.NewMockStore()
require.NoError(t, err)

defer func() {
require.NoError(t, store.Close())
}()

txn, err := store.Begin()
require.NoError(t, err)

// test the independent policy ID allocation.
m := meta.NewMeta(txn)

checkResourceGroup := func(ru uint64) {
rg, err := m.GetResourceGroup(1)
require.NoError(t, err)
require.Equal(t, rg.RURate, ru)
}

rg := &model.ResourceGroupInfo{
ID: 1,
Name: model.NewCIStr("aa"),
ResourceGroupSettings: &model.ResourceGroupSettings{
RURate: 100,
},
}
require.NoError(t, m.CreateResourceGroup(rg))
checkResourceGroup(100)

rg.RURate = 200
require.NoError(t, m.UpdateResourceGroup(rg))
checkResourceGroup(200)

m.DropResourceGroup(1)
_, err = m.GetResourceGroup(1)
require.Error(t, err)
}

func TestBackupAndRestoreAutoIDs(t *testing.T) {
store, err := mockstore.NewMockStore()
require.NoError(t, err)
Expand Down