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

api: supports /regions/key by hex key #8262

Merged
merged 8 commits into from
Jun 13, 2024

Conversation

HuSharp
Copy link
Member

@HuSharp HuSharp commented Jun 6, 2024

What problem does this PR solve?

Issue Number: Close #8261

What is changed and how does it work?

api: supports `/regions/key` by hex key

Check List

Tests

  • Unit test

Release note

None.

Signed-off-by: husharp <jinhao.hu@pingcap.com>
@HuSharp HuSharp requested review from JmPotato and lhy1024 June 6, 2024 05:06
Copy link
Contributor

ti-chi-bot bot commented Jun 6, 2024

[REVIEW NOTIFICATION]

This pull request has not been approved.

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 bot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 6, 2024
@HuSharp
Copy link
Member Author

HuSharp commented Jun 6, 2024

PTAL, thx! @yongman

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.33%. Comparing base (e52f5be) to head (364b209).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8262      +/-   ##
==========================================
- Coverage   77.41%   77.33%   -0.09%     
==========================================
  Files         471      471              
  Lines       61395    61405      +10     
==========================================
- Hits        47529    47486      -43     
- Misses      10314    10363      +49     
- Partials     3552     3556       +4     
Flag Coverage Δ
unittests 77.33% <87.50%> (-0.09%) ⬇️

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

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.

Can we add this new change to the PD HTTP SDK as well?

server/api/region.go Outdated Show resolved Hide resolved
Copy link
Contributor

ti-chi-bot bot commented Jun 6, 2024

@yongman: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

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.

@HuSharp
Copy link
Member Author

HuSharp commented Jun 6, 2024

Can we add this new change to the PD HTTP SDK as well?

The GetRegionsByKeyRange interface of the PD HTTP SDK only supports bytes, as does GetRegionByKey. Do we need hex support for both interfaces?

Signed-off-by: husharp <jinhao.hu@pingcap.com>
@ti-chi-bot ti-chi-bot bot added the dco-signoff: yes Indicates the PR's author has signed the dco. label Jun 6, 2024
@HuSharp HuSharp requested a review from JmPotato June 6, 2024 06:02
Copy link
Member

@okJiang okJiang left a comment

Choose a reason for hiding this comment

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

rest lgtm

@@ -336,6 +336,22 @@ func ParseKey(name string, input map[string]any) ([]byte, string, error) {
return returned, rawKey, nil
}

// ParseHexKeys decodes hexadecimal keys to bytes if the format is "hex".
func ParseHexKeys(format string, keys ...*string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Returning parsed key to user is better than returning result by input parameter implicitly.

Suggested change
func ParseHexKeys(format string, keys ...*string) error {
func ParseHexKeys(format string, keys []string) ([]string, error) {

Copy link
Member Author

Choose a reason for hiding this comment

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

want to reduce redundant code :(

Copy link
Member

@okJiang okJiang Jun 6, 2024

Choose a reason for hiding this comment

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

I know what you want... But this suggestion aims to avoid to changing data in the input implicitly, and each update operation, I think, should re-assign to the old value. Let's see what other reviewers think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps there is no need to provide a function. Because of the multiple arguments and the error check which will make code more redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

This involves converting between []byte and string. I prefer a more performant approach; a benchmark may help.

pkg/utils/apiutil/apiutil.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 6, 2024
Signed-off-by: husharp <jinhao.hu@pingcap.com>
@HuSharp HuSharp force-pushed the support_scan_regions_hex branch from 44aaf74 to 509c5fb Compare June 6, 2024 10:02
Signed-off-by: husharp <jinhao.hu@pingcap.com>
@@ -336,6 +336,22 @@ func ParseKey(name string, input map[string]any) ([]byte, string, error) {
return returned, rawKey, nil
}

// ParseHexKeys decodes hexadecimal keys to bytes if the format is "hex".
func ParseHexKeys(format string, keys []string) (hexStrings []string, 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.

Suggested change
func ParseHexKeys(format string, keys []string) (hexStrings []string, err error) {
func ParseHexKeys(format string, keys []string) (hexBytes [][]byte, err error) {

returning bytes can reduce some converting

Copy link
Member Author

@HuSharp HuSharp Jun 13, 2024

Choose a reason for hiding this comment

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

changed in 3f515a6
which change hex.String to hex.Decode, PTAL, thx!

Copy link
Contributor

ti-chi-bot bot commented Jun 7, 2024

@okJiang: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

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 bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 13, 2024
Comment on lines +341 to +343
if format != "hex" {
return keys, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Shall we move it out of this function?

Copy link
Member Author

@HuSharp HuSharp Jun 13, 2024

Choose a reason for hiding this comment

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

No, we only use it when the format is "hex" and want to extract common logic.
add more comment to ParseHexKeys, PTAL, thx!
ref #8262 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Since the function is named ParseHexKeys, I think it has already be in hex format before calling this function.

Signed-off-by: husharp <jinhao.hu@pingcap.com>
@HuSharp HuSharp force-pushed the support_scan_regions_hex branch from 7e69cb1 to 3f515a6 Compare June 13, 2024 06:16
Signed-off-by: husharp <jinhao.hu@pingcap.com>
@HuSharp HuSharp requested review from okJiang and rleungx June 13, 2024 06:29
Copy link
Contributor

ti-chi-bot bot commented Jun 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JmPotato, nolouch, okJiang, yongman

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 13, 2024
Copy link
Contributor

ti-chi-bot bot commented Jun 13, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-13 03:51:50.345656805 +0000 UTC m=+609464.398968722: ☑️ agreed by nolouch.
  • 2024-06-13 06:35:52.232052406 +0000 UTC m=+619306.285364329: ☑️ agreed by JmPotato.

@ti-chi-bot ti-chi-bot bot merged commit 14c68f6 into tikv:master Jun 13, 2024
20 checks passed
@HuSharp HuSharp deleted the support_scan_regions_hex branch June 13, 2024 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

supports /regions/key by hex key
6 participants