Search in sources :

Example 1 with ManagedLedgerInternalStats

use of org.apache.pulsar.common.policies.data.ManagedLedgerInternalStats in project pulsar by apache.

the class ManagedLedgerImpl method getManagedLedgerInternalStats.

@Override
public CompletableFuture<ManagedLedgerInternalStats> getManagedLedgerInternalStats(boolean includeLedgerMetadata) {
    CompletableFuture<ManagedLedgerInternalStats> statFuture = new CompletableFuture<>();
    ManagedLedgerInternalStats stats = new ManagedLedgerInternalStats();
    stats.entriesAddedCounter = this.getEntriesAddedCounter();
    stats.numberOfEntries = this.getNumberOfEntries();
    stats.totalSize = this.getTotalSize();
    stats.currentLedgerEntries = this.getCurrentLedgerEntries();
    stats.currentLedgerSize = this.getCurrentLedgerSize();
    stats.lastLedgerCreatedTimestamp = DateFormatter.format(this.getLastLedgerCreatedTimestamp());
    if (this.getLastLedgerCreationFailureTimestamp() != 0) {
        stats.lastLedgerCreationFailureTimestamp = DateFormatter.format(this.getLastLedgerCreationFailureTimestamp());
    }
    stats.waitingCursorsCount = this.getWaitingCursorsCount();
    stats.pendingAddEntriesCount = this.getPendingAddEntriesCount();
    stats.lastConfirmedEntry = this.getLastConfirmedEntry().toString();
    stats.state = this.getState().toString();
    stats.ledgers = Lists.newArrayList();
    this.getLedgersInfo().forEach((id, li) -> {
        ManagedLedgerInternalStats.LedgerInfo info = new ManagedLedgerInternalStats.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) {
            this.getLedgerMetadata(li.getLedgerId()).handle((lMetadata, ex) -> {
                if (ex == null) {
                    info.metadata = lMetadata;
                }
                return null;
            });
        }
        stats.cursors = Maps.newTreeMap();
        this.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());
            cs.state = cursor.getState();
            cs.numberOfEntriesSinceFirstNotAckedMessage = cursor.getNumberOfEntriesSinceFirstNotAckedMessage();
            cs.totalNonContiguousDeletedMessagesRange = cursor.getTotalNonContiguousDeletedMessagesRange();
            cs.properties = cursor.getProperties();
            stats.cursors.put(cursor.getName(), cs);
        });
    });
    statFuture.complete(stats);
    return statFuture;
}
Also used : ManagedLedgerInternalStats(org.apache.pulsar.common.policies.data.ManagedLedgerInternalStats) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) CompletableFuture(java.util.concurrent.CompletableFuture) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats)

Example 2 with ManagedLedgerInternalStats

use of org.apache.pulsar.common.policies.data.ManagedLedgerInternalStats in project pulsar by apache.

the class AdminApiTransactionTest method testGetPendingAckInternalStats.

@Test(timeOut = 20000)
public void testGetPendingAckInternalStats() throws Exception {
    initTransaction(1);
    TransactionImpl transaction = (TransactionImpl) getTransaction();
    final String topic = "persistent://public/default/testGetPendingAckInternalStats";
    final String subName = "test";
    admin.topics().createNonPartitionedTopic(topic);
    Producer<byte[]> producer = pulsarClient.newProducer(Schema.BYTES).topic(topic).create();
    Consumer<byte[]> consumer = pulsarClient.newConsumer(Schema.BYTES).topic(topic).subscriptionName(subName).subscribe();
    MessageId messageId = producer.send("Hello pulsar!".getBytes());
    consumer.acknowledgeAsync(messageId, transaction).get();
    TransactionPendingAckInternalStats stats = admin.transactions().getPendingAckInternalStatsAsync(topic, subName, true).get();
    ManagedLedgerInternalStats managedLedgerInternalStats = stats.pendingAckLogStats.managedLedgerInternalStats;
    assertEquals(TopicName.get(TopicDomain.persistent.toString(), "public", "default", "testGetPendingAckInternalStats" + "-" + subName + MLPendingAckStore.PENDING_ACK_STORE_SUFFIX).getPersistenceNamingEncoding(), stats.pendingAckLogStats.managedLedgerName);
    verifyManagedLegerInternalStats(managedLedgerInternalStats, 16);
    ManagedLedgerInternalStats finalManagedLedgerInternalStats = managedLedgerInternalStats;
    managedLedgerInternalStats.cursors.forEach((s, cursorStats) -> {
        assertEquals(s, MLPendingAckStore.PENDING_ACK_STORE_CURSOR_NAME);
        assertEquals(cursorStats.readPosition, finalManagedLedgerInternalStats.lastConfirmedEntry);
    });
    stats = admin.transactions().getPendingAckInternalStatsAsync(topic, subName, false).get();
    managedLedgerInternalStats = stats.pendingAckLogStats.managedLedgerInternalStats;
    assertEquals(TopicName.get(TopicDomain.persistent.toString(), "public", "default", "testGetPendingAckInternalStats" + "-" + subName + MLPendingAckStore.PENDING_ACK_STORE_SUFFIX).getPersistenceNamingEncoding(), stats.pendingAckLogStats.managedLedgerName);
    assertNull(managedLedgerInternalStats.ledgers.get(0).metadata);
}
Also used : ManagedLedgerInternalStats(org.apache.pulsar.common.policies.data.ManagedLedgerInternalStats) TransactionImpl(org.apache.pulsar.client.impl.transaction.TransactionImpl) TransactionPendingAckInternalStats(org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats) MessageId(org.apache.pulsar.client.api.MessageId) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

ManagedLedgerInternalStats (org.apache.pulsar.common.policies.data.ManagedLedgerInternalStats)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 ManagedLedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)1 LedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo)1 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)1 MessageId (org.apache.pulsar.client.api.MessageId)1 TransactionImpl (org.apache.pulsar.client.impl.transaction.TransactionImpl)1 PersistentTopicInternalStats (org.apache.pulsar.common.policies.data.PersistentTopicInternalStats)1 TransactionPendingAckInternalStats (org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats)1 Test (org.testng.annotations.Test)1