Skip to content

etcd(ticdc): update etcd cluster member correctly (#12646)#12649

Open
ti-chi-bot wants to merge 6 commits into
pingcap:release-7.5from
ti-chi-bot:cherry-pick-12646-to-release-7.5
Open

etcd(ticdc): update etcd cluster member correctly (#12646)#12649
ti-chi-bot wants to merge 6 commits into
pingcap:release-7.5from
ti-chi-bot:cherry-pick-12646-to-release-7.5

Conversation

@ti-chi-bot

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #12646

What problem does this PR solve?

Issue Number: close #12368

What is changed and how it works?

When updating etcd client URLs, remove the client that is not a member of the etcd cluster.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
tiup playground $VERSION --db 1 --kv 1 --pd 3 --ticdc 1 --tiflash 0 --without-monitor
tiup cdc:$VERSION cli changefeed create --sink-uri 'blackhole://'
tiup playground scale-out --pd 1
tiup playground display
tiup playground scale-in --pid 153389 # pick any one from the display

Print only once

[2026/05/21 10:03:39.588 +00:00] [INFO] [client.go:447] ["update endpoints"] [numChange=3->4] [lastEndpoints="[http://127.0.0.1:2382,http://127.0.0.1:2379,http://127.0.0.1:2384]"] [endpoints="[http://127.0.0.1:44765,http://127.0.0.1:2382,http://127.0.0.1:2384,http://127.0.0.1:2379]"]

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Fixed the bug of using an incorrect etcd client when scaling PD nodes

wk989898 and others added 6 commits May 25, 2026 05:01
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
@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/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR. labels May 25, 2026
@ti-chi-bot

ti-chi-bot Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

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 May 25, 2026

Copy link
Copy Markdown
Contributor

[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 holys 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

@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 etcd client by making the health check function private, removing the AutoSyncInterval configuration, and refining the healthyChecker to properly close and remove stale or offline clients. Feedback identifies a risk where an empty endpoint list could lead to the deletion of all healthy clients, suggesting an early return to preserve state. Additionally, it was noted that the timeout logic should use an else-if structure to prevent performing operations on clients that have already been closed and deleted.

Comment thread pkg/etcd/client.go
}

func (checker *healthyChecker) update(eps []string) {
updateEps := make(map[string]struct{}, len(eps))

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 eps is empty (which occurs if syncUrls fails to list members), this function will proceed to iterate over all existing clients in the checker and delete them because they won't be present in the empty updateEps map. This can lead to a complete loss of the healthy checker state due to transient etcd errors. Since an etcd cluster used by TiCDC should always have members, it is safer to return early if no endpoints are provided to preserve the current state.

	if len(eps) == 0 {
		return
	}
	updateEps := make(map[string]struct{}, len(eps))

Comment thread pkg/etcd/client.go
Comment on lines 520 to 529
if time.Since(lastHealthy) > etcdServerOfflineTimeout {
log.Info("some etcd server maybe offline", zap.String("endpoint", ep))
client.Close()
checker.Delete(ep)
}
if time.Since(lastHealthy) > etcdServerDisconnectedTimeout {
// try to reset client endpoint to trigger reconnect
client.(*healthyClient).Client.SetEndpoints([]string{}...)
client.(*healthyClient).Client.SetEndpoints(ep)
client.Client.SetEndpoints([]string{}...)
client.Client.SetEndpoints(ep)
}

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

The second if condition for etcdServerDisconnectedTimeout (1m) will always be true if the first if for etcdServerOfflineTimeout (30m) is met. This results in calling SetEndpoints on a client that has already been closed and deleted from the checker. Using an else if ensures that these operations are mutually exclusive and avoids unnecessary operations on a closed client.

			if time.Since(lastHealthy) > etcdServerOfflineTimeout {
				log.Info("some etcd server maybe offline", zap.String("endpoint", ep))
				client.Close()
				checker.Delete(ep)
			} else if time.Since(lastHealthy) > etcdServerDisconnectedTimeout {
				// try to reset client endpoint to trigger reconnect
				client.Client.SetEndpoints([]string{}...)
				client.Client.SetEndpoints(ep)
			}

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/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants