Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix can not consume all message if topics has > 1000 partitions (#354)
Browse files Browse the repository at this point in the history
fixes #353

1, `responseData` is `LinkedHashMap`, which implementation is not synchronized, therefore `responseValues` should not parallel.
2, `getExecutor schedule` may not process so fast for lots of partitions.
  • Loading branch information
dockerzhang authored Jan 27, 2021
1 parent 075f892 commit e44014b
Showing 1 changed file with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -304,8 +302,7 @@ private void readMessagesInternal(KafkaHeaderAndRequest fetch,
fetch.getHeader(), entriesRead.get(), allSize);
}

AtomicBoolean allPartitionsNoEntry = new AtomicBoolean(true);
responseValues.entrySet().parallelStream().forEach(responseEntries -> {
responseValues.entrySet().forEach(responseEntries -> {
final PartitionData partitionData;
TopicPartition kafkaPartition = responseEntries.getKey();
List<Entry> entries = responseEntries.getValue();
Expand Down Expand Up @@ -334,8 +331,6 @@ private void readMessagesInternal(KafkaHeaderAndRequest fetch,
null,
MemoryRecords.EMPTY);
} else {
allPartitionsNoEntry.set(false);

ManagedLedgerImpl managedLedger = (ManagedLedgerImpl) cursors
.get(kafkaPartition).getLeft().getManagedLedger();
long highWatermark = MessageIdUtils.getHighWatermark(managedLedger);
Expand Down Expand Up @@ -368,29 +363,13 @@ private void readMessagesInternal(KafkaHeaderAndRequest fetch,
responseData.put(kafkaPartition, partitionData);
});

if (allPartitionsNoEntry.get()) {
if (log.isDebugEnabled()) {
log.debug("Request {}: All partitions for request read 0 entry",
fetch.getHeader());
}

requestHandler.getPulsarService().getExecutor().schedule(() -> {
resultFuture.complete(
new FetchResponse(Errors.NONE,
resultFuture.complete(
new FetchResponse(
Errors.NONE,
responseData,
((Integer) THROTTLE_TIME_MS.defaultValue),
((FetchRequest) fetch.getRequest()).metadata().sessionId()));
this.recycle();
}, waitTime, TimeUnit.MILLISECONDS);
} else {
resultFuture.complete(
new FetchResponse(
Errors.NONE,
responseData,
((Integer) THROTTLE_TIME_MS.defaultValue),
((FetchRequest) fetch.getRequest()).metadata().sessionId()));
this.recycle();
}
this.recycle();
} else {
if (log.isDebugEnabled()) {
log.debug("Request {}: Read time or size not reach, do another round of read before return.",
Expand Down

0 comments on commit e44014b

Please sign in to comment.