shengminw commented on code in PR #4469:
URL: https://github.com/apache/rocketmq/pull/4469#discussion_r899718674
##########
store/src/main/java/org/apache/rocketmq/store/CommitLog.java:
##########
@@ -1480,11 +1480,15 @@ public static class MessageExtEncoder {
private final ByteBuf byteBuf;
// The maximum length of the message body.
private final int maxMessageBodySize;
-
+ // The maximum length of the full message.
+ private final int maxMessageSize;
MessageExtEncoder(final int maxMessageBodySize) {
ByteBufAllocator alloc = UnpooledByteBufAllocator.DEFAULT;
- byteBuf = alloc.directBuffer(maxMessageBodySize);
+ //Reserve 64kb for encoding buffer outside body
+ int maxMessageSize = maxMessageBodySize + 64 * 1024;
+ byteBuf = alloc.directBuffer(maxMessageSize);
Review Comment:
Most of parameters in the message encoding are fixed length, only the
properties and tpopic name content are variable. The maximum length of
properties should be less than or equal to Short.MAX_VALUE, and the topic name
content should be less than or equal to 127 bytes. Taking the maximum value, it
adds up to about 33kb. Considering to reserve some space for subsequent
adjustments, 64kb was chosen.
* org.apache.rocketmq.client.Validators#TOPIC_MAX_LENGTH
```java
public static final int TOPIC_MAX_LENGTH = 127;
```
* org.apache.rocketmq.store.CommitLog.MessageExtEncoder#encode
```java
if (propertiesLength > Short.MAX_VALUE) {
log.warn("putMessage message properties length too long. length={}",
propertiesData.length);
return new PutMessageResult(PutMessageStatus.PROPERTIES_SIZE_EXCEEDED,
null);
}
```
Note: The maximum length of the topic is set on the client side, and there
is no open interface for modification. Besides, the broker side does not
provide the parameter "TOPIC_MAX_LENGTH", so I directly select the extra space
as a fixed value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]