-
Notifications
You must be signed in to change notification settings - Fork 724
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
client, resource_manager: resource manager client #5810
Conversation
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Codecov ReportBase: 75.35% // Head: 74.91% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #5810 +/- ##
==========================================
- Coverage 75.35% 74.91% -0.44%
==========================================
Files 338 337 -1
Lines 33858 33941 +83
==========================================
- Hits 25514 25428 -86
- Misses 6137 6329 +192
+ Partials 2207 2184 -23
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
client/resoucemanager_client.go
Outdated
@@ -0,0 +1,265 @@ | |||
package pd |
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.
file name need to be resource
rather than resouce
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
client/resoucemanager_client.go
Outdated
// ListResourceGroups loads and returns target keyspace's metadata. | ||
func (c *client) ListResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, error) { | ||
req := &rmpb.ListResourceGroupsRequest{} | ||
resp, err := c.resouceManagerClient().ListResourceGroups(ctx, req) |
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.
Won't this cause panic if the c.resouceManagerClient()
return nil?
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.
Like leaderClient
, I don't think c.resouceManagerClient()
is going to return nil
client/resoucemanager_client.go
Outdated
} | ||
|
||
func (c *client) AddResourceGroup(ctx context.Context, resourceGroupName string, settings *rmpb.GroupSettings) (string, error) { | ||
return c.putResourceGroup(ctx, resourceGroupName, settings, 0 /* type add resource group */) |
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.
What about using an enum type to distinguish the type rather than the comment?
client/resoucemanager_client.go
Outdated
clientCtx: c.ctx, | ||
} | ||
req.Requeset = request | ||
c.tokenDispatcher.tokenBatchController.tokenRequestCh <- req |
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.
It seems that this will easily be blocked since the tokenRequestCh
's capacity is 1.
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.
Currently we have not implemented batch, so it will also be blocked by Wait()
?
client/resoucemanager_client.go
Outdated
dispatcher := &tokenDispatcher{ | ||
dispatcherCancel: dispatcherCancel, | ||
tokenBatchController: newTokenBatchController( | ||
make(chan *tokenRequest, 1)), |
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.
What about using a larger size?
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.
Currently we have not implemented batch and do not seem to need a larger size
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
const defaultInitialTokens = 10 * 10000 | ||
|
||
const defaultMaxTokens = 1e7 |
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.
const defaultInitialTokens = 10 * 10000 | |
const defaultMaxTokens = 1e7 | |
const ( | |
defaultInitialTokens = 10 * 10000 | |
defaultMaxTokens = 1e7 | |
) |
@@ -70,12 +88,57 @@ func (t *GroupTokenBucket) Update(now time.Time) { | |||
t.Tokens += float64(t.Settings.FillRate) * delta.Seconds() | |||
t.LastUpdate = &now | |||
} | |||
if t.Tokens > t.MaxTokens { |
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 also need to check the max tokens when it has not been initialized below?
var res rmpb.TokenBucket | ||
res.Settings = &rmpb.TokenLimitSettings{} | ||
// FillRate is used for the token server unavailable in abnormal situation. | ||
res.Settings.FillRate = 0 |
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.
I think this initialization is unnecessary.
var trickleTime = time.Duration(targetPeriodMs) * time.Millisecond | ||
availableRate := float64(t.Settings.FillRate) | ||
if debt := -t.Tokens; debt > 0 { | ||
fmt.Println(debt) |
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.
fmt.Println(debt) |
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
client/resourcemanager_client.go
Outdated
AcquireTokenBuckets(ctx context.Context, request *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error) | ||
} | ||
|
||
// resouceManagerClient gets the ResourceManager client of current PD leader. |
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.
I'm resouce
killer!!!🤣can found 10 resouce
by Ctrl-F
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
client/resourcemanager_client.go
Outdated
return nil | ||
} | ||
|
||
// ListResourceGroups loads and returns target keyspace's metadata. |
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.
resource groups
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.
The rest LGTM.
client/resourcemanager_client.go
Outdated
return nil | ||
} | ||
|
||
// ListResourceGroups loads and returns target keyspace's metadata. |
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.
The comment is incorrect.
// ListResourceGroups loads and returns target keyspace's metadata. | |
// ListResourceGroups loads and returns xxx. |
client/resourcemanager_client.go
Outdated
return nil | ||
} | ||
|
||
func (c *client) finishTokenRequest(t *tokenRequest, tokenBuckets []*rmpb.TokenBucketResponse, err error) { |
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.
It seems that this function is too simple to exist. Maybe we can just remove it to avoid some data copying.
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com> merge master Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
62b275c
to
6115bc6
Compare
) | ||
|
||
// ResourceManagerClient manages resource group info and token request. | ||
type ResourceManagerClient interface { |
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.
you can replace the client in tests/msc/resource_manager_test.go
to add the tests.
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.
LGTM
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.
lgtm
/merge |
@CabinfeverB: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
This pull request has been accepted and is ready to merge. Commit hash: d776fca
|
@CabinfeverB: Your PR was out of date, I have automatically updated it for you. If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: Ref #5851
impl resource manager client
What is changed and how does it work?
Check List
Tests
Related changes
pingcap/docs
/pingcap/docs-cn
:pingcap/tiup
:Release note