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

*: Truncate partition with global index improvement #55831

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

Conversation

mjonss
Copy link
Contributor

@mjonss mjonss commented Sep 3, 2024

What problem does this PR solve?

Issue Number: close #55819

Problem Summary:
During TRUNCATE PARTITION writes was blocked to partitions that was being truncated, also during StateDeleteReorganization, meaning the DDL would block writes to all truncated partitions for the full duration of the DDL, in case of a Global Index.

What changed and how does it work?

Instead of simply blocking writes to partitions being truncated, we are hiding the new partitions from Global Indexes StateWriteOnly and old partitions from StateDeleteOnly so that they cannot be seen, and not cause any anomaly, where you can find data or not depending on access method, i.e. it may be found if using Global Index, but not for table scan.

A side effect of this is that we are still blocking duplicate keys, if a write to a global unique index from a StateDeleteOnly client that collides with a not-yet cleaned up Global Index entry, or a write to a global unique index from StateWriteOnly (old partition, to be truncated) collides with a newly written entry in StateDeleteOnly (using the new emptied partition).

To not generate these kind of duplicate errors for too long period, duplicate key errors are not generated during StateDeleteReorganization if the duplicate comes from an old truncated partition, instead that global unique index entry is overwritten.

Also refactored/deduplicated code for cleaning up the global index entries from dropped/truncated partitions, so both DROP and TRUNCATE PARTITION uses the same code.

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.

Removed write blocking partitions involved in TRUNCATE PARTITIONs if they had a Global Index.

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/invalid-title size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 3, 2024
Copy link

tiprow bot commented Sep 3, 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.

@mjonss mjonss changed the title Truncate partition global index *: Truncate partition with global index improvement Sep 3, 2024
Copy link

codecov bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 72.22222% with 65 lines in your changes missing coverage. Please review.

Project coverage is 57.0900%. Comparing base (5da9d1a) to head (ace2802).
Report is 1 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #55831         +/-   ##
=================================================
- Coverage   73.2077%   57.0900%   -16.1177%     
=================================================
  Files          1652       1803        +151     
  Lines        456113     642928     +186815     
=================================================
+ Hits         333910     367048      +33138     
- Misses       101690     250698     +149008     
- Partials      20513      25182       +4669     
Flag Coverage Δ
integration 39.3748% <47.8632%> (?)
unit 72.5438% <72.2222%> (+0.0567%) ⬆️

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

Components Coverage Δ
dumpling 52.9478% <ø> (ø)
parser ∅ <ø> (∅)
br 63.1851% <ø> (+17.1972%) ⬆️

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 25, 2024
@mjonss
Copy link
Contributor Author

mjonss commented Oct 28, 2024

/retest

Copy link

tiprow bot commented Oct 28, 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.

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 30, 2024
@mjonss mjonss removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 30, 2024
@mjonss
Copy link
Contributor Author

mjonss commented Oct 30, 2024

/retest

Copy link

tiprow bot commented Oct 30, 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.

@fixdb fixdb requested a review from winoros October 30, 2024 22:05
@purelind
Copy link
Contributor

purelind commented Nov 1, 2024

/retest

Copy link

tiprow bot commented Nov 1, 2024

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

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

for planner part

Copy link

ti-chi-bot bot commented Nov 1, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: winoros
Once this PR has been reviewed and has the lgtm label, please assign benjamin2037 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

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 1, 2024
Copy link

ti-chi-bot bot commented Nov 1, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-01 16:13:06.31262172 +0000 UTC m=+625499.151777263: ☑️ agreed by winoros.

@@ -551,6 +583,32 @@ func FetchDuplicatedHandle(ctx context.Context, key kv.Key, distinct bool,
return true, nil, nil
}

// GetPartitionHandleFromVal creates a PartitionHandle from a global index value
func GetPartitionHandleFromVal(val []byte) (*kv.PartitionHandle, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just use DecodeHandleInIndexValue function?

@@ -2277,7 +2248,7 @@ func (w *worker) onDropTablePartition(jobCtx *jobContext, job *model.Job) (ver i
// Since the previous state do not use the dropping partitions,
// we can now actually remove them, allowing to write into the overlapping range
// of the higher range partition or LIST default partition.
physicalTableIDs = updateDroppingPartitionInfo(tblInfo, partNames)
_ = updateDroppingPartitionInfo(tblInfo, partNames)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ = updateDroppingPartitionInfo(tblInfo, partNames)
updateDroppingPartitionInfo(tblInfo, partNames)

@@ -2266,7 +2237,7 @@ func (w *worker) onDropTablePartition(jobCtx *jobContext, job *model.Job) (ver i
// Reason, see https://github.com/pingcap/tidb/issues/55888
// Only mark the partitions as to be dropped, so they are not used, but not yet removed.
originalDefs := tblInfo.Partition.Definitions
physicalTableIDs = updateDroppingPartitionInfo(tblInfo, partNames)
_ = updateDroppingPartitionInfo(tblInfo, partNames)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ = updateDroppingPartitionInfo(tblInfo, partNames)
updateDroppingPartitionInfo(tblInfo, partNames)

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. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner 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.

Truncate partition with global index blocks inserts also during delete reorganization state
4 participants