Search in sources :

Example 6 with LocatedStripedBlock

use of org.apache.hadoop.hdfs.protocol.LocatedStripedBlock in project hadoop by apache.

the class TestBlockTokenWithDFSStriped method tryRead.

@Override
protected void tryRead(final Configuration conf, LocatedBlock lblock, boolean shouldSucceed) {
    LocatedStripedBlock lsb = (LocatedStripedBlock) lblock;
    LocatedBlock[] internalBlocks = StripedBlockUtil.parseStripedBlockGroup(lsb, cellSize, dataBlocks, parityBlocks);
    for (LocatedBlock internalBlock : internalBlocks) {
        super.tryRead(conf, internalBlock, shouldSucceed);
    }
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock)

Example 7 with LocatedStripedBlock

use of org.apache.hadoop.hdfs.protocol.LocatedStripedBlock in project hadoop by apache.

the class DFSStripedInputStream method blockSeekTo.

/**
   * When seeking into a new block group, create blockReader for each internal
   * block in the group.
   */
private synchronized void blockSeekTo(long target) throws IOException {
    if (target >= getFileLength()) {
        throw new IOException("Attempted to read past end of file");
    }
    // Will be getting a new BlockReader.
    closeCurrentBlockReaders();
    // Compute desired striped block group
    LocatedStripedBlock targetBlockGroup = getBlockGroupAt(target);
    // Update current position
    this.pos = target;
    this.blockEnd = targetBlockGroup.getStartOffset() + targetBlockGroup.getBlockSize() - 1;
    currentLocatedBlock = targetBlockGroup;
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) IOException(java.io.IOException)

Example 8 with LocatedStripedBlock

use of org.apache.hadoop.hdfs.protocol.LocatedStripedBlock in project hadoop by apache.

the class DFSStripedInputStream method refreshLocatedBlock.

/**
   * The super method {@link DFSInputStream#refreshLocatedBlock} refreshes
   * cached LocatedBlock by executing {@link DFSInputStream#getBlockAt} again.
   * This method extends the logic by first remembering the index of the
   * internal block, and re-parsing the refreshed block group with the same
   * index.
   */
@Override
protected LocatedBlock refreshLocatedBlock(LocatedBlock block) throws IOException {
    int idx = StripedBlockUtil.getBlockIndex(block.getBlock().getLocalBlock());
    LocatedBlock lb = getBlockGroupAt(block.getStartOffset());
    // If indexing information is returned, iterate through the index array
    // to find the entry for position idx in the group
    LocatedStripedBlock lsb = (LocatedStripedBlock) lb;
    int i = 0;
    for (; i < lsb.getBlockIndices().length; i++) {
        if (lsb.getBlockIndices()[i] == idx) {
            break;
        }
    }
    if (DFSClient.LOG.isDebugEnabled()) {
        DFSClient.LOG.debug("refreshLocatedBlock for striped blocks, offset=" + block.getStartOffset() + ". Obtained block " + lb + ", idx=" + idx);
    }
    return StripedBlockUtil.constructInternalBlock(lsb, i, cellSize, dataBlkNum, idx);
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock)

Example 9 with LocatedStripedBlock

use of org.apache.hadoop.hdfs.protocol.LocatedStripedBlock in project hadoop by apache.

the class TestDecommissionWithStriped method assertBlockIndexAndTokenPosition.

/**
   * Verify block index and token values. Must update block indices and block
   * tokens after sorting.
   */
private void assertBlockIndexAndTokenPosition(List<LocatedBlock> lbs, List<HashMap<DatanodeInfo, Byte>> locToIndexList, List<HashMap<DatanodeInfo, Token<BlockTokenIdentifier>>> locToTokenList) {
    for (int i = 0; i < lbs.size(); i++) {
        LocatedBlock lb = lbs.get(i);
        LocatedStripedBlock stripedBlk = (LocatedStripedBlock) lb;
        HashMap<DatanodeInfo, Byte> locToIndex = locToIndexList.get(i);
        HashMap<DatanodeInfo, Token<BlockTokenIdentifier>> locToToken = locToTokenList.get(i);
        DatanodeInfo[] di = lb.getLocations();
        for (int j = 0; j < di.length; j++) {
            Assert.assertEquals("Block index value mismatches after sorting", (byte) locToIndex.get(di[j]), stripedBlk.getBlockIndices()[j]);
            Assert.assertEquals("Block token value mismatches after sorting", locToToken.get(di[j]), stripedBlk.getBlockTokens()[j]);
        }
    }
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) DatanodeInfo(org.apache.hadoop.hdfs.protocol.DatanodeInfo) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) Token(org.apache.hadoop.security.token.Token)

Example 10 with LocatedStripedBlock

use of org.apache.hadoop.hdfs.protocol.LocatedStripedBlock in project hadoop by apache.

the class TestDecommissionWithStriped method prepareBlockIndexAndTokenList.

private void prepareBlockIndexAndTokenList(List<LocatedBlock> lbs, List<HashMap<DatanodeInfo, Byte>> locToIndexList, List<HashMap<DatanodeInfo, Token<BlockTokenIdentifier>>> locToTokenList) {
    for (LocatedBlock lb : lbs) {
        HashMap<DatanodeInfo, Byte> locToIndex = new HashMap<DatanodeInfo, Byte>();
        locToIndexList.add(locToIndex);
        HashMap<DatanodeInfo, Token<BlockTokenIdentifier>> locToToken = new HashMap<DatanodeInfo, Token<BlockTokenIdentifier>>();
        locToTokenList.add(locToToken);
        DatanodeInfo[] di = lb.getLocations();
        LocatedStripedBlock stripedBlk = (LocatedStripedBlock) lb;
        for (int i = 0; i < di.length; i++) {
            locToIndex.put(di[i], stripedBlk.getBlockIndices()[i]);
            locToToken.put(di[i], stripedBlk.getBlockTokens()[i]);
        }
    }
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) DatanodeInfo(org.apache.hadoop.hdfs.protocol.DatanodeInfo) BlockTokenIdentifier(org.apache.hadoop.hdfs.security.token.block.BlockTokenIdentifier) HashMap(java.util.HashMap) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) Token(org.apache.hadoop.security.token.Token)

Aggregations

LocatedStripedBlock (org.apache.hadoop.hdfs.protocol.LocatedStripedBlock)43 LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)26 DatanodeInfo (org.apache.hadoop.hdfs.protocol.DatanodeInfo)20 Test (org.junit.Test)20 LocatedBlocks (org.apache.hadoop.hdfs.protocol.LocatedBlocks)17 Path (org.apache.hadoop.fs.Path)10 Block (org.apache.hadoop.hdfs.protocol.Block)9 DataNode (org.apache.hadoop.hdfs.server.datanode.DataNode)8 ExtendedBlock (org.apache.hadoop.hdfs.protocol.ExtendedBlock)7 Token (org.apache.hadoop.security.token.Token)7 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)6 HashMap (java.util.HashMap)5 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)5 BlockManager (org.apache.hadoop.hdfs.server.blockmanagement.BlockManager)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 BitSet (java.util.BitSet)4 StorageType (org.apache.hadoop.fs.StorageType)4 File (java.io.File)3 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)3