chenxu14 commented on a change in pull request #678: HBASE-23107 Avoid temp 
byte array creation when doing cacheDataOnWrite
URL: https://github.com/apache/hbase/pull/678#discussion_r334217500
 
 

 ##########
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java
 ##########
 @@ -1170,19 +1190,19 @@ int blockSizeWritten() {
      * cache. Can be called in the "writing" state or the "block ready" state.
      * Returns only the header and data, does not include checksum data.
      *
-     * @return Returns a copy of uncompressed block bytes for caching on write
+     * @return Returns an uncompressed block ByteBuff for caching on write
      */
-    @VisibleForTesting
-    ByteBuffer cloneUncompressedBufferWithHeader() {
+    ByteBuff cloneUncompressedBufferWithHeader() {
       expectState(State.BLOCK_READY);
-      byte[] uncompressedBlockBytesWithHeader = baosInMemory.toByteArray();
+      ByteBuff bytebuff = allocator.allocate(baosInMemory.size());
+      baosInMemory.toByteBuff(bytebuff);
       int numBytes = (int) ChecksumUtil.numBytes(
           onDiskBlockBytesWithHeader.size(),
           fileContext.getBytesPerChecksum());
-      putHeader(uncompressedBlockBytesWithHeader, 0,
-        onDiskBlockBytesWithHeader.size() + numBytes,
-        baosInMemory.size(), onDiskBlockBytesWithHeader.size());
-      return ByteBuffer.wrap(uncompressedBlockBytesWithHeader);
+      putHeader(bytebuff, onDiskBlockBytesWithHeader.size() + numBytes,
 
 Review comment:
   The bytes in baosInMemory has no header info, just reserved the header 
space, so we should overwrite it in putHeader. @openinx 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to