codelipenghui commented on pull request #10330:
URL: https://github.com/apache/pulsar/pull/10330#issuecomment-825619753


   Seems the problem is related to the crc32 checksum in the bookkeeper client. 
Since we have more than 1 component in the CompositeByteBuf, 
`CompositeByteBuf.hasMemoryAddress()` will return false, details to see 
implement at the CompositeByteBuf:
   
   ```
   public boolean hasMemoryAddress() {
           switch(this.componentCount) {
           case 0:
               return Unpooled.EMPTY_BUFFER.hasMemoryAddress();
           case 1:
               return this.components[0].buf.hasMemoryAddress();
           default:
               return false;
           }
       }
   ```
   
   For the crc32 checksum in the bookkeeper will use nioBuffer() to resume the 
CRC hash, due to `CompositeByteBuf..nioBuffer()` will copy the data to the 
HeapByteBuffer if the component size > 1.
   
   ```
   public static int resumeChecksum(int previousChecksum, ByteBuf payload) {
           if (payload.hasMemoryAddress() && (CRC32C_HASH instanceof 
Sse42Crc32C)) {
               return CRC32C_HASH.resume(previousChecksum, 
payload.memoryAddress() + payload.readerIndex(),
                   payload.readableBytes());
           } else if (payload.hasArray()) {
               return CRC32C_HASH.resume(previousChecksum, payload.array(), 
payload.arrayOffset() + payload.readerIndex(),
                   payload.readableBytes());
           } else {
               return CRC32C_HASH.resume(previousChecksum, payload.nioBuffer());
           }
       }
   ```


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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to