Skip to content

logservice: add baseline scan task logs#5512

Open
hongyunyan wants to merge 1 commit into
pingcap:masterfrom
hongyunyan:codex/cdc-baseline-scan-task-logs
Open

logservice: add baseline scan task logs#5512
hongyunyan wants to merge 1 commit into
pingcap:masterfrom
hongyunyan:codex/cdc-baseline-scan-task-logs

Conversation

@hongyunyan

@hongyunyan hongyunyan commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: None

This PR provides a baseline-only build to verify whether an existing changefeed creates new incremental scan tasks while another old-start-ts changefeed is catching up. It is intentionally separate from the scan-priority implementation PR so the original behavior can be compared against the experiment.

What is changed and how it works?

  • Thread changefeedID into SubscriptionClient.Subscribe and store it in subscribedSpan for logging only.
  • Add changefeedID to the existing subscribes span done log.
  • Add a new cdc region scan task enqueued log when a region scan task is pushed into the logpuller region task queue.
  • The new scan-task log includes changefeedID, subscriptionID, tableID, startTs, regionID, region epoch, task priority (high or low), and span.
  • Use a fixed synthetic id for schema-store DDL subscriptions.

This PR does not change task priority calculation, retry behavior, kvproto fields, or TiKV/CSE request behavior.

Check List

Tests

  • Unit test
    • make fmt
    • go test ./logservice/logpuller ./logservice/eventstore ./logservice/schemastore -run '^$'

Questions

Will it cause performance regression or break compatibility?

No compatibility impact. The change is observability-only. The added log is intentionally used for baseline experiments and should not be enabled for high-volume production diagnosis without considering log volume.

Do you need to update user documentation, design documentation or monitoring documentation?

No.

Release note

None

Summary by CodeRabbit

  • Bug Fixes
    • Improved subscription handling so changefeed-specific identifiers are consistently passed through background processing.
    • Added clearer logging when region scan tasks are queued, making it easier to trace subscription activity and task priority.
    • Updated related test coverage to match the revised subscription flow.

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

ti-chi-bot Bot commented Jun 26, 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 charlescheung96 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 Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Subscription registration now passes changefeed ID strings into the log puller subscription client, which stores the identifier on subscribed spans and includes it in subscription and region-scan logs. Event-store and schema-store callers, plus related tests and mocks, were updated for the new Subscribe signature.

Changes

Changefeed ID propagation

Layer / File(s) Summary
Subscription client API and logging
logservice/logpuller/subscription_client.go, logservice/logpuller/subscription_client_test.go
The subscription client stores changefeed IDs on subscribed spans, accepts them in Subscribe, and logs them during subscription completion and region-scan enqueue events; the span-creation tests use the updated argument order.
Caller wiring and mocks
logservice/eventstore/event_store.go, logservice/eventstore/event_store_test.go, logservice/schemastore/ddl_job_fetcher.go, logservice/logpuller/subscription_client_test.go
RegisterDispatcher, ddlJobFetcher.run, the event-store mock, and one subscription-client test call site pass the new leading changefeed identifier into Subscribe.

Sequence Diagram(s)

sequenceDiagram
  participant eventStore
  participant subClient
  participant subscriptionClient
  participant newSubscribedSpan
  eventStore->>subClient: Subscribe(changefeedID.String(), subID, ...)
  subClient->>subscriptionClient: Subscribe(changefeedID, subID, span, ...)
  subscriptionClient->>newSubscribedSpan: newSubscribedSpan(changefeedID, subID, span, ...)
  newSubscribedSpan-->>subscriptionClient: subscribedSpan.changefeedID
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • asddongmen
  • tenfyzhong

Poem

_/\
(•ᴥ•) I hop with changefeed names alight,
/ >🥕 Through logs and spans, all set just right.
EventStore taps the client’s door,
And bunnies grin at tidy lore.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change, tests, questions, and release note, but the required issue reference is not linked as requested by the template. Replace 'Issue Number: None' with a valid linked issue line using close or ref, as required by the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding baseline scan task logs.
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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 26, 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 introduces changefeedID tracking across the event store and subscription client to improve traceability. It also adds logging for enqueued region scan tasks. The reviewer pointed out that logging these tasks at the Info level could cause severe log flooding and disk I/O bottlenecks in large-scale environments, and suggested changing the log level to Debug.

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.

Comment on lines +832 to +841
log.Info("cdc region scan task enqueued",
zap.String("changefeedID", region.subscribedSpan.changefeedID),
zap.Uint64("subscriptionID", uint64(region.subscribedSpan.subID)),
zap.Int64("tableID", region.subscribedSpan.span.TableID),
zap.Uint64("startTs", region.subscribedSpan.startTs),
zap.Uint64("regionID", region.verID.GetID()),
zap.Uint64("regionEpochVersion", region.verID.GetVer()),
zap.Uint64("regionEpochConfVer", region.verID.GetConfVer()),
zap.String("priority", taskTypeLogName(priority)),
zap.String("span", common.FormatTableSpan(&region.span)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Logging at Info level for every region scan task enqueued can lead to severe log flooding in large-scale production environments with hundreds of thousands of regions. This can cause significant disk I/O bottlenecks, high CPU overhead, and rapid disk space consumption.

Since this log is intended for baseline experiments and debugging, it should be logged at Debug level instead of Info level.

Suggested change
log.Info("cdc region scan task enqueued",
zap.String("changefeedID", region.subscribedSpan.changefeedID),
zap.Uint64("subscriptionID", uint64(region.subscribedSpan.subID)),
zap.Int64("tableID", region.subscribedSpan.span.TableID),
zap.Uint64("startTs", region.subscribedSpan.startTs),
zap.Uint64("regionID", region.verID.GetID()),
zap.Uint64("regionEpochVersion", region.verID.GetVer()),
zap.Uint64("regionEpochConfVer", region.verID.GetConfVer()),
zap.String("priority", taskTypeLogName(priority)),
zap.String("span", common.FormatTableSpan(&region.span)))
log.Debug("cdc region scan task enqueued",
zap.String("changefeedID", region.subscribedSpan.changefeedID),
zap.Uint64("subscriptionID", uint64(region.subscribedSpan.subID)),
zap.Int64("tableID", region.subscribedSpan.span.TableID),
zap.Uint64("startTs", region.subscribedSpan.startTs),
zap.Uint64("regionID", region.verID.GetID()),
zap.Uint64("regionEpochVersion", region.verID.GetVer()),
zap.Uint64("regionEpochConfVer", region.verID.GetConfVer()),
zap.String("priority", taskTypeLogName(priority)),
zap.String("span", common.FormatTableSpan(&region.span)))

@ti-chi-bot

ti-chi-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-linked-issue label, please provide the linked issue number on one line in the PR body, for example: Issue Number: close #123 or Issue Number: ref #456.

📖 For more info, you can check the "Contribute Code" section in the development guide.

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

Actionable comments posted: 1

🤖 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 `@logservice/logpuller/subscription_client.go`:
- Around line 832-841: The hot-path enqueue log in subscription_client.go should
not use Info for every region scan task because it creates high-volume,
high-cardinality noise on the success path. Update the logging around the region
enqueue code near the cdc region scan task message to use debug-level logging,
sampling, or an aggregated counter instead of unconditional Info, and keep the
existing context fields only if they are still needed at that lower verbosity.
Use the region enqueue logic and the log.Info call in the subscription client as
the place to make the change.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c4f7ae10-a91c-46cc-8e09-acb21fc7000b

📥 Commits

Reviewing files that changed from the base of the PR and between a0066dc and 45fc5b0.

📒 Files selected for processing (5)
  • logservice/eventstore/event_store.go
  • logservice/eventstore/event_store_test.go
  • logservice/logpuller/subscription_client.go
  • logservice/logpuller/subscription_client_test.go
  • logservice/schemastore/ddl_job_fetcher.go

Comment on lines +832 to +841
log.Info("cdc region scan task enqueued",
zap.String("changefeedID", region.subscribedSpan.changefeedID),
zap.Uint64("subscriptionID", uint64(region.subscribedSpan.subID)),
zap.Int64("tableID", region.subscribedSpan.span.TableID),
zap.Uint64("startTs", region.subscribedSpan.startTs),
zap.Uint64("regionID", region.verID.GetID()),
zap.Uint64("regionEpochVersion", region.verID.GetVer()),
zap.Uint64("regionEpochConfVer", region.verID.GetConfVer()),
zap.String("priority", taskTypeLogName(priority)),
zap.String("span", common.FormatTableSpan(&region.span)))

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.

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

Avoid Info logging on every region scan enqueue.

Line 832 is on the success path for every region task enqueue. A baseline scan can enqueue one task per region, and retries/splits can enqueue more, so this adds very high-volume Info logs with high-cardinality fields (changefeedID, regionID, span). That turns an observability-only change into a hot-path CPU/disk cost and can drown out more useful signals. Please gate this behind debug/sampling or aggregate it instead. As per coding guidelines, "Logs are operational signals; see docs/agents/logging.md before adding, removing, or rewriting logs."

🤖 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.go` around lines 832 - 841, The
hot-path enqueue log in subscription_client.go should not use Info for every
region scan task because it creates high-volume, high-cardinality noise on the
success path. Update the logging around the region enqueue code near the cdc
region scan task message to use debug-level logging, sampling, or an aggregated
counter instead of unconditional Info, and keep the existing context fields only
if they are still needed at that lower verbosity. Use the region enqueue logic
and the log.Info call in the subscription client as the place to make the
change.

Source: Coding guidelines

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

Labels

do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant