BewareMyPower opened a new pull request, #16196:
URL: https://github.com/apache/pulsar/pull/16196

   Fixes https://github.com/apache/pulsar/issues/16195
   
   ### Motivation
   
   [PIP-132](https://github.com/apache/pulsar/pull/14007) considers the
   message metadata size when computing the payload chunk size and the
   number of chunks. However, it could make some messages whose size is
   less than `maxMessageSize` cannot be sent. There are two reasons:
   1. The `MessageMetadata` will be updated after computing the payload
      chunk size, i.e. the actual metadata size would be greater.
   2. `OpSendMsg#getMessageHeaderAndPayloadSize` doesn't exclude all bytes
      other than the metadata and payload, e.g. the 4 bytes checksum field.
   
   For example, if the max message size is 100, send a string whose size is
   60 with chunking enabled.
   1. The initial metadata size is 25 so the chunk size is 75, the message
      won't be spit into chunks.
   2. After `serializeAndSendMessage`, the metadata size becomes 32, so the
      serialized header's total size is 4 + 8 + 6 + 4 + 32 = 54, and the
     total size is 54 + 60 = 114, see `headerContentSize` in
     `serializeCommandSendWithSize`.
   3. In `getMessageHeaderAndPayloadSize`, the returned value is computed
      by 114 - 8 - 4 = 102 > 100. The 6 bytes magic and checksum and 4
      bytes metadata length field are not included.
   
   ### Modifications
   
   - Update the message metadata before computing the chunk size.
   - Compute the correct size in `getMessageHeaderAndPayloadSize`.
   
   ### Verifying this change
   
   Add `testChunkSize` to verify all sizes in range [1, maxMessageSize] can
   be sent successfully when chunking is enabled.
   
   ### Documentation
   
   Check the box below or label this PR directly.
   
   Need to update docs? 
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
     
   - [x] `doc-not-needed` 
   (Please explain why)
     
   - [ ] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)


-- 
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]

Reply via email to