Search in sources :

Example 11 with PositionImpl

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;
}
Also used : PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) Entry(org.apache.bookkeeper.mledger.Entry) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) ByteBuf(io.netty.buffer.ByteBuf)

Example 12 with PositionImpl

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());
    }
}
Also used : MessageIdData(com.yahoo.pulsar.common.api.proto.PulsarApi.MessageIdData) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl)

Example 13 with PositionImpl

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();
}
Also used : PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl)

Example 14 with PositionImpl

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();
}
Also used : CommandSuccess(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Aggregations

PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)14 ByteBuf (io.netty.buffer.ByteBuf)6 Test (org.testng.annotations.Test)5 MessageIdData (com.yahoo.pulsar.common.api.proto.PulsarApi.MessageIdData)3 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)2 PersistentSubscription (com.yahoo.pulsar.broker.service.persistent.PersistentSubscription)2 PersistentTopic (com.yahoo.pulsar.broker.service.persistent.PersistentTopic)2 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)2 CloseCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback)2 DeleteCursorCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteCursorCallback)2 OpenCursorCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.OpenCursorCallback)2 OpenLedgerCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.OpenLedgerCallback)2 Entry (org.apache.bookkeeper.mledger.Entry)2 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)2 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 NotAllowedException (com.yahoo.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)1 TopicBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.TopicBusyException)1