Search in sources :

Example 1 with ConcurrentBitSetRecyclable

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

the class AcknowledgementsGroupingTrackerTest method testDoIndividualBatchAckAsync.

@Test
public void testDoIndividualBatchAckAsync() throws Exception {
    ConsumerConfigurationData<?> conf = new ConsumerConfigurationData<>();
    AcknowledgmentsGroupingTracker tracker = new PersistentAcknowledgmentsGroupingTracker(consumer, conf, eventLoopGroup);
    MessageId messageId1 = new BatchMessageIdImpl(5, 1, 0, 3, 10, BatchMessageAckerDisabled.INSTANCE);
    BitSet bitSet = new BitSet(20);
    for (int i = 0; i < 20; i++) {
        bitSet.set(i, true);
    }
    MessageId messageId2 = new BatchMessageIdImpl(3, 2, 0, 5, 20, BatchMessageAcker.newAcker(bitSet));
    Method doIndividualBatchAckAsync = PersistentAcknowledgmentsGroupingTracker.class.getDeclaredMethod("doIndividualBatchAckAsync", BatchMessageIdImpl.class);
    doIndividualBatchAckAsync.setAccessible(true);
    doIndividualBatchAckAsync.invoke(tracker, messageId1);
    doIndividualBatchAckAsync.invoke(tracker, messageId2);
    Field pendingIndividualBatchIndexAcks = PersistentAcknowledgmentsGroupingTracker.class.getDeclaredField("pendingIndividualBatchIndexAcks");
    pendingIndividualBatchIndexAcks.setAccessible(true);
    ConcurrentHashMap<MessageIdImpl, ConcurrentBitSetRecyclable> batchIndexAcks = (ConcurrentHashMap<MessageIdImpl, ConcurrentBitSetRecyclable>) pendingIndividualBatchIndexAcks.get(tracker);
    MessageIdImpl position1 = new MessageIdImpl(5, 1, 0);
    MessageIdImpl position2 = new MessageIdImpl(3, 2, 0);
    assertTrue(batchIndexAcks.containsKey(position1));
    assertNotNull(batchIndexAcks.get(position1));
    assertEquals(batchIndexAcks.get(position1).cardinality(), 9);
    assertTrue(batchIndexAcks.containsKey(position2));
    assertNotNull(batchIndexAcks.get(position2));
    assertEquals(batchIndexAcks.get(position2).cardinality(), 19);
    tracker.close();
}
Also used : BitSet(java.util.BitSet) Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) ConcurrentBitSetRecyclable(org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MessageId(org.apache.pulsar.client.api.MessageId) Test(org.testng.annotations.Test)

Example 2 with ConcurrentBitSetRecyclable

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

the class PersistentAcknowledgmentsGroupingTracker method doIndividualBatchAckAsync.

private void doIndividualBatchAckAsync(BatchMessageIdImpl batchMessageId) {
    ConcurrentBitSetRecyclable bitSet = pendingIndividualBatchIndexAcks.computeIfAbsent(new MessageIdImpl(batchMessageId.getLedgerId(), batchMessageId.getEntryId(), batchMessageId.getPartitionIndex()), (v) -> {
        ConcurrentBitSetRecyclable value;
        if (batchMessageId.getAcker() != null && !(batchMessageId.getAcker() instanceof BatchMessageAckerDisabled)) {
            value = ConcurrentBitSetRecyclable.create(batchMessageId.getAcker().getBitSet());
        } else {
            value = ConcurrentBitSetRecyclable.create();
            value.set(0, batchMessageId.getOriginalBatchSize());
        }
        return value;
    });
    bitSet.clear(batchMessageId.getBatchIndex());
}
Also used : ConcurrentBitSetRecyclable(org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable)

Example 3 with ConcurrentBitSetRecyclable

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

the class Commands method newMultiMessageAckCommon.

private static BaseCommand newMultiMessageAckCommon(List<Triple<Long, Long, ConcurrentBitSetRecyclable>> entries) {
    BaseCommand cmd = localCmd(Type.ACK);
    CommandAck ack = cmd.setAck();
    int entriesCount = entries.size();
    for (int i = 0; i < entriesCount; i++) {
        long ledgerId = entries.get(i).getLeft();
        long entryId = entries.get(i).getMiddle();
        ConcurrentBitSetRecyclable bitSet = entries.get(i).getRight();
        MessageIdData msgId = ack.addMessageId().setLedgerId(ledgerId).setEntryId(entryId);
        if (bitSet != null) {
            long[] ackSet = bitSet.toLongArray();
            for (int j = 0; j < ackSet.length; j++) {
                msgId.addAckSet(ackSet[j]);
            }
            bitSet.recycle();
        }
    }
    return cmd;
}
Also used : CommandAck(org.apache.pulsar.common.api.proto.CommandAck) MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) ConcurrentBitSetRecyclable(org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable)

Aggregations

ConcurrentBitSetRecyclable (org.apache.pulsar.common.util.collections.ConcurrentBitSetRecyclable)3 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 BitSet (java.util.BitSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MessageId (org.apache.pulsar.client.api.MessageId)1 ConsumerConfigurationData (org.apache.pulsar.client.impl.conf.ConsumerConfigurationData)1 BaseCommand (org.apache.pulsar.common.api.proto.BaseCommand)1 CommandAck (org.apache.pulsar.common.api.proto.CommandAck)1 MessageIdData (org.apache.pulsar.common.api.proto.MessageIdData)1 Test (org.testng.annotations.Test)1