Search in sources :

Example 1 with BlockReaderInfo

use of org.apache.hadoop.hdfs.StripeReader.BlockReaderInfo in project hadoop by apache.

the class DFSStripedInputStream method createBlockReader.

boolean createBlockReader(LocatedBlock block, long offsetInBlock, LocatedBlock[] targetBlocks, BlockReaderInfo[] readerInfos, int chunkIndex) throws IOException {
    BlockReader reader = null;
    final ReaderRetryPolicy retry = new ReaderRetryPolicy();
    DFSInputStream.DNAddrPair dnInfo = new DFSInputStream.DNAddrPair(null, null, null);
    while (true) {
        try {
            // the cached block location might have been re-fetched, so always
            // get it from cache.
            block = refreshLocatedBlock(block);
            targetBlocks[chunkIndex] = block;
            // internal block has one location, just rule out the deadNodes
            dnInfo = getBestNodeDNAddrPair(block, null);
            if (dnInfo == null) {
                break;
            }
            reader = getBlockReader(block, offsetInBlock, block.getBlockSize() - offsetInBlock, dnInfo.addr, dnInfo.storageType, dnInfo.info);
        } catch (IOException e) {
            if (e instanceof InvalidEncryptionKeyException && retry.shouldRefetchEncryptionKey()) {
                DFSClient.LOG.info("Will fetch a new encryption key and retry, " + "encryption key was invalid when connecting to " + dnInfo.addr + " : " + e);
                dfsClient.clearDataEncryptionKey();
                retry.refetchEncryptionKey();
            } else if (retry.shouldRefetchToken() && tokenRefetchNeeded(e, dnInfo.addr)) {
                fetchBlockAt(block.getStartOffset());
                retry.refetchToken();
            } else {
                //TODO: handles connection issues
                DFSClient.LOG.warn("Failed to connect to " + dnInfo.addr + " for " + "block" + block.getBlock(), e);
                // re-fetch the block in case the block has been moved
                fetchBlockAt(block.getStartOffset());
                addToDeadNodes(dnInfo.info);
            }
        }
        if (reader != null) {
            readerInfos[chunkIndex] = new BlockReaderInfo(reader, dnInfo.info, offsetInBlock);
            return true;
        }
    }
    return false;
}
Also used : InvalidEncryptionKeyException(org.apache.hadoop.hdfs.protocol.datatransfer.InvalidEncryptionKeyException) ReaderRetryPolicy(org.apache.hadoop.hdfs.StripeReader.ReaderRetryPolicy) IOException(java.io.IOException) BlockReaderInfo(org.apache.hadoop.hdfs.StripeReader.BlockReaderInfo)

Example 2 with BlockReaderInfo

use of org.apache.hadoop.hdfs.StripeReader.BlockReaderInfo 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

BlockReaderInfo (org.apache.hadoop.hdfs.StripeReader.BlockReaderInfo)2 IOException (java.io.IOException)1 ReaderRetryPolicy (org.apache.hadoop.hdfs.StripeReader.ReaderRetryPolicy)1 LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)1 LocatedStripedBlock (org.apache.hadoop.hdfs.protocol.LocatedStripedBlock)1 InvalidEncryptionKeyException (org.apache.hadoop.hdfs.protocol.datatransfer.InvalidEncryptionKeyException)1 AlignedStripe (org.apache.hadoop.hdfs.util.StripedBlockUtil.AlignedStripe)1