Skip to content

pkg/dxf/importinto: limit conflicted row recording files max 1G#67119

Merged
ti-chi-bot[bot] merged 8 commits into
pingcap:masterfrom
D3Hunter:feature/conflict-recording-file-cap-1g
Mar 19, 2026
Merged

pkg/dxf/importinto: limit conflicted row recording files max 1G#67119
ti-chi-bot[bot] merged 8 commits into
pingcap:masterfrom
D3Hunter:feature/conflict-recording-file-cap-1g

Conversation

@D3Hunter
Copy link
Copy Markdown
Contributor

@D3Hunter D3Hunter commented Mar 18, 2026

What problem does this PR solve?

Issue Number: ref #66019

Problem Summary:
During IMPORT INTO collect-conflicts, conflicted rows can be continuously recorded to object storage. This may produce very large conflicted-row files and high storage usage. This PR introduces a hardcoded total-size cap for conflicted-row recording so we can collect feedback first before deciding whether/how to expose user configuration. as 1GB is already quite large for human to process manually, and storing those files unbounded will add cost

What changed and how does it work?

  • Add a hardcoded 1GiB limit for total conflicted-row file size in one collect-conflicts subtask.
  • Enforce the limit across concurrent collectors by sharing one atomic total-size counter.
  • Use Add then check threshold intentionally; a small overflow (typically one row) above the threshold is acceptable to keep concurrent accounting simple.
  • When limit is exceeded, stop writing more conflicted-row file content and close writer, while still keeping conflict row count/checksum accounting.
  • Refactor HandleEncodedRow to centralize RowCount/Checksum updates and move write/limit details to an inner helper.
  • Add/adjust unit tests to verify:
    • single-collector total-size limit behavior,
    • multi-collector shared limit behavior,
    • onTotalSizeLimitExceeded path is exercised (via stopRecording/writer state assertions).
  • Regenerate Bazel metadata (BUILD.bazel) via make bazel_prepare.

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.

None

Summary by CodeRabbit

  • New Features

    • Metadata now includes a flag indicating when conflicted-row recording was truncated.
  • Improvements

    • Enforced a global total-size cap for conflicted-row recordings to limit storage usage.
    • Coordinated size tracking across concurrent collectors so truncation is applied consistently.
    • Recording stops cleanly when the global cap is reached and resources are cleaned up.
  • Testing

    • Expanded tests for total-size limits, truncation behavior, error handling, and multi-collector scenarios.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 18, 2026

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 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. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. labels Mar 18, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 18, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a global atomic counter and enforcement for a per-subtask total size cap on conflicted-row files; collectors atomically account written bytes, stop recording when the cap is exceeded, and the subtask metadata records whether recording was truncated.

Changes

Cohort / File(s) Summary
Executor & step state
pkg/dxf/importinto/collect_conflicts.go
Adds sizeOfConflictRowFiles atomic.Int64 on executor, reset per subtask, passed into collectors; subtask meta now records ConflictedRowRecordingCapped.
Collector implementation
pkg/dxf/importinto/conflictedkv/collector.go
NewCollector gains sharedTotalFileSize *atomic.Int64; introduces maxTotalConflictRowFileSize (1 GiB), global atomic accounting, recordRowToFile refactor, onTotalSizeLimitExceeded, stopRecording handling, and CollectResult.RowRecordingCapped flag.
Collector tests
pkg/dxf/importinto/conflictedkv/collector_test.go
Updated tests to pass shared atomic counter; added tests for global cap, shared-cap across collectors, writer Close error paths, and RowRecordingCapped assertions.
Step tests
pkg/dxf/importinto/collect_conflicts_test.go
Updated non-truncation assertion; added TestCollectConflictsStepExecutorFilesTruncated (uses failpoints to force truncation) and asserts ConflictedRowRecordingCapped.
Proto / metadata
pkg/dxf/importinto/proto.go
Adds ConflictedRowRecordingCapped bool (json:"conflicted-row-recording-capped,omitempty") to CollectConflictsStepMeta; clarifies comment for ConflictedRowFilenames as "recorded conflicted rows".
Build/test config
pkg/dxf/importinto/conflictedkv/BUILD.bazel, pkg/dxf/importinto/BUILD.bazel
Increased go_test shard counts (conflictedkv_test 6→8, importinto_test 27→28).

Sequence Diagram(s)

sequenceDiagram
    participant Executor
    participant Collector
    participant ObjStore
    participant SharedCounter as SharedTotalSize
    participant Meta as SubtaskMeta

    Executor->>Collector: NewCollector(..., &SharedTotalSize, ...)
    loop for each encoded row
      Collector->>Collector: recordRowToFile(encodedRow)
      Collector->>Collector: compute rowSize
      Collector->>SharedCounter: atomic.Add(rowSize) / load total
      alt total <= maxTotalConflictRowFileSize
        Collector->>ObjStore: write row to current file
        Collector->>Collector: update currFileSize, TotalFileSize, RowCount
      else
        Collector->>Collector: onTotalSizeLimitExceeded()
        Collector->>ObjStore: close/clear writer
        Collector->>Meta: set ConflictedRowRecordingCapped = true
      end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • hawkingrei
  • joechenrh

Poem

🐰
I counted files with nimble paws,
An atom kept the ledger's laws.
When totals swelled beyond the seam,
I paused the pen and stopped the stream.
Now records rest in tidy rows.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a 1GiB limit for conflicted row recording files in the importinto package.
Description check ✅ Passed The PR description is comprehensive and follows the template structure with all required sections properly filled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 18, 2026
@tiprow
Copy link
Copy Markdown

tiprow Bot commented Mar 18, 2026

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.

@hawkingrei
Copy link
Copy Markdown
Member

/ok-to-test

