Skip to content

importinto: integrate async prepare flow for nextgen - #68668

Merged
ti-chi-bot[bot] merged 21 commits into
pingcap:masterfrom
D3Hunter:import-async-prepare
Jun 2, 2026
Merged

ti-chi-bot[bot] merged 21 commits into
pingcap:masterfrom
D3Hunter:import-async-prepare

Conversation

@D3Hunter

@D3Hunter D3Hunter commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #68580

Problem Summary:

For nextgen IMPORT INTO with global sort, prepare work still blocks submit time and some prepare outputs are produced too late for consistent lifecycle tracking. We need an async prepare stage that persists prepared metadata and exposes the preparing period in SHOW IMPORT JOBS.

What changed and how does it work?

  1. Added async prepare mode for nextgen global-sort IMPORT INTO tasks.
    • SubmitTask enables prepare mode for eligible plans and defers heavy prepare work from submit path to scheduler OnPrepare.
  2. Implemented prepare-stage execution in import scheduler.
    • OnPrepare now runs file discovery/resource calculation/chunk population, writes prepared chunk map to external storage, updates task meta, and persists prepared job info.
  3. Persisted and reused prepared metadata.
    • Added prepared_meta_external_path in task meta and corresponding prepared-meta helpers.
    • Planner now prefers reading prepared chunk map from external meta when generating import specs.
  4. Added explicit preparing lifecycle state for import jobs.
    • Introduced JobStepPreparing and prepared-info update path (source_file_size + detected format) before entering first business phase.
  5. Refined async submit precheck and format handling.
    • Added CheckRequirementsBeforeInitDataFiles for async-prepare submit path.
    • Guarded format update when plan parameters are not initialized and merged detected format into persisted job parameters.
  6. Improved user-facing visibility in SHOW IMPORT JOBS.
    • Shows preparing phase while task is still around init/prepare transition.
    • Shows SourceFileSize as N/A when the size is still unknown during pending/preparing.
  7. Expanded tests for async prepare flow.
    • Added/updated unit coverage for scheduler/importer/show behavior.
    • Added realtikv coverage for prepare timing visibility and non-retryable precheck failure.

Check List

Tests

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

before this PR, a 27.84TiB uncompressed CSV datasets takes 21s before submit

MySQL [test]> import into t from 's3://.....' with detached;
show import jb+--------+--------------------------+--------------+----------+-------+---------+------------------+---------------+----------------+----------------------------+------------+----------+------------+------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
| Job_ID | Group_Key | Data_Source  | Target_Table | Table_ID | Phase | Status  | Source_File_Size | Imported_Rows | Result_Message | Create_Time                | Start_Time | End_Time | Created_By | Last_Update_Time | Cur_Step | Cur_Step_Processed_Size | Cur_Step_Total_Size | Cur_Step_Progress_Pct | Cur_Step_Speed | Cur_Step_ETA |
+--------+-----------+--------------+--------------+----------+-------+---------+------------------+---------------+----------------+----------------------------+------------+----------+------------+------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
|      2 | NULL      | s3://nextgen | `test`.`t`   |       57 |       | pending | 27.84TiB         |          NULL |                | 2026-05-28 09:52:57.021328 | NULL       | NULL     | root@%     | NULL             | NULL     | NULL                    | NULL                | NULL                  | NULL           | NULL         |
+--------+-----------+--------------+--------------+----------+-------+---------+------------------+---------------+----------------+----------------------------+------------+----------+------------+------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
1 row in set (21.787 sec)

after this pr, job submit immediately, with N/A size

