franz1981 commented on a change in pull request #3370:
URL: https://github.com/apache/activemq-artemis/pull/3370#discussion_r753982983
##########
File path:
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
##########
@@ -748,21 +754,42 @@ public synchronized CoreMessage encode() {
public void encodeHeadersAndProperties(final ByteBuf buffer) {
final TypedProperties properties = getProperties();
- messageIDPosition = buffer.writerIndex();
- buffer.writeLong(messageID);
- SimpleString.writeNullableSimpleString(buffer, address);
- if (userID == null) {
- buffer.writeByte(DataConstants.NULL);
- } else {
- buffer.writeByte(DataConstants.NOT_NULL);
- buffer.writeBytes(userID.asBytes());
+ final int initialWriterIndex = buffer.writerIndex();
+ messageIDPosition = initialWriterIndex;
+ final UUID userID = this.userID;
+ final int userIDEncodedSize = userID == null ? Byte.BYTES : Byte.BYTES +
userID.asBytes().length;
+ final SimpleString address = this.address;
+ final int addressEncodedBytes =
SimpleString.sizeofNullableString(address);
+ final int headersSize =
+ Long.BYTES + // messageID
+ addressEncodedBytes + // address
+ userIDEncodedSize + // userID
+ Byte.BYTES + // type
+ Byte.BYTES + // durable
+ Long.BYTES + // expiration
+ Long.BYTES + // timestamp
+ Byte.BYTES; // priority
+ synchronized (properties) {
Review comment:
@clebertsuconic this is needed because there are tests/cases where
`properties`'s content can change concurrently and the presized underlying
buffer using `properties::getEncodeSize` is no longer valid.
I think we shouldn't allow `properties` to change concurrently while
encoding is happening: is it a valid use case?
--
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]