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

resourcemanager: do not check existence when add resource group (#6717) #6739

Merged
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: 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
Loading