Skip to content

Commit

Permalink
resourcemanager: do not check existence when add resource group (#6717)
Browse files Browse the repository at this point in the history
ref #5851, ref pingcap/tidb#45050

Signed-off-by: glorv <glorvs@163.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
glorv and ti-chi-bot[bot] authored Jul 3, 2023
1 parent 87b5ade commit 5f7236f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
5 changes: 0 additions & 5 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,6 @@ error = '''
invalid group settings, please check the group name, priority and the number of resources
'''

["PD:resourcemanager:ErrResourceGroupAlreadyExists"]
error = '''
the %s resource group already exists
'''

["PD:schedule:ErrCreateOperator"]
error = '''
unable to create operator, %s
Expand Down
7 changes: 3 additions & 4 deletions pkg/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ var (

// Resource Manager errors
var (
ErrResourceGroupAlreadyExists = errors.Normalize("the %s resource group already exists", errors.RFCCodeText("PD:resourcemanager:ErrResourceGroupAlreadyExists"))
ErrResourceGroupNotExists = errors.Normalize("the %s resource group does not exist", errors.RFCCodeText("PD:resourcemanager:ErrGroupNotExists"))
ErrDeleteReservedGroup = errors.Normalize("cannot delete reserved group", errors.RFCCodeText("PD:resourcemanager:ErrDeleteReservedGroup"))
ErrInvalidGroup = errors.Normalize("invalid group settings, please check the group name, priority and the number of resources", errors.RFCCodeText("PD:resourcemanager:ErrInvalidGroup"))
ErrResourceGroupNotExists = errors.Normalize("the %s resource group does not exist", errors.RFCCodeText("PD:resourcemanager:ErrGroupNotExists"))
ErrDeleteReservedGroup = errors.Normalize("cannot delete reserved group", errors.RFCCodeText("PD:resourcemanager:ErrDeleteReservedGroup"))
ErrInvalidGroup = errors.Normalize("invalid group settings, please check the group name, priority and the number of resources", errors.RFCCodeText("PD:resourcemanager:ErrInvalidGroup"))
)
8 changes: 2 additions & 6 deletions pkg/mcs/resourcemanager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func (m *Manager) Init(ctx context.Context) {
}

// AddResourceGroup puts a resource group.
// NOTE: AddResourceGroup should also be idempotent because tidb depends
// on this retry mechanism.
func (m *Manager) AddResourceGroup(grouppb *rmpb.ResourceGroup) error {
// Check the name.
if len(grouppb.Name) == 0 || len(grouppb.Name) > 32 {
Expand All @@ -163,12 +165,6 @@ func (m *Manager) AddResourceGroup(grouppb *rmpb.ResourceGroup) error {
if grouppb.GetPriority() > 16 {
return errs.ErrInvalidGroup
}
m.RLock()
_, ok := m.groups[grouppb.Name]
m.RUnlock()
if ok {
return errs.ErrResourceGroupAlreadyExists.FastGenByArgs(grouppb.Name)
}
group := FromProtoResourceGroup(grouppb)
m.Lock()
defer m.Unlock()
Expand Down
12 changes: 5 additions & 7 deletions tests/integrations/mcs/resourcemanager/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func (suite *resourceManagerClientTestSuite) TestBasicResourceGroupCURD() {
testCasesSet1 := []struct {
name string
mode rmpb.GroupMode
addSuccess bool
isNewGroup bool
modifySuccess bool
expectMarshal string
modifySettings func(*rmpb.ResourceGroup)
Expand Down Expand Up @@ -789,8 +789,8 @@ func (suite *resourceManagerClientTestSuite) TestBasicResourceGroupCURD() {
}
// Create Resource Group
resp, err := cli.AddResourceGroup(suite.ctx, group)
checkErr(err, tcase.addSuccess)
if tcase.addSuccess {
checkErr(err, true)
if tcase.isNewGroup {
finalNum++
re.Contains(resp, "Success!")
}
Expand Down Expand Up @@ -860,11 +860,9 @@ func (suite *resourceManagerClientTestSuite) TestBasicResourceGroupCURD() {
resp, err := http.Post(getAddr(i)+"/resource-manager/api/v1/config/group", "application/json", strings.NewReader(string(createJSON)))
re.NoError(err)
defer resp.Body.Close()
if tcase.addSuccess {
re.Equal(http.StatusOK, resp.StatusCode)
re.Equal(http.StatusOK, resp.StatusCode)
if tcase.isNewGroup {
finalNum++
} else {
re.Equal(http.StatusInternalServerError, resp.StatusCode)
}

// Modify Resource Group
Expand Down

0 comments on commit 5f7236f

Please sign in to comment.