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

client, resource_manager: resource manager client #5810

Merged
merged 21 commits into from
Jan 11, 2023

Conversation

CabinfeverB
Copy link
Member

@CabinfeverB CabinfeverB commented Dec 29, 2022

What problem does this PR solve?

Issue Number: Ref #5851
impl resource manager client

What is changed and how does it work?

impl resource manager client

Check List

Tests

  • Unit test
  • Integration test

Related changes

Release note

None.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Dec 29, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • JmPotato
  • nolouch

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Dec 29, 2022
@codecov
Copy link

codecov bot commented Dec 29, 2022

Codecov Report

Base: 75.35% // Head: 74.91% // Decreases project coverage by -0.43% ⚠️

Coverage data is based on head (00d13b6) compared to base (a1317a7).
Patch coverage: 25.18% of modified lines in pull request are covered.

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     
Flag Coverage Δ
unittests 74.91% <25.18%> (-0.44%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/mcs/resource_manager/server/token_bukets.go 89.18% <ø> (ø)
client/resourcemanager_client.go 24.62% <24.62%> (ø)
client/client.go 67.59% <100.00%> (+0.13%) ⬆️
pkg/storage/endpoint/resource_group.go 0.00% <0.00%> (-100.00%) ⬇️
pkg/mcs/resource_manager/server/manager.go 0.00% <0.00%> (-69.50%) ⬇️
pkg/mcs/resource_manager/server/grpc_service.go 0.00% <0.00%> (-40.58%) ⬇️
pkg/mcs/resource_manager/server/resource_group.go 25.23% <0.00%> (-34.58%) ⬇️
pkg/mcs/registry/registry.go 63.63% <0.00%> (-18.19%) ⬇️
pkg/dashboard/adapter/manager.go 78.16% <0.00%> (-3.45%) ⬇️
server/schedulers/random_merge.go 62.50% <0.00%> (-3.13%) ⬇️
... and 28 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.
📢 Do you have feedback about the report comment? Let us know in this issue.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

impl token request and fix update bug

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -0,0 +1,265 @@
package pd
Copy link
Member

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>
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 6, 2023
client/resoucemanager_client.go Outdated Show resolved Hide resolved
client/resoucemanager_client.go Outdated Show resolved Hide resolved
client/resoucemanager_client.go Outdated Show resolved Hide resolved
// 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)
Copy link
Member

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?

Copy link
Member Author

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 Show resolved Hide resolved
}

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 */)
Copy link
Member

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 Show resolved Hide resolved
clientCtx: c.ctx,
}
req.Requeset = request
c.tokenDispatcher.tokenBatchController.tokenRequestCh <- req
Copy link
Member

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.

Copy link
Member Author

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()

dispatcher := &tokenDispatcher{
dispatcherCancel: dispatcherCancel,
tokenBatchController: newTokenBatchController(
make(chan *tokenRequest, 1)),
Copy link
Member

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?

Copy link
Member Author

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

client/resoucemanager_client.go Outdated Show resolved Hide resolved
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 6, 2023
Comment on lines 28 to 30
const defaultInitialTokens = 10 * 10000

const defaultMaxTokens = 1e7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Println(debt)

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
AcquireTokenBuckets(ctx context.Context, request *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error)
}

// resouceManagerClient gets the ResourceManager client of current PD leader.
Copy link
Member

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>
return nil
}

// ListResourceGroups loads and returns target keyspace's metadata.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource groups

Copy link
Member

@JmPotato JmPotato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest LGTM.

return nil
}

// ListResourceGroups loads and returns target keyspace's metadata.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is incorrect.

Suggested change
// ListResourceGroups loads and returns target keyspace's metadata.
// ListResourceGroups loads and returns xxx.

return nil
}

func (c *client) finishTokenRequest(t *tokenRequest, tokenBuckets []*rmpb.TokenBucketResponse, err error) {
Copy link
Member

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>
)

// ResourceManagerClient manages resource group info and token request.
type ResourceManagerClient interface {
Copy link
Contributor

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.

Copy link
Member

@JmPotato JmPotato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

client/client.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 11, 2023
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jan 11, 2023
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 11, 2023
@CabinfeverB
Copy link
Member Author

/merge

@ti-chi-bot
Copy link
Member

@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.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: d776fca

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jan 11, 2023
@ti-chi-bot
Copy link
Member

@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.

@ti-chi-bot ti-chi-bot merged commit 59a6203 into tikv:master Jan 11, 2023
@rleungx rleungx mentioned this pull request Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants