Search in sources :

Example 1 with BitSetRecyclable

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

the class PositionAckSetUtil method andAckSet.

// This method is do `and` operation for position's ack set
public static void andAckSet(PositionImpl currentPosition, PositionImpl otherPosition) {
    if (currentPosition == null || otherPosition == null) {
        return;
    }
    BitSetRecyclable thisAckSet = BitSetRecyclable.valueOf(currentPosition.getAckSet());
    BitSetRecyclable otherAckSet = BitSetRecyclable.valueOf(otherPosition.getAckSet());
    thisAckSet.and(otherAckSet);
    currentPosition.setAckSet(thisAckSet.toLongArray());
    thisAckSet.recycle();
    otherAckSet.recycle();
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable)

Example 2 with BitSetRecyclable

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

the class PositionAckSetUtil method isAckSetOverlap.

// This method is to compare two ack set whether overlap or not
public static boolean isAckSetOverlap(long[] currentAckSet, long[] otherAckSet) {
    if (currentAckSet == null || otherAckSet == null) {
        return false;
    }
    BitSetRecyclable currentBitSet = BitSetRecyclable.valueOf(currentAckSet);
    BitSetRecyclable otherBitSet = BitSetRecyclable.valueOf(otherAckSet);
    currentBitSet.flip(0, currentBitSet.size());
    otherBitSet.flip(0, otherBitSet.size());
    currentBitSet.and(otherBitSet);
    boolean isAckSetRepeated = !currentBitSet.isEmpty();
    currentBitSet.recycle();
    otherBitSet.recycle();
    return isAckSetRepeated;
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable)

Example 3 with BitSetRecyclable

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

the class Consumer method getAckedCountForBatchIndexLevelEnabled.

private long getAckedCountForBatchIndexLevelEnabled(PositionImpl position, long batchSize, long[] ackSets) {
    long ackedCount = 0;
    if (isAcknowledgmentAtBatchIndexLevelEnabled && Subscription.isIndividualAckMode(subType) && pendingAcks.get(position.getLedgerId(), position.getEntryId()) != null) {
        long[] cursorAckSet = getCursorAckSet(position);
        if (cursorAckSet != null) {
            BitSetRecyclable cursorBitSet = BitSetRecyclable.create().resetWords(cursorAckSet);
            int lastCardinality = cursorBitSet.cardinality();
            BitSetRecyclable givenBitSet = BitSetRecyclable.create().resetWords(ackSets);
            cursorBitSet.and(givenBitSet);
            givenBitSet.recycle();
            int currentCardinality = cursorBitSet.cardinality();
            ackedCount = lastCardinality - currentCardinality;
            cursorBitSet.recycle();
        } else {
            ackedCount = batchSize - BitSet.valueOf(ackSets).cardinality();
        }
    }
    return ackedCount;
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable)

Example 4 with BitSetRecyclable

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

the class Consumer method getAckedCountForTransactionAck.

private long getAckedCountForTransactionAck(long batchSize, long[] ackSets) {
    BitSetRecyclable bitset = BitSetRecyclable.create().resetWords(ackSets);
    long ackedCount = batchSize - bitset.cardinality();
    bitset.recycle();
    return ackedCount;
}
Also used : BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable)

Example 5 with BitSetRecyclable

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

the class PendingAckHandleImpl method handleIndividualAckRecover.

protected void handleIndividualAckRecover(TxnID txnID, List<MutablePair<PositionImpl, Integer>> positions) {
    for (MutablePair<PositionImpl, Integer> positionIntegerMutablePair : positions) {
        PositionImpl position = positionIntegerMutablePair.left;
        // normal acknowledge,throw exception.
        if (((ManagedCursorImpl) persistentSubscription.getCursor()).isMessageDeleted(position)) {
            return;
        }
        if (position.hasAckSet()) {
            // in order to jude the bit set is over lap, so set the covering
            // the batch size bit to 1,should know the two
            // bit set don't have the same point is 0
            BitSetRecyclable bitSetRecyclable = BitSetRecyclable.valueOf(position.getAckSet());
            if (positionIntegerMutablePair.right > bitSetRecyclable.size()) {
                bitSetRecyclable.set(positionIntegerMutablePair.right);
            }
            bitSetRecyclable.set(positionIntegerMutablePair.right, bitSetRecyclable.size());
            long[] ackSetOverlap = bitSetRecyclable.toLongArray();
            bitSetRecyclable.recycle();
            if (isAckSetOverlap(ackSetOverlap, ((ManagedCursorImpl) persistentSubscription.getCursor()).getBatchPositionAckSet(position))) {
                return;
            }
            if (individualAckPositions != null && individualAckPositions.containsKey(position) && isAckSetOverlap(individualAckPositions.get(position).getLeft().getAckSet(), ackSetOverlap)) {
                return;
            }
        } else {
            if (individualAckPositions != null && individualAckPositions.containsKey(position)) {
                return;
            }
        }
    }
    handleIndividualAck(txnID, positions);
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl)

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