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

placement: return rules after clone #3892

Merged
merged 6 commits into from
Jul 27, 2021
Merged

Conversation

disksing
Copy link
Contributor

Signed-off-by: disksing i@disksing.com

What problem does this PR solve?

Fix #3886

What is changed and how it works?

Clone the rule before returning to callers. It should be safe to modify and update again.

Check List

Tests

  • Unit test
  • Integration test

Related changes

  • Need to cherry-pick to the release branch

Release note

Fix an issue where data is not stored when using max-replicas or location-labels to indirectly update default placement rule

@disksing disksing added type/bugfix This PR fixes a bug. needs-cherry-pick-release-5.0 The PR needs to cherry pick to release-5.0 branch. needs-cherry-pick-release-5.1 Type: Need cherry pick to release-5.1 labels Jul 20, 2021
@disksing disksing requested a review from HunDunDM July 20, 2021 07:41
@ti-chi-bot ti-chi-bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jul 20, 2021
@disksing disksing marked this pull request as draft July 22, 2021 07:58
@ti-chi-bot ti-chi-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 22, 2021
Signed-off-by: disksing <i@disksing.com>
@codecov
Copy link

codecov bot commented Jul 22, 2021

Codecov Report

Merging #3892 (a20fac3) into master (a2ea41c) will decrease coverage by 0.06%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3892      +/-   ##
==========================================
- Coverage   74.47%   74.40%   -0.07%     
==========================================
  Files         246      246              
  Lines       24854    24868      +14     
==========================================
- Hits        18509    18504       -5     
- Misses       4685     4693       +8     
- Partials     1660     1671      +11     
Flag Coverage Δ
unittests 74.40% <85.71%> (-0.07%) ⬇️

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

Impacted Files Coverage Δ
server/server.go 71.27% <50.00%> (-0.35%) ⬇️
pkg/typeutil/comparison.go 85.71% <60.00%> (-14.29%) ⬇️
server/schedule/placement/rule.go 96.15% <100.00%> (+0.40%) ⬆️
server/schedule/placement/rule_manager.go 83.13% <100.00%> (+0.25%) ⬆️
server/region_syncer/server.go 83.33% <0.00%> (-6.07%) ⬇️
server/tso/tso.go 57.45% <0.00%> (-4.98%) ⬇️
pkg/etcdutil/etcdutil.go 84.70% <0.00%> (-3.53%) ⬇️
server/schedulers/random_merge.go 60.00% <0.00%> (-3.34%) ⬇️
pkg/dashboard/adapter/manager.go 79.78% <0.00%> (-3.20%) ⬇️
server/kv/etcd_kv.go 69.56% <0.00%> (-2.90%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2ea41c...a20fac3. Read the comment docs.

@disksing disksing marked this pull request as ready for review July 22, 2021 08:36
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 22, 2021
@disksing
Copy link
Contributor Author

Please take a look. @HunDunDM @bufferflies

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 the status/LGT1 Indicates that a PR has LGTM 1. label Jul 22, 2021
Copy link
Member

@HunDunDM HunDunDM left a comment

Choose a reason for hiding this comment

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

Does Copy-on-Write perform better?

server/server.go Outdated
@@ -1378,3 +1376,15 @@ func (s *Server) SaveTTLConfig(data map[string]interface{}, ttl time.Duration) e
}
return nil
}

func stringsEqual(a, b []string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Judge the situation where len is all 0, then we can still use reflect.DeepEqual directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then it will be if len(a) == 0 && len(b) == 0 || reflect.DeepEqual(a, ), looks not very elegant I think.

server/server.go Outdated Show resolved Hide resolved
@disksing
Copy link
Contributor Author

disksing commented Jul 23, 2021

Does Copy-on-Write perform better?

copy-on-write should be better. The problem is that Go does not have const, it is easy to miss use. I think for the methods that are mainly used by HTTP API, it is acceptable to clone every rule.

@bufferflies
Copy link
Contributor

lgtm

Signed-off-by: disksing <i@disksing.com>
@nolouch
Copy link
Contributor

nolouch commented Jul 27, 2021

PTAL @HunDunDM @bufferflies

@bufferflies
Copy link
Contributor

lgtm

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • bufferflies
  • 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 status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 27, 2021
@nolouch
Copy link
Contributor

nolouch commented Jul 27, 2021

/merge

@ti-chi-bot
Copy link
Member

@nolouch: 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: 82c6b74

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 27, 2021
@ti-chi-bot ti-chi-bot merged commit 9e15727 into tikv:master Jul 27, 2021
ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Jul 27, 2021
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #3914.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #3915.

HunDunDM pushed a commit to HunDunDM/pd that referenced this pull request Jul 28, 2021
* placement: return rules after clone

Signed-off-by: disksing <i@disksing.com>

* fix test

Signed-off-by: disksing <i@disksing.com>

* move stringsEqual to typeutils

Signed-off-by: disksing <i@disksing.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
ti-chi-bot added a commit that referenced this pull request Aug 16, 2021
* This is an automated cherry-pick of #3892

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>

* resolve conflicts

Signed-off-by: disksing <i@disksing.com>

Co-authored-by: disksing <i@disksing.com>
@disksing disksing deleted the issue-3886 branch August 18, 2021 03:11
ti-chi-bot added a commit that referenced this pull request Sep 13, 2021
* placement: return rules after clone

Signed-off-by: disksing <i@disksing.com>

* fix test

Signed-off-by: disksing <i@disksing.com>

* move stringsEqual to typeutils

Signed-off-by: disksing <i@disksing.com>

Co-authored-by: disksing <i@disksing.com>
Co-authored-by: 混沌DM <hundundm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.0 The PR needs to cherry pick to release-5.0 branch. needs-cherry-pick-release-5.1 Type: Need cherry pick to release-5.1 release-note Denotes a PR that will be considered when it comes time to generate release notes. status/can-merge Indicates a PR has been approved by a committer. 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.

The replica count of default placement rule stays constant after replication.max-replicas is updated
5 participants