@ti-chi-bot ti-chi-bot Bot added the ok-to-test Indicates a PR is ready to be tested. label Mar 18, 2026
@D3Hunter D3Hunter removed the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Mar 18, 2026
@ti-chi-bot ti-chi-bot Bot added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Mar 18, 2026
@D3Hunter D3Hunter removed the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Mar 18, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 89.74359% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.5012%. Comparing base (0f00d92) to head (9d3f51e).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #67119        +/-   ##
================================================
- Coverage   77.7074%   77.5012%   -0.2063%     
================================================
  Files          2016       1936        -80     
  Lines        552163     543625      -8538     
================================================
- Hits         429072     421316      -7756     
- Misses       121349     122298       +949     
+ Partials       1742         11      -1731     
Flag Coverage Δ
integration 41.1038% <0.0000%> (-7.0208%) ⬇️
unit 76.7327% <89.7435%> (+0.4898%) ⬆️

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

Components Coverage Δ
dumpling 57.0098% <ø> (ø)
parser ∅ <ø> (∅)
br 47.5317% <ø> (-13.3463%) ⬇️
🚀 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 marked this pull request as ready for review March 18, 2026 10:51
@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 Mar 18, 2026
@pantheon-ai
Copy link
Copy Markdown

pantheon-ai Bot commented Mar 18, 2026

Review Complete

Findings: 1 issues
Posted: 1
Duplicates/Skipped: 0

ℹ️ Learn more details on Pantheon AI.

Comment thread pkg/dxf/importinto/conflictedkv/collector.go Outdated
@ingress-bot
Copy link
Copy Markdown

🔍 New commits detected — starting re-review...

@pingcap pingcap deleted a comment from ingress-bot Mar 18, 2026
@pingcap pingcap deleted a comment from ingress-bot Mar 18, 2026
Copy link
Copy Markdown

@ingress-bot ingress-bot left a comment

Choose a reason for hiding this comment

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

This review was generated by AI and should be verified by a human reviewer.
Manual follow-up is recommended before merge.

Summary

  • Total findings: 4
  • Inline comments: 3
  • Summary-only findings (no inline anchor): 1
Findings (highest risk first)

🟡 [Minor] (3)

  1. TestCollectResultMerge does not verify FilesTruncated OR-propagation (pkg/dxf/importinto/conflictedkv/collector_test.go:43-86 (TestCollectResultMerge / checkResultFn))
  2. handleEncodedRowInner uses a mechanical "Inner" suffix instead of describing behavior (pkg/dxf/importinto/conflictedkv/collector.go:172)
  3. Writer not nil'd on close failure in onTotalSizeLimitExceeded causes double-close (pkg/dxf/importinto/conflictedkv/collector.go:243-252 (onTotalSizeLimitExceeded writer-close block))

🧹 [Nit] (1)

  1. FilesTruncated could be read as "file contents were truncated" rather than "file recording was capped" (pkg/dxf/importinto/conflictedkv/collector.go:58, pkg/dxf/importinto/proto.go:163)

Unanchored findings

🧹 [Nit] (1)

  1. FilesTruncated could be read as "file contents were truncated" rather than "file recording was capped"
    • Scope: pkg/dxf/importinto/conflictedkv/collector.go:58, pkg/dxf/importinto/proto.go:163
    • Request: Consider renaming to RecordingTruncated or RowRecordingCapped to match the cause-oriented naming of TooManyConflictsFromIndex. If the current name is intentional for JSON-schema stability, add a brief inline note at the declaration explaining the naming choice.

Comment thread pkg/dxf/importinto/conflictedkv/collector.go Outdated
Comment thread pkg/dxf/importinto/conflictedkv/collector.go Outdated
Comment thread pkg/dxf/importinto/conflictedkv/collector.go
@D3Hunter
Copy link
Copy Markdown
Contributor Author

Addressed the unanchored naming nit.

  • CollectResult.FilesTruncated -> RowRecordingCapped
  • CollectConflictsStepMeta.ConflictedRowFilesTruncated -> ConflictedRowRecordingCapped

For compatibility with persisted subtask metadata, the struct field keeps the historical JSON key (conflicted-row-files-truncated) with an inline comment documenting the reason.

@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 Mar 19, 2026
@D3Hunter
Copy link
Copy Markdown
Contributor Author

/retest

Copy link
Copy Markdown
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

Comment on lines +118 to +120
if sharedTotalFileSize == nil {
sharedTotalFileSize = &atomic.Int64{}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this some defensive checking? Seems no caller pass nil pointer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, i let AI add a comment

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 19, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 19, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 19, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Mar 19, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-03-19 06:35:21.964100072 +0000 UTC m=+425249.051757599: ☑️ agreed by GMHDBJD.
  • 2026-03-19 07:17:45.456331775 +0000 UTC m=+427792.543989312: ☑️ agreed by joechenrh.

@D3Hunter D3Hunter changed the title pkg/dxf/importinto: hardcode 1GiB cap for conflicted row recording pkg/dxf/importinto: limit conflicted row recording files max 1G Mar 19, 2026
@D3Hunter
Copy link
Copy Markdown
Contributor Author

/retest

5 similar comments
@D3Hunter
Copy link
Copy Markdown
Contributor Author

/retest

@D3Hunter
Copy link
Copy Markdown
Contributor Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member

/retest

@D3Hunter
Copy link
Copy Markdown
Contributor Author

/retest

@hawkingrei
Copy link
Copy Markdown
Member

/retest

@ti-chi-bot ti-chi-bot Bot merged commit 8b2f0dc into pingcap:master Mar 19, 2026
35 checks passed
@D3Hunter D3Hunter deleted the feature/conflict-recording-file-cap-1g branch March 20, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants