gaoran10 commented on a change in pull request #12523:
URL: https://github.com/apache/pulsar/pull/12523#discussion_r744277998



##########
File path: 
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
##########
@@ -1141,6 +1144,53 @@ public long getEstimatedBacklogSize() {
         }
     }
 
+    @Override
+    public long getEarliestMessagePublishTimeInBacklog() {
+        PositionImpl pos = getMarkDeletePositionOfSlowestConsumer();
+
+        return getEarliestMessagePublishTimeOfPos(pos);
+    }
+
+    public long getEarliestMessagePublishTimeOfPos(PositionImpl pos) {
+        if (pos == null) {
+            return 0L;
+        }
+        PositionImpl nextPos = getNextValidPosition(pos);
+
+        CompletableFuture<Long> future = new CompletableFuture<>();
+        asyncReadEntry(nextPos, new ReadEntryCallback() {
+            @Override
+            public void readEntryComplete(Entry entry, Object ctx) {
+                ByteBuf metadataAndPayload = entry.getDataBuffer();
+                BrokerEntryMetadata brokerEntryMetadata = 
Commands.parseBrokerEntryMetadataIfExist(metadataAndPayload);
+                if (brokerEntryMetadata != null && 
brokerEntryMetadata.hasBrokerTimestamp()) {
+                    future.complete(brokerEntryMetadata.getBrokerTimestamp());
+                } else {
+                    MessageMetadata messageMetadata = 
Commands.parseMessageMetadata(metadataAndPayload);
+                    if (messageMetadata.hasPublishTime()) {
+                        future.complete(messageMetadata.getPublishTime());
+                    } else {
+                        future.complete(0L);
+                    }
+                }
+            }
+
+            @Override
+            public void readEntryFailed(ManagedLedgerException exception, 
Object ctx) {
+                future.completeExceptionally(exception);
+            }
+        }, null);
+
+        long result;
+        try {
+            result = future.get();

Review comment:
       Maybe we could refer to the interface 
`CompletableFuture<PersistentTopicInternalStats> getInternalStats(boolean 
includeLedgerMetadata)` of the class `org.apache.pulsar.broker.service.Topic`.




-- 
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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to