Search in sources :

Example 6 with LongPair

use of org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair in project pulsar by apache.

the class Consumer method removePendingAcks.

/**
 * first try to remove ack-position from the current_consumer's pendingAcks.
 * if ack-message doesn't present into current_consumer's pendingAcks
 *  a. try to remove from other connected subscribed consumers (It happens when client
 * tries to acknowledge message through different consumer under the same subscription)
 *
 * @param position
 */
private void removePendingAcks(PositionImpl position) {
    Consumer ackOwnedConsumer = null;
    if (pendingAcks.get(position.getLedgerId(), position.getEntryId()) == null) {
        for (Consumer consumer : subscription.getConsumers()) {
            if (!consumer.equals(this) && consumer.getPendingAcks().containsKey(position.getLedgerId(), position.getEntryId())) {
                ackOwnedConsumer = consumer;
                break;
            }
        }
    } else {
        ackOwnedConsumer = this;
    }
    // remove pending message from appropriate consumer and unblock unAckMsg-flow if requires
    LongPair ackedPosition = ackOwnedConsumer != null ? ackOwnedConsumer.getPendingAcks().get(position.getLedgerId(), position.getEntryId()) : null;
    if (ackedPosition != null) {
        if (!ackOwnedConsumer.getPendingAcks().remove(position.getLedgerId(), position.getEntryId())) {
            // Message was already removed by the other consumer
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug("[{}-{}] consumer {} received ack {}", topicName, subscription, consumerId, position);
        }
        // unblock consumer-throttling when limit check is disabled or receives half of maxUnackedMessages =>
        // consumer can start again consuming messages
        int unAckedMsgs = UNACKED_MESSAGES_UPDATER.get(ackOwnedConsumer);
        if ((((unAckedMsgs <= getMaxUnackedMessages() / 2) && ackOwnedConsumer.blockedConsumerOnUnackedMsgs) && ackOwnedConsumer.shouldBlockConsumerOnUnackMsgs()) || !shouldBlockConsumerOnUnackMsgs()) {
            ackOwnedConsumer.blockedConsumerOnUnackedMsgs = false;
            flowConsumerBlockedPermits(ackOwnedConsumer);
        }
    }
}
Also used : LongPair(org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair)

Aggregations

LongPair (org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair)6 Test (org.junit.Test)3 HashMap (java.util.HashMap)1 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)1 MessageIdData (org.apache.pulsar.common.api.proto.MessageIdData)1