Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-26659

The ByteBuffer of metadata in RAMQueueEntry in BucketCache could be reused.

    XMLWordPrintableJSON

Details

    • Reviewed

    Description

      Currently, the process to write HFileBlocks into IOEngine in BucketCache is:

       if (data instanceof HFileBlock) {
                // If an instance of HFileBlock, save on some allocations.
                HFileBlock block = (HFileBlock) data;
                ByteBuff sliceBuf = block.getBufferReadOnly();
                ByteBuffer metadata = block.getMetaData();
                ioEngine.write(sliceBuf, offset);
                ioEngine.write(metadata, offset + len - metadata.limit());
              }
      

      The getMetaData() function in HFileBlock is:

      public ByteBuffer getMetaData() {
          ByteBuffer bb = ByteBuffer.allocate(BLOCK_METADATA_SPACE);
          bb = addMetaData(bb, true);
          bb.flip();
          return bb;
        }
      

      It will allocate new ByteBuffer every time.
      We could reuse a local variable of WriterThread to reduce the new allocation of this small piece ByteBuffer.
      Reasons:
      1. In a WriterThread, blocks in doDrain() function are written into IOEngine sequentially, there is no multi-threads problem.
      2. After IOEngine.write() function, the data in metadata ByteBuffer has been transferred into ByteArray (ByteBufferIOEngine) or FileChannel (FileIOEngine) safely. The lifecycle of it is within the if statement above. So that it could be cleared and reused by the next block's writing process.

      Attachments

        Issue Links

          Activity

            People

              xytss123 Yutong Xiao
              xytss123 Yutong Xiao
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: