Skip to content

logpuller: send CDC scan priority#5480

Open
hongyunyan wants to merge 15 commits into
pingcap:masterfrom
hongyunyan:codex/cdc-scan-priority-end-to-end
Open

logpuller: send CDC scan priority#5480
hongyunyan wants to merge 15 commits into
pingcap:masterfrom
hongyunyan:codex/cdc-scan-priority-end-to-end

Conversation

@hongyunyan

@hongyunyan hongyunyan commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Background

TiCDC creates different kinds of log puller region tasks. Bootstrap scans for newly created changefeeds should not have the same downstream scan priority as repair or retry scans that affect existing changefeed lag.

Motivation

Propagating scan priority through ChangeDataRequest lets CSE protect high-priority CDC scans while scheduling new changefeed bootstrap scans as low priority.

Summary

  • Map log puller task types to cdcpb.ScanPriority.
  • Set ChangeDataRequest.ScanPriority when building CDC requests.
  • Preserve request priority across busy and congested retry paths.
  • Add focused tests for task priority mapping, request construction, and retry behavior.
  • Update github.com/pingcap/kvproto to the protocol branch pseudo-version.
  • Merge the latest master and preserve event store changefeed IDs when creating log puller subscriptions.

Dependencies

Validation

  • go mod tidy
  • make fmt
  • make cdc
  • NEXT_GEN=1 make cdc
  • go test ./logservice/eventstore ./logservice/logpuller
  • tools/bin/golangci-lint run --timeout 10m0s --new-from-rev=2258270f041a2267ede73126a033f889f4d51632

Summary by CodeRabbit

  • New Features
    • Added configuration option old-start-ts-scan-low-priority-threshold (default: 30m) to influence initial scan priority.
    • Introduced scan-priority mapping (high/low) with unknown priorities normalized to low, plus realtime scan priority that upgrades region/range work to high after the subscription catches up.
    • Updated dashboards to include additional scan scheduler queue/running/latency panels and descriptions.
  • Bug Fixes
    • Improved retry scheduling to preserve the original scan priority and use the correct priority source for retried work.
    • Enhanced warnings and subscription/dispatch logs with changefeed identifiers and priority context.
  • Tests
    • Added unit tests for scan-priority mappings, request priority behavior, and realtime retry upgrades.
  • Chores
    • Updated the kvproto dependency.

@ti-chi-bot

ti-chi-bot Bot commented Jun 23, 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 do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 23, 2026
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

This PR adds scan-priority scheduling in logpuller, threads changefeedID through subscription call paths, introduces a configurable old-start-ts threshold, and updates request creation, retry handling, tests, and Grafana dashboards to carry scan-priority metadata.

Changes

Scan Priority Scheduling and ChangefeedID Threading

Layer / File(s) Summary
Priority mapping and config
go.mod, logservice/logpuller/priority_task.go, logservice/logpuller/priority_task_test.go, pkg/config/debug.go, logservice/logpuller/region_state.go, logservice/logpuller/region_req_cache_test.go
Bumps kvproto, adds TaskTypecdcpb.ScanPriority helpers and tests, introduces the old-start-ts threshold config, and stores scan priority on region state.
Subscription client priority flow
logservice/logpuller/subscription_client.go, logservice/logpuller/region_event_handler.go
Adds changefeedID and realtime scan priority state, computes initial task priority, enables realtime priority after catch-up, and derives retry priority from prior scan priority.
Region request propagation
logservice/logpuller/region_request_worker.go, logservice/logpuller/region_request_worker_test.go
Carries normalized scan priority into outgoing region requests and updates the request builder test.
ChangefeedID call-site updates
logservice/eventstore/event_store.go, logservice/eventstore/event_store_test.go, logservice/schemastore/ddl_job_fetcher.go
Threads changefeedID through dispatcher registration and subscription call sites, updates the mock signature, and formats the DDL subscription name.
Scan-priority and call-path tests
logservice/logpuller/subscription_client_test.go
Updates existing tests for the new signatures and adds coverage for scan-priority mapping, retry preservation, initial priority selection, and realtime priority upgrades.
Grafana scan scheduler panels
metrics/grafana/ticdc_new_arch.json, metrics/nextgengrafana/ticdc_new_arch_next_gen.json
Adds CDC scan scheduler panels, descriptions, PromQL targets, and layout shifts in both dashboard JSON files.

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

