[client] Recover admin writes after coordinator leader failover - #4216
Open
litiliu wants to merge 1 commit into
Open
[client] Recover admin writes after coordinator leader failover#4216litiliu wants to merge 1 commit into
litiliu wants to merge 1 commit into
Conversation
A long-lived Admin client caches the coordinator leader. After failover to a standby, coordinator write operations (dropDatabase, etc.) kept failing with NotCoordinatorLeaderException because: 1. FlussAdmin wrapped only the read-only gateway with retry, so the write gateway never refreshed metadata after a failover. 2. Even after refreshing to the new leader's address, NettyClient reused the stale connection cached under the coordinator uid "cs-0" (both coordinators share id 0), so requests kept hitting the old leader that is still alive as a standby. Fixes: - RetryableGatewayClientProxy now takes separate refresh and retry predicates. The write gateway refreshes metadata on any recoverable error (NotCoordinatorLeaderException or network errors after a failover/upgrade) so the stale coordinator connection is repointed and a manual retry can recover, but auto-retries only NotCoordinatorLeaderException -- which the server rejects before invoking the write API, so a retry cannot duplicate an already-executed, non-idempotent mutation. Read-only gateways keep retrying any RetriableException. - NettyClient recreates the connection when the address for a server uid changes, closing the stale connection. Tests: - RetryableGatewayClientProxyTest: retry on the safe error; refresh-but-no-retry on network errors; no refresh/retry when neither predicate matches. - NettyClientTest: reconnect when a uid's address changes. - CoordinatorFailoverAdminITCase: keeps one Admin open across a coordinator leader failover and verifies a write succeeds afterward. Closes apache#4027
Contributor
Author
|
@loserwang1024 Could you take a look on this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Linked issue: close #4027
A long-lived Java
Adminclient caches the coordinator leader inMetadataUpdater. After coordinator leadership moves to a standby, coordinator write operations (e.g.dropDatabase,createTable,alterTable) keep being sent to the old coordinator and fail withNotCoordinatorLeaderExceptionuntil the connection is recreated.Two root causes:
FlussAdminwrapped only the read-only gateway withRetryableGatewayClientProxy; the write gateway never refreshed metadata after a failover.NettyClientreused the connection cached under the coordinator uidcs-0(both coordinators share id0), so requests kept hitting the old leader that is still alive as a standby.This is an alternative implementation of #4200 and incorporates @loserwang1024's review feedback there: refresh metadata on any recoverable error, but auto-retry only the provably-safe
NotCoordinatorLeaderException.Brief change log
RetryableGatewayClientProxynow takes separaterefreshPredicateandretryPredicate. On failure it refreshes metadata whenrefreshPredicatematches, and additionally retries once only whenretryPredicatematches. Read-only gateways keep usingRetriableExceptionfor both (unchanged behavior).FlussAdminwrite gateway:refreshPredicate=NotCoordinatorLeaderException || RetriableException— refreshes metadata on any recoverable error, includingNetworkException/TimeoutExceptionwhen the old coordinator's IP is not reused after an upgrade.retryPredicate=NotCoordinatorLeaderExceptiononly — safe to auto-retry becauseFlussRequestHandlerrejects the request before invoking the write API, so the mutation was never executed. Network/timeout failures refresh metadata but surface the original error for a manual retry (non-idempotent-safe).NettyClientrecreates the connection when the address behind a server uid changes (a coordinator failover reusescs-0at a new host/port) and closes the stale connection.Tests
Run:
./mvnw -pl fluss-rpc,fluss-client -am -Dtest=RetryableGatewayClientProxyTest,NettyClientTest,CoordinatorFailoverAdminITCase -DfailIfNoSpecifiedTests=false testRetryableGatewayClientProxyTest: retry on the safe error; refresh-but-no-retry on network errors; no refresh/retry when neither predicate matches.NettyClientTest#testReconnectWhenServerAddressChangesForSameUid: a same-uid address change reconnects instead of reusing the stale connection.CoordinatorFailoverAdminITCase#testAdminWriteRecoversAfterCoordinatorFailover: keeps oneAdminopen across a coordinator leader failover and verifiesdropDatabasesucceeds afterward.API and Format
No public API or storage format changes.
RetryableGatewayClientProxy(@Internal) gains a two-predicate factory overload; the existing signature is preserved.Documentation
No. Bug fix; no user-facing feature or documentation change.
Generative AI disclosure: Yes — GitHub Copilot (Claude Opus 4.8) was used to help author this PR.