GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@poorbarcode poorbarcode commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
poorbarcode added 3 commits November 11, 2026 20:48
@poorbarcode
[fix][broker] Require the elected transaction coordinator for v5 hand…
c06d4ed
…shakes

Assisted-by: OpenAI Codex
@poorbarcode
[fix][broker] Verify v5 coordinator leadership in the current metadat…
f24d6ee
…a session

Assisted-by: OpenAI Codex
@poorbarcode
[fix][metadata] Retry leader election revalidation after transient fa…
3f44907
…ilures

Assisted-by: OpenAI Codex
@poorbarcode poorbarcode added ready-to-test release/4.2.6 release/4.0.15 release/5.0.2 labels Nov 11, 2026
@poorbarcode poorbarcode self-assigned this Nov 11, 2026
codelipenghui
codelipenghui reviewed Nov 11, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@lhotari

lhotari commented Nov 11, 2026

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lhotari
lhotari reviewed Nov 11, 2026
View reviewed changes
Comment thread ...data/src/main/java/org/apache/pulsar/metadata/coordination/impl/CoordinationServiceImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@poorbarcode
[fix][broker] Verify v5 handshake ownership directly in the metadata …
cc3bed8
…store

Assisted-by: OpenAI Codex
@poorbarcode poorbarcode mentioned this pull request Nov 12, 2026
[fix][meta] Retry failed leader election session revalidation #27593
Merged
10 tasks
@poorbarcode poorbarcode removed release/4.2.6 release/4.0.15 labels Nov 12, 2026
@poorbarcode

poorbarcode commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@poorbarcode
poorbarcode requested review from codelipenghui and lhotari November 12, 2026 02:46
@poorbarcode poorbarcode added this to the 5.1.0 milestone Nov 12, 2026
codelipenghui
codelipenghui approved these changes Nov 12, 2026
View reviewed changes
@poorbarcode
poorbarcode merged commit 26c33db into apache:master Nov 12, 2026
44 checks passed

Uh oh!

There was an error while loading. Please reload this page.

poorbarcode added a commit that referenced this pull request Nov 12, 2026
@poorbarcode
[fix][broker] Accept v5 transaction coordinator handshakes only on th…
4d68343
…e elected leader (#27580)

(cherry picked from commit 26c33db)
@poorbarcode poorbarcode added the cherry-picked/branch-5.0 label Nov 12, 2026
codelipenghui added a commit to codelipenghui/incubator-pulsar that referenced this pull request Nov 23, 2026
@codelipenghui @claude
Merge remote-tracking branch 'apache/master' into penghui/fix-tc-assi…
6f3de9c
…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]>
@codelipenghui codelipenghui mentioned this pull request Nov 24, 2026
[Bug][client] V5 transaction coordinator discovery: listener-aware leader URLs and watch connection handling #27739
Open
3 tasks done
@lhotari lhotari mentioned this pull request Nov 25, 2026
[fix][client] Distinguish direct TC discovery from proxy pairing #27387
Merged
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes
@lhotari lhotari Awaiting requested review from lhotari

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@poorbarcode poorbarcode

Labels

cherry-picked/branch-5.0 ready-to-test release/5.0.2

Projects

None yet

Milestone

5.1.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@poorbarcode @lhotari @codelipenghui
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.