Possibly related PRs

  • pingcap/ticdc#4507: Also updates the Grafana dashboard JSON layout and panel positioning.

Suggested reviewers: lidezhu, asddongmen

Sequence Diagram(s)

sequenceDiagram
  participant RegionEventHandler
  participant SubscriptionClient
  participant RegionRequestWorker
  participant cdcpb.ChangeDataRequest

  RegionEventHandler->>SubscriptionClient: maybeEnableRealtimeScanPriority(span, resolvedTs)
  SubscriptionClient->>SubscriptionClient: newSubscribedSpan(changefeedID, ...)
  SubscriptionClient->>SubscriptionClient: initial priority + effectiveScanTaskPriority
  SubscriptionClient->>RegionRequestWorker: scheduleRegionRequest / scheduleRangeRequest
  RegionRequestWorker->>cdcpb.ChangeDataRequest: createRegionRequest(ScanPriority)
  SubscriptionClient->>SubscriptionClient: doHandleError(retryPriority)
Loading

Poem

A rabbit hops where priorities glow,
High and low in a tidy row.
ChangefeedID jingles along the track,
Realtime wakes when scans come back.
🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change, but it does not follow the required template and is missing the issue number, checklist, questions, and release note. Add the required sections: What problem does this PR solve?, Issue Number, What is changed and how it works?, Tests, Questions, and Release note.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the main logpuller change to send scan priority.
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

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

❤️ Share

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

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 23, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the kvproto dependency and introduces support for preserving scan priority across retries when handling congested or busy server errors in logpuller. It adds mapping utilities between TaskType and cdcpb.ScanPriority, stores the scan priority in regionInfo, and ensures it is propagated and maintained during retries. Comprehensive unit tests are also added to verify these mappings and retry behaviors. I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@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 Jun 26, 2026
Signed-off-by: hongyunyan <649330952@qq.com>
@ti-chi-bot

ti-chi-bot Bot commented Jun 27, 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 nongfushanquan 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

Signed-off-by: hongyunyan <649330952@qq.com>
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 29, 2026
Signed-off-by: hongyunyan <649330952@qq.com>
Signed-off-by: hongyunyan <649330952@qq.com>
Signed-off-by: hongyunyan <649330952@qq.com>
@hongyunyan hongyunyan marked this pull request as ready for review July 7, 2026 06:46
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 7, 2026
@hongyunyan hongyunyan added release-note-none Denotes a PR that doesn't merit a release note. skip-issue-check Indicates that a PR no need to check linked issue. labels Jul 7, 2026
@ti-chi-bot ti-chi-bot Bot removed do-not-merge/needs-linked-issue do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 7, 2026

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
logservice/logpuller/subscription_client_test.go (1)

537-731: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Well-structured coverage of scan-priority behavior; minor duplication across new tests.

Assertions for TestInitialScanTaskPriority, TestSubscribeUsesInitialScanTaskPriority, TestRealtimeScanPriorityEnabledAfterSubscriptionCatchesUp, and the retry-upgrade tests all match the priority computation/upgrade logic shown in subscription_client.go (initialScanTaskPriority, maybeEnableRealtimeScanPriority, effectiveScanTaskPriority, doHandleError).

The rawSpan/subscribedSpan/regionInfo construction block (Lines 406-417, 480-491, 666-678, 695-707) is duplicated near-verbatim across four test functions. Consider extracting a small helper (e.g. newTestRegionWithScanPriority(t, subID, priority)) to reduce duplication and ease future maintenance.

