BewareMyPower commented on code in PR #23983:
URL: https://github.com/apache/pulsar/pull/23983#discussion_r1955456208
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:
##########
@@ -671,8 +671,15 @@ public void updateSubscribeRateLimiter() {
}
private void asyncAddEntry(ByteBuf headersAndPayload, PublishContext
publishContext) {
- ledger.asyncAddEntry(headersAndPayload,
- (int) publishContext.getNumberOfMessages(), this, publishContext);
+ // Retain the buffer in advance to avoid the buffer might have been
released when it's passed to `asyncAddEntry`
+ final var buffer = headersAndPayload.retain();
+ try {
+ ledger.getExecutor().execute(() -> ledger.asyncAddEntry(buffer,
(int) publishContext.getNumberOfMessages(),
+ this, publishContext));
Review Comment:
~~I think we should restore the `synchronized` keyword to the
`asyncAddEntry` method to make it thread safe as it is before~~
Instead of that, I still think the synchronization should be performed from
the caller. `asyncAddEntry` only needs to synchronize it with other
`asyncAddEntry` or `addEntry` method calls. It does not need to synchronize
with other managed ledger's synchronized methods. Let me improve the `apiNotes`
parts
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]