Repository navigation
[fix][meta] Don't lose SessionReestablished when a listener invalidates the new session - #26861
Merged
Merged
Conversation
…es the new session ZKSessionWatcher.checkState overwrote the status that a listener set while it was notified: when ZKMetadataStore failed to recreate its persistent watch on SessionReestablished and marked the session invalid, checkState set SessionReestablished again after the listeners returned, so the next session sent nothing and the lock managers never revalidated their locks. - checkState sets the status before notifying the listeners and decides from the previous status whether to send SessionReestablished, so a status set during the notification stays in effect. - ZKMetadataStore marks a PulsarZooKeeperClient's session replaced, by its session id, so that the replaced session's own events don't reestablish it before the next session connects. - checkState ignores Closed events, which come from a closed ZooKeeper handle and say nothing about the current handle's connection. Fixes #26860 Assisted-by: Claude Code (claude-opus-5-5)
11 tasks
This was referenced Oct 12, 2026
merlimat
approved these changes
Oct 12, 2026
4 of 5 tasks
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Nov 16, 2026
…es the new session (apache#26861) (cherry picked from commit cc346d2)
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.
Fixes #26860
Motivation
When a broker's ZooKeeper session is lost and a new one is established,
ZKSessionWatchersendsReconnectedandSessionReestablished.ZKMetadataStorerecreates its persistent watch before it forwardsSessionReestablishedto the other listeners, such asLockManagerImpl, which revalidates the broker's locks, its bundle ownerships among them. When recreating the watch fails, the store marks the session invalid withZKSessionWatcher.setSessionInvalid()and makesPulsarZooKeeperClientreplace the session, so that the next session sendsSessionReestablishedagain.When the watch fails while
ZKSessionWatcher.checkStateis still notifying the listeners, on the same thread,checkStateoverwrites the invalid status withSessionReestablishedafter the listeners return. The replaced handle'sClosedevent and the new session'sSyncConnectedthen send nothing, and the lock managers never getSessionReestablished.In a run of
network/metadata-takeoverwith the network conditions of the Pulsar Performance Testing Framework (#26859), this left a broker whose session had expired with bundle ownerships that another broker had taken over: both brokers served the bundles' topics and fenced each other's ledgers, and about 16,000 sends were never acknowledged. #26860 has the broker's log.Modifications
ZKSessionWatcher.checkStatesets the status toSessionReestablishedbefore notifying the listeners, and decides whether to sendSessionReestablishedfrom the previous status. A status that a listener sets during the notification stays in effect.SessionReestablishedis sent even if notifyingReconnectedthrows.ZKMetadataStore, when it fails to recreate its watch on aPulsarZooKeeperClient, marks the session replaced with the newZKSessionWatcher.setSessionReplaced(), which records the session's id. Until another session connects, the replaced session's own events, such as a periodic connection check that still succeeds beforePulsarZooKeeperClientcloses it, don't reestablish it: otherwise the new session'sSyncConnectedwould find the statusSessionReestablishedalready and send nothing, the same loss. With another ZooKeeper client, which isn't replaced, the store marks the session invalid as before, so that the next connection of the same session sendsSessionReestablishedand the store tries the watch again.checkStateignoresClosedevents. AClosedevent comes from a ZooKeeper handle that was closed: the previous handle whenPulsarZooKeeperClientreplaces an expired session, or the client when the store closes. It says nothing about the current handle's connection. Before, it fell into thedefaultbranch, which treats any other state as a reconnection, so a replaced handle'sClosedevent could sendSessionReestablishedbefore the new session was connected.Verifying this change
This change added tests and can be verified as follows:
ZKSessionWatcherTest.sessionReplacedWhileNotifiedIsReestablishedWithNextSessiondelivers the events of the broker's log in [Bug][meta] SessionReestablished is lost when recreating ZKMetadataStore's persistent watch fails, so the broker never revalidates its locks #26860 with distinct session ids:Expired,Closed,SyncConnectedof session 1, whose listener marks it replaced when it getsSessionReestablished, thenSyncConnectedof session 1 again, as a connection check would,Closed, andSyncConnectedof session 2. The listener gets nothing for theClosedevents and session 1's second connection, andReconnectedandSessionReestablishedfor session 2. With master'scheckState, the first version of this test, which marked the session invalid instead of replaced, failed the same way the broker did: the listener got nothing after the firstSessionReestablished.ZKSessionTest,LockManagerTest,LeaderElectionTestandZKMetadataStoreTestpass.network/metadata-takeoverof [improve][test] Add network conditions, network faults and geo-replication to the performance tests #26859 reproduces the original problem, though not in every run.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes