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

privilege/privileges: sort user records in privilege cache #7211

Merged
merged 8 commits into from
Aug 2, 2018

Conversation

tiancaiamao
Copy link
Contributor

What have you changed? (mandatory)

Sort the user records according to MySQL rules.

What is the type of the changes? (mandatory)

  • Bug fix (non-breaking change which fixes an issue)

How has this PR been tested? (mandatory)

unit test

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

no

Does this PR affect tidb-ansible update? (mandatory)

no

Does this PR need to be added to the release notes? (mandatory)

no

Refer to a related PR or issue link (optional)

fix #7182

return 0
}

// For other case, the order is nondeterministic.
Copy link
Member

Choose a reason for hiding this comment

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

192.168.% is larger than 192.168.199.%.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a check by length.

case xEnd && !yEnd:
return 1
case xEnd && yEnd:
// 192.168.199.% smaller than 192.168.%
Copy link
Contributor

Choose a reason for hiding this comment

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

what about '192.%.128.%' and '192.168.1.%' ?
create user 'test'@'192.%.1.%' will be ok in MySQL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The result will be nondeterministic

Copy link
Contributor

Choose a reason for hiding this comment

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

OK
We may add a FIXME label here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I add a TODO in at the beginning of this function.

@@ -194,6 +194,7 @@ func (s sortedUserRecord) Less(i, j int) bool {
}

// compareHost compares two host string using some special rules, return value 1, 0, -1 means > = <.
// TODO: Check how MySQL do it exactly, instead of guess its rules.
Copy link
Contributor

Choose a reason for hiding this comment

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

create an issue for this TODO, and add the link here

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

Addressing the comment makes a LGTM

@tiancaiamao
Copy link
Contributor Author

@XuHuaiyu I've add a TODO comment at the start of function compareHost

XuHuaiyu
XuHuaiyu previously approved these changes Aug 1, 2018
Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM
We need to create an issue to avoid the TODO becomes a NEVERDO.

@tiancaiamao
Copy link
Contributor Author

PTAL @shenli

@coocood coocood added the type/bugfix This PR fixes a bug. label Aug 2, 2018
@@ -47,7 +48,8 @@ func computePrivMask(privs []mysql.PrivilegeType) mysql.PrivilegeType {
return mask
}

type userRecord struct {
// UserRecord is used to represent a user record in privilege cache.
type UserRecord struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe no need to make this public if want to test it.

maybe try this trick...https://github.com/lysu/tidb/blob/87ce884b2e0dc679554cb666b05f3347b3c72957/types/export_test.go#L17

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cache_test.go use a different package, so this trick can't work.

type sortedUserRecord []UserRecord

func (s sortedUserRecord) Len() int {
return len([]UserRecord(s))
Copy link
Contributor

Choose a reason for hiding this comment

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

return len(s) works


func (s sortedUserRecord) Less(i, j int) bool {
x := ([]UserRecord(s))[i]
y := ([]UserRecord(s))[j]
Copy link
Contributor

Choose a reason for hiding this comment

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

	x := s[i]
	y := s[j]

works too~


func (s sortedUserRecord) Swap(i, j int) {
s1 := []UserRecord(s)
s1[i], s1[j] = s1[j], s1[i]
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto~

}

// compareHost compares two host string using some special rules, return value 1, 0, -1 means > = <.
// TODO: Check how MySQL do it exactly, instead of guess its rules.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

wild_one='_'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be overkill, if some user really meet the complex cases and complain, I'll consider.
If you are interested, you can self-assign this one #7229

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

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

LGTM

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@tiancaiamao tiancaiamao added status/LGT2 Indicates that a PR has LGTM 2. status/all tests passed labels Aug 2, 2018
@tiancaiamao tiancaiamao merged commit 90e4d02 into pingcap:master Aug 2, 2018
@tiancaiamao tiancaiamao deleted the sort-privilege branch August 2, 2018 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

connection verification is diff from mysql
5 participants