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

Add escape for management key #4363

Merged

Conversation

zenmiao7
Copy link
Contributor

@zenmiao7 zenmiao7 commented Mar 8, 2022

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

Summary about this PR

Changelog

  • Improvement

Related Issues

#3792

Test Plan

Unit Tests

Stateless Tests

@vercel
Copy link

vercel bot commented Mar 8, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/databend/databend/FLTk2rWATjRtJDCecyQxhaRCM75Y
✅ Preview: https://databend-git-fork-blacksmith96-u-blacksmith96ad-b08314-databend.vercel.app

@mergify
Copy link
Contributor

mergify bot commented Mar 8, 2022

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@zenmiao7 zenmiao7 marked this pull request as ready for review March 8, 2022 16:13
@BohuTANG
Copy link
Member

BohuTANG commented Mar 9, 2022

@mergify update

@mergify
Copy link
Contributor

mergify bot commented Mar 9, 2022

update

✅ Branch has been successfully updated

Hey, I reacted but my real name is @Mergifyio

@BohuTANG
Copy link
Member

BohuTANG commented Mar 9, 2022

We can move the common function escape_for_key from common/management/ to common/base

@zenmiao7
Copy link
Contributor Author

zenmiao7 commented Mar 9, 2022

Hi, @zhang2014 Could I have a question about why we need unescape_for_key function in cluster_mgr.rs?
https://github.com/datafuselabs/databend/blob/7bbafdc4c58c724019465a88298fe92f6b77cbc4/common/management/src/cluster/cluster_mgr.rs#L165-L178
Will the id field in node_info change after kv write & read?

@zhang2014
Copy link
Member

Hi, @zhang2014 Could I have a question about why we need unescape_for_key function in cluster_mgr.rs?

unescape_for_key for SELECT id FROM system.clusters.

Will the id field in node_info change after kv write & read?

No, it's immutable.

@BohuTANG
Copy link
Member

@mergify update

@BohuTANG BohuTANG requested a review from flaneur2020 March 14, 2022 05:44
@mergify
Copy link
Contributor

mergify bot commented Mar 14, 2022

update

✅ Branch has been successfully updated

Hey, I reacted but my real name is @Mergifyio


use std::string::FromUtf8Error;

pub fn escape_for_key(key: &str) -> Result<String, FromUtf8Error> {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to add some comments about this escape?
Like the raw string is, now we escape to what?
Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also,some unit test cases for this string_func module is prefered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have add comment and unit test.

while index < bytes.len() {
match bytes[index] {
b'%' => {
let mut num = unhex(bytes[index + 1]) * 16;
Copy link
Contributor

@ariesdevil ariesdevil Mar 15, 2022

Choose a reason for hiding this comment

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

Should we check the index out of range if the index is already the last byte? If we can guarantee % does not appear in the last position, we should leave a comment here.

Copy link
Contributor

Choose a reason for hiding this comment

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

For me I prefer to use iterator here so that we just call next() and peek() do stuff, and it's idiomatic rust way.

Copy link
Contributor Author

@zenmiao7 zenmiao7 Mar 16, 2022

Choose a reason for hiding this comment

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

hould we check the index out of range if the index is already the last byte? If we can guarantee % does not appear in the last position, we should leave a comment here.

This function is only used with reverse case of escape_for_key. I think there is no need to check the input. I have leave a comment in the code.

For me I prefer to use iterator here so that we just call next() and peek() do stuff, and it's idiomatic rust way.

In this function, the iterator sometimes needs to move 3 steps. Using index would be easier.

@zenmiao7
Copy link
Contributor Author

@mergify update

@mergify
Copy link
Contributor

mergify bot commented Mar 16, 2022

update

☑️ Nothing to do

  • -closed [:pushpin: update requirement]
  • #commits-behind>0 [:pushpin: update requirement]

Hey, I reacted but my real name is @Mergifyio

use common_exception::Result;

#[test]
fn test_progress() -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

How about adding the slash case?
@drmingdrmer expected your suggestions on the escape case :)

Copy link
Member

Choose a reason for hiding this comment

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

@BohuTANG
Looks good to me.
And it does not look like affecting me at all. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BohuTANG Thanks for your advise. I have changed the test case.

Copy link
Contributor

@ariesdevil ariesdevil left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your contribution and patience

@BohuTANG
Copy link
Member

Thank you @Blacksmith96 !

@BohuTANG BohuTANG merged commit 170fa7d into databendlabs:main Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants