Skip to content
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

[fix][client] Fix negative ack not redelivery. #15312

Merged
merged 2 commits into from
Apr 26, 2022
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 @@ -106,6 +106,9 @@ public void testNegativeAcks(boolean batching, boolean usePartitions, Subscripti
log.info("Test negative acks batching={} partitions={} subType={} negAckDelayMs={}", batching, usePartitions,
subscriptionType, negAcksDelayMillis);
String topic = BrokerTestUtil.newUniqueName("testNegativeAcks");
if (usePartitions) {
admin.topics().createPartitionedTopic(topic, 2);
Technoboy- marked this conversation as resolved.
Show resolved Hide resolved
}

@Cleanup
Consumer<String> consumer = pulsarClient.newConsumer(Schema.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,10 @@ private synchronized void triggerRedelivery(Timeout t) {
}

public synchronized void add(MessageId messageId) {
if (messageId instanceof BatchMessageIdImpl) {
BatchMessageIdImpl batchMessageId = (BatchMessageIdImpl) messageId;
messageId = new MessageIdImpl(batchMessageId.getLedgerId(), batchMessageId.getEntryId(),
batchMessageId.getPartitionIndex());
}

if (nackedMessages == null) {
nackedMessages = new HashMap<>();
}
nackedMessages.put(messageId, System.nanoTime() + nackDelayNanos);

if (this.timeout == null) {
// Schedule a task and group all the redeliveries for same period. Leave a small buffer to allow for
// nack immediately following the current one will be batched into the same redeliver request.
this.timeout = timer.newTimeout(this::triggerRedelivery, timerIntervalNanos, TimeUnit.NANOSECONDS);
}
add(messageId, 0);
}

public synchronized void add(Message<?> message) {
if (negativeAckRedeliveryBackoff == null) {
add(message.getMessageId());
return;
}
add(message.getMessageId(), message.getRedeliveryCount());
}

Expand All @@ -127,7 +108,12 @@ private synchronized void add(MessageId messageId, int redeliveryCount) {
nackedMessages = new HashMap<>();
}

long backoffNs = TimeUnit.MILLISECONDS.toNanos(negativeAckRedeliveryBackoff.next(redeliveryCount));
long backoffNs;
if (negativeAckRedeliveryBackoff != null) {
backoffNs = TimeUnit.MILLISECONDS.toNanos(negativeAckRedeliveryBackoff.next(redeliveryCount));
} else {
backoffNs = nackDelayNanos;
}
nackedMessages.put(messageId, System.nanoTime() + backoffNs);

if (this.timeout == null) {
Expand Down