codelipenghui commented on a change in pull request #12523:
URL: https://github.com/apache/pulsar/pull/12523#discussion_r744069637
##########
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:
Previously, the broker only aggregated the data cached in memory, but
after this change, we will get the data from the bookkeeper which introduced IO
operations, so it's better to change the PersistentTopics.getStats() to an
async way to make sure we don't block the jetty thread.
Here is an example:
https://github.com/apache/pulsar/blob/04ddc9b0324e6d09b6926bbfe5402f006ad633c3/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java#L1131
--
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]