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

ddl: Fixed partitioning a non-partitioned table with placement rules #57560

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

Conversation

mjonss
Copy link
Contributor

@mjonss mjonss commented Nov 20, 2024

What problem does this PR solve?

Issue Number: close #55705

Problem Summary:
When updating the placement rule bundle, the table ID was included both as the table and the partition id.

What changed and how does it work?

Not adding it as partition id for non-partitioned table (which uses the original table as a single partition, hence the same ID).

Also simplified the bundle handling during schema update / ApplyDiff, by removing logic that:

  • first went through all partitions and marked the partition to update the bundle, then went through all partition updates and updated its table

to

  • mark the table directly that it should update the bundle.

For REORGANIZE PARTITION, there the bundles will be updated twice, first with the intermediate set of partitions (both old and new), so that data copying and index creations on the new partitions will follow the correct policies directly, and then with the final partition set, avoiding having to move the data again when the DDL is done.

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.

fixed an issue with partitioning a non-partitioned table with placement rules.

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 20, 2024
Copy link

tiprow bot commented Nov 20, 2024

Hi @mjonss. 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.

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no suggestions.

end string
}
keys := make([]keyRange, 0, rules)
for k := range m.bundles {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we only need to check the rules inside one bundle just now. If GroupBundle.Override is set to true, it is allowed to have multiple leader rules.

And in one RuleGroup when a rule has Override==true, it should also be skipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the below is OK?

if rule.Role == pd.Leader && !m.bundles[k].Override {
				keys = append(keys, keyRange{start: k + ":" + rule.StartKeyHex, end: k + ":" + rule.EndKeyHex})
			}

Copy link
Collaborator

Choose a reason for hiding this comment

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

We still need to check the rules in one bundle even bundle[k].Override is true, but the current implementation skips all rules in such bundle?

Copy link
Contributor

Choose a reason for hiding this comment

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

We still need to check the rules in one bundle even bundle[k].Override is true

true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lcwangchao @xhebox please review the new duplicate leader range check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, why not only validating the input bundles one by one? I think the current version does not care the overlaps across different rules.

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 17 lines in your changes missing coverage. Please review.

Project coverage is 74.8011%. Comparing base (ad5ca42) to head (2f97ac7).
Report is 31 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57560        +/-   ##
================================================
+ Coverage   72.8329%   74.8011%   +1.9681%     
================================================
  Files          1676       1721        +45     
  Lines        463539     478136     +14597     
================================================
+ Hits         337609     357651     +20042     
+ Misses       105125      98140      -6985     
- Partials      20805      22345      +1540     
Flag Coverage Δ
integration 49.2534% <66.6666%> (?)
unit 72.2204% <83.3333%> (+0.0011%) ⬆️

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

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 60.9294% <ø> (+15.5728%) ⬆️
---- 🚨 Try these New Features:

pkg/ddl/partition.go Outdated Show resolved Hide resolved
pkg/ddl/placement_policy_test.go Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 20, 2024
Copy link

ti-chi-bot bot commented Nov 20, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-20 14:36:48.070107027 +0000 UTC m=+42395.689761543: ☑️ agreed by Defined2014.

@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 Nov 20, 2024
@mjonss mjonss added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 20, 2024
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 21, 2024
Copy link

ti-chi-bot bot commented Nov 21, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Defined2014
Once this PR has been reviewed and has the lgtm label, please assign gmhdbjd for approval. 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

Copy link

ti-chi-bot bot commented Nov 21, 2024

@Defined2014: Your lgtm message is repeated, so it is ignored.

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

// - not removing any placement rules for removed partitions
// - not leaving anything in case of failure/rollback!
// So we will:
// 1) First write the new bundles including both new and old partitions,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the new bundles should include old partitions? The old bundles have already defined these rules and still take effects 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.

Oh, so if the Bundle is overwritten, the older bundle rules will still be in effect?
Like if the first bundle had rules for table id 111, part id 112 and 113, and the new bundle would have table id 111, partition id 113 and 114, would part id 112 still be placed as the old bundle rules or would it be placed without any rules?

Copy link
Contributor

Choose a reason for hiding this comment

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

or would it be placed without any rules?

This, I believe.

// it will filter the rules depends on the interval index override in the same group or the
// group-index override between different groups
// For example, given rules:
// ruleA: group_id: 4, id: 2, override: true
// ruleB: group_id: 4, id: 1, override: true
// ruleC: group_id: 3
// ruleD: group_id: 2
// RuleGroupA: id:4, override: false
// RuleGroupB: id:3, override: true
// RuleGroupC: id:2, override: false
// Finally only ruleA and ruleC will be selected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A better example:

CREATE TABLE t (a int) partition by range (a) (partition p0 values less than (1000000), partition p1M values less than (2000000)) placement policy pp1;
ALTER TABLE t REORGANIZE PARTITION p1M INTO (PARTITION p1M values less than (2000000), partition p2M values less than (3000000));

During the DDL we would still want the original p1M to follow the table level rule, so we keep it in the bundle.
When the final bundles will be created it will not be included.
Since the table keeps its table id (for REORGANIZE PARTITION) there are no other bundles that covers the inherited table's placement rules for the original partition p1M, which means we need to cover it during the time of the DDL, since it can still be accessed (and double written).

Another alternative would be to create partition level bundles for the old replaced partitions, and let them be removed by GC later, but I think that would qualify for a separate PR.

@lcwangchao
Copy link
Collaborator

@xhebox PTAL

@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 21, 2024
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 22, 2024
pkg/ddl/partition.go Show resolved Hide resolved
pkg/ddl/partition.go Outdated Show resolved Hide resolved
pkg/ddl/partition.go Outdated Show resolved Hide resolved
@mjonss
Copy link
Contributor Author

mjonss commented Nov 22, 2024

/retest

Copy link

tiprow bot commented Nov 22, 2024

@mjonss: 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.

end string
}
keys := make([]keyRange, 0, rules)
for k := range m.bundles {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, why not only validating the input bundles one by one? I think the current version does not care the overlaps across different rules.

return keys[i].start < keys[j].start
})
for i := 1; i < len(keys); i++ {
if keys[i].start < keys[i-1].end && !keys[i].override {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we have two groups, should the below case also report an error if order by group id first?

// when i==1 `keys[i].start < keys[i-1].end`
[0] {group_id: 1, override: false, rules: [(start: 0xF0, end: 0xF2)]}
[1] {group_id: 2, override: false, rules: [(start: 0x01, end: 0x02)]}

Copy link
Collaborator

Choose a reason for hiding this comment

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

And for below case, I think it should still report an error but seems not

{
  group_id: 1,
  rules: [
    {override: false, start: 0x01, end: 0x0F},
    {override: true, start: 0x02, end: 0x03},
    {override: false, start: 0x04, end: 0x05}
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-1-more-lgtm Indicates a PR needs 1 more LGTM. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail to partition table after changing placement rule
4 participants