Search in sources :

Example 6 with ReplicatorStats

use of org.apache.pulsar.common.policies.data.ReplicatorStats in project incubator-pulsar by apache.

the class ReplicatorTest method testReplicatorClearBacklog.

@Test(timeOut = 30000)
public void testReplicatorClearBacklog() throws Exception {
    // This test is to verify that reset cursor fails on global topic
    SortedSet<String> testDests = new TreeSet<String>();
    final TopicName dest = TopicName.get("persistent://pulsar/global/ns/clearBacklogTopic");
    testDests.add(dest.toString());
    MessageProducer producer1 = new MessageProducer(url1, dest);
    MessageConsumer consumer1 = new MessageConsumer(url3, dest);
    // Produce from cluster1 and consume from the rest
    producer1.produce(2);
    producer1.close();
    PersistentTopic topic = (PersistentTopic) pulsar1.getBrokerService().getTopicReference(dest.toString());
    PersistentReplicator replicator = (PersistentReplicator) spy(topic.getReplicators().get(topic.getReplicators().keys().get(0)));
    replicator.readEntriesFailed(new ManagedLedgerException.InvalidCursorPositionException("failed"), null);
    replicator.clearBacklog().get();
    Thread.sleep(100);
    // for code-coverage
    replicator.updateRates();
    // for code-coverage
    replicator.expireMessages(1);
    ReplicatorStats status = replicator.getStats();
    assertTrue(status.replicationBacklog == 0);
    consumer1.close();
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PersistentReplicator(org.apache.pulsar.broker.service.persistent.PersistentReplicator) TreeSet(java.util.TreeSet) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) ReplicatorStats(org.apache.pulsar.common.policies.data.ReplicatorStats) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Example 7 with ReplicatorStats

use of org.apache.pulsar.common.policies.data.ReplicatorStats in project incubator-pulsar by apache.

the class PersistentTopic method getStats.

public PersistentTopicStats getStats() {
    PersistentTopicStats stats = new PersistentTopicStats();
    ObjectObjectHashMap<String, PublisherStats> remotePublishersStats = new ObjectObjectHashMap<String, PublisherStats>();
    producers.forEach(producer -> {
        PublisherStats publisherStats = producer.getStats();
        stats.msgRateIn += publisherStats.msgRateIn;
        stats.msgThroughputIn += publisherStats.msgThroughputIn;
        if (producer.isRemote()) {
            remotePublishersStats.put(producer.getRemoteCluster(), publisherStats);
        } else {
            stats.publishers.add(publisherStats);
        }
    });
    stats.averageMsgSize = stats.msgRateIn == 0.0 ? 0.0 : (stats.msgThroughputIn / stats.msgRateIn);
    subscriptions.forEach((name, subscription) -> {
        SubscriptionStats subStats = subscription.getStats();
        stats.msgRateOut += subStats.msgRateOut;
        stats.msgThroughputOut += subStats.msgThroughputOut;
        stats.subscriptions.put(name, subStats);
    });
    replicators.forEach((cluster, replicator) -> {
        ReplicatorStats replicatorStats = replicator.getStats();
        // Add incoming msg rates
        PublisherStats pubStats = remotePublishersStats.get(replicator.getRemoteCluster());
        if (pubStats != null) {
            replicatorStats.msgRateIn = pubStats.msgRateIn;
            replicatorStats.msgThroughputIn = pubStats.msgThroughputIn;
            replicatorStats.inboundConnection = pubStats.address;
            replicatorStats.inboundConnectedSince = pubStats.connectedSince;
        }
        stats.msgRateOut += replicatorStats.msgRateOut;
        stats.msgThroughputOut += replicatorStats.msgThroughputOut;
        stats.replication.put(replicator.getRemoteCluster(), replicatorStats);
    });
    stats.storageSize = ledger.getEstimatedBacklogSize();
    stats.deduplicationStatus = messageDeduplication.getStatus().toString();
    return stats;
}
Also used : SubscriptionStats(org.apache.pulsar.common.policies.data.SubscriptionStats) PublisherStats(org.apache.pulsar.common.policies.data.PublisherStats) ReplicatorStats(org.apache.pulsar.common.policies.data.ReplicatorStats) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) ObjectObjectHashMap(com.carrotsearch.hppc.ObjectObjectHashMap)

