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());
}
}
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));
}
}
}
}
}
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);
}
Aggregations