Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[fix] [broker] Fix acknowledgeCumulativeAsync block when ackReceipt is enabled #23841

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,40 @@ public void testAckResponse() throws PulsarClientException, InterruptedException
Assert.assertTrue(e.getCause() instanceof PulsarClientException.NotAllowedException);
}
}
@Test(timeOut = 30000)
public void testAckReceipt() throws Exception {
String topic = "testAckReceipt";
@Cleanup
Producer<Integer> producer = pulsarClient.newProducer(Schema.INT32)
.topic(topic)
.enableBatching(false)
.create();
@Cleanup
ConsumerImpl<Integer> consumer = (ConsumerImpl<Integer>) pulsarClient.newConsumer(Schema.INT32)
.topic(topic)
.subscriptionName("sub")
.isAckReceiptEnabled(true)
.subscribe();
for (int i = 0; i < 10; i++) {
producer.send(i);
}
Message<Integer> message = consumer.receive();
MessageId messageId = message.getMessageId();
consumer.acknowledgeCumulativeAsync(messageId).get();
consumer.acknowledgeCumulativeAsync(messageId).get();
consumer.close();
@Cleanup
ConsumerImpl<Integer> consumer2 = (ConsumerImpl<Integer>) pulsarClient.newConsumer(Schema.INT32)
.topic(topic)
.subscriptionName("sub")
.isAckReceiptEnabled(true)
.acknowledgmentGroupTime(0, TimeUnit.SECONDS)
.subscribe();
message = consumer2.receive();
messageId = message.getMessageId();
consumer2.acknowledgeCumulativeAsync(messageId).get();
consumer2.acknowledgeCumulativeAsync(messageId).get();
}

@Test
public void testIndividualAck() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ private CompletableFuture<Void> doCumulativeAck(MessageIdAdv messageId, Map<Stri
Optional<Lock> readLock = acquireReadLock();
try {
doCumulativeAckAsync(messageId, bitSet);
return readLock.map(__ -> currentCumulativeAckFuture).orElse(CompletableFuture.completedFuture(null));
return readLock.map(__ -> {
if (consumer.isAckReceiptEnabled() && lastCumulativeAck.compareTo(messageId) == 0) {
return CompletableFuture.<Void>completedFuture(null);
}
return currentCumulativeAckFuture;
}).orElse(CompletableFuture.completedFuture(null));
} finally {
readLock.ifPresent(Lock::unlock);
}
Expand Down
Loading