Search in sources :

Example 6 with SubType

use of org.apache.pulsar.common.api.proto.CommandSubscribe.SubType in project pulsar by apache.

the class AbstractTopic method subTypeStringsToEnumSet.

private EnumSet<SubType> subTypeStringsToEnumSet(Set<String> getSubscriptionTypesEnabled) {
    EnumSet<SubType> subTypes = EnumSet.noneOf(SubType.class);
    for (String subTypeStr : CollectionUtils.emptyIfNull(getSubscriptionTypesEnabled)) {
        try {
            SubType subType = SubType.valueOf(subTypeStr);
            subTypes.add(subType);
        } catch (Throwable t) {
        // ignore invalid SubType strings.
        }
    }
    if (subTypes.isEmpty()) {
        return null;
    } else {
        return subTypes;
    }
}
Also used : SubType(org.apache.pulsar.common.api.proto.CommandSubscribe.SubType)

Example 7 with SubType

use of org.apache.pulsar.common.api.proto.CommandSubscribe.SubType in project pulsar by apache.

the class PersistentSubscription method getStats.

public SubscriptionStatsImpl getStats(Boolean getPreciseBacklog, boolean subscriptionBacklogSize, boolean getEarliestTimeInBacklog) {
    SubscriptionStatsImpl subStats = new SubscriptionStatsImpl();
    subStats.lastExpireTimestamp = lastExpireTimestamp;
    subStats.lastConsumedFlowTimestamp = lastConsumedFlowTimestamp;
    subStats.lastMarkDeleteAdvancedTimestamp = lastMarkDeleteAdvancedTimestamp;
    subStats.bytesOutCounter = bytesOutFromRemovedConsumers.longValue();
    subStats.msgOutCounter = msgOutFromRemovedConsumer.longValue();
    Dispatcher dispatcher = this.dispatcher;
    if (dispatcher != null) {
        Map<Consumer, List<Range>> consumerKeyHashRanges = getType() == SubType.Key_Shared ? ((PersistentStickyKeyDispatcherMultipleConsumers) dispatcher).getConsumerKeyHashRanges() : null;
        dispatcher.getConsumers().forEach(consumer -> {
            ConsumerStatsImpl consumerStats = consumer.getStats();
            subStats.consumers.add(consumerStats);
            subStats.msgRateOut += consumerStats.msgRateOut;
            subStats.msgThroughputOut += consumerStats.msgThroughputOut;
            subStats.bytesOutCounter += consumerStats.bytesOutCounter;
            subStats.msgOutCounter += consumerStats.msgOutCounter;
            subStats.msgRateRedeliver += consumerStats.msgRateRedeliver;
            subStats.chunkedMessageRate += consumerStats.chunkedMessageRate;
            subStats.unackedMessages += consumerStats.unackedMessages;
            subStats.lastConsumedTimestamp = Math.max(subStats.lastConsumedTimestamp, consumerStats.lastConsumedTimestamp);
            subStats.lastAckedTimestamp = Math.max(subStats.lastAckedTimestamp, consumerStats.lastAckedTimestamp);
            if (consumerKeyHashRanges != null && consumerKeyHashRanges.containsKey(consumer)) {
                consumerStats.keyHashRanges = consumerKeyHashRanges.get(consumer).stream().map(Range::toString).collect(Collectors.toList());
            }
        });
    }
    SubType subType = getType();
    subStats.type = getTypeString();
    if (dispatcher instanceof PersistentDispatcherSingleActiveConsumer) {
        Consumer activeConsumer = ((PersistentDispatcherSingleActiveConsumer) dispatcher).getActiveConsumer();
        if (activeConsumer != null) {
            subStats.activeConsumerName = activeConsumer.consumerName();
        }
    }
    if (Subscription.isIndividualAckMode(subType)) {
        if (dispatcher instanceof PersistentDispatcherMultipleConsumers) {
            PersistentDispatcherMultipleConsumers d = (PersistentDispatcherMultipleConsumers) dispatcher;
            subStats.unackedMessages = d.getTotalUnackedMessages();
            subStats.blockedSubscriptionOnUnackedMsgs = d.isBlockedDispatcherOnUnackedMsgs();
            subStats.msgDelayed = d.getNumberOfDelayedMessages();
        }
    }
    subStats.msgBacklog = getNumberOfEntriesInBacklog(getPreciseBacklog);
    if (subscriptionBacklogSize) {
        subStats.backlogSize = ((ManagedLedgerImpl) topic.getManagedLedger()).getEstimatedBacklogSize((PositionImpl) cursor.getMarkDeletedPosition());
    }
    if (getEarliestTimeInBacklog && subStats.msgBacklog > 0) {
        ManagedLedgerImpl managedLedger = ((ManagedLedgerImpl) cursor.getManagedLedger());
        PositionImpl markDeletedPosition = (PositionImpl) cursor.getMarkDeletedPosition();
        long result = 0;
        try {
            result = managedLedger.getEarliestMessagePublishTimeOfPos(markDeletedPosition).get();
        } catch (InterruptedException | ExecutionException e) {
            result = -1;
        }
        subStats.earliestMsgPublishTimeInBacklog = result;
    }
    subStats.msgBacklogNoDelayed = subStats.msgBacklog - subStats.msgDelayed;
    subStats.msgRateExpired = expiryMonitor.getMessageExpiryRate();
    subStats.totalMsgExpired = expiryMonitor.getTotalMessageExpired();
    subStats.isReplicated = isReplicated();
    subStats.subscriptionProperties = subscriptionProperties;
    subStats.isDurable = cursor.isDurable();
    if (getType() == SubType.Key_Shared && dispatcher instanceof PersistentStickyKeyDispatcherMultipleConsumers) {
        PersistentStickyKeyDispatcherMultipleConsumers keySharedDispatcher = (PersistentStickyKeyDispatcherMultipleConsumers) dispatcher;
        subStats.allowOutOfOrderDelivery = keySharedDispatcher.isAllowOutOfOrderDelivery();
        subStats.keySharedMode = keySharedDispatcher.getKeySharedMode().toString();
        LinkedHashMap<Consumer, PositionImpl> recentlyJoinedConsumers = keySharedDispatcher.getRecentlyJoinedConsumers();
        if (recentlyJoinedConsumers != null && recentlyJoinedConsumers.size() > 0) {
            recentlyJoinedConsumers.forEach((k, v) -> {
                subStats.consumersAfterMarkDeletePosition.put(k.consumerName(), v.toString());
            });
        }
    }
    subStats.nonContiguousDeletedMessagesRanges = cursor.getTotalNonContiguousDeletedMessagesRange();
    subStats.nonContiguousDeletedMessagesRangesSerializedSize = cursor.getNonContiguousDeletedMessagesRangeSerializedSize();
    return subStats;
}
Also used : SubType(org.apache.pulsar.common.api.proto.CommandSubscribe.SubType) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) Dispatcher(org.apache.pulsar.broker.service.Dispatcher) Range(org.apache.pulsar.client.api.Range) SubscriptionStatsImpl(org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) Consumer(org.apache.pulsar.broker.service.Consumer) ConsumerStatsImpl(org.apache.pulsar.common.policies.data.stats.ConsumerStatsImpl) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

SubType (org.apache.pulsar.common.api.proto.CommandSubscribe.SubType)7 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)4 PersistentSubscription (org.apache.pulsar.broker.service.persistent.PersistentSubscription)4 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)4 KeySharedMeta (org.apache.pulsar.common.api.proto.KeySharedMeta)4 ConsumerStatsImpl (org.apache.pulsar.common.policies.data.stats.ConsumerStatsImpl)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Promise (io.netty.util.concurrent.Promise)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Collectors (java.util.stream.Collectors)3 Entry (org.apache.bookkeeper.mledger.Entry)3 Position (org.apache.bookkeeper.mledger.Position)3 MutableInt (org.apache.commons.lang3.mutable.MutableInt)3 TxnID (org.apache.pulsar.client.api.transaction.TxnID)3 CommandAck (org.apache.pulsar.common.api.proto.CommandAck)3 InitialPosition (org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition)3