Skip to content

Commit

Permalink
[Broker] Fix direct memory leak in getLastMessageId (apache#10977)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7417ca8)
  • Loading branch information
lhotari committed Jun 21, 2021
1 parent 0d86b04 commit 321afb9
Showing 1 changed file with 12 additions and 7 deletions.
Expand Up @@ -2571,13 +2571,18 @@ public CompletableFuture<MessageId> getLastMessageId() {
ledgerImpl.asyncReadEntry(position, new AsyncCallbacks.ReadEntryCallback() {
@Override
public void readEntryComplete(Entry entry, Object ctx) {
MessageMetadata metadata = Commands.parseMessageMetadata(entry.getDataBuffer());
if (metadata.hasNumMessagesInBatch()) {
completableFuture.complete(new BatchMessageIdImpl(position.getLedgerId(), position.getEntryId(),
partitionIndex, metadata.getNumMessagesInBatch() - 1));
} else {
completableFuture
.complete(new MessageIdImpl(position.getLedgerId(), position.getEntryId(), partitionIndex));
try {
MessageMetadata metadata = Commands.parseMessageMetadata(entry.getDataBuffer());
if (metadata.hasNumMessagesInBatch()) {
completableFuture.complete(new BatchMessageIdImpl(position.getLedgerId(), position.getEntryId(),
partitionIndex, metadata.getNumMessagesInBatch() - 1));
} else {
completableFuture
.complete(new MessageIdImpl(position.getLedgerId(), position.getEntryId(),
partitionIndex));
}
} finally {
entry.release();
}
}

Expand Down

0 comments on commit 321afb9

Please sign in to comment.