Skip to content

importinto: log chunk count and size - #70271

Merged
ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
D3Hunter:codex/import-chunk-diagnostics
Aug 4, 2026
Merged

ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
D3Hunter:codex/import-chunk-diagnostics

Conversation

@D3Hunter

@D3Hunter D3Hunter commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #61702

Problem Summary:

Import Into encode subtasks do not currently expose how many chunks they need to process or the size of each chunk, making chunk-related failures harder to diagnose.

What changed and how does it work?

  • Log the number of chunks after the encode subtask metadata is fully loaded.
  • Add the chunk size, calculated as EndOffset - Offset, to the per-chunk logger.
  • Verify that the chunk processing log contains the expected chunk size.

Check List

Tests

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

parquet

[2026/08/03 10:38:30.868 +08:00] [INFO] [task_executor.go:285] ["start processing chunks"] [keyspaceName=SYSTEM] [task-id=1] [task-key=SYSTEM/ImportInto/1] [step=encode] [subtask-id=1] [chunkCount=1]
[2026/08/03 10:38:30.871 +08:00] [INFO] [chunk_process.go:403] ["process chunk start"] [keyspaceName=SYSTEM] [task-id=1] [task-key=SYSTEM/ImportInto/1] [step=encode] [subtask-id=1] [key=1col-1row.parquet:0] [chunkSize=254]
[2026/08/03 10:38:30.871 +08:00] [INFO] [chunk_process.go:407] ["process chunk completed"] [keyspaceName=SYSTEM] [task-id=1] [task-key=SYSTEM/ImportInto/1] [step=encode] [subtask-id=1] [key=1col-1row.parquet:0] [chunkSize=254] [readDur=65.583µs] [encodeDur=53.25µs] [checksum="{cksum=12129104817369816750,size=33,kvs=1}"] [deliverDur=59.375µs] [type=file] [takeTime=215.5µs] []

csv

[2026/08/03 10:40:01.161 +08:00] [INFO] [task_executor.go:285] ["start processing chunks"] [keyspaceName=SYSTEM] [task-id=2] [task-key=SYSTEM/ImportInto/2] [step=encode] [subtask-id=4] [chunkCount=1]
[2026/08/03 10:40:01.163 +08:00] [INFO] [chunk_process.go:403] ["process chunk start"] [keyspaceName=SYSTEM] [task-id=2] [task-key=SYSTEM/ImportInto/2] [step=encode] [subtask-id=4] [key=1.csv:0] [chunkSize=10]
[2026/08/03 10:40:01.164 +08:00] [INFO] [chunk_process.go:407] ["process chunk completed"] [keyspaceName=SYSTEM] [task-id=2] [task-key=SYSTEM/ImportInto/2] [step=encode] [subtask-id=4] [key=1.csv:0] [chunkSize=10] [readDur=39.79µs] [encodeDur=64.873µs] [checksum="{cksum=13668931463816667584,size=165,kvs=5}"] [deliverDur=87.375µs] [type=file] [takeTime=241.833µs] []
  • No need to test
    • I checked and no code files have been changed.

Targeted validation:

./tools/check/failpoint-go-test.sh pkg/dxf/importinto -run 'TestImportStepExecutorCleanupAllLocalEnginesOnRetry' -count=1
./tools/check/failpoint-go-test.sh pkg/executor/importer -run 'TestFileChunkProcess/process_success' -count=1
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.

None

Summary by CodeRabbit

  • Enhancements

    • Import processing logs now include the total number of chunks and each chunk’s source size.
    • Chunk sizes are reported consistently for Parquet and other source formats.
  • Tests

    • Added coverage verifying that chunk-processing logs record the source chunk size.

@ti-chi-bot

ti-chi-bot Bot commented Jul 31, 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-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02043723-357b-4eaa-a235-d33e46a58f36

📥 Commits

Reviewing files that changed from the base of the PR and between e9fcb79 and 992053c.

📒 Files selected for processing (2)
  • pkg/executor/importer/BUILD.bazel
  • pkg/executor/importer/table_import.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/executor/importer/BUILD.bazel
  • pkg/executor/importer/table_import.go

📝 Walkthrough

Walkthrough

The importer now reports subtask chunk counts and source chunk sizes in structured logs. Chunk.GetSize handles Parquet and non-Parquet chunks. Tests verify the chunk-size log.

Changes

Import observability

Layer / File(s) Summary
Chunk size logging
pkg/executor/importer/table_import.go, pkg/executor/importer/chunk_process.go, pkg/executor/importer/chunk_process_testkit_test.go, pkg/executor/importer/BUILD.bazel
Chunk.GetSize returns the source size. The chunk processor logs chunkSize. The test observes and verifies the emitted log.
Subtask count logging
pkg/dxf/importinto/task_executor.go
RunSubtask logs the subtask chunk count before processing.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: joechenrh

Poem

A rabbit logs each chunk in line,
Parquet sizes stay precise and fine.
Subtasks count before they start,
Tests watch each message play its part.
Hop, hop—imports leave a trace!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the added Import Into chunk count and size logging.
Description check ✅ Passed The description includes the issue reference, problem, implementation details, tests, validation steps, impact checklist, and release note.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="Running error: context loading failed: failed to load packages: failed to load packages: failed to load with go/packages: context deadline exceeded"
level=error msg="Timeout exceeded: try increasing it by passing --timeout option"


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.

@D3Hunter
D3Hunter marked this pull request as ready for review August 3, 2026 02:42
@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 Aug 3, 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 (2)
pkg/executor/importer/table_import.go (1)

122-129: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document both GetSize semantics.

GetSize returns EndOffset - Offset for non-Parquet chunks but FileSize for Parquet chunks. Update the exported comment to describe both branches so callers do not interpret chunkSize as a byte span for Parquet.

As per coding guidelines, exported-symbol comments should preserve semantic constraints.

Proposed comment
-// GetSize get the original file size of this chunk.
+// GetSize returns the source size represented by the chunk.
+// For Parquet chunks, Offset and EndOffset are row offsets, so FileSize is returned.
🤖 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/executor/importer/table_import.go` around lines 122 - 129, Update the
exported comment for Chunk.GetSize to document both semantics: non-Parquet
chunks return the byte span EndOffset minus Offset, while Parquet chunks return
FileSize because Offset and EndOffset represent rows.

Source: Coding guidelines

pkg/executor/importer/chunk_process_testkit_test.go (1)

147-160: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise offset subtraction in the test.

chunkInfo.Offset is zero, so len(sourceData) equals EndOffset. The test would pass if GetSize ignored Offset. Use a valid non-zero row-boundary offset or add focused tests for both non-Parquet and Parquet chunks.

The PR objective requires the logged size to reflect the chunk-size contract.

🤖 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/executor/importer/chunk_process_testkit_test.go` around lines 147 - 160,
Update the test around NewFileChunkProcessor to exercise the chunk-size contract
with a non-zero chunkInfo.Offset, setting EndOffset so the expected logged
chunkSize equals EndOffset minus Offset. Ensure the assertions validate that
subtraction rather than merely comparing against len(sourceData), and add
equivalent focused coverage for both non-Parquet and Parquet chunk paths if they
are separate.
🤖 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/executor/importer/chunk_process_testkit_test.go`:
- Around line 147-160: Update the test around NewFileChunkProcessor to exercise
the chunk-size contract with a non-zero chunkInfo.Offset, setting EndOffset so
the expected logged chunkSize equals EndOffset minus Offset. Ensure the
assertions validate that subtraction rather than merely comparing against
len(sourceData), and add equivalent focused coverage for both non-Parquet and
Parquet chunk paths if they are separate.

In `@pkg/executor/importer/table_import.go`:
- Around line 122-129: Update the exported comment for Chunk.GetSize to document
both semantics: non-Parquet chunks return the byte span EndOffset minus Offset,
while Parquet chunks return FileSize because Offset and EndOffset represent
rows.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d7dc4f44-8e38-4b39-bd2e-2207f4ed53d8

📥 Commits

Reviewing files that changed from the base of the PR and between 48f8e16 and e9fcb79.

📒 Files selected for processing (5)
  • pkg/dxf/importinto/task_executor.go
  • pkg/executor/importer/BUILD.bazel
  • pkg/executor/importer/chunk_process.go
  • pkg/executor/importer/chunk_process_testkit_test.go
  • pkg/executor/importer/table_import.go

@codecov

codecov Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.5652%. Comparing base (a45a797) to head (992053c).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #70271        +/-   ##
================================================
- Coverage   76.3269%   73.5652%   -2.7617%     
================================================
  Files          2041       2078        +37     
  Lines        559033     582628     +23595     
================================================
+ Hits         426693     428612      +1919     
- Misses       131440     153559     +22119     
+ Partials        900        457       -443     
Flag Coverage Δ
integration 40.9924% <0.0000%> (+1.3238%) ⬆️

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

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

@D3Hunter

D3Hunter commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@ingress-bot

Copy link
Copy Markdown

🔍 Starting code review for this PR...

@ingress-bot ingress-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.

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

Summary

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

🟡 [Minor] (2)

  1. chunkSize log field only added to the file-based chunk processor, not the parallel query-based one (pkg/executor/importer/chunk_process.go:444, pkg/executor/importer/chunk_process.go:592)
  2. GetSize doc comment says "original file size" but returns a per-chunk byte range for non-parquet sources (pkg/executor/importer/table_import.go:122, pkg/executor/importer/table_import.go:106)

Unanchored findings

🟡 [Minor] (1)

  1. chunkSize log field only added to the file-based chunk processor, not the parallel query-based one
    • Request: Either add an equivalent size-related field to newQueryChunkProcessor's logger (even if it is a query-specific proxy such as row count, or explicitly omitted with a comment noting query chunks have no byte size), or keep the two constructors' logger enrichment intentionally documented as diverging so the field isn't assumed universal.

return c.Path + ":" + strconv.FormatInt(c.Offset, 10)
}

// GetSize get the original file size of this chunk.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 [Minor] GetSize doc comment says "original file size" but returns a per-chunk byte range for non-parquet sources

Impact
For every non-parquet chunk, GetSize returns EndOffset - Offset, which is the byte range assigned to this specific chunk, not the size of the source file it came from. The Chunk struct already has a distinct FileSize field (the actual original file size, see table_import.go:106 and its use at table_import.go:539) populated from region.FileMeta.FileSize when large files are split into multiple chunks by MakeTableRegions.
A reader who trusts the doc comment could assume GetSize() and FileSize are interchangeable, which is wrong whenever a file is split (StrictFormat/MaxChunkSize) into more than one chunk.

Scope

  • pkg/executor/importer/table_import.go:122 — Chunk.GetSize
  • pkg/executor/importer/table_import.go:106 — Chunk.FileSize

Evidence
table_import.go:122-129 defines GetSize with the comment // GetSize get the original file size of this chunk., but the body returns c.EndOffset - c.Offset for non-parquet types — a sub-range of the file, not the file's original size. The struct already carries the true original file size in the separate FileSize field, populated from region.FileMeta.FileSize (table_import.go:539), so the two concepts (chunk byte range vs. whole-file size) are conflated under one misleading comment.

Change request
Reword the comment to describe what is actually returned, e.g. "GetSize returns the byte size of this chunk's data range (or the file size for parquet, where Offset/EndOffset are row indices), used for size-based logging/decisions" — and make clear it can be smaller than FileSize when the source file is split into multiple chunks.

@D3Hunter

D3Hunter commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/retest

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

ti-chi-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

[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 Aug 4, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-08-04 03:30:13.127294546 +0000 UTC m=+2498799.163389622: ☑️ agreed by joechenrh.
  • 2026-08-04 08:47:21.117303313 +0000 UTC m=+2517827.153398359: ☑️ agreed by GMHDBJD.

@D3Hunter

D3Hunter commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@ti-chi-bot
ti-chi-bot Bot merged commit 807e18e into pingcap:master Aug 4, 2026
34 checks passed
@D3Hunter
D3Hunter deleted the codex/import-chunk-diagnostics branch August 4, 2026 09:42
@D3Hunter

D3Hunter commented Aug 4, 2026

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: #70338.

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.

ti-chi-bot Bot pushed a commit that referenced this pull request Aug 5, 2026
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants