Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIP 132] Include message header size when check maxMessageSize for non-batch message on the client side. #13591

Closed
Jason918 opened this issue Dec 31, 2021 · 1 comment
Assignees
Milestone

Comments

@Jason918
Copy link
Contributor

Motivation

Currently, Pulsar client (Java) only checks payload size for max message size validation.

Client throws TimeoutException if we produce a message with too many properties, see [1].
But the root cause is that is trigged TooLongFrameException in broker server.

In this PIP, I propose to include message header size when check maxMessageSize of non-batch messages, this brings the following benefits.

  1. Clients can throw InvalidMessageException immediately if properties takes too much storage space.
  2. This will make the behaviour consistent with topic level max message size check in broker.
  3. Strictly limit the entry size less than maxMessageSize, avoid sending message to bookkeeper failed.

Goal

Include message header size when check maxMessageSize for non-batch message on the client side.

Implementation

// Add a size check in org.apache.pulsar.client.impl.ProducerImpl#processOpSendMsg
if (op.msg != null // for non-batch messages only
    && op.getMessageHeaderAndPayloadSize() > ClientCnx.getMaxMessageSize()) {
    // finish send op with InvalidMessageException
    releaseSemaphoreForSendOp(op);
    op.sendComplete(new PulsarClientException(new InvalidMessageException, op.sequenceId));
}


// org.apache.pulsar.client.impl.ProducerImpl.OpSendMsg#getMessageHeaderAndPayloadSize

public int getMessageHeaderAndPayloadSize() {
    ByteBuf cmdHeader = cmd.getFirst();
    cmdHeader.markReaderIndex();
    int totalSize = cmdHeader.readInt();
    int cmdSize = cmdHeader.readInt();
    int msgHeadersAndPayloadSize = totalSize - cmdSize - 4;
    cmdHeader.resetReaderIndex();
    return msgHeadersAndPayloadSize;
}

Reject Alternatives

Add a new property like "maxPropertiesSize" or "maxHeaderSize" in broker.conf and pass it to client like maxMessageSize.
But the implementation is much more complex, and don't have the benefit 2 and 3 mentioned in Motivation.

Compatibility Issue

As a matter of fact, this PIP narrows down the sendable range. Previously, when maxMessageSize is 1KB, it's ok to send message with 1KB properties and 1KB payload. But with this PIP, the sending will fail with InvalidMessageException.

One conservative way is to add a boolean config "includeHeaderInSizeCheck" to enable this feature. But I think it's OK to enable this directly as it's more reasonable, and I don't see good migration plan if we add a config for this.

The compatibility issue is worth discussing. And any suggestions are appreciated.

[1] #13560

@github-actions
Copy link

The issue had no activity for 30 days, mark with Stale label.

codelipenghui pushed a commit that referenced this issue Mar 8, 2022
…on-batch message on the client side. (#14007)

Master Issue: #13591

### Motivation

See #13591

### Modifications

1. Add max message size check before sending request for non-batch and non-chunked messages.
2. Decrease chunk size by metadata size  for chunked messages.
gaozhangmin pushed a commit to gaozhangmin/pulsar that referenced this issue Mar 8, 2022
…on-batch message on the client side. (apache#14007)

Master Issue: apache#13591

### Motivation

See apache#13591

### Modifications

1. Add max message size check before sending request for non-batch and non-chunked messages.
2. Decrease chunk size by metadata size  for chunked messages.
@codelipenghui codelipenghui added this to the 2.11.0 milestone Mar 16, 2022
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this issue Apr 20, 2022
…on-batch message on the client side. (apache#14007)

Master Issue: apache#13591

### Motivation

See apache#13591

### Modifications

1. Add max message size check before sending request for non-batch and non-chunked messages.
2. Decrease chunk size by metadata size  for chunked messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants