Skip to content
Open
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 @@ -473,8 +473,6 @@ private Map<Consumer, List<Entry>> filterAndGroupEntriesForDispatching(List<Entr
boolean lookAheadAllowed = isReplayQueueSizeBelowLimit();
// in normal read mode, keep track of consumers that are blocked by hash, to check if look-ahead could be useful
Set<Consumer> blockedByHashConsumers = lookAheadAllowed && readType == ReadType.Normal ? new HashSet<>() : null;
// in replay read mode, keep track of consumers for entries, used for look-ahead check
Set<Consumer> consumersForEntriesForLookaheadCheck = lookAheadAllowed ? new HashSet<>() : null;
// track already blocked hashes to block any further messages with the same hash
IntOpenHashSet alreadyBlockedHashes = new IntOpenHashSet();

Expand All @@ -496,9 +494,6 @@ private Map<Consumer, List<Entry>> filterAndGroupEntriesForDispatching(List<Entr
if (!hashIsAlreadyBlocked) {
consumer = selector.select(stickyKeyHash);
if (consumer != null) {
if (lookAheadAllowed) {
consumersForEntriesForLookaheadCheck.add(consumer);
}
final var canUpdateBlockedByHash = lookAheadAllowed && readType == ReadType.Normal;
MutableInt permits =
permitsForConsumer.computeIfAbsent(consumer,
Expand Down Expand Up @@ -565,7 +560,8 @@ private Map<Consumer, List<Entry>> filterAndGroupEntriesForDispatching(List<Entr
if (!triggerLookAhead.booleanValue()) {
for (Consumer consumer : getConsumers()) {
// filter out the consumers that are already checked when the entries were processed for entries
if (!consumersForEntriesForLookaheadCheck.contains(consumer)) {
// permitsForConsumer records every selected consumer before the dispatch decision
if (!permitsForConsumer.containsKey(consumer)) {
// if another consumer has available permits, then look-ahead could be useful
if (getAvailablePermits(consumer) > 0) {
triggerLookAhead.setTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,27 @@ public void testSendMessage() {
entries.forEach(Entry::release);
}

@Test
public void testSelectedConsumerDoesNotPreventLookAheadForAnotherConsumer() {
persistentDispatcher.addConsumer(consumerMock).join();
Consumer consumerWithoutPermits = createMockConsumer();
doReturn("consumer-without-permits").when(consumerWithoutPermits).consumerName();
doReturn(0).when(consumerWithoutPermits).getAvailablePermits();
doReturn(true).when(consumerWithoutPermits).isWritable();
persistentDispatcher.addConsumer(consumerWithoutPermits).join();
String key = generateKeyForConsumer(persistentDispatcher.getSelector(), consumerWithoutPermits);
doReturn(true).when(cursorMock).hasMoreEntries();

EntryImpl entry = createEntry(1, 1, "message1", 1, key);

assertTrue(persistentDispatcher.trySendMessagesToConsumers(
PersistentDispatcherMultipleConsumers.ReadType.Normal,
new ArrayList<>(List.of(entry))));
assertFalse(persistentDispatcher.canReplayMessages());
assertTrue(persistentDispatcher.canReplayMessages());
assertEquals(entry.refCnt(), 0);
}

@Test
public void testSkipRedeliverTemporally() throws InterruptedException {
// add first consumer
Expand Down