MySQL [test]> import into t from 's3://.....' with detached;
+--------+-----------+--------------+--------------+----------+-------+---------+------------------+---------------+----------------+----------------------------+------------+----------+------------+------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
| Job_ID | Group_Key | Data_Source  | Target_Table | Table_ID | Phase | Status  | Source_File_Size | Imported_Rows | Result_Message | Create_Time                | Start_Time | End_Time | Created_By | Last_Update_Time | Cur_Step | Cur_Step_Processed_Size | Cur_Step_Total_Size | Cur_Step_Progress_Pct | Cur_Step_Speed | Cur_Step_ETA |
+--------+-----------+--------------+--------------+----------+-------+---------+------------------+---------------+----------------+----------------------------+------------+----------+------------+------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
|  30001 | NULL      | s3://nextgen | `test`.`t`   |       57 |       | pending | N/A              |          NULL |                | 2026-05-28 10:22:33.647192 | NULL       | NULL     | root@%     | NULL             | NULL     | NULL                    | NULL                | NULL                  | NULL           | NULL         |
+--------+-----------+--------------+--------------+----------+-------+---------+------------------+---------------+----------------+----------------------------+------------+----------+------------+------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
1 row in set (0.443 sec)

enter preparing

MySQL [test]> show import job 30001;
+--------+-----------+--------------+--------------+----------+-----------+---------+------------------+---------------+----------------+----------------------------+----------------------------+----------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
| Job_ID | Group_Key | Data_Source  | Target_Table | Table_ID | Phase     | Status  | Source_File_Size | Imported_Rows | Result_Message | Create_Time                | Start_Time                 | End_Time | Created_By | Last_Update_Time           | Cur_Step | Cur_Step_Processed_Size | Cur_Step_Total_Size | Cur_Step_Progress_Pct | Cur_Step_Speed | Cur_Step_ETA |
+--------+-----------+--------------+--------------+----------+-----------+---------+------------------+---------------+----------------+----------------------------+----------------------------+----------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
|  30001 | NULL      | s3://nextgen | `test`.`t`   |       57 | preparing | running | N/A              |             0 |                | 2026-05-28 10:22:33.647192 | 2026-05-28 10:22:35.475950 | NULL     | root@%     | 2026-05-28 10:22:35.475950 | init     | 0B                      | 0B                  | N/A                   | 0B/s           | N/A          |
+--------+-----------+--------------+--------------+----------+-----------+---------+------------------+---------------+----------------+----------------------------+----------------------------+----------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
1 row in set (0.009 sec)

prepare finished, we can see the data size now

MySQL [test]> show import job 30001;
+--------+-----------+--------------+--------------+----------+----------------+---------+------------------+---------------+----------------+----------------------------+----------------------------+----------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
| Job_ID | Group_Key | Data_Source  | Target_Table | Table_ID | Phase          | Status  | Source_File_Size | Imported_Rows | Result_Message | Create_Time                | Start_Time                 | End_Time | Created_By | Last_Update_Time           | Cur_Step | Cur_Step_Processed_Size | Cur_Step_Total_Size | Cur_Step_Progress_Pct | Cur_Step_Speed | Cur_Step_ETA |
+--------+-----------+--------------+--------------+----------+----------------+---------+------------------+---------------+----------------+----------------------------+----------------------------+----------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
|  30001 | NULL      | s3://nextgen | `test`.`t`   |       57 | global-sorting | running | 27.84TiB         |             0 |                | 2026-05-28 10:22:33.647192 | 2026-05-28 10:22:35.475950 | NULL     | root@%     | 2026-05-28 10:22:56.477322 | prepared | 0B                      | 0B                  | 0                     | 0B/s           | N/A          |
+--------+-----------+--------------+--------------+----------+----------------+---------+------------------+---------------+----------------+----------------------------+----------------------------+----------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
1 row in set (0.009 sec)
  • No need to test
    • I checked and no code files have been changed.

Unit test commands:

./tools/check/failpoint-go-test.sh pkg/dxf/importinto -run 'TestSubmitTaskNextgen|TestLogicalPlan|TestSchedulerExtGlobalSort' -count=1
./tools/check/failpoint-go-test.sh pkg/executor/importer -run 'TestJobHappyPath|TestCheckRequirements|TestInitOptionsPositiveCase' -count=1

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.

Enhance nextgen IMPORT INTO by adding an asynchronous prepare phase that persists prepared metadata and exposes a preparing state in SHOW IMPORT JOBS.

