Skip to content

server: honor scheduler concurrency for coordinator (#4832)#5396

Open
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-4832-to-release-8.5
Open

server: honor scheduler concurrency for coordinator (#4832)#5396
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-4832-to-release-8.5

Conversation

@ti-chi-bot

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #4832

What problem does this PR solve?

Issue Number: close #4831

What is changed and how it works?

The coordinator was constructed with hard-coded scheduling settings:

  • max task concurrency: 10000
  • balance interval: time.Minute

This bypassed Debug.Scheduler.MaxTaskConcurrency and Debug.Scheduler.CheckBalanceInterval. During bulk changefeed creation, the basic scheduler could therefore schedule a very large number of absent changefeeds at once, causing many maintainer bootstraps to run concurrently.

This PR reads the coordinator scheduler settings from the validated global server config before constructing the coordinator. With the default config, maintainer scheduling concurrency returns to 10, which reduces creation-time memory and CPU spikes by throttling concurrent bootstrap work.

Check List

Tests

  • Unit test
  • Manual test
go test ./server

Questions

Will it cause performance regression or break compatibility?

It should reduce CPU and memory spikes during bulk changefeed creation by honoring the existing scheduler concurrency config. It may make very large bulk creation finish more gradually compared with the previous hard-coded 10000 concurrency, but that behavior matches the intended configurable scheduler limit and can be tuned via server config.

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

No. This PR makes existing scheduler config effective for coordinator scheduling.

Release note

Fix TiCDC coordinator to honor scheduler max task concurrency when scheduling changefeed maintainers.

Summary by CodeRabbit

  • Chores

    • Election setup now accepts scheduler settings from server config, enabling configurable task concurrency and balance-check intervals.
  • Bug Fixes / Behavior Changes

    • Resume now uses latest persisted changefeed metadata from storage for validation and updates, avoiding stale in-memory overwrites.
    • Changefeed retrieval returns a safe copy to prevent races when callers mutate returned data.
  • Tests

    • Added tests covering scheduler settings capture, resume behavior with persisted metadata, and mutation/race safety of returned changefeed info.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Jun 15, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
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.

@ti-chi-bot

ti-chi-bot Bot commented Jun 15, 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 3aceshowhand 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 15, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 25b6826b-9f7e-43d9-9cea-0a88c80ed6cc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ 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.

@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 15, 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 improves changefeed resume validation by retrieving persisted metadata from the backend instead of using stale in-memory copies, and clones changefeed info in GetChangefeed to prevent concurrent mutation issues. It also captures scheduler settings from the server startup configuration. The review feedback highlights three potential nil pointer dereference panics: when overwriting cfInfo with the result of GetPersistedChangefeedInfo in ResumeChangefeed, when dereferencing info in EtcdBackend.GetChangefeedInfo, and when accessing schedulerCfg in coordinatorSchedulerSettings.

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 thread api/v2/changefeed.go
Comment on lines +751 to +755
cfInfo, err = co.GetPersistedChangefeedInfo(ctx, cfInfo.ChangefeedID)
if err != nil {
_ = c.Error(err)
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Overwriting cfInfo directly with the result of GetPersistedChangefeedInfo before checking if it is nil can lead to a nil pointer dereference panic later in the function (e.g., when accessing cfInfo.ChangefeedID or cfInfo.Config). Using a temporary variable to perform a nil check ensures safety.

	persistedInfo, err := co.GetPersistedChangefeedInfo(ctx, cfInfo.ChangefeedID)
	if err != nil {
		_ = c.Error(err)
		return
	}
	if persistedInfo == nil {
		_ = c.Error(errors.ErrChangeFeedNotExists.GenWithStackByArgs(cfInfo.ChangefeedID.Name()))
		return
	}
	cfInfo = persistedInfo

Comment on lines +129 to +132
info, err := b.etcdClient.GetChangeFeedInfo(ctx, id.DisplayName)
if err != nil {
return nil, errors.Trace(err)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

If b.etcdClient.GetChangeFeedInfo returns nil, nil (which can happen in certain error/mock scenarios), dereferencing info.ChangefeedID on line 136 will cause a nil pointer panic. Adding a defensive nil check right after retrieving the info prevents this.

Suggested change
info, err := b.etcdClient.GetChangeFeedInfo(ctx, id.DisplayName)
if err != nil {
return nil, errors.Trace(err)
}
info, err := b.etcdClient.GetChangeFeedInfo(ctx, id.DisplayName)
if err != nil {
return nil, errors.Trace(err)
}
if info == nil {
return nil, errors.Trace(cerror.ErrChangeFeedNotExists.GenWithStackByArgs(id.Name()))
}

Comment thread server/module_election.go
Comment on lines +200 to +202
func coordinatorSchedulerSettings(schedulerCfg *config.SchedulerConfig) (int, time.Duration) {
return schedulerCfg.MaxTaskConcurrency, time.Duration(schedulerCfg.CheckBalanceInterval)
}

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

If schedulerCfg is nil (which can happen during tests or if the configuration is partially initialized), accessing schedulerCfg.MaxTaskConcurrency will cause a panic. Adding a defensive nil check and returning the previous hardcoded defaults (10000 and time.Minute) as fallback values improves robustness.

func coordinatorSchedulerSettings(schedulerCfg *config.SchedulerConfig) (int, time.Duration) {
	if schedulerCfg == nil {
		return 10000, time.Minute
	}
	return schedulerCfg.MaxTaskConcurrency, time.Duration(schedulerCfg.CheckBalanceInterval)
}

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

Labels

do-not-merge/cherry-pick-not-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. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants