clientv3/concurrency: preserve leadership state on failed Resign - #22124
clientv3/concurrency: preserve leadership state on failed Resign#22124AkashKumar7902 wants to merge 1 commit into
Conversation
Previously, `Election.Resign` cleared its local leadership state even when the underlying delete transaction failed. This left the leader key in etcd, but made subsequent `Resign` calls no-ops. This prevented immediate retries and delayed leadership handoff until the lease expired. This change fixes the issue by: - Preserving `leaderKey` and `leaderSession` if the transaction returns an error. - Clearing the leadership state only after receiving a successful response. - Adding an integration test that cancels a resignation, verifies the key remains, retries, and confirms successful deletion. Retries remain safe because the existing create-revision comparison prevents the deletion of a newer leader key. There are no changes to the exported API. Fixes etcd-io#22123 Signed-off-by: Akash Kumar <meakash7902@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: AkashKumar7902 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @AkashKumar7902. Thanks for your PR. I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
Refs #22123.
What changed
Resignreturns a transaction error.Why
Election.Resignpreviously clearedleaderKeyandleaderSessioneven when the delete transaction returned an error. If the request never reached etcd, the server-side leader key remained while the client forgot how to remove it.The existing create-revision comparison makes a retry safe: it cannot delete a newer incarnation of the same key. A successful transaction response still retires the local state, including when the comparison does not match.
Impact
Callers can retry
Resignafter an RPC error. Successful resignation behavior and the exported API are unchanged.This is complementary to #21165 and distinct from #19598 and #21128. Those changes concern
Campaigncleanup or waiting-session expiration rather than errors returned byResignitself.Backport candidate:
release-3.7andrelease-3.6.Testing
mainbecause the failed call clearsElection.Key().cd tests && go test ./integration/clientv3/concurrency -run '^TestElectionResignCanRetryAfterError$' -count=20cd tests && go test ./integration/clientv3/concurrency -count=1cd tests && go test -race ./integration/clientv3/concurrency -run '^TestElectionResignCanRetryAfterError$' -count=1cd client/v3 && go test ./concurrency -count=1cd client/v3 && go vet ./concurrencymake verify-lintgit diff --checkThe aggregate
make verifycannot complete faithfully on this Darwin/arm64 host: the local BOM generator excludes the amd64-only Antithesis SDK and therefore differs from the checked-in Linux BOM. All non-BOM verify targets were run separately.