Package org.apache.hadoop.hbase.io.util
Class BlockIOUtils
java.lang.Object
org.apache.hadoop.hbase.io.util.BlockIOUtils
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static void
annotateBytesRead
(io.opentelemetry.api.common.AttributesBuilder attributesBuilder, long directBytesRead, long heapBytesRead) Conditionally annotateattributesBuilder
with appropriate attributes when values are non-zero.private static void
annotateHeapBytesRead
(io.opentelemetry.api.common.AttributesBuilder attributesBuilder, int heapBytesRead) Conditionally annotatespan
with the appropriate attribute when value is non-zero.private static io.opentelemetry.api.common.AttributesBuilder
builderFromContext
(io.opentelemetry.context.Context context) Construct a freshAttributesBuilder
from the providedContext
, populated with relevant attributes populated byHFileContextAttributesBuilderConsumer.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 leastnecessaryLen
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 leastnecessaryLen
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
Read length bytes into ByteBuffers directly.static void
readFullyWithHeapBuffer
(InputStream in, ByteBuff out, int length) Copying bytes from InputStream toByteBuff
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 leastnecessaryLen
and if possible,extraLen
also if available.
-
Field Details
-
LOG
-
byteBufferPositionedReadMethod
-
-
Constructor Details
-
BlockIOUtils
private BlockIOUtils()
-
-
Method Details
-
initByteBufferPositionReadableMethod
-
isByteBufferReadable
-
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 destinationByteBuff
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 toByteBuff
by using an temporary heap byte[] (default size is 1024 now).- Parameters:
in
- the InputStream to readout
- the destinationByteBuff
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 leastnecessaryLen
and if possible,extraLen
also if available. Analogous toIOUtils.readFully(InputStream, byte[], int, int)
, but specifies a number of "extra" bytes to also optionally read.- Parameters:
in
- the input stream to read frombuf
- the buffer to read intobufOffset
- the destination offset in the buffernecessaryLen
- the number of bytes that are absolutely necessary to readextraLen
- 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 destinationByteBuff
.dis
- input stream to read.necessaryLen
- bytes which we must readextraLen
- 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 leastnecessaryLen
and if possible,extraLen
also if available. Analogous toIOUtils.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 fromposition
- the position within the stream from which to start readingnecessaryLen
- the number of bytes that are absolutely necessary to readextraLen
- 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 leastnecessaryLen
and if possible,extraLen
also if available. Analogous toIOUtils.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 fromposition
- the position within the stream from which to start readingnecessaryLen
- the number of bytes that are absolutely necessary to readextraLen
- the number of extra bytes that would be nice to readreadAllBytes
- 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
- Throws:
IOException
-
builderFromContext
private static io.opentelemetry.api.common.AttributesBuilder builderFromContext(io.opentelemetry.context.Context context) Construct a freshAttributesBuilder
from the providedContext
, populated with relevant attributes populated byHFileContextAttributesBuilderConsumer.CONTEXT_KEY
. -
annotateHeapBytesRead
private static void annotateHeapBytesRead(io.opentelemetry.api.common.AttributesBuilder attributesBuilder, int heapBytesRead) Conditionally annotatespan
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 annotateattributesBuilder
with appropriate attributes when values are non-zero.
-