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();
}
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;
}
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;
}
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;
}
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);
}
Aggregations