Repository navigation
ZOOKEEPER-5131: LeaderElectionSupport fails on a withdrawn offer and leaves its own offer behind - #2506
Open
SpookyJumpyBeans wants to merge 1 commit into
Open
ZOOKEEPER-5131: LeaderElectionSupport fails on a withdrawn offer and leaves its own offer behind#2506SpookyJumpyBeans wants to merge 1 commit into
SpookyJumpyBeans wants to merge 1 commit into
Conversation
|
@SpookyJumpyBeans Please fix the pr-merge issue |
…leaves its own offer behind LeaderElectionSupport lists the offers and then reads each one. If a competing offer was withdrawn in between, getData failed with NoNode and start() moved to FAILED, an ordinary race. The failed election also left its own offer in place, so later contenders waited behind an offer that was no longer taking part, until stop() or the session ended. Skip an offer that disappears while the offers are read; this also keeps getLeaderHostName from failing in the same race. When the election fails, in start() or after a watch, remove its offer before sending the failed event, if it can be removed. If our own offer has been removed by someone else, fail the election instead of stopping without an event, and don't overwrite STOP when a listener stopped the election. A NodeDeleted watch now runs the election holding the same lock as start() and stop(), so a stop() can't interleave with it; listeners are called holding that lock. start() and stop() restore the interrupt status; process() runs on the client's event thread and does not.
SpookyJumpyBeans
force-pushed
the
ZOOKEEPER-5131
branch
from
November 22, 2026 14:55
2e46a64 to
71387d5
Compare
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.
https://issues.apache.org/jira/browse/ZOOKEEPER-5131
LeaderElectionSupportlists the election offers and then reads each one with a separategetData. If a competing offer was withdrawn in between,getDatafailed withNoNodeandstart()moved to FAILED. The failed election also kept its own offer, so later contenders waited behind an offer that was no longer taking part, and no one became leader until the failed instance calledstop()or its session ended.Changes
toLeaderOffers()skips an offer that disappears while the offers are read.getLeaderHostName()goes through the same method, so it no longer fails in this race either; it can return the next contender's host.start()or in an election run after a watch, it removes its own offer and only then sends FAILED. A listener that starts the election again on FAILED therefore gets a new offer that is kept. If the offer can't be removed, it is kept forstop()as before.NodeDeletedwatch runs the election holding the same lock asstart()andstop(), so a concurrentstop()can't be followed by a FAILED event. Other watch events (connection state) don't take the lock. Listeners for a watch-triggered election are now called holding the instance lock, as they already were fromstart(), so they must not block on that client's event thread.start()andstop()restore the interrupt status.process()runs on the client's event thread and does not, so the shared client keeps delivering events.zooKeeperis nowvolatile, since it is read both with and without the lock (SpotBugs IS2_INCONSISTENT_SYNC).Not changed
createinmakeOffer()can still leave an offer whose path the client never learned, until the session ends.stop()doesn't remove watches, and a listener that callsstop()on ELECTED_START still gets ELECTED_COMPLETE afterwards.Tests
New tests in
LeaderElectionSupportTest:testCompetingOfferDeletedWhileReadingOfferstestFailedStartRemovesItsOfferstart()fails after its offer was createdtestFailureAfterWatchRemovesOffertestRestartFromFailedListenerKeepsNewOffertestOwnOfferMissingFailsElectiontestStopDuringElectionAfterWatchSendsNoFailurestop()from another thread while a watch-triggered election runstestStopFromReadyListenerSendsNoFailurestop()testStopAfterOfferSendsNoFailurestop()How the tests were run: Maven currently skips the recipe tests that extend
ClientBase(ZOOKEEPER-5132, #2508), so I ran the class with the JUnit console launcher:All 16 tests pass (3 runs); on master 6 of the new tests fail as listed.
-Pfull-build apache-rat:check verify -DskipTests spotbugs:check checkstyle:checkpasses for the module.