Search in sources :

Example 6 with BitSetRecyclable

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

the class PendingAckHandleImpl method individualAckAbortCommon.

private void individualAckAbortCommon(TxnID txnID, HashMap<PositionImpl, PositionImpl> currentTxn) {
    for (Map.Entry<PositionImpl, PositionImpl> entry : currentTxn.entrySet()) {
        if (entry.getValue().hasAckSet() && individualAckPositions.containsKey(entry.getValue())) {
            BitSetRecyclable thisBitSet = BitSetRecyclable.valueOf(entry.getValue().getAckSet());
            int batchSize = individualAckPositions.get(entry.getValue()).right;
            thisBitSet.flip(0, batchSize);
            BitSetRecyclable otherBitSet = BitSetRecyclable.valueOf(individualAckPositions.get(entry.getValue()).left.getAckSet());
            otherBitSet.or(thisBitSet);
            if (otherBitSet.cardinality() == batchSize) {
                individualAckPositions.remove(entry.getValue());
            } else {
                individualAckPositions.get(entry.getKey()).left.setAckSet(otherBitSet.toLongArray());
            }
            otherBitSet.recycle();
            thisBitSet.recycle();
        } else {
            individualAckPositions.remove(entry.getValue());
        }
    }
    individualAckOfTransaction.remove(txnID);
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) LinkedMap(org.apache.commons.collections4.map.LinkedMap) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 7 with BitSetRecyclable

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

the class PersistentTopicsBase method calculatePositionAckSet.

private PositionImpl calculatePositionAckSet(boolean isExcluded, int batchSize, int batchIndex, MessageIdImpl messageId) {
    PositionImpl seekPosition;
    if (batchSize > 0) {
        long[] ackSet;
        BitSetRecyclable bitSet = BitSetRecyclable.create();
        bitSet.set(0, batchSize);
        if (isExcluded) {
            bitSet.clear(0, Math.max(batchIndex + 1, 0));
            if (bitSet.length() > 0) {
                ackSet = bitSet.toLongArray();
                seekPosition = PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId(), ackSet);
            } else {
                seekPosition = PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId());
                seekPosition = seekPosition.getNext();
            }
        } else {
            if (batchIndex - 1 >= 0) {
                bitSet.clear(0, batchIndex);
                ackSet = bitSet.toLongArray();
                seekPosition = PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId(), ackSet);
            } else {
                seekPosition = PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId());
            }
        }
        bitSet.recycle();
    } else {
        seekPosition = PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId());
        seekPosition = isExcluded ? seekPosition.getNext() : seekPosition;
    }
    return seekPosition;
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl)

Example 8 with BitSetRecyclable

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

the class ConsumerImpl method doTransactionAcknowledgeForResponse.

private CompletableFuture<Void> doTransactionAcknowledgeForResponse(MessageId messageId, AckType ackType, ValidationError validationError, Map<String, Long> properties, TxnID txnID) {
    BitSetRecyclable bitSetRecyclable = null;
    long ledgerId;
    long entryId;
    ByteBuf cmd;
    long requestId = client.newRequestId();
    if (messageId instanceof BatchMessageIdImpl) {
        BatchMessageIdImpl batchMessageId = (BatchMessageIdImpl) messageId;
        bitSetRecyclable = BitSetRecyclable.create();
        ledgerId = batchMessageId.getLedgerId();
        entryId = batchMessageId.getEntryId();
        if (ackType == AckType.Cumulative) {
            batchMessageId.ackCumulative();
            bitSetRecyclable.set(0, batchMessageId.getBatchSize());
            bitSetRecyclable.clear(0, batchMessageId.getBatchIndex() + 1);
        } else {
            bitSetRecyclable.set(0, batchMessageId.getBatchSize());
            bitSetRecyclable.clear(batchMessageId.getBatchIndex());
        }
        cmd = Commands.newAck(consumerId, ledgerId, entryId, bitSetRecyclable, ackType, validationError, properties, txnID.getLeastSigBits(), txnID.getMostSigBits(), requestId, batchMessageId.getBatchSize());
        bitSetRecyclable.recycle();
    } else {
        MessageIdImpl singleMessage = (MessageIdImpl) messageId;
        ledgerId = singleMessage.getLedgerId();
        entryId = singleMessage.getEntryId();
        cmd = Commands.newAck(consumerId, ledgerId, entryId, bitSetRecyclable, ackType, validationError, properties, txnID.getLeastSigBits(), txnID.getMostSigBits(), requestId);
    }
    if (ackType == AckType.Cumulative) {
        unAckedMessageTracker.removeMessagesTill(messageId);
    } else {
        unAckedMessageTracker.remove(messageId);
    }
    return cnx().newAckForReceipt(cmd, requestId);
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) ByteBuf(io.netty.buffer.ByteBuf)

Example 9 with BitSetRecyclable

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

the class PersistentAcknowledgmentsGroupingTracker method doImmediateBatchIndexAck.

private CompletableFuture<Void> doImmediateBatchIndexAck(BatchMessageIdImpl msgId, int batchIndex, int batchSize, AckType ackType, Map<String, Long> properties) {
    ClientCnx cnx = consumer.getClientCnx();
    if (cnx == null) {
        return FutureUtil.failedFuture(new PulsarClientException.ConnectException("Consumer connect fail! consumer state:" + consumer.getState()));
    }
    BitSetRecyclable bitSet;
    if (msgId.getAcker() != null && !(msgId.getAcker() instanceof BatchMessageAckerDisabled)) {
        bitSet = BitSetRecyclable.valueOf(msgId.getAcker().getBitSet().toLongArray());
    } else {
        bitSet = BitSetRecyclable.create();
        bitSet.set(0, batchSize);
    }
    if (ackType == AckType.Cumulative) {
        bitSet.clear(0, batchIndex + 1);
    } else {
        bitSet.clear(batchIndex);
    }
    CompletableFuture<Void> completableFuture = newMessageAckCommandAndWrite(cnx, consumer.consumerId, msgId.ledgerId, msgId.entryId, bitSet, ackType, null, properties, true, null, null);
    bitSet.recycle();
    return completableFuture;
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) ConcurrentBitSetRecyclable(org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException)

Example 10 with BitSetRecyclable

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

the class PersistentAcknowledgmentsGroupingTracker method doCumulativeBatchIndexAck.

private CompletableFuture<Void> doCumulativeBatchIndexAck(BatchMessageIdImpl batchMessageId, Map<String, Long> properties) {
    if (acknowledgementGroupTimeMicros == 0 || (properties != null && !properties.isEmpty())) {
        return doImmediateBatchIndexAck(batchMessageId, batchMessageId.getBatchIndex(), batchMessageId.getBatchSize(), AckType.Cumulative, properties);
    } else {
        BitSetRecyclable bitSet = BitSetRecyclable.create();
        bitSet.set(0, batchMessageId.getBatchSize());
        bitSet.clear(0, batchMessageId.getBatchIndex() + 1);
        return doCumulativeAck(batchMessageId, null, bitSet);
    }
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) ConcurrentBitSetRecyclable(org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable)

Aggregations

BitSetRecyclable (org.apache.pulsar.common.util.collections.BitSetRecyclable)22 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)7 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 ManagedLedgerException.getManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException)3 ManagedCursorImpl (org.apache.bookkeeper.mledger.impl.ManagedCursorImpl)3 ManagedLedgerImpl.createManagedLedgerException (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.createManagedLedgerException)3 Test (org.testng.annotations.Test)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 BKException (org.apache.bookkeeper.client.BKException)2 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)2 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)2