-
Notifications
You must be signed in to change notification settings - Fork 735
mcs: init default resource group name when access new keyspace #9393
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
base: master
Are you sure you want to change the base?
Changes from all commits
27a18fa
ce5ce28
146d493
06ddc0e
ce71b64
4457cde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,21 @@ | |
return m.krgms[keyspaceID] | ||
} | ||
|
||
func (m *Manager) accessKeyspaceResourceGroupManager(keyspaceID uint32, groupName string) (*keyspaceResourceGroupManager, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to add it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need, we can return "Not found" error if the keyspace is not inited. |
||
var krgm *keyspaceResourceGroupManager | ||
if groupName == DefaultResourceGroupName { | ||
// For the default resource group, if the keyspace manager doesn't exist yet | ||
// and the group name is the default resource group name, we try to get or create it. | ||
krgm = m.getOrCreateKeyspaceResourceGroupManager(keyspaceID, true) | ||
} else { | ||
krgm = m.getKeyspaceResourceGroupManager(keyspaceID) | ||
} | ||
if krgm == nil { | ||
return nil, errs.ErrKeyspaceNotExists.FastGenByArgs(keyspaceID) | ||
} | ||
return krgm, nil | ||
} | ||
|
||
// Init initializes the resource group manager. | ||
func (m *Manager) Init(ctx context.Context) error { | ||
v, err := m.storage.LoadControllerConfig() | ||
|
@@ -296,15 +311,16 @@ | |
// ModifyResourceGroup modifies an existing resource group. | ||
func (m *Manager) ModifyResourceGroup(grouppb *rmpb.ResourceGroup) error { | ||
keyspaceID := ExtractKeyspaceID(grouppb.GetKeyspaceId()) | ||
krgm := m.getKeyspaceResourceGroupManager(keyspaceID) | ||
if krgm == nil { | ||
return errs.ErrKeyspaceNotExists.FastGenByArgs(keyspaceID) | ||
krgm, err := m.accessKeyspaceResourceGroupManager(keyspaceID, grouppb.Name) | ||
if err != nil { | ||
return err | ||
} | ||
return krgm.modifyResourceGroup(grouppb) | ||
} | ||
|
||
// DeleteResourceGroup deletes a resource group. | ||
func (m *Manager) DeleteResourceGroup(keyspaceID uint32, name string) error { | ||
// "default" group can't be deleted, so there is not need to call accessKeyspaceResourceGroupManager | ||
krgm := m.getKeyspaceResourceGroupManager(keyspaceID) | ||
if krgm == nil { | ||
return errs.ErrKeyspaceNotExists.FastGenByArgs(keyspaceID) | ||
|
@@ -313,38 +329,38 @@ | |
} | ||
|
||
// GetResourceGroup returns a copy of a resource group. | ||
func (m *Manager) GetResourceGroup(keyspaceID uint32, name string, withStats bool) *ResourceGroup { | ||
krgm := m.getKeyspaceResourceGroupManager(keyspaceID) | ||
if krgm == nil { | ||
return nil | ||
func (m *Manager) GetResourceGroup(keyspaceID uint32, name string, withStats bool) (*ResourceGroup, error) { | ||
krgm, err := m.accessKeyspaceResourceGroupManager(keyspaceID, name) | ||
if err != nil { | ||
lhy1024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil, err | ||
} | ||
return krgm.getResourceGroup(name, withStats) | ||
return krgm.getResourceGroup(name, withStats), nil | ||
} | ||
|
||
// GetMutableResourceGroup returns a mutable resource group. | ||
func (m *Manager) GetMutableResourceGroup(keyspaceID uint32, name string) *ResourceGroup { | ||
krgm := m.getKeyspaceResourceGroupManager(keyspaceID) | ||
if krgm == nil { | ||
return nil | ||
func (m *Manager) GetMutableResourceGroup(keyspaceID uint32, name string) (*ResourceGroup, error) { | ||
krgm, err := m.accessKeyspaceResourceGroupManager(keyspaceID, name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return krgm.getMutableResourceGroup(name) | ||
return krgm.getMutableResourceGroup(name), nil | ||
} | ||
|
||
// GetResourceGroupList returns copies of resource group list. | ||
func (m *Manager) GetResourceGroupList(keyspaceID uint32, withStats bool) []*ResourceGroup { | ||
krgm := m.getKeyspaceResourceGroupManager(keyspaceID) | ||
if krgm == nil { | ||
return nil | ||
func (m *Manager) GetResourceGroupList(keyspaceID uint32, withStats bool) ([]*ResourceGroup, error) { | ||
krgm, err := m.accessKeyspaceResourceGroupManager(keyspaceID, DefaultResourceGroupName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return krgm.getResourceGroupList(withStats, true) | ||
return krgm.getResourceGroupList(withStats, true), nil | ||
} | ||
|
||
func (m *Manager) getRUTracker(keyspaceID uint32, name string) *ruTracker { | ||
krgm := m.getKeyspaceResourceGroupManager(keyspaceID) | ||
if krgm == nil { | ||
return nil | ||
func (m *Manager) getRUTracker(keyspaceID uint32, name string) (*ruTracker, error) { | ||
krgm, err := m.accessKeyspaceResourceGroupManager(keyspaceID, DefaultResourceGroupName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return krgm.getOrCreateRUTracker(name) | ||
return krgm.getOrCreateRUTracker(name), nil | ||
} | ||
|
||
func (m *Manager) persistLoop(ctx context.Context) { | ||
|
@@ -496,11 +512,21 @@ | |
sinceLastRecord := m.metrics.recordConsumption(consumptionInfo, keyspaceName, m.controllerConfig, now) | ||
resourceGroupName := consumptionInfo.resourceGroupName | ||
// TODO: maybe we need to distinguish background ru. | ||
if rg := m.GetMutableResourceGroup(keyspaceID, resourceGroupName); rg != nil { | ||
if rg, err := m.GetMutableResourceGroup(keyspaceID, resourceGroupName); rg != nil { | ||
rg.UpdateRUConsumption(consumptionInfo.Consumption) | ||
} else { | ||
log.Error("failed to get mutable resource group", | ||
zap.Uint32("keyspace-id", keyspaceID), | ||
zap.String("resource-group-name", resourceGroupName), | ||
zap.Error(err)) | ||
} | ||
if rt := m.getRUTracker(keyspaceID, resourceGroupName); rt != nil { | ||
if rt, err := m.getRUTracker(keyspaceID, resourceGroupName); rt != nil { | ||
rt.sample(now, consumptionInfo.RRU+consumptionInfo.WRU, sinceLastRecord) | ||
} else { | ||
log.Error("failed to get RU tracker", | ||
zap.Uint32("keyspace-id", keyspaceID), | ||
zap.String("resource-group-name", resourceGroupName), | ||
zap.Error(err)) | ||
} | ||
case <-cleanUpTicker.C: | ||
// Clean up the metrics that have not been updated for a long time. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -973,7 +973,7 @@ func (suite *resourceManagerClientTestSuite) TestBasicResourceGroupCURD() { | |
re.NoError(err) | ||
re.Contains(dresp, "Success!") | ||
_, err = cli.GetResourceGroup(suite.ctx, g.Name) | ||
re.EqualError(err, fmt.Sprintf("get resource group %v failed, rpc error: code = Unknown desc = resource group not found", g.Name)) | ||
re.EqualError(err, fmt.Sprintf("get resource group %v failed, rpc error: code = Unknown desc = [PD:resourcemanager:ErrGroupNotExists]the %v resource group does not exist", g.Name, g.Name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why has the error message here changed? Can it be kept the same as before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace |
||
} | ||
|
||
// to test the deletion of persistence | ||
|
@@ -1620,7 +1620,7 @@ func (suite *resourceManagerClientTestSuite) TestResourceGroupCURDWithKeyspace() | |
|
||
// Get and List resource group without keyspace id | ||
rg, err := cli.GetResourceGroup(suite.ctx, group.Name) | ||
re.EqualError(err, fmt.Sprintf("get resource group %v failed, rpc error: code = Unknown desc = resource group not found", group.Name)) | ||
re.EqualError(err, fmt.Sprintf("get resource group %v failed, rpc error: code = Unknown desc = [PD:resourcemanager:ErrGroupNotExists]the %v resource group does not exist", group.Name, group.Name)) | ||
re.Nil(rg) | ||
rgs, err := cli.ListResourceGroups(suite.ctx) | ||
re.NoError(err) | ||
|
@@ -1695,7 +1695,7 @@ func (suite *resourceManagerClientTestSuite) TestResourceGroupCURDWithKeyspace() | |
re.NoError(err) | ||
re.Contains(resp, "Success!") | ||
rg, err = clientKeyspace.GetResourceGroup(suite.ctx, group.Name, pd.WithRUStats) | ||
re.EqualError(err, fmt.Sprintf("get resource group %v failed, rpc error: code = Unknown desc = resource group not found", group.Name)) | ||
re.EqualError(err, fmt.Sprintf("get resource group %v failed, rpc error: code = Unknown desc = [PD:resourcemanager:ErrGroupNotExists]the %v resource group does not exist", group.Name, group.Name)) | ||
re.Nil(rg) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a status code?