Skip to content

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

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

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

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-8.1 This PR is cherry-picked to release-8.1 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 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

@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 adjusting imports, making the health check function private, and improving the healthyChecker logic to explicitly close and remove stale clients. Feedback highlights two critical issues: the potential for an empty endpoint list to clear all cached clients and a logic error that could lead to a panic by accessing a client after it has been closed.

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 syncUrls fails (e.g., due to a transient network issue), it returns an empty slice. In this scenario, the update function will iterate over all existing clients in the healthyChecker and delete them because they are not present in the empty updateEps map. This wipes out all cached healthy clients and causes the main client to lose all its endpoints temporarily. It is safer to skip the update if the provided endpoint list is empty, as an etcd cluster should always have at least one voting member.

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

Comment thread pkg/etcd/client.go
Comment on lines 528 to 532
if time.Since(lastHealthy) > etcdServerOfflineTimeout {
log.Info("some etcd server maybe offline", zap.String("endpoint", ep))
client.Close()
checker.Delete(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.

high

When a client is identified as offline (exceeding etcdServerOfflineTimeout), it is closed and deleted from the checker. However, the code continues to the next if block which checks for etcdServerDisconnectedTimeout. Since the offline timeout is significantly larger than the disconnected timeout, this second block will also execute, calling SetEndpoints on the already closed client. This can lead to panics or unexpected behavior in the gRPC client. You should skip the disconnected check if the client was just deleted.

			if time.Since(lastHealthy) > etcdServerOfflineTimeout {
				log.Info("some etcd server maybe offline", zap.String("endpoint", ep))
				client.Close()
				checker.Delete(ep)
				continue
			}

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-8.1 This PR is cherry-picked to release-8.1 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants