From d0881e7a865631a0922a091b91f4461d2a32e412 Mon Sep 17 00:00:00 2001 From: glorv Date: Thu, 2 Feb 2023 12:38:41 +0800 Subject: [PATCH 1/2] fix remove resource group --- meta/meta.go | 2 +- meta/meta_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/meta/meta.go b/meta/meta.go index 41a8231130be0..3e3906867ac53 100644 --- a/meta/meta.go +++ b/meta/meta.go @@ -558,7 +558,7 @@ func (m *Meta) DropResourceGroup(groupID int64) error { 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 diff --git a/meta/meta_test.go b/meta/meta_test.go index d1d932821bce3..0d6c37cc31d43 100644 --- a/meta/meta_test.go +++ b/meta/meta_test.go @@ -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) From abfaec9d94285afa5f0f5de73c44ffbfbb506f42 Mon Sep 17 00:00:00 2001 From: glorv Date: Thu, 2 Feb 2023 13:42:09 +0800 Subject: [PATCH 2/2] remove useless code --- meta/meta.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/meta/meta.go b/meta/meta.go index 3e3906867ac53..e0779a9549603 100644 --- a/meta/meta.go +++ b/meta/meta.go @@ -555,9 +555,6 @@ 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(mResourceGroups, groupKey); err != nil { return errors.Trace(err) }