You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/05/27 09:03:05 UTC

[GitHub] [pulsar] eolivelli commented on a change in pull request #10725: [Transaction] Transaction admin api get buffer internal stats

eolivelli commented on a change in pull request #10725:
URL: https://github.com/apache/pulsar/pull/10725#discussion_r640426781



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
##########
@@ -789,4 +796,69 @@ protected void validatePersistencePolicies(PersistencePolicies persistence) {
                         persistence.getBookkeeperAckQuorum()));
 
     }
+
+    protected CompletableFuture<ManagedLedgerInternalStats> getManageLedgerInternalStats(ManagedLedger ledger,
+                                                                                       boolean includeLedgerMetadata,
+                                                                                       String topic) {
+        CompletableFuture<ManagedLedgerInternalStats> statFuture = new CompletableFuture<>();
+        ManagedLedgerInternalStats stats = new ManagedLedgerInternalStats();
+
+        ManagedLedgerImpl ml = (ManagedLedgerImpl) ledger;
+        stats.entriesAddedCounter = ml.getEntriesAddedCounter();
+        stats.numberOfEntries = ml.getNumberOfEntries();
+        stats.totalSize = ml.getTotalSize();
+        stats.currentLedgerEntries = ml.getCurrentLedgerEntries();
+        stats.currentLedgerSize = ml.getCurrentLedgerSize();
+        stats.lastLedgerCreatedTimestamp = DateFormatter.format(ml.getLastLedgerCreatedTimestamp());
+        if (ml.getLastLedgerCreationFailureTimestamp() != 0) {
+            stats.lastLedgerCreationFailureTimestamp = DateFormatter.format(ml.getLastLedgerCreationFailureTimestamp());
+        }
+
+        stats.waitingCursorsCount = ml.getWaitingCursorsCount();
+        stats.pendingAddEntriesCount = ml.getPendingAddEntriesCount();
+
+        stats.lastConfirmedEntry = ml.getLastConfirmedEntry().toString();
+        stats.state = ml.getState();
+
+        stats.ledgers = Lists.newArrayList();
+        ml.getLedgersInfo().forEach((id, li) -> {
+            ManagedLedgerInternalStats.LedgerInfo info = new PersistentTopicInternalStats.LedgerInfo();
+            info.ledgerId = li.getLedgerId();
+            info.entries = li.getEntries();
+            info.size = li.getSize();
+            info.offloaded = li.hasOffloadContext() && li.getOffloadContext().getComplete();
+            stats.ledgers.add(info);
+            if (includeLedgerMetadata) {
+                ml.getLedgerMetadata(li.getLedgerId()).handle((lMetadata, ex) -> {
+                    if (ex == null) {
+                        info.metadata = lMetadata;
+                    }
+                    return null;
+                });
+            }
+
+            stats.cursors = Maps.newTreeMap();
+            ml.getCursors().forEach(c -> {
+                ManagedCursorImpl cursor = (ManagedCursorImpl) c;
+                PersistentTopicInternalStats.CursorStats cs = new PersistentTopicInternalStats.CursorStats();
+                cs.markDeletePosition = cursor.getMarkDeletedPosition().toString();
+                cs.readPosition = cursor.getReadPosition().toString();
+                cs.waitingReadOp = cursor.hasPendingReadRequest();
+                cs.pendingReadOps = cursor.getPendingReadOpsCount();
+                cs.messagesConsumedCounter = cursor.getMessagesConsumedCounter();
+                cs.cursorLedger = cursor.getCursorLedger();
+                cs.cursorLedgerLastEntry = cursor.getCursorLedgerLastEntry();
+                cs.individuallyDeletedMessages = cursor.getIndividuallyDeletedMessages();
+                cs.lastLedgerSwitchTimestamp = DateFormatter.format(cursor.getLastLedgerSwitchTimestamp());

Review comment:
       can this getLastLedgerSwitchTimestamp  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.

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