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

*: Reorg partition fix delete ranges and handling non-clustered tables with concurrent DML (#57114) #58124

Merged

Conversation

ti-chi-bot
Copy link
Member

@ti-chi-bot ti-chi-bot commented Dec 10, 2024

This is an automated cherry-pick of #57114

What problem does this PR solve?

Issue Number: close #56822 ref #45133 close #57510

based on #56974.

Problem Summary:
First the DeleteRange did not include the old replaced Global Indexes,
Then I found an issue with non-clustered tables and reorganize partition,
where double written records during StateWriteOnly/StateWriteReorganization would get Duplicate key errors, due to they would generate new _tidb_rowid in the new partition, making it impossible to detect if an index entry came from Backfilling or if it is new, when recreating the indexes.

What changed and how does it work?

Fixed the DeleteRange, by adding a list of TableID+IndexID ranges that should also be cleaned by DeleteRanges.

Instead of first copy all records and then recreate the indexes, I now use AddRecord table interface, and created both the table record as well as all the index entries for that row. Note that AddRecord will also generate a new _tidb_rowid, so that part of the reorg code is removed as well.

Drawbacks are:

  • I'm not sure if we can workaround an index lookup for each unique index entry needed to be written (i.e. if we can batch them instead of do one lookup at a time, or rely on optimistic commit).
  • Big change and little time to test it further, including performance difference (correctness is more important though).

Benefits are:

  • Simpler code, just check if the record was written with the original handle (_tidb_rowid) and skip if so, otherwise use AddRecord.
  • Skipping reading the partitions twice, once for the 'table' records and once for generating the indexes.

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.

Fix for REORGANIZE PARTITION on non-clustered tables, which could lead to duplicated rows for concurrently inserted ones.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added ok-to-test Indicates a PR is ready to be tested. 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. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR. labels Dec 10, 2024
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 12, 2024
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 suggestion.

Files not reviewed (1)
  • pkg/ddl/tests/partition/BUILD.bazel: Language not supported
Comments skipped due to low confidence (1)

pkg/table/tables/partition.go:1632

  • [nitpick] The variable name 'recordID' is ambiguous in this context. It should be renamed to 'partitionRecordID' to avoid confusion.
tbl = t.GetPartition(pid)

pkg/ddl/ddl.go Outdated Show resolved Hide resolved
@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 Dec 12, 2024
Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 77.50000% with 18 lines in your changes missing coverage. Please review.

Please upload report for BASE (release-7.5@b298e21). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-7.5     #58124   +/-   ##
================================================
  Coverage               ?   72.1470%           
================================================
  Files                  ?       1416           
  Lines                  ?     413292           
  Branches               ?          0           
================================================
  Hits                   ?     298178           
  Misses                 ?      95110           
  Partials               ?      20004           
Flag Coverage Δ
unit 72.1470% <77.5000%> (?)

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

Components Coverage Δ
dumpling 52.9400% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 53.5264% <0.0000%> (?)

@mjonss
Copy link
Contributor

mjonss commented Dec 12, 2024

/retest

@mjonss mjonss self-requested a review December 12, 2024 23:04
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 12, 2024
Comment on lines -3210 to -3217
if prr.warning != nil {
if _, ok := warningsCountMap[prr.warning.ID()]; ok {
warningsCountMap[prr.warning.ID()]++
} else {
warningsCountMap[prr.warning.ID()] = 1
warningsMap[prr.warning.ID()] = prr.warning
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

warnings were never set, and cannot happen, since we are copying data without any conversions.

@mjonss mjonss requested a review from tangenta December 13, 2024 01:23
Copy link
Member

@bb7133 bb7133 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 bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 13, 2024
Copy link

ti-chi-bot bot commented Dec 13, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-12-12 23:04:16.142670556 +0000 UTC m=+566046.231473098: ☑️ agreed by mjonss.
  • 2024-12-13 02:22:18.213465267 +0000 UTC m=+577928.302267810: ☑️ agreed by bb7133.

Copy link

ti-chi-bot bot commented Dec 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, mjonss, tangenta

The full list of commands accepted by this bot can be found here.

The pull request process is described 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 approved label Dec 13, 2024
@bb7133
Copy link
Member

bb7133 commented Dec 13, 2024

/retest

@ti-chi-bot ti-chi-bot bot merged commit 3157fc3 into pingcap:release-7.5 Dec 13, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants