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