Skip to content

ddl: observe TiKV capacity and ingested SST for add index#69712

Open
expxiaoli wants to merge 1 commit into
pingcap:masterfrom
expxiaoli:tikv_precheck_PR_observe
Open

ddl: observe TiKV capacity and ingested SST for add index#69712
expxiaoli wants to merge 1 commit into
pingcap:masterfrom
expxiaoli:tikv_precheck_PR_observe

Conversation

@expxiaoli

@expxiaoli expxiaoli commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #68354

Problem Summary:

This PR is split from #68490.

Before adding TiKV disk-space prediction and enforcement for add index, we need observability data to know:

  • The initial TiKV capacity before add-index execution.
  • How many SST bytes are actually ingested after add-index execution.

The observability data for ingested SST bytes should be used only for post-run validation. It should not become part of the add-index execution state, task meta, or subtask summary.

What changed and how does it work?

This PR adds record-only observability for add-index distributed backfill:

  • Collects a TiKV capacity snapshot through PD HTTP before submitting the add-index distributed task, then logs total bytes, available bytes, store count, job ID, and task key.
  • Records successfully ingested SST metadata through a local in-memory collector owned by ingest control.
  • Logs per-subtask ingested SST bytes, SST count, zero-size count, invalid identity count, reliability state, and reliability reason.
  • Deduplicates ingested SST records by identity before logging.
  • Supports both classic local ingest SST metadata and next-gen SST metadata.
  • Keeps ingested SST and TiKV capacity observability out of task meta and SubtaskSummary; there is no task-end aggregation or writeback.

Compared with #68490, this PR intentionally makes the following changes:

  1. Remove the InitialTiKVCapacity task meta field and the ingested SST fields from SubtaskSummary. They are changed to pure log observations.
  2. Change capacity collection from the PD gRPC path to the PD HTTP path. This can introduce about 0.05% observation error, but it reduces TiDB-to-PD IO, improves performance, and reuses the existing PD HTTP capacity data path.
  3. Remove the source grouping layer from the diagnostic fields in ingestedSSTRecorder. The extra source layer does not add much diagnostic value.

This PR does not reject add-index tasks, does not add disk-space prediction, and does not change add-index scheduling behavior.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
GOPATH=/Users/xiaoli/go GOSUMDB=sum.golang.org make bazel_prepare
GOPATH=/Users/xiaoli/go GOSUMDB=sum.golang.org ./tools/check/failpoint-go-test.sh pkg/ddl -run 'TestEstimateTableSizeByIDUsesMaxApproximateSizes|TestCollectTiKVStoreCapacityFromPDHTTP|TestIngestedSSTRecorder' -count=1
GOPATH=/Users/xiaoli/go GOSUMDB=sum.golang.org go test -tags=intest,deadlock ./pkg/ingestor/ingestcli -run 'TestWriteClientWriteChunk|TestClientIngest|TestClientIngestError' -count=1
GOPATH=/Users/xiaoli/go GOSUMDB=sum.golang.org ./tools/check/failpoint-go-test.sh pkg/ingestor/ingestctrl -run 'TestRegionJobBaseWorker|TestCloudRegionJobWorker' -count=1
GOPATH=/Users/xiaoli/go GOSUMDB=sum.golang.org go test -tags=intest,deadlock ./pkg/dxf/framework/taskexecutor/execute -run '^$' -count=1
GOPATH=/Users/xiaoli/go GOSUMDB=sum.golang.org make lint
git diff --check

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

    • Added tracking of ingested SST sizes and counts during index backfill and ingest operations.
    • Added cluster capacity observations during add-index scheduling to improve visibility into available storage.
  • Bug Fixes

    • Improved handling of missing or zero-size SST metadata by marking observations as unreliable instead of reporting misleading totals.
    • Updated ingest responses and tests to carry SST size information consistently.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 7, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign gmhdbjd for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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

@coderabbitai

coderabbitai Bot commented Jul 7, 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

Run ID: 94ace769-a234-45bb-8d40-65643e635306

📥 Commits

Reviewing files that changed from the base of the PR and between 90689d6 and fa03b0f.

📒 Files selected for processing (13)
  • pkg/ddl/backfilling_dist_executor.go
  • pkg/ddl/backfilling_import_cloud.go
  • pkg/ddl/backfilling_read_index.go
  • pkg/ddl/index.go
  • pkg/ddl/reorg_util_test.go
  • pkg/dxf/framework/taskexecutor/execute/interface.go
  • pkg/ingestor/ingestcli/client.go
  • pkg/ingestor/ingestcli/client_test.go
  • pkg/ingestor/ingestcli/interface.go
  • pkg/ingestor/ingestctrl/BUILD.bazel
  • pkg/ingestor/ingestctrl/job_worker.go
  • pkg/ingestor/ingestctrl/job_worker_test.go
  • pkg/ingestor/ingestctrl/region_job.go
💤 Files with no reviewable changes (1)
  • pkg/dxf/framework/taskexecutor/execute/interface.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/ddl/backfilling_dist_executor.go
🚧 Files skipped from review as they are similar to previous changes (11)
  • pkg/ingestor/ingestctrl/BUILD.bazel
  • pkg/ingestor/ingestcli/client_test.go
  • pkg/ingestor/ingestcli/client.go
  • pkg/ingestor/ingestctrl/region_job.go
  • pkg/ingestor/ingestcli/interface.go
  • pkg/ingestor/ingestctrl/job_worker.go
  • pkg/ddl/index.go
  • pkg/ingestor/ingestctrl/job_worker_test.go
  • pkg/ddl/reorg_util_test.go
  • pkg/ddl/backfilling_import_cloud.go
  • pkg/ddl/backfilling_read_index.go

📝 Walkthrough

Walkthrough

This PR adds PD-based TiKV capacity observation for add-index scheduling, records ingested SST byte metadata across cloud, read-index, and classic ingest paths, and extends SST response metadata with a size field and accessors.

Changes

Observability feature

Layer / File(s) Summary
SST metadata contract and collector accessors
pkg/ingestor/ingestcli/client.go, pkg/ingestor/ingestcli/interface.go, pkg/ingestor/ingestcli/client_test.go
nextGenSSTMeta gains a Size field reflected in String(); WriteResponse gains NewWriteResponseWithSSTMeta and GetSSTMeta(); tests update to assert via the accessor.
ingestedSSTRecorder implementation
pkg/ddl/backfilling_import_cloud.go, pkg/ddl/reorg_util_test.go
Adds ingestCollector/ingestedSSTRecorder with dedup-by-identity tracking of bytes, count, zero-size, and invalid-identity, plus Reset, Snapshot, and logIngestedSSTObservation, verified by tests.
Cloud import executor wiring
pkg/ddl/backfilling_import_cloud.go
cloudImportExecutor gains an ingestedSSTs field, is initialized in the constructor, reset per subtask/summary reset, wired into ingestCollector, and logged after ingest.
Local read-index executor wiring
pkg/ddl/backfilling_read_index.go
readIndexStepExecutor gains an ingestedSSTs recorder, registers it during local pipeline runs, resets it on subtask/summary reset, and logs post-pipeline.
TiKV capacity snapshot from PD
pkg/ddl/index.go, pkg/ddl/reorg_util_test.go
Introduces TiKVClusterCapacity and PD-based store aggregation, wired into executeDistTask and verified with mocked PD HTTP client tests.
Classic ingest path recording
pkg/ingestor/ingestctrl/job_worker.go, pkg/ingestor/ingestctrl/region_job.go, pkg/ingestor/ingestctrl/job_worker_test.go, pkg/ingestor/ingestctrl/BUILD.bazel
Adds ingestedSSTCollector and recordIngestedSST, wires recording into object-storage and TiKV classic ingest success paths, with tests covering identity/size recording and partial-failure truncation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • pingcap/tidb#68490: Both PRs touch the DXF add-index TiKV capacity observation flow in pkg/ddl/index.go.
  • pingcap/tidb#69658: Both PRs modify the ingest-observation plumbing in pkg/ddl/backfilling_import_cloud.go and pkg/ddl/backfilling_read_index.go.

Suggested reviewers: D3Hunter, wjhuang2016, GMHDBJD

Poem

I hop through bytes with bright-eyed glee,
And count each SST carefully.
PD hums, the ingests sing,
Tiny logs go wandering.
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change to observe TiKV capacity and ingested SSTs for add index.
Description check ✅ Passed The description includes the issue link, problem summary, changes, test checklist, side effects, documentation, 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.

@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 (3)
pkg/ingestor/ingestctrl/job_worker_test.go (1)

511-525: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test only covers the !ok branch of the next-gen recording path.

writeResult: &tikvWriteResult{} leaves nextGenWriteResp nil, so GetSSTMeta() always returns ok=false here, and the assertion []recordedIngestedSST{{}} only exercises the empty-record branch in job_worker.go's ingest(). The success branch (recordIngestedSST(w.collector, "next-gen/"+strconv.FormatInt(id, 10), size)) has no test coverage in this file.

Consider adding a case where nextGenWriteResp has valid SST metadata to verify the populated-identity recording path.

🤖 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/ingestor/ingestctrl/job_worker_test.go` around lines 511 - 525, The
“ingest success” test in job_worker_test.go only covers the empty next-gen
record path because `tikvWriteResult` has no `nextGenWriteResp`, so
`job_worker.go`’s `ingest()` never exercises the `recordIngestedSST(...)`
branch. Add a test case using `regionJob` with a populated
`nextGenWriteResp`/SST metadata so `GetSSTMeta()` returns ok and verify the
collector records the expected non-empty identity and size via
`recordIngestedSST` in addition to the existing nil-metadata case.
pkg/ddl/backfilling_import_cloud.go (2)

349-360: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Redundant reliability condition.

observation.count > 0 && observation.bytes == 0 is already implied by observation.zeroSizeCount > 0 for the classic source: since size is a uint64, bytes can only be zero when every recorded entry had size 0, which means zeroSizeCount == count. The extra clause is dead weight but harmless.

🤖 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/ddl/backfilling_import_cloud.go` around lines 349 - 360, The reliability
check in the observation switch has a redundant classic-source condition: in the
logic around the observation struct, `observation.count > 0 && observation.bytes
== 0` is already covered by `observation.zeroSizeCount > 0`. Update the `switch`
branch for `ingestedSSTBytesSourceClassic` to rely only on the zero-size case,
keeping the `observation.reliable` and `observation.reason` assignments
unchanged.

271-322: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Document concurrency guarantees for the new recorder types.

ingestCollector and ingestedSSTRecorder are new mutex-protected shared state accessed concurrently from ingest callbacks and the executor goroutine, but neither has a comment describing the thread-safety contract (e.g., that RecordIngestedSST may be called concurrently while Snapshot/Reset run on the executor goroutine).

As per coding guidelines, "Comments SHOULD explain non-obvious intent, constraints, invariants, concurrency guarantees, SQL/compatibility contracts, or important performance trade-offs."

🤖 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/ddl/backfilling_import_cloud.go` around lines 271 - 322, Add a
concurrency comment for the new recorder types in backfilling import flow:
document that ingest callbacks may invoke ingestCollector.Processed and
ingestCollector.RecordIngestedSST concurrently, while ingestedSSTRecorder’s
state is protected by its mutex. Update the struct/comment near ingestCollector
and ingestedSSTRecorder to state the thread-safety contract, including that
RecordIngestedSST is safe for concurrent use and any snapshot/reset-style access
must remain serialized on the executor goroutine.

Source: Coding guidelines

🤖 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/ddl/index.go`:
- Around line 3368-3372: The task-end capacity observation in the add-index
reorg flow is skipped whenever g.Wait() returns an error, so terminal outcomes
like KV disk-full auto-pause never capture the end snapshot. Update the
error-handling path around g.Wait() in the add-index reorg code so
w.logTiKVCapacityForAddIndexObservation is recorded for terminal/paused
completions, especially ErrKVDiskFull-related cases, before returning. Use the
existing reorgInfo.mergingTmpIdx check and the observedTiKVUsagePhaseTaskEnd
symbol to keep the snapshot logic consistent.

---

Nitpick comments:
In `@pkg/ddl/backfilling_import_cloud.go`:
- Around line 349-360: The reliability check in the observation switch has a
redundant classic-source condition: in the logic around the observation struct,
`observation.count > 0 && observation.bytes == 0` is already covered by
`observation.zeroSizeCount > 0`. Update the `switch` branch for
`ingestedSSTBytesSourceClassic` to rely only on the zero-size case, keeping the
`observation.reliable` and `observation.reason` assignments unchanged.
- Around line 271-322: Add a concurrency comment for the new recorder types in
backfilling import flow: document that ingest callbacks may invoke
ingestCollector.Processed and ingestCollector.RecordIngestedSST concurrently,
while ingestedSSTRecorder’s state is protected by its mutex. Update the
struct/comment near ingestCollector and ingestedSSTRecorder to state the
thread-safety contract, including that RecordIngestedSST is safe for concurrent
use and any snapshot/reset-style access must remain serialized on the executor
goroutine.