🤖 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 `@logservice/logpuller/subscription_client_test.go` around lines 537 - 731, The
new scan-priority tests repeat the same raw span, subscribed span, and region
setup in several places, so factor that shared construction into a small helper
to keep the tests maintainable. Extract the repeated setup around
TestInitialScanTaskPriority, TestSubscribeUsesInitialScanTaskPriority,
TestRealtimeScanPriorityEnabledAfterSubscriptionCatchesUp, and the retry-upgrade
tests into a helper such as newTestRegionWithScanPriority or
newTestSubscribedSpan, then reuse it while keeping each test focused on its
specific priority assertion.
🤖 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 `@logservice/logpuller/subscription_client_test.go`:
- Around line 537-731: The new scan-priority tests repeat the same raw span,
subscribed span, and region setup in several places, so factor that shared
construction into a small helper to keep the tests maintainable. Extract the
repeated setup around TestInitialScanTaskPriority,
TestSubscribeUsesInitialScanTaskPriority,
TestRealtimeScanPriorityEnabledAfterSubscriptionCatchesUp, and the retry-upgrade
tests into a helper such as newTestRegionWithScanPriority or
newTestSubscribedSpan, then reuse it while keeping each test focused on its
specific priority assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d06ba2b-1f41-4995-9b2f-4421ea62b717

📥 Commits

Reviewing files that changed from the base of the PR and between 2258270 and 3a26268.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (14)
  • go.mod
  • logservice/eventstore/event_store.go
  • logservice/eventstore/event_store_test.go
  • logservice/logpuller/priority_task.go
  • logservice/logpuller/priority_task_test.go
  • logservice/logpuller/region_event_handler.go
  • logservice/logpuller/region_req_cache_test.go
  • logservice/logpuller/region_request_worker.go
  • logservice/logpuller/region_request_worker_test.go
  • logservice/logpuller/region_state.go
  • logservice/logpuller/subscription_client.go
  • logservice/logpuller/subscription_client_test.go
  • logservice/schemastore/ddl_job_fetcher.go
  • pkg/config/debug.go

Signed-off-by: hongyunyan <649330952@qq.com>
Signed-off-by: hongyunyan <649330952@qq.com>
Signed-off-by: hongyunyan <649330952@qq.com>
Signed-off-by: hongyunyan <649330952@qq.com>
Signed-off-by: hongyunyan <649330952@qq.com>

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
metrics/grafana/ticdc_new_arch.json (1)

22661-22745: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor: count-panel Y-axis format inconsistent with similar panels.

Queue Length and Running panels use "format": "none" for the count axis, whereas a similar counter panel ("Unresolved Region Request Count") uses "format": "short". Purely cosmetic.

Also applies to: 22746-22851

🤖 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 `@metrics/grafana/ticdc_new_arch.json` around lines 22661 - 22745, The count
panel’s Y-axis formatting is inconsistent with the similar counter panel; in the
Grafana panel definition for CDC Scan Scheduler Queue Length (and the matching
panel referenced by the review), update the first yaxes entry to use the same
count format as the “Unresolved Region Request Count” panel. Keep the change
limited to the panel JSON around the graph configuration so the axis formatting
is consistent across these related panels.
🤖 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 `@metrics/grafana/ticdc_new_arch.json`:
- Around line 22661-22745: The count panel’s Y-axis formatting is inconsistent
with the similar counter panel; in the Grafana panel definition for CDC Scan
Scheduler Queue Length (and the matching panel referenced by the review), update
the first yaxes entry to use the same count format as the “Unresolved Region
Request Count” panel. Keep the change limited to the panel JSON around the graph
configuration so the axis formatting is consistent across these related panels.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 74ff9c3c-9edc-4e41-9170-adba50fb17c8

📥 Commits

Reviewing files that changed from the base of the PR and between ab05078 and 0d7ab0b.

📒 Files selected for processing (4)
  • logservice/logpuller/region_request_worker.go
  • logservice/logpuller/region_request_worker_test.go
  • metrics/grafana/ticdc_new_arch.json
  • metrics/nextgengrafana/ticdc_new_arch_next_gen.json
💤 Files with no reviewable changes (2)
  • logservice/logpuller/region_request_worker_test.go
  • logservice/logpuller/region_request_worker.go

Signed-off-by: hongyunyan <649330952@qq.com>
Signed-off-by: hongyunyan <649330952@qq.com>
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. skip-issue-check Indicates that a PR no need to check linked issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant