Search in sources :

Example 1 with AlignedStripe

use of org.apache.hadoop.hdfs.util.StripedBlockUtil.AlignedStripe in project hadoop by apache.

the class DFSStripedInputStream method readOneStripe.

/**
   * Read a new stripe covering the current position, and store the data in the
   * {@link #curStripeBuf}.
   */
private void readOneStripe(CorruptedBlocks corruptedBlocks) throws IOException {
    resetCurStripeBuffer();
    // compute stripe range based on pos
    final long offsetInBlockGroup = getOffsetInBlockGroup();
    final long stripeLen = cellSize * dataBlkNum;
    final int stripeIndex = (int) (offsetInBlockGroup / stripeLen);
    final int stripeBufOffset = (int) (offsetInBlockGroup % stripeLen);
    final int stripeLimit = (int) Math.min(currentLocatedBlock.getBlockSize() - (stripeIndex * stripeLen), stripeLen);
    StripeRange stripeRange = new StripeRange(offsetInBlockGroup, stripeLimit - stripeBufOffset);
    LocatedStripedBlock blockGroup = (LocatedStripedBlock) currentLocatedBlock;
    AlignedStripe[] stripes = StripedBlockUtil.divideOneStripe(ecPolicy, cellSize, blockGroup, offsetInBlockGroup, offsetInBlockGroup + stripeRange.getLength() - 1, curStripeBuf);
    final LocatedBlock[] blks = StripedBlockUtil.parseStripedBlockGroup(blockGroup, cellSize, dataBlkNum, parityBlkNum);
    // read the whole stripe
    for (AlignedStripe stripe : stripes) {
        // Parse group to get chosen DN location
        StripeReader sreader = new StatefulStripeReader(stripe, ecPolicy, blks, blockReaders, corruptedBlocks, decoder, this);
        sreader.readStripe();
    }
    curStripeBuf.position(stripeBufOffset);
    curStripeBuf.limit(stripeLimit);
    curStripeRange = stripeRange;
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) StripeRange(org.apache.hadoop.hdfs.util.StripedBlockUtil.StripeRange) AlignedStripe(org.apache.hadoop.hdfs.util.StripedBlockUtil.AlignedStripe) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock)

Example 2 with AlignedStripe

use of org.apache.hadoop.hdfs.util.StripedBlockUtil.AlignedStripe in project hadoop by apache.

the class DFSStripedInputStream method fetchBlockByteRange.

/**
   * Real implementation of pread.
   */
@Override
protected void fetchBlockByteRange(LocatedBlock block, long start, long end, ByteBuffer buf, CorruptedBlocks corruptedBlocks) throws IOException {
    // Refresh the striped block group
    LocatedStripedBlock blockGroup = getBlockGroupAt(block.getStartOffset());
    AlignedStripe[] stripes = StripedBlockUtil.divideByteRangeIntoStripes(ecPolicy, cellSize, blockGroup, start, end, buf);
    final LocatedBlock[] blks = StripedBlockUtil.parseStripedBlockGroup(blockGroup, cellSize, dataBlkNum, parityBlkNum);
    final BlockReaderInfo[] preaderInfos = new BlockReaderInfo[groupSize];
    try {
        for (AlignedStripe stripe : stripes) {
            // Parse group to get chosen DN location
            StripeReader preader = new PositionStripeReader(stripe, ecPolicy, blks, preaderInfos, corruptedBlocks, decoder, this);
            try {
                preader.readStripe();
            } finally {
                preader.close();
            }
        }
        buf.position(buf.position() + (int) (end - start + 1));
    } finally {
        for (BlockReaderInfo preaderInfo : preaderInfos) {
            closeReader(preaderInfo);
        }
    }
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) AlignedStripe(org.apache.hadoop.hdfs.util.StripedBlockUtil.AlignedStripe) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) BlockReaderInfo(org.apache.hadoop.hdfs.StripeReader.BlockReaderInfo)

Aggregations

LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)2 LocatedStripedBlock (org.apache.hadoop.hdfs.protocol.LocatedStripedBlock)2 AlignedStripe (org.apache.hadoop.hdfs.util.StripedBlockUtil.AlignedStripe)2 BlockReaderInfo (org.apache.hadoop.hdfs.StripeReader.BlockReaderInfo)1 StripeRange (org.apache.hadoop.hdfs.util.StripedBlockUtil.StripeRange)1