Skip to content

dxf, importinto: compare subtask task IDs as strings#69884

Merged
ti-chi-bot[bot] merged 6 commits into
pingcap:masterfrom
D3Hunter:codex/fix-subtask-task-key-comparison
Jul 17, 2026
Merged

dxf, importinto: compare subtask task IDs as strings#69884
ti-chi-bot[bot] merged 6 commits into
pingcap:masterfrom
D3Hunter:codex/fix-subtask-task-key-comparison

Conversation

@D3Hunter

@D3Hunter D3Hunter commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #61702, ref #69788

Problem Summary:

Subtask task_key columns store decimal task IDs as strings, but several callers bind integer values. TiDB can coerce these comparisons to DOUBLE, so adjacent IDs above 2^53 may compare equal and equality predicates cannot use the task_key index as intended.
passing string also make sure the table index is used for querying

What changed and how does it work?

  • Add a shared canonical task-ID-to-key conversion and use it for DXF and Import Into subtask predicates.
  • Update test and test utility queries to compare string keys without numeric coercion.
  • Add regression coverage for adjacent task IDs above 2^53.

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.

Test commands:

./tools/check/failpoint-go-test.sh pkg/dxf/framework/storage -run '^TestGetActiveSubtasks$' -count=1
./tools/check/failpoint-go-test.sh pkg/dxf/importinto/jobhistory -run '^TestGetFromHistory$' -count=1
./tools/check/failpoint-go-test.sh pkg/dxf/importinto -run '^TestGetJobLastUpdateTime$' -count=1
./tools/check/failpoint-go-test.sh tests/realtikvtest/addindextest1 -run '^TestAddIndexScheduleAway$' -count=1 -args -tikv-path 'tikv://127.0.0.1:12379?disableGC=true'
./tools/check/failpoint-go-test.sh tests/realtikvtest/addindextest3 -run '^TestMergeTempIndexBasic$' -count=1 -args -tikv-path 'tikv://127.0.0.1:12379?disableGC=true'
./tools/check/failpoint-go-test.sh tests/realtikvtest/importintotest4 -run '^TestImportInto/TestGlobalSortSummary$' -count=1 -args -tikv-path 'tikv://127.0.0.1:12379?disableGC=true'
make lint

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 incorrect DXF subtask matching when task IDs exceed the exact integer range of floating-point comparisons.

Summary by CodeRabbit

  • Bug Fixes
    • Improved distributed task and subtask lookups by consistently handling task identifiers stored as text.
    • Fixed history and active-subtask queries for large, adjacent task IDs, preventing results from being mixed between tasks.
    • Improved accuracy when retrieving job history and last-update times across active and historical subtasks.
    • Strengthened recovery, cancellation, pausing, resuming, and task modification operations.

@ti-chi-bot

ti-chi-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This change standardizes DXF task ID parameters as decimal string keys for subtask storage queries and updates related tests. IMPORT INTO active/history lookups gain regression coverage for adjacent large task IDs near 2^53.

Changes

Task-key normalization

Layer / File(s) Summary
Canonical storage key propagation
pkg/dxf/framework/storage/...
Adds TaskIDToKey and applies it across subtask reads, writes, state transitions, and history transfers.
Storage and integration validation
pkg/dxf/framework/storage/table_test.go, pkg/dxf/framework/testutil/table_util.go, pkg/dxf/framework/integrationtests/..., tests/realtikvtest/...
Updates SQL assertions and helpers to use quoted task keys and adds adjacent-large-ID filtering coverage.
IMPORT INTO lookup corrections
pkg/dxf/importinto/..., .agents/skills/...
Uses canonical keys for job timestamp and history queries, adds active/history regression tests, updates the test shard count, and documents coverage.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • pingcap/tidb#69442: Both changes align task-key filtering with the string representation stored in background subtask tables.

Suggested labels: component/import

Suggested reviewers: wjhuang2016, gmhdbjd, joechenrh

Poem

I’m a rabbit with keys in a row,
String-shaped task IDs now flow.
Through history and active lanes,
Large neighbors no longer cause pains.
Hop, hop—tests keep the paths bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly states the main change: comparing DXF and Import Into subtask task IDs as strings.
Description check ✅ Passed The description covers the required sections, includes issue refs, test commands, and a release note.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 16, 2026
@D3Hunter
D3Hunter marked this pull request as ready for review July 16, 2026 09:48
@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 Jul 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/dxf/importinto/job.go (1)

404-407: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Prefer UNION ALL to avoid deduplication overhead.

Since the outer query calculates the MAX() of all returned timestamps, the implicit deduplication step of UNION is unnecessary. Using UNION ALL skips the deduplication overhead and provides slightly better execution performance.

♻️ Proposed refactor
-				(select state_update_time from mysql.tidb_background_subtask where task_key = %?
-					union
-				select state_update_time from mysql.tidb_background_subtask_history where task_key = %?
+				(select state_update_time from mysql.tidb_background_subtask where task_key = %?
+					union all
+				select state_update_time from mysql.tidb_background_subtask_history where task_key = %?
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/dxf/importinto/job.go` around lines 404 - 407, Update the SQL query in
the task timestamp lookup to use UNION ALL instead of UNION, preserving the
existing subqueries and outer MAX() behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/dxf/importinto/job.go`:
- Around line 404-407: Update the SQL query in the task timestamp lookup to use
UNION ALL instead of UNION, preserving the existing subqueries and outer MAX()
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2bef91a2-639b-4d1b-b159-bdb1a89b8559

📥 Commits

Reviewing files that changed from the base of the PR and between 531e40c and f98b4f8.

📒 Files selected for processing (18)
  • .agents/skills/tidb-test-guidelines/references/dxf-case-map.md
  • pkg/dxf/framework/integrationtests/framework_err_handling_test.go
  • pkg/dxf/framework/integrationtests/modify_test.go
  • pkg/dxf/framework/storage/converter.go
  • pkg/dxf/framework/storage/history.go
  • pkg/dxf/framework/storage/subtask_state.go
  • pkg/dxf/framework/storage/table_test.go
  • pkg/dxf/framework/storage/task_state.go
  • pkg/dxf/framework/storage/task_table.go
  • pkg/dxf/framework/testutil/table_util.go
  • pkg/dxf/importinto/BUILD.bazel
  • pkg/dxf/importinto/job.go
  • pkg/dxf/importinto/job_testkit_test.go
  • pkg/dxf/importinto/jobhistory/history.go
  • pkg/dxf/importinto/jobhistory/history_test.go
  • tests/realtikvtest/addindextest1/disttask_test.go
  • tests/realtikvtest/addindextest3/temp_index_test.go
  • tests/realtikvtest/importintotest4/import_summary_test.go

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 16, 2026
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.9361%. Comparing base (531e40c) to head (f98b4f8).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69884        +/-   ##
================================================
- Coverage   76.3207%   73.9361%   -2.3846%     
================================================
  Files          2041       2058        +17     
  Lines        559975     580556     +20581     
================================================
+ Hits         427377     429241      +1864     
- Misses       131697     150745     +19048     
+ Partials        901        570       -331     
Flag Coverage Δ
integration 40.9617% <0.0000%> (+1.2564%) ⬆️

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

Components Coverage Δ
dumpling 60.4471% <ø> (ø)
parser ∅ <ø> (∅)
br 47.4060% <ø> (-15.3154%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joechenrh, wjhuang2016

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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 17, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-16 10:13:15.742484481 +0000 UTC m=+881381.778579547: ☑️ agreed by joechenrh.
  • 2026-07-17 08:01:07.309384408 +0000 UTC m=+959853.345479483: ☑️ agreed by wjhuang2016.

@D3Hunter

Copy link
Copy Markdown
Contributor Author

/retest

@ti-chi-bot
ti-chi-bot Bot merged commit 66be7a6 into pingcap:master Jul 17, 2026
34 checks passed
@D3Hunter
D3Hunter deleted the codex/fix-subtask-task-key-comparison branch July 17, 2026 09:43
@D3Hunter

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-nextgen-202603

@ti-chi-bot

Copy link
Copy Markdown
Member

@D3Hunter: new pull request created to branch release-nextgen-202603: #69912.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-nextgen-202603

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants