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

*: avoid notify privilege update for all users #57042

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Oct 31, 2024

What problem does this PR solve?

Issue Number: ref #55563

Problem Summary:

In the previous commit, I have maintained the active user lists, this commit intend to fix the notify part.
When privilege change, just notify the changed users and update data for them, instead of all the users.

What changed and how does it work?

The code changes including:

  • notify privilege update will encoding the changed user list into the etcd message
  • the domain privilege loop will decode the user list and update only the active users among them
  • fix bug on the privilege handle merge operation, the old "append diff + sort + dedup" can not handle the reovke privilege operation
  • the roles of a user is also consider as the privilege data and ensureActiveUse() need to load them
  • ensureActiveUser() should load the privilege data of the user, the roles of the data, plus the data of roles recursively
  • ensureActiveUser() is called more widely now to make the CI pass (we'd better optimize here later)

Check List

Tests

  • Unit test

  • Integration test

  • Manual test (add detailed scripts or steps below)

  • No need to test

    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added 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. labels Oct 31, 2024
Copy link

tiprow bot commented Oct 31, 2024

Hi @tiancaiamao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes-sigs/prow repository.

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 82.82443% with 45 lines in your changes missing coverage. Please review.

Project coverage is 74.9233%. Comparing base (56e7093) to head (db9a92d).
Report is 56 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57042        +/-   ##
================================================
+ Coverage   72.9672%   74.9233%   +1.9561%     
================================================
  Files          1662       1717        +55     
  Lines        458718     479730     +21012     
================================================
+ Hits         334714     359430     +24716     
+ Misses       103425      98000      -5425     
- Partials      20579      22300      +1721     
Flag Coverage Δ
integration 49.1373% <74.8091%> (?)
unit 72.2557% <81.2977%> (-0.0546%) ⬇️

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

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 60.3631% <0.0000%> (+15.3172%) ⬆️

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 4, 2024
Copy link

ti-chi-bot bot commented Nov 5, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign bornchanger, d3hunter for approval, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@tiancaiamao
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Nov 5, 2024

@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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 kubernetes-sigs/prow repository.

@tiancaiamao
Copy link
Contributor Author

/test check-dev2

Copy link

tiprow bot commented Nov 7, 2024

@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test check-dev2

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 kubernetes-sigs/prow repository.

@tiancaiamao
Copy link
Contributor Author

/test pull-br-integration-test

Copy link

tiprow bot commented Nov 8, 2024

@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test pull-br-integration-test

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 kubernetes-sigs/prow repository.

pkg/domain/domain.go Outdated Show resolved Hide resolved
pkg/domain/domain.go Outdated Show resolved Hide resolved
pkg/executor/simple.go Show resolved Hide resolved
@tiancaiamao
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Nov 11, 2024

@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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 kubernetes-sigs/prow repository.

pkg/domain/domain.go Outdated Show resolved Hide resolved
pkg/domain/domain.go Outdated Show resolved Hide resolved
pkg/domain/domain.go Show resolved Hide resolved
pkg/domain/domain.go Outdated Show resolved Hide resolved
@tiancaiamao
Copy link
Contributor Author

/test unit-test

Copy link

tiprow bot commented Nov 18, 2024

@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test unit-test

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 kubernetes-sigs/prow repository.

@@ -200,7 +200,7 @@ func (rc *SnapClient) afterSystemTablesReplaced(ctx context.Context, db string,
var err error
for _, table := range tables {
if table == "user" {
if serr := rc.dom.NotifyUpdatePrivilege(); serr != nil {
if serr := rc.dom.NotifyUpdatePrivilege(nil); serr != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does NotifyUpdatePrivilege actually do when input an empty user list?

ok := true
select {
case <-do.exit:
return
case _, ok = <-watchCh:
case resp, ok = <-watchCh:
if ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Though it is not introduced in this PR, do we need to handle the ok == false here? If the watchCh closed unexpectedly for some reason, this loop would run frequent.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just like this issue #49273

func (h *Handle) Update() error {
var priv MySQLPrivilege
err := priv.LoadAll(h.sctx)
func (h *Handle) Update(userList []string) error {
Copy link
Contributor

@D3Hunter D3Hunter Nov 19, 2024

Choose a reason for hiding this comment

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

please split into UpdateAll and Update, a nil userList []string is not a clear parameter to mean we want to update all, it's more common to mean we want to update nothing

Comment on lines +2773 to +2792
func encodeUserList(userList []string) string {
// use base64 encoding for the user and use ',' to separate them.
// Because the user name itself may contains special char like ','
encoded := make([]string, 0, len(userList))
for _, user := range userList {
encoded = append(encoded, base64.StdEncoding.EncodeToString([]byte(user)))
}
return strings.Join(encoded, ",")
}

func decodeUserList(userList []string, val string) []string {
users := strings.Split(val, ",")
for _, userRaw := range users {
user, err := base64.StdEncoding.DecodeString(userRaw)
if err == nil {
userList = append(userList, string(user))
}
}
return userList
}
Copy link
Contributor

Choose a reason for hiding this comment

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

please use a json as the value of the etcd key, easy to en/decode and extend

also what's the size of the list, etcd is not fit to store large data, max 1.5m by default

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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants