mattisonchao commented on code in PR #20718:
URL: https://github.com/apache/pulsar/pull/20718#discussion_r1257624834


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherSingleActiveConsumer.java:
##########
@@ -626,4 +633,57 @@ public void recycle() {
             recyclerHandle.recycle(this);
         }
     }
+
+    public static void readCompactedEntries(TopicCompactionService 
topicCompactionService, ManagedCursor cursor,
+                                            int numberOfEntriesToRead, boolean 
isFirstRead,
+                                            AsyncCallbacks.ReadEntriesCallback 
callback, Consumer consumer) {
+        final PositionImpl readPosition;
+        if (isFirstRead && 
MessageId.earliest.equals(consumer.getStartMessageId())){
+            readPosition = PositionImpl.EARLIEST;
+        } else {
+            readPosition = (PositionImpl) cursor.getReadPosition();
+        }
+
+        // TODO: redeliver epoch link 
https://github.com/apache/pulsar/issues/13690
+        ReadEntriesCtx readEntriesCtx = ReadEntriesCtx.create(consumer, 
DEFAULT_CONSUMER_EPOCH);
+
+        CompletableFuture<Position> lastCompactedPositionFuture = 
topicCompactionService.getLastCompactedPosition();
+
+        lastCompactedPositionFuture.thenCompose(lastCompactedPosition -> {
+            if (lastCompactedPosition == null
+                    || readPosition.compareTo(
+                    lastCompactedPosition.getLedgerId(), 
lastCompactedPosition.getEntryId()) > 0) {
+                cursor.asyncReadEntriesOrWait(numberOfEntriesToRead, callback, 
readEntriesCtx, PositionImpl.LATEST);
+                return CompletableFuture.completedFuture(null);
+            }
+
+            return topicCompactionService.readCompactedEntries(readPosition, 
numberOfEntriesToRead)
+                    .thenApply(entries -> {

Review Comment:
   Please use ''thenAccept` if there is always a return null.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to