Package org.apache.hadoop.hdfs.util
Class StripedBlockUtil
java.lang.Object
org.apache.hadoop.hdfs.util.StripedBlockUtil
When accessing a file in striped layout, operations on logical byte ranges
in the file need to be mapped to physical byte ranges on block files stored
on DataNodes. This utility class facilities this mapping by defining and
exposing a number of striping-related concepts. The most basic ones are
illustrated in the following diagram. Unless otherwise specified, all
range-related calculations are inclusive (the end offset of the previous
range should be 1 byte lower than the start offset of the next one).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classGiven a requested byte range on a striped block group, an AlignedStripe represents an inclusiveStripedBlockUtil.VerticalRangethat is aligned with both the byte range and boundaries of all internal blocks.static classStruct holding the read statistics.static classA utility to manage ByteBuffer slices for a reader.static classUsed to indicate the buffered data's range in the block group.static classCell is the unit of encoding used inDFSStripedOutputStream.static classIndicates the coverage of anStripedBlockUtil.AlignedStripeon an internal block, and the state of the chunk in the context of the read request.static classThis class represents result from a striped read request.static classA simple utility class representing an arbitrary vertical inclusive range starting atStripedBlockUtil.VerticalRange.offsetInBlockand lasting forStripedBlockUtil.VerticalRange.spanInBlockbytes in an internal block. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckBlocks(ExtendedBlock blockGroup, int i, ExtendedBlock blocki) Check if the information such as IDs and generation stamps in block-i match the block group.static ExtendedBlockconstructInternalBlock(ExtendedBlock blockGroup, int cellSize, int dataBlkNum, int idxInBlockGroup) This method creates an internalExtendedBlockat the given index of a block group.static ExtendedBlockconstructInternalBlock(ExtendedBlock blockGroup, ErasureCodingPolicy ecPolicy, int idxInBlockGroup) static LocatedBlockconstructInternalBlock(LocatedStripedBlock bg, int idxInReturnedLocs, int cellSize, int dataBlkNum, int idxInBlockGroup) This method creates an internal block at the given index of a block group.static StripedBlockUtil.AlignedStripe[]divideByteRangeIntoStripes(ErasureCodingPolicy ecPolicy, int cellSize, LocatedStripedBlock blockGroup, long rangeStartInBlockGroup, long rangeEndInBlockGroup, ByteBuffer buf) This method divides a requested byte range into an array of inclusiveStripedBlockUtil.AlignedStripe.static StripedBlockUtil.AlignedStripe[]divideOneStripe(ErasureCodingPolicy ecPolicy, int cellSize, LocatedStripedBlock blockGroup, long rangeStartInBlockGroup, long rangeEndInBlockGroup, ByteBuffer buf) Similar functionality withdivideByteRangeIntoStripes(org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy, int, org.apache.hadoop.hdfs.protocol.LocatedStripedBlock, long, long, java.nio.ByteBuffer), but is used by stateful read and uses ByteBuffer as reading target buffer.static intgetBlockIndex(Block reportedBlock) static longgetInternalBlockLength(long dataSize, int cellSize, int numDataBlocks, int idxInBlockGroup) Get the size of an internal block at the given index of a block group.static longgetInternalBlockLength(long dataSize, ErasureCodingPolicy ecPolicy, int idxInBlockGroup) getNextCompletedStripedRead(CompletionService<StripedBlockUtil.BlockReadStats> readService, Map<Future<StripedBlockUtil.BlockReadStats>, Integer> futures, long timeoutMillis) Get the next completed striped read task.static longgetSafeLength(ErasureCodingPolicy ecPolicy, long[] blockLens) Compute the safe length given the internal block lengths.static longoffsetInBlkToOffsetInBG(int cellSize, int dataBlkNum, long offsetInBlk, int idxInBlockGroup) Given a byte's offset in an internal block, calculate the offset in the block group.static LocatedBlock[]parseStripedBlockGroup(LocatedStripedBlock bg, int cellSize, int dataBlkNum, int parityBlkNum) This method parses a striped block group into individual blocks.static longspaceConsumedByStripedBlock(long numDataBlkBytes, int dataBlkNum, int parityBlkNum, int cellSize) Get the total usage of the striped blocks, which is the total of data blocks and parity blocks.
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG
-
-
Constructor Details
-
StripedBlockUtil
public StripedBlockUtil()
-
-
Method Details
-
parseStripedBlockGroup
public static LocatedBlock[] parseStripedBlockGroup(LocatedStripedBlock bg, int cellSize, int dataBlkNum, int parityBlkNum) This method parses a striped block group into individual blocks.- Parameters:
bg- The striped block groupcellSize- The size of a striping celldataBlkNum- The number of data blocks- Returns:
- An array containing the blocks in the group
-
constructInternalBlock
public static LocatedBlock constructInternalBlock(LocatedStripedBlock bg, int idxInReturnedLocs, int cellSize, int dataBlkNum, int idxInBlockGroup) This method creates an internal block at the given index of a block group.- Parameters:
idxInReturnedLocs- The index in the stored locations in theLocatedStripedBlockobjectidxInBlockGroup- The logical index in the striped block group- Returns:
- The constructed internal block
-
constructInternalBlock
public static ExtendedBlock constructInternalBlock(ExtendedBlock blockGroup, ErasureCodingPolicy ecPolicy, int idxInBlockGroup) -
constructInternalBlock
public static ExtendedBlock constructInternalBlock(ExtendedBlock blockGroup, int cellSize, int dataBlkNum, int idxInBlockGroup) This method creates an internalExtendedBlockat the given index of a block group. -
getInternalBlockLength
public static long getInternalBlockLength(long dataSize, ErasureCodingPolicy ecPolicy, int idxInBlockGroup) -
getInternalBlockLength
public static long getInternalBlockLength(long dataSize, int cellSize, int numDataBlocks, int idxInBlockGroup) Get the size of an internal block at the given index of a block group.- Parameters:
dataSize- Size of the block group only counting data blockscellSize- The size of a striping cellnumDataBlocks- The number of data blocksidxInBlockGroup- The logical index in the striped block group- Returns:
- The size of the internal block at the specified index
-
getSafeLength
Compute the safe length given the internal block lengths.- Parameters:
ecPolicy- The EC policy used for the block groupblockLens- The lengths of internal blocks- Returns:
- The safe length
-
offsetInBlkToOffsetInBG
public static long offsetInBlkToOffsetInBG(int cellSize, int dataBlkNum, long offsetInBlk, int idxInBlockGroup) Given a byte's offset in an internal block, calculate the offset in the block group. -
getNextCompletedStripedRead
public static StripedBlockUtil.StripingChunkReadResult getNextCompletedStripedRead(CompletionService<StripedBlockUtil.BlockReadStats> readService, Map<Future<StripedBlockUtil.BlockReadStats>, Integer> futures, long timeoutMillis) throws InterruptedExceptionGet the next completed striped read task.- Returns:
StripedBlockUtil.StripingChunkReadResultindicating the status of the read task succeeded, and the block index of the task. If the method times out without getting any completed read tasks, -1 is returned as block index.- Throws:
InterruptedException
-
spaceConsumedByStripedBlock
public static long spaceConsumedByStripedBlock(long numDataBlkBytes, int dataBlkNum, int parityBlkNum, int cellSize) Get the total usage of the striped blocks, which is the total of data blocks and parity blocks.- Parameters:
numDataBlkBytes- Size of the block group only counting data blocksdataBlkNum- The number of data blocksparityBlkNum- The number of parity blockscellSize- The size of a striping cell- Returns:
- The total usage of data blocks and parity blocks
-
divideOneStripe
public static StripedBlockUtil.AlignedStripe[] divideOneStripe(ErasureCodingPolicy ecPolicy, int cellSize, LocatedStripedBlock blockGroup, long rangeStartInBlockGroup, long rangeEndInBlockGroup, ByteBuffer buf) Similar functionality withdivideByteRangeIntoStripes(org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy, int, org.apache.hadoop.hdfs.protocol.LocatedStripedBlock, long, long, java.nio.ByteBuffer), but is used by stateful read and uses ByteBuffer as reading target buffer. Besides the read range is within a single stripe thus the calculation logic is simpler. -
divideByteRangeIntoStripes
public static StripedBlockUtil.AlignedStripe[] divideByteRangeIntoStripes(ErasureCodingPolicy ecPolicy, int cellSize, LocatedStripedBlock blockGroup, long rangeStartInBlockGroup, long rangeEndInBlockGroup, ByteBuffer buf) This method divides a requested byte range into an array of inclusiveStripedBlockUtil.AlignedStripe.- Parameters:
ecPolicy- The codec policy for the file, which carries the numbers of data / parity blockscellSize- Cell size of stripeblockGroup- The striped block grouprangeStartInBlockGroup- The byte range's start offset in block grouprangeEndInBlockGroup- The byte range's end offset in block groupbuf- Destination buffer of the read operation for the byte range At most 5 stripes will be generated from each logical range, as demonstrated in the header ofStripedBlockUtil.AlignedStripe.
-
checkBlocks
public static void checkBlocks(ExtendedBlock blockGroup, int i, ExtendedBlock blocki) throws IOException Check if the information such as IDs and generation stamps in block-i match the block group.- Throws:
IOException
-
getBlockIndex
-