In `@pkg/ingestor/ingestctrl/job_worker_test.go`:
- Around line 511-525: The “ingest success” test in job_worker_test.go only
covers the empty next-gen record path because `tikvWriteResult` has no
`nextGenWriteResp`, so `job_worker.go`’s `ingest()` never exercises the
`recordIngestedSST(...)` branch. Add a test case using `regionJob` with a
populated `nextGenWriteResp`/SST metadata so `GetSSTMeta()` returns ok and
verify the collector records the expected non-empty identity and size via
`recordIngestedSST` in addition to the existing nil-metadata case.
🪄 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: 1d5beac2-84da-4226-a3d6-3fadd94c91e6

📥 Commits

Reviewing files that changed from the base of the PR and between cd225b6 and 69acd2e.

📒 Files selected for processing (15)
  • pkg/ddl/BUILD.bazel
  • pkg/ddl/backfilling_clean_s3.go
  • pkg/ddl/backfilling_dist_executor.go
  • pkg/ddl/backfilling_import_cloud.go
  • pkg/ddl/backfilling_read_index.go
  • pkg/ddl/index.go
  • pkg/ddl/reorg_util_test.go
  • pkg/dxf/framework/taskexecutor/execute/interface.go
  • pkg/ingestor/ingestcli/client.go
  • pkg/ingestor/ingestcli/client_test.go
  • pkg/ingestor/ingestcli/interface.go
  • pkg/ingestor/ingestctrl/BUILD.bazel
  • pkg/ingestor/ingestctrl/job_worker.go
  • pkg/ingestor/ingestctrl/job_worker_test.go
  • pkg/ingestor/ingestctrl/region_job.go

Comment thread pkg/ddl/index.go Outdated
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 184 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.8542%. Comparing base (09d2140) to head (fa03b0f).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69712        +/-   ##
================================================
- Coverage   76.3227%   75.8542%   -0.4686%     
================================================
  Files          2041       2079        +38     
  Lines        560399     580392     +19993     
================================================
+ Hits         427712     440252     +12540     
- Misses       131786     138030      +6244     
- Partials        901       2110      +1209     
Flag Coverage Δ
integration 45.7762% <0.0000%> (+6.0709%) ⬆️

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

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

@expxiaoli

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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 (2)
pkg/ddl/index.go (1)

3562-3586: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Inconsistent log field key naming in new observation logs.

This function mixes "jobID"/"taskID" (camelCase), "task-key" (kebab-case), and "observation_phase"/"tikv_total_bytes" (snake_case) within the same log calls, while the rest of this file consistently uses kebab-case keys like "job-id"/"task-id" (see lines 3195-3197). Inconsistent keys make these new structured logs harder to grep/aggregate — a real cost for an observability-focused feature.

✏️ Align keys with existing file convention
-		logutil.DDLLogger().Warn("skip TiKV capacity observation for add-index task because TiKV capacity snapshot failed",
-			zap.Int64("jobID", jobID),
-			zap.Int64("taskID", taskID),
+		logutil.DDLLogger().Warn("skip TiKV capacity observation for add-index task because TiKV capacity snapshot failed",
+			zap.Int64("job-id", jobID),
+			zap.Int64("task-id", taskID),
 			zap.String("task-key", taskKey),
 			zap.String("observation_phase", phase),
 			zap.Error(err))

(apply similarly to the other two log calls in this function)

As per coding guidelines: "Go code: Follow existing package-local conventions first and keep style consistent with nearby files."

🤖 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/ddl/index.go` around lines 3562 - 3586, The new TiKV capacity observation
logs in the add-index flow use inconsistent structured field names; align them
with the existing kebab-case convention used elsewhere in this file. Update the
log calls in the capacity observation helper to use the same key style as nearby
DDLLogger usages, especially for job and task identifiers, and apply the same
naming consistently across the warn/info branches.

Source: Coding guidelines

pkg/ingestor/ingestctrl/job_worker_test.go (1)

511-546: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider consolidating the two near-identical "ingest success" subtests.

Both subtests (Lines 511-525 and 527-545) share the exact same setup/assertion shape and differ only in writeResult.nextGenWriteResp and the expected recorded snapshot. A table-driven variant would reduce duplication, though the current form is clear and functionally correct.

🤖 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/ingestor/ingestctrl/job_worker_test.go` around lines 511 - 546, The two
`t.Run` cases in `job_worker_test.go` for `cloudW.ingest` are nearly identical
and should be consolidated into a single table-driven test. Keep the shared
setup around `recordingIngestedSSTCollector`, `regionJob`,
`mockIngestCli.EXPECT().Ingest`, and `ctrl.Satisfied()`, and vary only
`writeResult.nextGenWriteResp` plus the expected `collector.snapshot()` for each
case.
🤖 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/ddl/index.go`:
- Around line 3267-3269: The add-index capacity observation is currently
executed inline in the critical DDL flow, which can block task submission and
task completion; update the call sites around
logTiKVCapacityForAddIndexObservation in the add-index reorg path to run
asynchronously in a background goroutine instead of waiting synchronously. Keep
the existing warning-only failure handling inside
logTiKVCapacityForAddIndexObservation, and apply the same non-blocking change to
all referenced call sites so the DDL path never waits on PD capacity logging.

---

Nitpick comments:
In `@pkg/ddl/index.go`:
- Around line 3562-3586: The new TiKV capacity observation logs in the add-index
flow use inconsistent structured field names; align them with the existing
kebab-case convention used elsewhere in this file. Update the log calls in the
capacity observation helper to use the same key style as nearby DDLLogger
usages, especially for job and task identifiers, and apply the same naming
consistently across the warn/info branches.

In `@pkg/ingestor/ingestctrl/job_worker_test.go`:
- Around line 511-546: The two `t.Run` cases in `job_worker_test.go` for
`cloudW.ingest` are nearly identical and should be consolidated into a single
table-driven test. Keep the shared setup around `recordingIngestedSSTCollector`,
`regionJob`, `mockIngestCli.EXPECT().Ingest`, and `ctrl.Satisfied()`, and vary
only `writeResult.nextGenWriteResp` plus the expected `collector.snapshot()` for
each case.
🪄 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: ccf1b67b-daf0-4855-ba2b-ce512129ac0d

📥 Commits

Reviewing files that changed from the base of the PR and between 69acd2e and 55fc6a9.

📒 Files selected for processing (13)
  • pkg/ddl/backfilling_dist_executor.go
  • pkg/ddl/backfilling_import_cloud.go
  • pkg/ddl/backfilling_read_index.go
  • pkg/ddl/index.go
  • pkg/ddl/reorg_util_test.go
  • pkg/dxf/framework/taskexecutor/execute/interface.go
  • pkg/ingestor/ingestcli/client.go
  • pkg/ingestor/ingestcli/client_test.go
  • pkg/ingestor/ingestcli/interface.go
  • pkg/ingestor/ingestctrl/BUILD.bazel
  • pkg/ingestor/ingestctrl/job_worker.go
  • pkg/ingestor/ingestctrl/job_worker_test.go
  • pkg/ingestor/ingestctrl/region_job.go
💤 Files with no reviewable changes (1)
  • pkg/dxf/framework/taskexecutor/execute/interface.go
✅ Files skipped from review due to trivial changes (2)
  • pkg/ddl/backfilling_dist_executor.go
  • pkg/ingestor/ingestcli/client.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • pkg/ingestor/ingestcli/interface.go
  • pkg/ingestor/ingestctrl/BUILD.bazel
  • pkg/ingestor/ingestcli/client_test.go
  • pkg/ingestor/ingestctrl/region_job.go
  • pkg/ingestor/ingestctrl/job_worker.go
  • pkg/ddl/backfilling_read_index.go

@expxiaoli expxiaoli force-pushed the tikv_precheck_PR_observe branch from 55fc6a9 to 90689d6 Compare July 7, 2026 11:59
@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 7, 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)
pkg/ddl/index.go (1)

3574-3583: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use errors package instead of fmt.Errorf for consistency and stack traces.

This function otherwise uses errors.New/errors.Annotatef (lines 3589, 3599, 3603) from github.com/pingcap/errors, which capture stack traces useful for debugging. The type-assertion failure at line 3577 uses fmt.Errorf, losing that context and breaking local consistency.

♻️ Proposed fix
-		return nil, fmt.Errorf("store %T does not implement helper.Storage", store)
+		return nil, errors.Errorf("store %T does not implement helper.Storage", store)

As per coding guidelines: "Go code: Follow existing package-local conventions first and keep style consistent with nearby files."

🤖 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/ddl/index.go` around lines 3574 - 3583, In collectTiKVStoreCapacity,
replace the fmt.Errorf used for the helper.Storage type-assertion failure with
the github.com/pingcap/errors package to match the surrounding error handling
style and preserve stack traces. Keep the existing behavior the same, but return
the error using the local errors convention already used in this function
(alongside errors.New and errors.Annotatef) so the failure is consistent and
debuggable.

Source: Coding guidelines

🤖 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/ddl/index.go`:
- Around line 3264-3266: The add-index flow only records TiKV capacity before
task submission, so the end-of-task snapshot is missing. Update the add-index
path around g.Wait() in the relevant reorg/add-index logic to call
w.logTiKVCapacityForAddIndexObservation again after the wait completes, ensuring
the final capacity state is captured for both success and failure cases.

---

Nitpick comments:
In `@pkg/ddl/index.go`:
- Around line 3574-3583: In collectTiKVStoreCapacity, replace the fmt.Errorf
used for the helper.Storage type-assertion failure with the
github.com/pingcap/errors package to match the surrounding error handling style
and preserve stack traces. Keep the existing behavior the same, but return the
error using the local errors convention already used in this function (alongside
errors.New and errors.Annotatef) so the failure is consistent and debuggable.
🪄 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: 104ae46b-f137-4f7b-92c7-ed4a972e227b

📥 Commits

Reviewing files that changed from the base of the PR and between 55fc6a9 and 90689d6.

📒 Files selected for processing (13)
  • pkg/ddl/backfilling_dist_executor.go
  • pkg/ddl/backfilling_import_cloud.go
  • pkg/ddl/backfilling_read_index.go
  • pkg/ddl/index.go
  • pkg/ddl/reorg_util_test.go
  • pkg/dxf/framework/taskexecutor/execute/interface.go
  • pkg/ingestor/ingestcli/client.go
  • pkg/ingestor/ingestcli/client_test.go
  • pkg/ingestor/ingestcli/interface.go
  • pkg/ingestor/ingestctrl/BUILD.bazel
  • pkg/ingestor/ingestctrl/job_worker.go
  • pkg/ingestor/ingestctrl/job_worker_test.go
  • pkg/ingestor/ingestctrl/region_job.go
💤 Files with no reviewable changes (1)
  • pkg/dxf/framework/taskexecutor/execute/interface.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/ddl/backfilling_dist_executor.go
🚧 Files skipped from review as they are similar to previous changes (10)
  • pkg/ingestor/ingestcli/client_test.go
  • pkg/ingestor/ingestctrl/BUILD.bazel
  • pkg/ingestor/ingestcli/interface.go
  • pkg/ingestor/ingestctrl/job_worker.go
  • pkg/ingestor/ingestcli/client.go
  • pkg/ingestor/ingestctrl/region_job.go
  • pkg/ddl/reorg_util_test.go
  • pkg/ingestor/ingestctrl/job_worker_test.go
  • pkg/ddl/backfilling_read_index.go
  • pkg/ddl/backfilling_import_cloud.go

Comment thread pkg/ddl/index.go
Comment on lines +3264 to +3266
if !reorgInfo.mergingTmpIdx {
w.logTiKVCapacityForAddIndexObservation(ctx, job.ID, taskKey)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Restore the end-of-task TiKV capacity snapshot. The current path only logs capacity before task submission; add the matching observation after g.Wait() so add-index still captures the end state on both success and failure.

🤖 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/ddl/index.go` around lines 3264 - 3266, The add-index flow only records
TiKV capacity before task submission, so the end-of-task snapshot is missing.
Update the add-index path around g.Wait() in the relevant reorg/add-index logic
to call w.logTiKVCapacityForAddIndexObservation again after the wait completes,
ensuring the final capacity state is captured for both success and failure
cases.

@expxiaoli expxiaoli force-pushed the tikv_precheck_PR_observe branch from 90689d6 to fa03b0f Compare July 7, 2026 12:25
@expxiaoli

Copy link
Copy Markdown
Contributor Author

/retest-required

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

Labels

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.

1 participant