Search in sources :

Example 41 with LocatedStripedBlock

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

the class TestStripedBlockUtil method testParseDummyStripedBlock.

@Test
public void testParseDummyStripedBlock() {
    LocatedStripedBlock lsb = createDummyLocatedBlock(stripeSize * stripesPerBlock);
    LocatedBlock[] blocks = parseStripedBlockGroup(lsb, cellSize, dataBlocks, parityBlocks);
    assertEquals(dataBlocks + parityBlocks, blocks.length);
    for (int i = 0; i < dataBlocks; i++) {
        assertFalse(blocks[i].isStriped());
        assertEquals(i, BlockIdManager.getBlockIndex(blocks[i].getBlock().getLocalBlock()));
        assertEquals(0, blocks[i].getStartOffset());
        assertEquals(1, blocks[i].getLocations().length);
        assertEquals(i, blocks[i].getLocations()[0].getIpcPort());
        assertEquals(i, blocks[i].getLocations()[0].getXferPort());
    }
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) Test(org.junit.Test)

Example 42 with LocatedStripedBlock

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

the class TestStripedBlockUtil method testDivideByteRangeIntoStripes.

/**
   * Test dividing a byte range into aligned stripes and verify the aligned
   * ranges can be translated back to the byte range.
   */
@Test
public void testDivideByteRangeIntoStripes() {
    ByteBuffer assembled = ByteBuffer.allocate(stripesPerBlock * stripeSize);
    for (int bgSize : blockGroupSizes) {
        LocatedStripedBlock blockGroup = createDummyLocatedBlock(bgSize);
        byte[][] internalBlkBufs = createInternalBlkBuffers(bgSize);
        for (int brStart : byteRangeStartOffsets) {
            for (int brSize : byteRangeSizes) {
                if (brStart + brSize > bgSize) {
                    continue;
                }
                AlignedStripe[] stripes = divideByteRangeIntoStripes(ecPolicy, cellSize, blockGroup, brStart, brStart + brSize - 1, assembled);
                for (AlignedStripe stripe : stripes) {
                    for (int i = 0; i < dataBlocks; i++) {
                        StripingChunk chunk = stripe.chunks[i];
                        if (chunk == null || chunk.state != StripingChunk.REQUESTED) {
                            continue;
                        }
                        int done = 0;
                        int len;
                        for (ByteBuffer slice : chunk.getChunkBuffer().getSlices()) {
                            len = slice.remaining();
                            slice.put(internalBlkBufs[i], (int) stripe.getOffsetInBlock() + done, len);
                            done += len;
                        }
                    }
                }
                for (int i = 0; i < brSize; i++) {
                    if (hashIntToByte(brStart + i) != assembled.get(i)) {
                        System.out.println("Oops");
                    }
                    assertEquals("Byte at " + (brStart + i) + " should be the same", hashIntToByte(brStart + i), assembled.get(i));
                }
            }
        }
    }
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 43 with LocatedStripedBlock

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

the class TestStripedBlockUtil method createDummyLocatedBlock.

private LocatedStripedBlock createDummyLocatedBlock(int bgSize) {
    final long blockGroupID = -1048576;
    DatanodeInfo[] locs = new DatanodeInfo[groupSize];
    String[] storageIDs = new String[groupSize];
    StorageType[] storageTypes = new StorageType[groupSize];
    byte[] indices = new byte[groupSize];
    for (int i = 0; i < groupSize; i++) {
        indices[i] = (byte) ((i + 2) % dataBlocks);
        // Location port always equal to logical index of a block,
        // for easier verification
        locs[i] = DFSTestUtil.getLocalDatanodeInfo(indices[i]);
        storageIDs[i] = locs[i].getDatanodeUuid();
        storageTypes[i] = StorageType.DISK;
    }
    return new LocatedStripedBlock(new ExtendedBlock("pool", blockGroupID, bgSize, 1001), locs, storageIDs, storageTypes, indices, 0, false, null);
}
Also used : LocatedStripedBlock(org.apache.hadoop.hdfs.protocol.LocatedStripedBlock) DatanodeInfo(org.apache.hadoop.hdfs.protocol.DatanodeInfo) StorageType(org.apache.hadoop.fs.StorageType) ExtendedBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock)

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