use of org.apache.bookkeeper.mledger.impl.PositionImpl in project pulsar by yahoo.
the class Consumer method updatePermitsAndPendingAcks.
int updatePermitsAndPendingAcks(final List<Entry> entries) throws PulsarServerException {
int permitsToReduce = 0;
Iterator<Entry> iter = entries.iterator();
boolean unsupportedVersion = false;
boolean clientSupportBatchMessages = cnx.isBatchMessageCompatibleVersion();
while (iter.hasNext()) {
Entry entry = iter.next();
ByteBuf metadataAndPayload = entry.getDataBuffer();
int batchSize = getBatchSizeforEntry(metadataAndPayload);
if (batchSize == -1) {
// this would suggest that the message might have been corrupted
iter.remove();
entry.release();
PositionImpl pos = PositionImpl.get((PositionImpl) entry.getPosition());
subscription.acknowledgeMessage(pos, AckType.Individual);
continue;
}
if (pendingAcks != null) {
PositionImpl pos = PositionImpl.get((PositionImpl) entry.getPosition());
pendingAcks.put(pos, batchSize);
}
// check if consumer supports batch message
if (batchSize > 1 && !clientSupportBatchMessages) {
unsupportedVersion = true;
}
permitsToReduce += batchSize;
}
// reduce permit and increment unackedMsg count with total number of messages in batch-msgs
int permits = MESSAGE_PERMITS_UPDATER.addAndGet(this, -permitsToReduce);
incrementUnackedMessages(permitsToReduce);
if (unsupportedVersion) {
throw new PulsarServerException("Consumer does not support batch-message");
}
if (permits < 0) {
if (log.isDebugEnabled()) {
log.debug("[{}] [{}] message permits dropped below 0 - {}", subscription, consumerId, permits);
}
}
return permitsToReduce;
}
use of org.apache.bookkeeper.mledger.impl.PositionImpl in project pulsar by yahoo.
the class Consumer method messageAcked.
void messageAcked(CommandAck ack) {
MessageIdData msgId = ack.getMessageId();
PositionImpl position = PositionImpl.get(msgId.getLedgerId(), msgId.getEntryId());
if (ack.hasValidationError()) {
log.error("[{}] [{}] Received ack for corrupted message at {} - Reason: {}", subscription, consumerId, position, ack.getValidationError());
}
if (subType == SubType.Shared) {
// On shared subscriptions, cumulative ack is not supported
checkArgument(ack.getAckType() == AckType.Individual);
// Only ack a single message
removePendingAcks(position);
subscription.acknowledgeMessage(position, AckType.Individual);
} else {
subscription.acknowledgeMessage(position, ack.getAckType());
}
}
use of org.apache.bookkeeper.mledger.impl.PositionImpl in project pulsar by yahoo.
the class PersistentTopic method addComplete.
@Override
public void addComplete(Position pos, Object ctx) {
PublishCallback callback = (PublishCallback) ctx;
PositionImpl position = (PositionImpl) pos;
// Message has been successfully persisted
callback.completed(null, position.getLedgerId(), position.getEntryId());
position.recycle();
}
use of org.apache.bookkeeper.mledger.impl.PositionImpl in project pulsar by yahoo.
the class ServerCnxTest method testAckCommand.
@Test(timeOut = 30000)
public void testAckCommand() throws Exception {
resetChannel();
setChannelConnected();
ByteBuf clientCommand = Commands.newSubscribe(successTopicName, successSubName, 1, /* consumer id */
1, /*
* request id
*/
SubType.Exclusive, 0, "test");
channel.writeInbound(clientCommand);
assertTrue(getResponse() instanceof CommandSuccess);
PositionImpl pos = new PositionImpl(0, 0);
clientCommand = Commands.newAck(1, /* consumer id */
pos.getLedgerId(), pos.getEntryId(), AckType.Individual, null);
channel.writeInbound(clientCommand);
// verify nothing is sent out on the wire after ack
assertNull(channel.outboundMessages().peek());
channel.finish();
}
Aggregations