Skip to content

Conversation

@D3Hunter
Copy link
Contributor

@D3Hunter D3Hunter commented May 9, 2025

What problem does this PR solve?

Issue Number: close #xxx

Problem Summary:

What changed and how does it work?

  • collect and resolve conflicts in parallel, use subtask concurrency
  • get/commit KVs in batch
  • avoid get KV if it's already collected
  • avoid map query if the savedHandle map is empty
  • abstract collector and deleter out
  • delete KVs in a separate group of routines to pipeline get and delete
  • read conflict KV files in parallel, currently we use 2 routines
  • fix a bug that we might recreate one file for each conflicted row after the overall row size reach MaxConflictRowFileSize

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

schema

create table test.t(
    pk bigint primary key,
    a bigint,
    b bigint,
    c bigint,
    d bigint,
    e bigint,
    pad varchar(1024),
    unique(a),
    unique(b),
    unique(c),
    unique(d),
    index(e)
);

ENV

1 * PD 1 * TiDB 3 * TiKV
8c16g 16c32g 8c32g

for a case with 500000 conflicted rows, all rows are conflicted due to UK. after this PR, conflict resolution speed is about 18518 rows/seconds, ~70 times faster.

+----------------------+----------+----------+
| step                 |  before  |  after   |
+----------------------+----------+----------+
| 0. total             | 00:35:58 | 00:00:53 |
| 1. encode            | 00:00:16 | 00:00:16 |
| 3. ingest            | 00:00:06 | 00:00:06 |
| 4. collect-conflicts | 00:07:45 | 00:00:04 |
| 5. resolve-conflicts | 00:27:46 | 00:00:23 |
| 6. post-process      | 00:00:00 | 00:00:00 |
+----------------------+----------+----------+

for a case with 15000000 conflicted rows, all rows are conflicted due to UK. after this PR, conflict resolution speed is about 20270 rows/seconds.

+----------------------+----------+
| step                 | duration |
+----------------------+----------+
| 0. total             | 00:14:55 |
| 1. encode            | 00:00:40 |
| 3. ingest            | 00:01:46 |
| 4. collect-conflicts | 00:02:27 |
| 5. resolve-conflicts | 00:09:53 |
| 6. post-process      | 00:00:01 |
+----------------------+----------+
  • 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 do-not-merge/invalid-title do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 9, 2025
@tiprow
Copy link

tiprow bot commented May 9, 2025

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

Details

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.

@codecov
Copy link

codecov bot commented May 9, 2025

Codecov Report

Attention: Patch coverage is 7.28929% with 407 lines in your changes missing coverage. Please review.

Please upload report for BASE (feature/release-8.1-gsort-test@60e993c). Learn more about missing BASE report.

Additional details and impacted files
@@                         Coverage Diff                         @@
##             feature/release-8.1-gsort-test     #61059   +/-   ##
===================================================================
  Coverage                                  ?   71.0574%           
===================================================================
  Files                                     ?       1473           
  Lines                                     ?     425816           
  Branches                                  ?          0           
===================================================================
  Hits                                      ?     302574           
  Misses                                    ?     102648           
  Partials                                  ?      20594           
Flag Coverage Δ
unit 71.0574% <7.2892%> (?)

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

Components Coverage Δ
dumpling 52.9656% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 41.6258% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@D3Hunter D3Hunter changed the title [WIP]Parallel resolve conflicts [WIP]Parallel resolve conflicts | tidb-test=release-8.1.2 May 14, 2025
@D3Hunter D3Hunter changed the title [WIP]Parallel resolve conflicts | tidb-test=release-8.1.2 importinto: optimize conflicts resolution | tidb-test=release-8.1.2 May 15, 2025
@ti-chi-bot ti-chi-bot bot removed do-not-merge/invalid-title do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels May 15, 2025
@D3Hunter
Copy link
Contributor Author

/retest

@tiprow
Copy link

tiprow bot commented May 16, 2025

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

Details

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
Contributor

@joechenrh joechenrh left a comment

Choose a reason for hiding this comment

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

Rest LGTM

c.logger.Info("too many conflict rows from index, skip checking",
zap.String("handleSize", units.BytesSize(float64(c.savedHandleSize.Load()))))
c.skipSaveHandle = true
c.savedHandles = make(map[string]bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not clear the saved handle here and let it merged into e.result? Since we can ensure that the total map size won't exceed the limit.

@ti-chi-bot
Copy link

ti-chi-bot bot commented May 16, 2025

@joechenrh: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Rest LGTM

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
Collaborator

@Benjamin2037 Benjamin2037 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 needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels May 16, 2025
@D3Hunter
Copy link
Contributor Author

/hold

will fix the comment later

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 16, 2025
@ti-chi-bot ti-chi-bot bot added the lgtm label May 16, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented May 16, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Benjamin2037, GMHDBJD, joechenrh

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

The pull request process is described here

Details 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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 16, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented May 16, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-05-16 07:44:10.114354657 +0000 UTC m=+98616.370252054: ☑️ agreed by Benjamin2037.
  • 2025-05-16 09:45:41.695622181 +0000 UTC m=+105907.951519579: ☑️ agreed by GMHDBJD.

@D3Hunter
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 16, 2025
@D3Hunter
Copy link
Contributor Author

/retest

@tiprow
Copy link

tiprow bot commented May 16, 2025

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

Details

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 merged commit 8010c96 into pingcap:feature/release-8.1-gsort-test May 16, 2025
18 checks passed
@D3Hunter D3Hunter deleted the parallel-resolve-conflicts branch May 16, 2025 11:06
D3Hunter added a commit to D3Hunter/tidb that referenced this pull request Nov 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. 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.

4 participants