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
… (#6739)

ref #5851, ref pingcap/tidb#45050

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

Co-authored-by: glorv <glorvs@163.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 12, 2023
1 parent 627ec8a commit b0477c9
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 @@ -596,11 +596,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 @@ -368,8 +368,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/resource_manager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,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 @@ -165,12 +167,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/resource_manager/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,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 @@ -738,8 +738,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 @@ -809,11 +809,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 b0477c9

Please sign in to comment.