Class BlockIOUtils

java.lang.Object
org.apache.hadoop.hbase.io.util.BlockIOUtils

@Private public final class BlockIOUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static Method
     
    private static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    annotateBytesRead(io.opentelemetry.api.common.AttributesBuilder attributesBuilder, long directBytesRead, long heapBytesRead)
    Conditionally annotate attributesBuilder with appropriate attributes when values are non-zero.
    private static void
    annotateHeapBytesRead(io.opentelemetry.api.common.AttributesBuilder attributesBuilder, int heapBytesRead)
    Conditionally annotate span with the appropriate attribute when value is non-zero.
    private static io.opentelemetry.api.common.AttributesBuilder
    builderFromContext(io.opentelemetry.context.Context context)
    Construct a fresh AttributesBuilder from the provided Context, populated with relevant attributes populated by HFileContextAttributesBuilderConsumer.CONTEXT_KEY.
    private static int
    copyToByteBuff(byte[] buf, int offset, int len, ByteBuff out)
     
    private static void
     
    static boolean
    isByteBufferReadable(org.apache.hadoop.fs.FSDataInputStream is)
     
    static boolean
    preadWithExtra(ByteBuff buff, org.apache.hadoop.fs.FSDataInputStream dis, long position, int necessaryLen, int extraLen)
    Read from an input stream at least necessaryLen and if possible, extraLen also if available.
    static boolean
    preadWithExtra(ByteBuff buff, org.apache.hadoop.fs.FSDataInputStream dis, long position, int necessaryLen, int extraLen, boolean readAllBytes)
    Read from an input stream at least necessaryLen and if possible, extraLen also if available.
    private static boolean
    preadWithExtraDirectly(ByteBuff buff, org.apache.hadoop.fs.FSDataInputStream dis, long position, int necessaryLen, int extraLen, boolean readAllBytes)
     
    private static boolean
    preadWithExtraOnHeap(ByteBuff buff, org.apache.hadoop.fs.FSDataInputStream dis, long position, int necessaryLen, int extraLen, boolean readAllBytes)
     
    static void
    readFully(ByteBuff buf, org.apache.hadoop.fs.FSDataInputStream dis, int length)
    Read length bytes into ByteBuffers directly.
    static void
    Copying bytes from InputStream to ByteBuff by using an temporary heap byte[] (default size is 1024 now).
    static boolean
    readWithExtra(ByteBuff buf, org.apache.hadoop.fs.FSDataInputStream dis, int necessaryLen, int extraLen)
    Read bytes into ByteBuffers directly, those buffers either contains the extraLen bytes or only contains necessaryLen bytes, which depends on how much bytes do the last time we read.
    private static boolean
    readWithExtraOnHeap(InputStream in, byte[] buf, int bufOffset, int necessaryLen, int extraLen)
    Read from an input stream at least necessaryLen and if possible, extraLen also if available.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • initByteBufferPositionReadableMethod

      private static void initByteBufferPositionReadableMethod()
    • isByteBufferReadable

      public static boolean isByteBufferReadable(org.apache.hadoop.fs.FSDataInputStream is)
    • readFully

      public static void readFully(ByteBuff buf, org.apache.hadoop.fs.FSDataInputStream dis, int length) throws IOException
      Read length bytes into ByteBuffers directly.
      Parameters:
      buf - the destination ByteBuff
      dis - the HDFS input stream which implement the ByteBufferReadable interface.
      length - bytes to read.
      Throws:
      IOException - exception to throw if any error happen
    • readFullyWithHeapBuffer

      public static void readFullyWithHeapBuffer(InputStream in, ByteBuff out, int length) throws IOException
      Copying bytes from InputStream to ByteBuff by using an temporary heap byte[] (default size is 1024 now).
      Parameters:
      in - the InputStream to read
      out - the destination ByteBuff
      length - to read
      Throws:
      IOException - if any io error encountered.
    • readWithExtraOnHeap

      private static boolean readWithExtraOnHeap(InputStream in, byte[] buf, int bufOffset, int necessaryLen, int extraLen) throws IOException
      Read from an input stream at least necessaryLen and if possible, extraLen also if available. Analogous to IOUtils.readFully(InputStream, byte[], int, int), but specifies a number of "extra" bytes to also optionally read.
      Parameters:
      in - the input stream to read from
      buf - the buffer to read into
      bufOffset - the destination offset in the buffer
      necessaryLen - the number of bytes that are absolutely necessary to read
      extraLen - the number of extra bytes that would be nice to read
      Returns:
      true if succeeded reading the extra bytes
      Throws:
      IOException - if failed to read the necessary bytes
    • readWithExtra

      public static boolean readWithExtra(ByteBuff buf, org.apache.hadoop.fs.FSDataInputStream dis, int necessaryLen, int extraLen) throws IOException
      Read bytes into ByteBuffers directly, those buffers either contains the extraLen bytes or only contains necessaryLen bytes, which depends on how much bytes do the last time we read.
      Parameters:
      buf - the destination ByteBuff.
      dis - input stream to read.
      necessaryLen - bytes which we must read
      extraLen - bytes which we may read
      Returns:
      if the returned flag is true, then we've finished to read the extraLen into our ByteBuffers, otherwise we've not read the extraLen bytes yet.
      Throws:
      IOException - if failed to read the necessary bytes.
    • preadWithExtra

      public static boolean preadWithExtra(ByteBuff buff, org.apache.hadoop.fs.FSDataInputStream dis, long position, int necessaryLen, int extraLen) throws IOException
      Read from an input stream at least necessaryLen and if possible, extraLen also if available. Analogous to IOUtils.readFully(InputStream, byte[], int, int), but uses positional read and specifies a number of "extra" bytes that would be desirable but not absolutely necessary to read. If the input stream supports ByteBufferPositionedReadable, it reads to the byte buffer directly, and does not allocate a temporary byte array.
      Parameters:
      buff - ByteBuff to read into.
      dis - the input stream to read from
      position - the position within the stream from which to start reading
      necessaryLen - the number of bytes that are absolutely necessary to read
      extraLen - the number of extra bytes that would be nice to read
      Returns:
      true if and only if extraLen is > 0 and reading those extra bytes was successful
      Throws:
      IOException - if failed to read the necessary bytes
    • preadWithExtra

      public static boolean preadWithExtra(ByteBuff buff, org.apache.hadoop.fs.FSDataInputStream dis, long position, int necessaryLen, int extraLen, boolean readAllBytes) throws IOException
      Read from an input stream at least necessaryLen and if possible, extraLen also if available. Analogous to IOUtils.readFully(InputStream, byte[], int, int), but uses positional read and specifies a number of "extra" bytes that would be desirable but not absolutely necessary to read. If the input stream supports ByteBufferPositionedReadable, it reads to the byte buffer directly, and does not allocate a temporary byte array.
      Parameters:
      buff - ByteBuff to read into.
      dis - the input stream to read from
      position - the position within the stream from which to start reading
      necessaryLen - the number of bytes that are absolutely necessary to read
      extraLen - the number of extra bytes that would be nice to read
      readAllBytes - whether we must read the necessaryLen and extraLen
      Returns:
      true if and only if extraLen is > 0 and reading those extra bytes was successful
      Throws:
      IOException - if failed to read the necessary bytes
    • preadWithExtraOnHeap

      private static boolean preadWithExtraOnHeap(ByteBuff buff, org.apache.hadoop.fs.FSDataInputStream dis, long position, int necessaryLen, int extraLen, boolean readAllBytes) throws IOException
      Throws:
      IOException
    • preadWithExtraDirectly

      private static boolean preadWithExtraDirectly(ByteBuff buff, org.apache.hadoop.fs.FSDataInputStream dis, long position, int necessaryLen, int extraLen, boolean readAllBytes) throws IOException
      Throws:
      IOException
    • copyToByteBuff

      private static int copyToByteBuff(byte[] buf, int offset, int len, ByteBuff out) throws IOException
      Throws:
      IOException
    • builderFromContext

      private static io.opentelemetry.api.common.AttributesBuilder builderFromContext(io.opentelemetry.context.Context context)
      Construct a fresh AttributesBuilder from the provided Context, populated with relevant attributes populated by HFileContextAttributesBuilderConsumer.CONTEXT_KEY.
    • annotateHeapBytesRead

      private static void annotateHeapBytesRead(io.opentelemetry.api.common.AttributesBuilder attributesBuilder, int heapBytesRead)
      Conditionally annotate span with the appropriate attribute when value is non-zero.
    • annotateBytesRead

      private static void annotateBytesRead(io.opentelemetry.api.common.AttributesBuilder attributesBuilder, long directBytesRead, long heapBytesRead)
      Conditionally annotate attributesBuilder with appropriate attributes when values are non-zero.