Summary by CodeRabbit

  • New Features

    • Async "prepare" phase for IMPORT INTO with external prepared-chunk metadata support
    • New "preparing" job phase to track preparation progress
  • Improvements

    • IMPORT INTO can load prepared chunk maps from external storage for global-sort imports
    • Split pre-checks to allow deferred initialization in async-prepare paths; submission logs now surface global-sort/async-prepare info
    • Source file size is shown as "N/A" when unknown during preparation
  • Tests

    • Added integration and unit tests covering async-prepare flows, timing, and transitions

Review Change Stack

@ti-chi-bot ti-chi-bot Bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 27, 2026
@pantheon-ai

pantheon-ai Bot commented May 27, 2026 •

Copy link
Copy Markdown

@D3Hunter I've received your pull request and will start the review. I'll conduct a thorough review covering code quality, potential issues, and implementation details.

⏳ This process typically takes 10-30 minutes depending on the complexity of the changes.

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 27, 2026
@tiprow

tiprow Bot commented May 27, 2026

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown

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

Implements async prepare for IMPORT INTO: promotes framework prepare hook, gates prepare at submit, persists prepared-chunk metadata externally, scheduler OnPrepare prepares chunks and updates job/task, executor defers init and splits prechecks, adds job DB helpers and tests.

Changes

Async Prepare Phase for IMPORT INTO

