use of org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair in project pulsar by apache.
the class Consumer method getBatchSize.
private long getBatchSize(MessageIdData msgId) {
long batchSize = 1;
if (Subscription.isIndividualAckMode(subType)) {
LongPair longPair = pendingAcks.get(msgId.getLedgerId(), msgId.getEntryId());
// Consumer may ack the msg that not belongs to it.
if (longPair == null) {
Consumer ackOwnerConsumer = getAckOwnerConsumer(msgId.getLedgerId(), msgId.getEntryId());
longPair = ackOwnerConsumer.getPendingAcks().get(msgId.getLedgerId(), msgId.getEntryId());
if (longPair != null) {
batchSize = longPair.first;
}
} else {
batchSize = longPair.first;
}
}
return batchSize;
}
use of org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair in project pulsar by apache.
the class ConcurrentLongLongPairHashMapTest method simpleInsertions.
@Test
public void simpleInsertions() {
ConcurrentLongLongPairHashMap map = ConcurrentLongLongPairHashMap.newBuilder().expectedItems(16).build();
assertTrue(map.isEmpty());
assertTrue(map.put(1, 1, 11, 11));
assertFalse(map.isEmpty());
assertTrue(map.put(2, 2, 22, 22));
assertTrue(map.put(3, 3, 33, 33));
assertEquals(map.size(), 3);
assertEquals(map.get(1, 1), new LongPair(11, 11));
assertEquals(map.size(), 3);
assertTrue(map.remove(1, 1));
assertEquals(map.size(), 2);
assertEquals(map.get(1, 1), null);
assertEquals(map.get(5, 5), null);
assertEquals(map.size(), 2);
assertTrue(map.put(1, 1, 11, 11));
assertEquals(map.size(), 3);
assertTrue(map.put(1, 1, 111, 111));
assertEquals(map.size(), 3);
}
use of org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair in project pulsar by apache.
the class ConcurrentLongLongPairHashMapTest method testPutIfAbsent.
@Test
public void testPutIfAbsent() {
ConcurrentLongLongPairHashMap map = ConcurrentLongLongPairHashMap.newBuilder().build();
assertTrue(map.putIfAbsent(1, 1, 11, 11));
assertEquals(map.get(1, 1), new LongPair(11, 11));
assertFalse(map.putIfAbsent(1, 1, 111, 111));
assertEquals(map.get(1, 1), new LongPair(11, 11));
}
use of org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair in project pulsar by apache.
the class ConcurrentLongLongPairHashMapTest method testAsMap.
@Test
public void testAsMap() {
ConcurrentLongLongPairHashMap lmap = ConcurrentLongLongPairHashMap.newBuilder().expectedItems(16).concurrencyLevel(1).build();
lmap.put(1, 1, 11, 11);
lmap.put(2, 2, 22, 22);
lmap.put(3, 3, 33, 33);
Map<LongPair, LongPair> map = new HashMap<>();
map.put(new LongPair(1, 1), new LongPair(11, 11));
map.put(new LongPair(2, 2), new LongPair(22, 22));
map.put(new LongPair(3, 3), new LongPair(33, 33));
assertEquals(map, lmap.asMap());
}
use of org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair in project pulsar by apache.
the class Consumer method redeliverUnacknowledgedMessages.
public void redeliverUnacknowledgedMessages(List<MessageIdData> messageIds) {
int totalRedeliveryMessages = 0;
List<PositionImpl> pendingPositions = Lists.newArrayList();
for (MessageIdData msg : messageIds) {
PositionImpl position = PositionImpl.get(msg.getLedgerId(), msg.getEntryId());
LongPair longPair = pendingAcks.get(position.getLedgerId(), position.getEntryId());
if (longPair != null) {
int unAckedCount = (int) getUnAckedCountForBatchIndexLevelEnabled(position, longPair.first);
pendingAcks.remove(position.getLedgerId(), position.getEntryId());
totalRedeliveryMessages += unAckedCount;
pendingPositions.add(position);
}
}
addAndGetUnAckedMsgs(this, -totalRedeliveryMessages);
blockedConsumerOnUnackedMsgs = false;
if (log.isDebugEnabled()) {
log.debug("[{}-{}] consumer {} received {} msg-redelivery {}", topicName, subscription, consumerId, totalRedeliveryMessages, pendingPositions.size());
}
subscription.redeliverUnacknowledgedMessages(this, pendingPositions);
msgRedeliver.recordMultipleEvents(totalRedeliveryMessages, totalRedeliveryMessages);
int numberOfBlockedPermits = PERMITS_RECEIVED_WHILE_CONSUMER_BLOCKED_UPDATER.getAndSet(this, 0);
// if permitsReceivedWhileConsumerBlocked has been accumulated then pass it to Dispatcher to flow messages
if (numberOfBlockedPermits > 0) {
MESSAGE_PERMITS_UPDATER.getAndAdd(this, numberOfBlockedPermits);
if (log.isDebugEnabled()) {
log.debug("[{}-{}] Added {} blockedPermits to broker.service.Consumer's messagePermits for consumer {}", topicName, subscription, numberOfBlockedPermits, consumerId);
}
subscription.consumerFlow(this, numberOfBlockedPermits);
}
}
Aggregations