Example 8 with ReplicatorStats

use of org.apache.pulsar.common.policies.data.ReplicatorStats in project incubator-pulsar by apache.

the class NamespaceStatsAggregator method getTopicStats.

private static void getTopicStats(Topic topic, TopicStats stats) {
    stats.reset();
    if (topic instanceof PersistentTopic) {
        // Managed Ledger stats
        ManagedLedgerMBeanImpl mlStats = (ManagedLedgerMBeanImpl) ((PersistentTopic) topic).getManagedLedger().getStats();
        stats.storageSize = mlStats.getStoredMessagesSize();
        stats.storageWriteLatencyBuckets.addAll(mlStats.getInternalAddEntryLatencyBuckets());
        stats.storageWriteLatencyBuckets.refresh();
        stats.entrySizeBuckets.addAll(mlStats.getInternalEntrySizeBuckets());
        stats.entrySizeBuckets.refresh();
        stats.storageWriteRate = mlStats.getAddEntryMessagesRate();
        stats.storageReadRate = mlStats.getReadEntriesRate();
    }
    topic.getProducers().forEach(producer -> {
        if (producer.isRemote()) {
            AggregatedReplicationStats replStats = stats.replicationStats.computeIfAbsent(producer.getRemoteCluster(), k -> new AggregatedReplicationStats());
            replStats.msgRateIn += producer.getStats().msgRateIn;
            replStats.msgThroughputIn += producer.getStats().msgThroughputIn;
        } else {
            // Local producer
            stats.producersCount++;
            stats.rateIn += producer.getStats().msgRateIn;
            stats.throughputIn += producer.getStats().msgThroughputIn;
        }
    });
    topic.getSubscriptions().forEach((name, subscription) -> {
        stats.subscriptionsCount++;
        stats.msgBacklog += subscription.getNumberOfEntriesInBacklog();
        subscription.getConsumers().forEach(consumer -> {
            stats.consumersCount++;
            stats.rateOut += consumer.getStats().msgRateOut;
            stats.throughputOut += consumer.getStats().msgThroughputOut;
        });
    });
    topic.getReplicators().forEach((cluster, replicator) -> {
        AggregatedReplicationStats aggReplStats = stats.replicationStats.computeIfAbsent(cluster, k -> new AggregatedReplicationStats());
        ReplicatorStats replStats = replicator.getStats();
        aggReplStats.msgRateOut += replStats.msgRateOut;
        aggReplStats.msgThroughputOut += replStats.msgThroughputOut;
        aggReplStats.replicationBacklog += replStats.replicationBacklog;
    });
}
Also used : PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) ManagedLedgerMBeanImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl) ReplicatorStats(org.apache.pulsar.common.policies.data.ReplicatorStats)

Aggregations

ReplicatorStats (org.apache.pulsar.common.policies.data.ReplicatorStats)8 Test (org.testng.annotations.Test)5 PublisherStats (org.apache.pulsar.common.policies.data.PublisherStats)4 PersistentTopicStats (org.apache.pulsar.common.policies.data.PersistentTopicStats)3 SubscriptionStats (org.apache.pulsar.common.policies.data.SubscriptionStats)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)2 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)2 ObjectObjectHashMap (com.carrotsearch.hppc.ObjectObjectHashMap)1 TreeSet (java.util.TreeSet)1 ManagedLedgerAlreadyClosedException (org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerAlreadyClosedException)1 ManagedLedgerFencedException (org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerFencedException)1 ManagedLedgerTerminatedException (org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerTerminatedException)1 ManagedLedgerMBeanImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl)1 BrokerServiceException (org.apache.pulsar.broker.service.BrokerServiceException)1 ConsumerBusyException (org.apache.pulsar.broker.service.BrokerServiceException.ConsumerBusyException)1 NamingException (org.apache.pulsar.broker.service.BrokerServiceException.NamingException)1 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 PersistenceException (org.apache.pulsar.broker.service.BrokerServiceException.PersistenceException)1 ProducerBusyException (org.apache.pulsar.broker.service.BrokerServiceException.ProducerBusyException)1 ServerMetadataException (org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException)1