Layer / File(s) Summary
Framework prepare hook promotion and stubs
pkg/dxf/framework/scheduler/..., pkg/dxf/example/scheduler.go, pkg/ddl/backfilling_dist_scheduler.go
Promotes OnPrepare invocation to s.OnPrepare, removes BaseScheduler no-op, and adds small no-op OnPrepare stubs used by components.
Planner / TaskMeta: prepare-mode & external prepared-chunk map
pkg/dxf/importinto/planner.go, pkg/dxf/importinto/proto.go, pkg/ingestor/globalsort/*, pkg/dxf/importinto/planner_test.go
Adds PrepareMode and PreparedChunkMapExternalPath to LogicalPlan/TaskMeta; serialize/deserialize; read prepared chunk map from external storage when path is present; tests for external prepared meta path.
Scheduler OnPrepare and step transitions
pkg/dxf/importinto/scheduler.go
Implements OnPrepare to build/init controller, validate total matched size, compute resource params, persist prepared job info, populate chunks, write prepared chunk map externally, and update task meta/runtime; adjusts step transition calls for prepare-required jobs.
Submit-time gating and logging
pkg/dxf/importinto/job.go, pkg/dxf/importinto/job_testkit_test.go
Adds ShouldUseAsyncPrepare; when true, marks plan PrepareModeRequired and constrains thread/node counts at submit; updates submission logging and adds test coverage for persisted task extra params.
Executor deferral & precheck split
pkg/executor/import_into.go, pkg/executor/importer/precheck.go, pkg/executor/importer/import.go
Conditionally defer InitDataFiles/CalResourceParams for async-prepare; introduce CheckRequirementsBeforeInitDataFiles to skip total-file-size check; export option-tracking and non-CSV option validation adjustments; add/adjust unit tests.
Job DB helpers and states
pkg/executor/importer/job.go, pkg/executor/importer/job_test.go
Add JobStepPreparing, JobInfo.IsSourceFileSizeUnknown, and UpdateJobPreparedInfo to update running job parameters/source size; tests for prepare->business-step transitions.
Tests and integration
tests/realtikvtest/..., pkg/dxf/importinto/*_test.go, pkg/executor/*_test.go
Extensive unit and integration tests: scheduler testkit, real TiKV integration tests for detached jobs and timing around prepare, precheck behavior, and show/import job output formatting.
Misc small changes
pkg/ingestor/globalsort/util.go, pkg/dxf/importinto/BUILD.bazel, pkg/dxf/example/scheduler.go, pkg/ddl/backfilling_dist_scheduler.go
PreparedMetaPath helper and tests, BUILD shard/deps tweak, example/DDL scheduler OnPrepare stubs, and small test tweaks.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • pingcap/tidb#68581: Introduced StepPrepared and framework-level prepare-mode support that this PR builds upon.

Suggested labels

ok-to-test, approved, lgtm

Suggested reviewers

  • joechenrh
  • GMHDBJD
  • wjhuang2016

"🐰
I nibbled through tasks and built a plan,
Chunks tucked in boxes, written neat by hand,
Scheduler paused, then hummed to start,
Prepare then sort — each chunk plays its part,
Hooray, the import hopped right to land!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 32.14% 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
Title check ✅ Passed The title 'importinto: integrate async prepare flow for nextgen' accurately summarizes the main change: adding an async prepare phase for nextgen IMPORT INTO with global sort.
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.
Description check ✅ Passed PR description comprehensively covers the problem, solution, changes, tests, and includes a detailed release note following best practices.

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

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

@D3Hunter D3Hunter changed the title dxf, executor: add async Init->Prepared flow for nextgen IMPORT INTO importinto: add async Init->Prepared flow for nextgen May 27, 2026
@D3Hunter D3Hunter changed the title importinto: add async Init->Prepared flow for nextgen importinto: integrate async prepare flow for nextgen May 27, 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/realtikvtest/importintotest/job_test.go (1)

658-662: 💤 Low value

Consider: Timeout multiplier may be excessive.

Line 662 uses 3*maxWaitTime while other tests in this file use maxWaitTime. If this is intentional due to the non-prepare-mode path having different timing characteristics, a brief comment explaining why would be helpful. Otherwise, consider using the standard maxWaitTime for consistency.

🤖 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 `@tests/realtikvtest/importintotest/job_test.go` around lines 658 - 662, The
test uses a longer timeout (3*maxWaitTime) in the s.Require().Eventually call
for checking the import job status (jobID → importer.JobStatusFinished) which is
inconsistent with other tests that use maxWaitTime; either revert this call to
use maxWaitTime for consistency or, if the longer timeout is required for the
non-prepare-mode path, add a short explanatory comment above the
s.Require().Eventually line indicating why 3*maxWaitTime is necessary (e.g.,
non-prepare-mode tends to take ~3x longer) so future readers understand the
intentional deviation.
🤖 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.

Inline comments:
In `@pkg/dxf/importinto/scheduler_testkit_test.go`:
- Around line 199-201: The test is being skipped because the guard uses
importinto.ShouldUseAsyncPrepare(&logicalPlan.Plan) which returns false for the
local-sort plan built here, so change the guard or the plan: either replace the
skip guard with a check for kernel/runtime support (e.g., the runtime/kernel
feature flag used elsewhere in tests) so the subtest runs when the environment
supports async prepare, or modify the subtest to build a prepare-eligible plan
(make the logical plan non-local-sort or call the helper that produces an
async-prepare-capable plan) so ShouldUseAsyncPrepare(&logicalPlan.Plan) is true
and the preparing→importing assertions execute; update references to
ShouldUseAsyncPrepare and logicalPlan.Plan accordingly.

---

Nitpick comments:
In `@tests/realtikvtest/importintotest/job_test.go`:
- Around line 658-662: The test uses a longer timeout (3*maxWaitTime) in the
s.Require().Eventually call for checking the import job status (jobID →
importer.JobStatusFinished) which is inconsistent with other tests that use
maxWaitTime; either revert this call to use maxWaitTime for consistency or, if
the longer timeout is required for the non-prepare-mode path, add a short
explanatory comment above the s.Require().Eventually line indicating why
3*maxWaitTime is necessary (e.g., non-prepare-mode tends to take ~3x longer) so
future readers understand the intentional deviation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3c67e398-2467-451e-a264-956172cf616e

📥 Commits

Reviewing files that changed from the base of the PR and between 5b35a62 and 95c27a5.

📒 Files selected for processing (22)
  • pkg/ddl/backfilling_dist_scheduler.go
  • pkg/dxf/example/scheduler.go
  • pkg/dxf/framework/scheduler/scheduler.go
  • pkg/dxf/importinto/BUILD.bazel
  • pkg/dxf/importinto/job.go
  • pkg/dxf/importinto/job_testkit_test.go
  • pkg/dxf/importinto/planner.go
  • pkg/dxf/importinto/planner_test.go
  • pkg/dxf/importinto/proto.go
  • pkg/dxf/importinto/scheduler.go
  • pkg/dxf/importinto/scheduler_test.go
  • pkg/dxf/importinto/scheduler_testkit_test.go
  • pkg/executor/import_into.go
  • pkg/executor/importer/import.go
  • pkg/executor/importer/job.go
  • pkg/executor/importer/job_test.go
  • pkg/executor/importer/precheck.go
  • pkg/executor/importer/precheck_test.go
  • pkg/executor/show_test.go
  • pkg/ingestor/globalsort/util.go
  • pkg/ingestor/globalsort/util_test.go
  • tests/realtikvtest/importintotest/job_test.go

Comment thread pkg/dxf/importinto/scheduler_testkit_test.go Outdated
@codecov

codecov Bot commented May 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 1.60000% with 246 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.6602%. Comparing base (0c98567) to head (eaf4e40).
⚠️ Report is 26 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #68668        +/-   ##
================================================
+ Coverage   76.3025%   76.6602%   +0.3576%     
================================================
  Files          2041       2054        +13     
  Lines        563407     577340     +13933     
================================================
+ Hits         429894     442590     +12696     
+ Misses       132597     132573        -24     
- Partials        916       2177      +1261     
Flag Coverage Δ
integration 46.8423% <1.6000%> (+7.0652%) ⬆️

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

Components Coverage Δ
dumpling 60.4679% <ø> (ø)
parser ∅ <ø> (∅)
br 65.6935% <ø> (+2.8711%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@pkg/dxf/importinto/planner.go`:
- Around line 428-435: readPreparedChunkMap currently only decodes the new
PreparedMeta shape and will silently yield an empty ChunkMap for legacy JSON;
update readPreparedChunkMap to attempt backward-compatible decoding by first
trying to ReadJSONInto PreparedMeta (PreparedMeta.ReadJSONFromExternalStorage)
and if that produces an empty ChunkMap, re-read/unmarshal the same external JSON
into the legacy chunk-map-only shape (e.g., the previous ChunkMap type or a
map[string]... matching the old format) and populate
preparedChunkMapMeta.ChunkMap from that legacy structure so old exports still
produce import specs.

In `@pkg/dxf/importinto/scheduler_testkit_test.go`:
- Around line 216-218: The test currently defers server.Stop() before checking
error from fakestorage.NewServerWithOptions which can panic if server is nil;
change the order so you first assert success (e.g., call require.NoError(t, err)
or check err==nil) and only then call defer server.Stop(); locate the
NewServerWithOptions call and the server.Stop defer in scheduler_testkit_test.go
and move the defer to immediately after the successful creation check.

In `@pkg/executor/importer/job.go`:
- Around line 147-157: The IsSourceFileSizeUnknown method incorrectly returns
false once Status != JobStatusRunning which causes jobs that failed or were
cancelled during JobStepPreparing with SourceFileSize==0 to be treated as known
zero; change the predicate in JobInfo.IsSourceFileSizeUnknown to return true
when SourceFileSize == 0 AND (Status == jobStatusPending OR Step ==
JobStepPreparing) so that prepare-time failures/cancels (which preserve Step via
FailJob/CancelJob) still report size as unknown.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c31477e3-76de-4957-bec9-c21adc45e1a1

📥 Commits

Reviewing files that changed from the base of the PR and between 95c27a5 and 03d9278.

📒 Files selected for processing (15)
  • pkg/dxf/importinto/BUILD.bazel
  • pkg/dxf/importinto/job.go
  • pkg/dxf/importinto/planner.go
  • pkg/dxf/importinto/planner_test.go
  • pkg/dxf/importinto/proto.go
  • pkg/dxf/importinto/scheduler.go
  • pkg/dxf/importinto/scheduler_testkit_test.go
  • pkg/executor/importer/import.go
  • pkg/executor/importer/importer_testkit_test.go
  • pkg/executor/importer/job.go
  • pkg/executor/importer/job_test.go
  • pkg/executor/importer/table_import.go
  • pkg/executor/show.go
  • pkg/executor/show_test.go
  • tests/realtikvtest/importintotest/job_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/executor/importer/table_import.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • pkg/dxf/importinto/BUILD.bazel
  • pkg/executor/importer/import.go
  • pkg/dxf/importinto/job.go
  • pkg/dxf/importinto/scheduler.go
  • tests/realtikvtest/importintotest/job_test.go

Comment thread pkg/dxf/importinto/planner.go
Comment thread pkg/dxf/importinto/scheduler_testkit_test.go
Comment on lines +147 to +157
func (j *JobInfo) IsSourceFileSizeUnknown() bool {
// if the job is not using async prepare, source_file_size is determined
// when creating the job, and it will never be 0 since we check total file
// size > 0 in precheck.
if j.SourceFileSize > 0 {
return false
}
if j.Status == jobStatusPending {
return true
}
return j.Status == JobStatusRunning && j.Step == JobStepPreparing

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Keep source_file_size unknown after prepare-time failure/cancel.

This returns false as soon as the job leaves running, so a job that fails or is cancelled during JobStepPreparing with source_file_size = 0 will be reported as a real 0 instead of “unknown”. In this file, FailJob and CancelJob preserve step, so the safer predicate is “size is zero and the job is still pending or its step is preparing”.

Suggested fix
 func (j *JobInfo) IsSourceFileSizeUnknown() bool {
 	// if the job is not using async prepare, source_file_size is determined
 	// when creating the job, and it will never be 0 since we check total file
 	// size > 0 in precheck.
 	if j.SourceFileSize > 0 {
 		return false
 	}
-	if j.Status == jobStatusPending {
-		return true
-	}
-	return j.Status == JobStatusRunning && j.Step == JobStepPreparing
+	return j.Status == jobStatusPending || j.Step == JobStepPreparing
 }
🤖 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/job.go` around lines 147 - 157, The
IsSourceFileSizeUnknown method incorrectly returns false once Status !=
JobStatusRunning which causes jobs that failed or were cancelled during
JobStepPreparing with SourceFileSize==0 to be treated as known zero; change the
predicate in JobInfo.IsSourceFileSizeUnknown to return true when SourceFileSize
== 0 AND (Status == jobStatusPending OR Step == JobStepPreparing) so that
prepare-time failures/cancels (which preserve Step via FailJob/CancelJob) still
report size as unknown.

@D3Hunter D3Hunter left a comment

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.

Summary

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

⚠️ [Major] (1)

  1. Async prepare re-discovers server-disk files on scheduler owner instead of using submit-time chunk map (pkg/dxf/importinto/job.go:51; pkg/dxf/importinto/job.go:71; pkg/executor/import_into.go:109; pkg/dxf/importinto/scheduler.go:336; pkg/dxf/importinto/planner.go:372)

🟡 [Minor] (2)

  1. Plan keeps two option-presence registries without one canonical source (pkg/executor/importer/import.go:324; pkg/executor/importer/import.go:325; pkg/executor/importer/import.go:767; pkg/executor/importer/import.go:768; pkg/executor/importer/import.go:1845)
  2. Prepare-mode scheduler test hardcodes port and defers cleanup before setup assertion (pkg/dxf/importinto/scheduler_testkit_test.go:207; pkg/dxf/importinto/scheduler_testkit_test.go:217)

Comment thread pkg/dxf/importinto/job.go
Comment thread pkg/executor/importer/import.go
Comment thread pkg/dxf/importinto/scheduler_testkit_test.go Outdated
@D3Hunter

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented May 28, 2026

Copy link
Copy Markdown

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

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.

@ingress-bot

Copy link
Copy Markdown

🔍 Starting code review for this PR...

@D3Hunter

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented May 28, 2026

Copy link
Copy Markdown

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

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.

@D3Hunter

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented May 28, 2026

Copy link
Copy Markdown

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

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.

@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)

96-107: ⚡ Quick win

Avoid mutating caller-owned plan for temporary async defaults.

plan.ThreadCnt and plan.MaxNodeCnt are set to 1 and never restored. Even if intended as temporary values for scheduling, this leaks state outside doSubmitTask. Use local variables for planCtx instead.

Proposed fix
 	asyncPrepare := ShouldUseAsyncPrepare(plan)
+	threadCnt := plan.ThreadCnt
+	maxNodeCnt := plan.MaxNodeCnt
 	if asyncPrepare {
 		logicalPlan.PrepareMode = proto.PrepareModeRequired
 		// below params will be filled later in async prepare, init to 1 temporarily.
-		plan.ThreadCnt = 1
-		plan.MaxNodeCnt = 1
+		threadCnt = 1
+		maxNodeCnt = 1
 	}
 	planCtx := planner.PlanCtx{
 		Ctx:        ctx,
 		TaskType:   proto.ImportInto,
-		ThreadCnt:  plan.ThreadCnt,
-		MaxNodeCnt: plan.MaxNodeCnt,
+		ThreadCnt:  threadCnt,
+		MaxNodeCnt: maxNodeCnt,
 	}
🤖 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 96 - 107, The code mutates
caller-owned plan by setting plan.ThreadCnt and plan.MaxNodeCnt to 1 for async
prepare and never restores them; instead, compute local threadCnt/ maxNodeCnt
variables (e.g., threadCnt := plan.ThreadCnt; maxNodeCnt := plan.MaxNodeCnt; if
asyncPrepare { threadCnt = 1; maxNodeCnt = 1 }) and use those when constructing
planner.PlanCtx (and leave plan.ThreadCnt/plan.MaxNodeCnt unchanged), while
still setting logicalPlan.PrepareMode = proto.PrepareModeRequired when
ShouldUseAsyncPrepare(...) is true.
🤖 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 96-107: The code mutates caller-owned plan by setting
plan.ThreadCnt and plan.MaxNodeCnt to 1 for async prepare and never restores
them; instead, compute local threadCnt/ maxNodeCnt variables (e.g., threadCnt :=
plan.ThreadCnt; maxNodeCnt := plan.MaxNodeCnt; if asyncPrepare { threadCnt = 1;
maxNodeCnt = 1 }) and use those when constructing planner.PlanCtx (and leave
plan.ThreadCnt/plan.MaxNodeCnt unchanged), while still setting
logicalPlan.PrepareMode = proto.PrepareModeRequired when
ShouldUseAsyncPrepare(...) is true.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b5e82cc6-8b8b-4f31-a079-f453990af958

📥 Commits

Reviewing files that changed from the base of the PR and between b04b92c and eaf4e40.

📒 Files selected for processing (1)
  • pkg/dxf/importinto/job.go


// IsSourceFileSizeUnknown returns whether source_file_size has not been
// determined yet for async-prepare jobs.
func (j *JobInfo) IsSourceFileSizeUnknown() bool {

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.

Can we just show N/A for zero file size, and show actual size for any positive file size, regardless of the job status?

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.

since the source file size = 0 precheck is moved to async prepare part, it can be 0 in this case

@D3Hunter

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented May 28, 2026

Copy link
Copy Markdown

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

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 added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 29, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 2, 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 approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 2, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-05-29 01:27:48.308331096 +0000 UTC m=+574738.278496156: ☑️ agreed by joechenrh.
  • 2026-06-02 07:19:57.471856581 +0000 UTC m=+253298.542173961: ☑️ agreed by GMHDBJD.

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/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