GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — [improve][broker] PIP-473 P5.3: metadata-store TC leader election + assignment watch by merlimat · Pull Request #25929 · apache/pulsar Conversation
Contributor
MotivationThe scalable-topics transaction coordinator (PIP-473) so far reused the This PR makes the scalable-topics TC's leader election depend on the metadata store only, and replaces the topic-lookup-based discovery with a dedicated assignment watch. The coordinator now rests directly on the metadata store it already hard-depends on for every header read/write, instead of on a layer above it.
ModificationsBroker election
Discovery (new wire commands)
Client
Backward compatibilityPurely additive on the wire. The assign-topic remains the v4 / fallback discovery surface during the deprecation window:
Defaults are unchanged — the scalable-topics TC stays off; the default flip lands in P5.4. Tests
Scope note: the integration tests exercise the transaction lifecycle (newTransaction / commit / abort) over the discovered connections — the full surface the new client discovery path drives. A data-in-transaction e2e (produce/ack inside a txn) additionally needs the scalable-topic buffer + pending-ack providers and
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…ssignment watch Motivation: the scalable-topics transaction coordinator (PIP-473) reused the transaction_coordinator_assign topic for both leader election and client discovery, tying TC coordination liveness to the topic/bundle/load-balancer machinery even though the TC keeps no state in that topic. This makes election depend only on the metadata store. Modifications: - Broker election: per-partition LeaderElection over /txn/tc/leader/<N> via the existing CoordinationService; a degree-of-parallelism config (transactionCoordinatorScalableTopicsParallelism, default 16) replaces the assign-topic partition count. TransactionCoordinatorV5.isLeaderFor(int) now gates both client-connect and the timeout/GC sweeps. - Discovery: new CommandWatchTcAssignments / ...Update / ...Close wire commands. The client opens one watch and the broker pushes the full partition->leader snapshot, re-pushing it on any leadership change (no point lookup, no diff/ hash — the map is small and changes rarely). Gated by a new supports_tc_metadata_discovery feature flag. - Client: TcDiscovery strategy selects WatchTcAssignmentsDiscovery (new path) when the broker advertises the flag, else the existing assign-topic flow (still the v4 path). Handlers connect directly to each coordinator's elected leader and retarget when a snapshot moves leadership. - Tests: TransactionCoordinatorV5Test election/leadership coverage; Commands round-trip; multi-broker docker integration test (TcMetadataDiscoveryTest) covering the transaction lifecycle over the watch and survival of a leader broker failure. The assign-topic remains in place as the v4 / fallback discovery surface during the deprecation window; defaults are unchanged (flip lands in P5.4). startAsync() probed the broker's supports_tc_metadata_discovery flag via getConnectionToServiceUrl(), which throws InvalidServiceURL for http:// service URLs (it requires binary-proto lookup). That broke every transaction client configured with an HTTP service URL — the prior code used getPartitionedTopicMetadata(), which works over both HTTP and binary. selectDiscovery() now short-circuits to the assign-topic flow when the lookup service isn't binary-proto (HTTP URL), since the metadata-store assignment watch needs a binary connection anyway. Only probe the feature flag when binary lookup is available. …n in tests Two follow-up fixes after the discovery refactor: - selectDiscovery() now falls back to the assign-topic flow if the feature-flag probe connection fails. Fixes testClientStartWithRetry, which uses a multi-host service URL with a deliberately-bad endpoint: the single probe connection has no cross-host retry, whereas the assign-topic lookup does. Falling back is always safe (the assign topic still works against v5 brokers during the deprecation window). - The handler array moved from TransactionCoordinatorClientImpl into the TcDiscovery strategies, which broke tests reflecting on the private "handlers" field. Add TcDiscovery.handlers() + a @VisibleForTesting TransactionCoordinatorClientImpl.getHandlers() accessor and switch TransactionClientConnectTest to it (no reflection into private state, per the repo testing guideline). …REFIX_ The scalable-topics TC settings were passed as bare env vars, but apply-config-from-env.py only applies bare names to keys already present in broker.conf. transactionCoordinatorScalableTopicsEnabled / ...Parallelism aren't in broker.conf, so they were silently ignored: the v5 TC never started and the cluster ran 16 legacy assign-topic coordinators (assertion saw 16, expected 4). Prefix both new keys with PULSAR_PREFIX_ so they're appended as new config. transactionCoordinatorEnabled stays bare (it is in broker.conf). Also make the lifecycle assertion await-based: at startup a partition can be briefly mid-election and absent from the first assignment snapshot, so loop until every coordinator has minted a txn rather than assuming a fixed count.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
lhotari
approved these changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, however please check the local Claude Code review findings about the possible bugs.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsFixes from lhotari's review on apache#25929: - Snapshot completeness (BUG): buildAssignmentsSnapshot now uses the async LeaderElection.getLeaderValue() (loads from the metadata store on a cache miss) instead of the cache-only getLeaderValueIfPresent(), so a follower that just transitioned for a partition doesn't omit it from the snapshot. ServerCnx schedules a short re-push when a snapshot is incomplete (a partition still mid-election) or fails to build, so the client converges without an external trigger. - Client watch recovery (BUG): WatchTcAssignmentsDiscovery now reconnects on every post-initial death path — a reconnected broker lacking the feature flag, and post-initial onError (ClientCnx has already removed the session, so nothing else recovers it). Previously these froze the watch on a stale snapshot. - Initial-open retry (BUG): the initial watch open retries retryable failures up to the lookup deadline instead of hard-failing transaction-client startup (the probe and the watch can land on different brokers). - TLS-only URL (NPE): HandlerState.setRedirectedClusterURI throws a clear URISyntaxException instead of new URI(null) NPE when no usable URL is selected; onSnapshot isolates per-partition failures so one bad leader URL can't tear down the watch. - Parallelism (config): minValue=1; the value is persisted cluster-wide at /txn/tc/parallelism on first start and every broker fails fast on mismatch. Documented the fixed-at-bring-up constraint (incl. aborted-txn retention). - Integration test now asserts the metadata-discovery path was actually selected, so a watch-path regression can't pass via the silent assign-topic fallback. - handlers() reads the field into a local to avoid a concurrent-close NPE.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. …oker-paired connection The integration test's new assertion (isUsingMetadataDiscovery) caught that a client connecting through the proxy fell back to assign-topic discovery: - The proxy's handleBrokerConnected forwarded only supportsTopicWatchers and supportsScalableTopics from the broker's CONNECTED, dropping the new supportsTcMetadataDiscovery flag. Forward it too. - selectDiscovery() probed getConnectionToServiceUrl(), which through a proxy returns the proxy's lookup-handshake CONNECTED (no broker flags) rather than a broker's. Probe getAnyBrokerProxyConnection() instead — it pairs to an actual broker (the same connection the watch uses), so the forwarded feature flags reflect the broker. On failure it still falls back to assign-topic, so multi-host / transient cases are safe. …proxied The watch-mode TransactionMetaStoreHandler connected directly to each leader's advertised broker URL, which is unreachable when the client talks through a proxy (the leader address isn't a proxiable target on its own) — causing newTransaction to time out with "connection: null". Mirror the scalable-topics client's proven pattern: the watch connection reports whether it's proxied (ClientCnx.isProxied()); when it is, dial the leader through the proxy (logical=leader, physical=proxy) via the new ConnectionHandler.grabCnx(uri, useProxy), otherwise connect directly. The handler now holds (leaderUri, useProxy), reconnects to the leader on connection loss (passing the leader URI rather than falling back to the service URL), and WatchTcAssignmentsDiscovery derives useProxy from the watch connection and selects the TLS/plaintext leader URL. …ver IT robust Verified locally against a built docker image (2-broker + proxy cluster), two consecutive green runs of TcMetadataDiscoveryTest (lifecycle + failover). - ConnectionHandler.reconnectLater() called the no-arg grabCnx() on a failed connection attempt, falling back to the service URL instead of re-dialling the intended broker. For v5 TC metadata-store discovery the per-coordinator handler must keep targeting its elected leader, so remember the explicit target (explicitHostURI, set by grabCnx(uri,useProxy) and connectionClosed(...hostUrl)) and reuse it on the error-retry path. - The integration test's runTxnOnEveryCoordinator spun a tight no-wait retry loop and threw the moment a coordinator's handler was still connecting (handlers connect asynchronously; after a failover one is briefly mid-reconnect). Replace it with a bounded Awaitility wait that ignores transient MetaStoreHandlerNotReady/timeout — the assertion is "every coordinator becomes reachable", not "on the first attempt". The failover case now relies on this shared wait instead of a second nested await. Uh oh!
There was an error while loading. Please reload this page.
lhotari
reviewed
Comment on lines
+208
to
+213
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just wondering what happens when the target broker goes down? does the retry loop exit?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
3 tasks done
1 task done
1 of 10 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. | |||||||||||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |