-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][ml] Fix the CAS operation in initiate() failure #24498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dao-jun
wants to merge
3
commits into
apache:master
Choose a base branch
from
dao-jun:fix/op_add_entry_not_send2bk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
# Conflicts: # managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java
nodece
reviewed
Jul 29, 2025
Comment on lines
174
to
179
if (STATE_UPDATER.compareAndSet(OpAddEntry.this, State.OPEN, State.INITIATED)) { | ||
// Fail the add operation if the managed ledger is in a state that prevents adding entries. | ||
ManagedLedgerException exbw = ml.interceptorException; | ||
if (exbw != null) { | ||
ml.pendingAddEntries.remove(this); |
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.
It looks unnecessary.
nodece
reviewed
Jul 29, 2025
return; | ||
} | ||
|
||
ByteBuf duplicateBuffer = data.retainedDuplicate(); |
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.
You can directly set the ManagedLedgerException.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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
In our pulsar cluster, we have encountered an extremely strange problem.
A topic has been running for a long time, but at a time, it starts
fenced
for a long time(more than 3 hours, until we unload it manually).After we analysis the heap dump and broker log, we find the root cause:
For some reason the CAS operation in

OpAddEntry.initiate()
failed, but it logsinitiate with unexpected state OPEN, expect OPEN state.
Which means the
state
isOPEN
, but the CAS operation still fails.Because of the CAS operation failed, the request did not send to bookies.
The next request passed the CAS operation and sent to bookies and received the response, when doing callback, it will check the


ml.pendingAddEntries
.It polls the 1st entry, but the 1st entry did not send to bookies, so it will
firstInQueue.failed(...)
the 1st entry, and the topic will be fenced.But the 2nd entry will always hang there, because it only fails the 1st entry but do nothing to itself. So the topic keeps fencing and never be unfenced.
The PR change maybe could causes message out of ordering, so do not merge.
Modifications
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete