Skip to content
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 @@ -595,6 +595,7 @@ private CompletableFuture<Long> individualAckNormal(CommandAck ack, Map<String,
ackedCount = getAckedCountForMsgIdNoAckSets(batchSize, position, ackOwnerConsumer);
if (checkCanRemovePendingAcksAndHandle(ackOwnerConsumer, position, msgId)) {
addAndGetUnAckedMsgs(ackOwnerConsumer, -(int) ackedCount);
updateBlockedConsumerOnUnackedMsgs(ackOwnerConsumer);
Comment thread
lhotari marked this conversation as resolved.
}
}

Expand Down Expand Up @@ -1081,6 +1082,11 @@ private boolean removePendingAcks(Consumer ackOwnedConsumer, Position position)
if (log.isDebugEnabled()) {
log.debug("[{}-{}] consumer {} received ack {}", topicName, subscription, consumerId, position);
}
updateBlockedConsumerOnUnackedMsgs(ackOwnedConsumer);
return true;
}

public void updateBlockedConsumerOnUnackedMsgs(Consumer ackOwnedConsumer) {
// unblock consumer-throttling when limit check is disabled or receives half of maxUnackedMessages =>
// consumer can start again consuming messages
int unAckedMsgs = UNACKED_MESSAGES_UPDATER.get(ackOwnedConsumer);
Expand All @@ -1090,7 +1096,6 @@ private boolean removePendingAcks(Consumer ackOwnedConsumer, Position position)
ackOwnedConsumer.blockedConsumerOnUnackedMsgs = false;
flowConsumerBlockedPermits(ackOwnedConsumer);
}
return true;
}

public PendingAcksMap getPendingAcks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,47 @@ public void testDuplicateAcknowledgement() throws Exception {
.get("sub-1").getUnackedMessages(), 0);
}

@Test
public void testBlockedConsumerOnUnackedMsgs() throws Exception {
final String ns = "prop/ns-test";
admin.namespaces().createNamespace(ns, 2);
admin.namespaces().setMaxUnackedMessagesPerConsumer(ns, 1);

final String topicName = "persistent://prop/ns-test/testBlockedConsumerOnUnackedMsgs";
@Cleanup
Producer<byte[]> producer = pulsarClient.newProducer()
.topic(topicName)
.create();
@Cleanup
Consumer<byte[]> consumer = pulsarClient.newConsumer()
.topic(topicName)
.subscriptionName("sub-test")
.acknowledgmentGroupTime(0, TimeUnit.SECONDS)
.subscriptionType(SubscriptionType.Shared)
.isAckReceiptEnabled(true)
.receiverQueueSize(0)
.subscribe();

producer.send("1".getBytes(StandardCharsets.UTF_8));
producer.send("2".getBytes(StandardCharsets.UTF_8));

// 1. receive message
Message<byte[]> message = consumer.receive();
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

SubscriptionStats subscriptionStats = admin.topics().getStats(topicName).getSubscriptions().get("sub-test");
assertEquals(subscriptionStats.getUnackedMessages(), 1);
assertTrue(subscriptionStats.getConsumers().get(0).isBlockedConsumerOnUnackedMsgs());

// 2、ack this message
consumer.acknowledge(message);
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

subscriptionStats = admin.topics().getStats(topicName).getSubscriptions().get("sub-test");
assertEquals(subscriptionStats.getUnackedMessages(), 0);
assertFalse(subscriptionStats.getConsumers().get(0).isBlockedConsumerOnUnackedMsgs());
}

@Test
public void testUnsubscribeNonDurableSub() throws Exception {
final String ns = "prop/ns-test";
Expand Down