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
|
@loserwang1024 Could you take a look on this? |
|
@litiliu, I'm working on #4256 in #4263 and noticed that #4216 explicitly intends the NettyClient address-change handling to cover TabletServer rolling upgrades as well. The two PRs therefore overlap on the same transport behavior but use different policies: #4216 replaces and closes the connection for a UID, while #4263 keys physical connections by UID + host + port. I'd like to avoid competing fixes. Would you be open to coordinating on which direction should land? I'm happy to adapt #4263 or move its deterministic regression coverage to the preferred implementation. |
|
@BackendArchitectX Thanks for pointing this out. After comparing the two approaches, I agree that keying physical connections by UID + host + port is cleaner at the transport layer. NettyClient receives a complete ServerNode and should not need to decide which endpoint is newer. It also avoids concurrent requests based on old and new metadata repeatedly replacing each other’s connections. Unused old connections will eventually be cleaned up by the configured idle timeout. |
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.