Package org.apache.hadoop.hdfs.protocol
Class BlockListAsLongs
java.lang.Object
org.apache.hadoop.hdfs.protocol.BlockListAsLongs
- All Implemented Interfaces:
Iterable<BlockListAsLongs.BlockReportReplica>
@Private
@Evolving
public abstract class BlockListAsLongs
extends Object
implements Iterable<BlockListAsLongs.BlockReportReplica>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BlockListAsLongs.Builderbuilder()static BlockListAsLongs.Builderbuilder(int maxDataLength) static BlockListAsLongsdecodeBuffer(int numBlocks, org.apache.hadoop.thirdparty.protobuf.ByteString blocksBuf, int maxDataLength) Prepare an instance to in-place decode the given ByteString buffer.static BlockListAsLongsdecodeBuffers(int numBlocks, List<org.apache.hadoop.thirdparty.protobuf.ByteString> blocksBufs) Prepare an instance to in-place decode the given ByteString buffers.static BlockListAsLongsdecodeBuffers(int numBlocks, List<org.apache.hadoop.thirdparty.protobuf.ByteString> blocksBufs, int maxDataLength) Prepare an instance to in-place decode the given ByteString buffers.static BlockListAsLongsdecodeLongs(List<Long> blocksList) Prepare an instance to in-place decode the given list of Longs.static BlockListAsLongsdecodeLongs(List<Long> blocksList, int maxDataLength) Prepare an instance to in-place decode the given list of Longs.static BlockListAsLongsencode(Collection<? extends Replica> replicas) Prepare an instance to encode the collection of replicas into an efficient ByteString.abstract long[]Convert block report to old-style list of longs.abstract org.apache.hadoop.thirdparty.protobuf.ByteStringVery efficient encoding of the block report into a ByteString to avoid the overhead of protobuf repeating fields.List<org.apache.hadoop.thirdparty.protobuf.ByteString>List of ByteStrings that encode this block reportabstract intThe number of blocksabstract Iterator<BlockListAsLongs.BlockReportReplica>iterator()Returns a singleton iterator over blocks in the block report.static BlockListAsLongsreadFrom(InputStream is, int maxDataLength) voidwriteTo(OutputStream os) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
EMPTY
-
-
Constructor Details
-
BlockListAsLongs
public BlockListAsLongs()
-
-
Method Details
-
decodeBuffer
public static BlockListAsLongs decodeBuffer(int numBlocks, org.apache.hadoop.thirdparty.protobuf.ByteString blocksBuf, int maxDataLength) Prepare an instance to in-place decode the given ByteString buffer.- Parameters:
numBlocks- - blocks in the bufferblocksBuf- - ByteString encoded varintsmaxDataLength- - maximum allowable data size in protobuf message- Returns:
- BlockListAsLongs
-
decodeBuffers
@VisibleForTesting public static BlockListAsLongs decodeBuffers(int numBlocks, List<org.apache.hadoop.thirdparty.protobuf.ByteString> blocksBufs) Prepare an instance to in-place decode the given ByteString buffers.- Parameters:
numBlocks- - blocks in the buffersblocksBufs- - list of ByteString encoded varints- Returns:
- BlockListAsLongs
-
decodeBuffers
public static BlockListAsLongs decodeBuffers(int numBlocks, List<org.apache.hadoop.thirdparty.protobuf.ByteString> blocksBufs, int maxDataLength) Prepare an instance to in-place decode the given ByteString buffers.- Parameters:
numBlocks- - blocks in the buffersblocksBufs- - list of ByteString encoded varintsmaxDataLength- - maximum allowable data size in protobuf message- Returns:
- BlockListAsLongs
-
decodeLongs
Prepare an instance to in-place decode the given list of Longs. Note it's much more efficient to decode ByteString buffers and only exists for compatibility.- Parameters:
blocksList- - list of longs- Returns:
- BlockListAsLongs
-
decodeLongs
Prepare an instance to in-place decode the given list of Longs. Note it's much more efficient to decode ByteString buffers and only exists for compatibility.- Parameters:
blocksList- - list of longsmaxDataLength- - maximum allowable data size in protobuf message- Returns:
- BlockListAsLongs
-
encode
Prepare an instance to encode the collection of replicas into an efficient ByteString.- Parameters:
replicas- - replicas to encode- Returns:
- BlockListAsLongs
-
readFrom
- Throws:
IOException
-
writeTo
- Throws:
IOException
-
builder
-
builder
-
getNumberOfBlocks
public abstract int getNumberOfBlocks()The number of blocks- Returns:
- - the number of blocks
-
getBlocksBuffer
public abstract org.apache.hadoop.thirdparty.protobuf.ByteString getBlocksBuffer()Very efficient encoding of the block report into a ByteString to avoid the overhead of protobuf repeating fields. Primitive repeating fields require re-allocs of an ArrayList<Long> and the associated (un)boxing overhead which puts pressure on GC. The structure of the buffer is as follows: - each replica is represented by 4 longs: blockId, block length, genstamp, replica state- Returns:
- ByteString encoded block report
-
getBlocksBuffers
List of ByteStrings that encode this block report- Returns:
- ByteStrings
-
getBlockListAsLongs
public abstract long[] getBlockListAsLongs()Convert block report to old-style list of longs. Only used to re-encode the block report when the DN detects an older NN. This is inefficient, but in practice a DN is unlikely to be upgraded first The structure of the array is as follows: 0: the length of the finalized replica list; 1: the length of the under-construction replica list; - followed by finalized replica list where each replica is represented by 3 longs: one for the blockId, one for the block length, and one for the generation stamp; - followed by the invalid replica represented with three -1s; - followed by the under-construction replica list where each replica is represented by 4 longs: three for the block id, length, generation stamp, and the fourth for the replica state.- Returns:
- list of longs
-
iterator
Returns a singleton iterator over blocks in the block report. Do not add the returned blocks to a collection.- Specified by:
iteratorin interfaceIterable<BlockListAsLongs.BlockReportReplica>- Returns:
- Iterator
-