GeezerVison is showing github.com — [fix][broker] Accept v5 transaction coordinator handshakes only on the elected leader by poorbarcode · Pull Request #27580 · apache/pulsar
Conversation
poorbarcode
commented
Nov 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Background
In a three-broker test, the broker that owned the legacy coordinator assignment bundle accepted a v5 handshake for a partition led by another broker. During failover, a former leader can also still report Leading locally after another broker acquires the election node.
Motivation
A successful v5 handshake should tell the client that it reached the elected coordinator. #25929 introduced metadata-store elections and assignment watches for v5, and #25945 routed v4 and v5 requests to their respective coordinators. A client using a stale assignment needs a retryable error so it can reconnect. #27378 addresses the related client-side handling of transient failures. #27593 tracks the shared election's revalidation retry separately.
Modifications
- For v5, check the partition range, local election state and metadata session, then read the partition's election node directly. Accept the handshake only if the node belongs to this session and the broker still leads the partition. Compare the broker's session-loss counter before and after the read so a delayed response from an expired session cannot authorize the connection.
- Return
TransactionCoordinatorNotFound if the node is missing, the read fails, the session changes, or the coordinator closes. V4 handshakes continue to use assign-topic ownership.
- All 31 targeted broker tests and the repository-wide
quickCheck passed locally. The tests cover v4 and v5 on different owners, takeover with stale local leadership, a handshake read spanning session expiry, closure during the read, and accepting the current lock owner after the election's own revalidation failed. The failover tests used simulated ZooKeeper sessions. Actual Oxia failover remains untested.
Does this pull request potentially affect one of the following parts:
- Dependencies (add or upgrade a dependency)
- The public API
- The schema
- The default values of configurations
- The threading model
- The binary protocol — a v5 handshake on a broker that cannot confirm ownership receives the existing
TransactionCoordinatorNotFound error. The command and response formats stay the same.
- The REST endpoints
- The admin CLI options
- The metrics
- Anything that affects deployment
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…shakes
Assisted-by: OpenAI Codex
…a session
Assisted-by: OpenAI Codex
…ilures
Assisted-by: OpenAI Codex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tracking this down. The problem is real: the old 'handleClientConnect' fell back to assign-topic bundle ownership, which v5 clients never need (they only send 'scalable=true' via 'WatchTcAssignmentsDiscovery'). 'isLeaderFor()' can also report 'Leading' after a session expiry until revalidation finishes.
I think the fix can stay inside 'TransactionCoordinatorV5', without the new 'LeaderElection#isLeaderInCurrentSession()' API or the session token in 'CoordinationServiceImpl'. The handshake happens once per connection, and NEW_TXN/END_TXN rely on metadata CAS anyway, so it can ask the store directly:
- reject if the TC is closed, the id is out of range, '!isLeaderFor(p)' or 'isMetadataSessionLost()';
- read 'TxnPaths.tcLeaderPath(p)' and accept only if the node exists and 'isCreatedBySelf()' is true, the session is still not lost, and 'getMetadataSessionLossCount()' hasn't changed;
- if the read fails, return 'CoordinatorNotFound'.
That's about 20 lines and leaves pulsar-metadata alone.
I tried this on your head commit with the pulsar-metadata changes reverted. I kept your 'TransactionCoordinatorV5Test' and 'TransactionMetaStoreAssignmentTest' changes. I adapted 'TransactionCoordinatorV5SessionTest' to check four cases:
- a stale former leader whose election still says 'Leading' is rejected;
- a broker whose revalidation failed but which owns the node is accepted;
- a read that spans a session loss is rejected;
- a failed read is rejected.
The focused v5 TC tests pass (27), and so does 'TransactionMetaStoreAssignmentTest' (3, including 'testScalableHandshakeRequiresElectedLeader'). 'quickCheck' passes for both modules. Oxia failover is still untested.
The failed-revalidation retry looks like a real bug in master: the election stays in 'ElectionInProgress' with no retry until the next session event. It also affects the broker leader election and the ELM channel owner, so I'd send it as a separate pulsar-metadata PR.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Since this PR contains release/4.0.15 and release/4.2.6 labels, is the intention to backport the LeaderElection* related changes to maintenance branches? Would it make sense to split this PR into 2 PRs? That would make backporting easier to manage.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…store
Assisted-by: OpenAI Codex
|
@codelipenghui I switched the v5 handshake to read the election node directly. It verifies ownership and checks the broker's session-loss counter again when the read completes. The failover tests confirm that the former leader rejects the connection even while it still reports Leading, and the current lock owner can accept a new connection after its election revalidation failed. All 31 targeted broker tests passed locally, including the v4 handshake on the assignment-bundle owner.
@lhotari I split the shared election retry into #27593 so it can be backported independently to 4.0, 4.2 and 5.0. I removed the two 4.x release labels from this PR because those branches have no v5 coordinator. This PR now targets 5.0 for backport.
|
lhotari reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
codelipenghui
added a commit
to codelipenghui/incubator-pulsar
that referenced
this pull request
Nov 23, 2026
…gnment-watch-20261105
Resolve the import conflict in TransactionCoordinatorV5Test with apache#27580, which removed the
BrokerService mock from the test.
Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewers
lhotari
Awaiting requested review from lhotari
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully 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.
|