[fix][broker] Avoid load shedding and metadata writes from a former leader - #26253
Open
void-ptr974 wants to merge 2 commits into
Open
[fix][broker] Avoid load shedding and metadata writes from a former leader#26253void-ptr974 wants to merge 2 commits into
void-ptr974 wants to merge 2 commits into
Conversation
…eader Recheck leader state before load-shedding side effects and metadata writes so a task that was already running stops after leadership changes.
void-ptr974
force-pushed
the
fix/modular-load-manager-leader-guard
branch
from
July 28, 2026 01:58
ef5750a to
d5e269e
Compare
Dream95
reviewed
Jul 28, 2026
| pulsar.getAdminClient().namespaces() | ||
| .unloadNamespaceBundle(namespaceName, bundleRange, destBroker.get()); | ||
| if (!isLeader()) { | ||
| return; |
Contributor
There was a problem hiding this comment.
This return is inside nested forEach lambdas, so it only skips the current foreach.This could be optimized.
Contributor
Author
There was a problem hiding this comment.
Fixed in 68869bc. Replaced the nested lambdas with regular loops so leadership loss exits the load-shedding operation.
Contributor
|
Leader can still change between the isLeader() check and the actual unload, so this cannot fully prevent a former leader from triggering an unload. |
Contributor
Author
|
Thanks. This PR intentionally provides only a best-effort guard and does not address the narrow race between the leadership check and the unload itself. Providing a strong guarantee would require a broader fencing design, which is out of scope for this focused change. |
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.
Motivation
Load-balancer tasks are started only while a broker is the leader. However, cancelling a scheduled task does not stop an invocation that is already in progress. If leadership changes during such an invocation, the former leader can still initiate bundle unloading or persist load-balancing metadata.
Modifications
Verifying this change
This change added tests and can be verified as follows:
./gradlew :pulsar-broker:test -PtestGroups=broker -PexcludedTestGroups='' --tests org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImplTest --console=plain./gradlew :pulsar-broker:checkstyleMain :pulsar-broker:checkstyleTest --console=plainDoes this pull request potentially affect one of the following parts: