BlockInfoStriped extends BlockInfo { @Override boolean addStorage(DatanodeStorageInfo storage, Block reportedBlock) { Preconditions.checkArgument(BlockIdManager.isStripedBlockID( reportedBlock.getBlockId()), "reportedBlock is not striped"); Preconditions.checkArgument(BlockIdManager.convertToStripedID( reportedBlock.getBlockId()) == this.getBlockId(), "reported blk_%s does not belong to the group of stored blk_%s", reportedBlock.getBlockId(), this.getBlockId()); int blockIndex = BlockIdManager.getBlockIndex(reportedBlock); int index = blockIndex; DatanodeStorageInfo old = getStorageInfo(index); if (old != null && !old.equals(storage)) { int i = findStorageInfo(storage); if (i == -1) { index = findSlot(); } else { return true; } } addStorage(storage, index, blockIndex); return true; } BlockInfoStriped(Block blk, ErasureCodingPolicy ecPolicy); short getTotalBlockNum(); short getDataBlockNum(); short getParityBlockNum(); int getCellSize(); short getRealDataBlockNum(); short getRealTotalBlockNum(); ErasureCodingPolicy getErasureCodingPolicy(); @VisibleForTesting byte getStorageBlockIndex(DatanodeStorageInfo storage); long spaceConsumed(); @Override final boolean isStriped(); @Override BlockType getBlockType(); @Override int numNodes(); Iterable<StorageAndBlockIndex> getStorageAndIndexInfos();  }
@Test public void testAddStorage() { DatanodeStorageInfo[] storageInfos = DFSTestUtil.createDatanodeStorageInfos( totalBlocks); Block[] blocks = createReportedBlocks(totalBlocks); int i = 0; for (; i < storageInfos.length; i += 2) { info.addStorage(storageInfos[i], blocks[i]); Assert.assertEquals(i/2 + 1, info.numNodes()); } i /= 2; for (int j = 1; j < storageInfos.length; j += 2) { Assert.assertTrue(info.addStorage(storageInfos[j], blocks[j])); Assert.assertEquals(i + (j+1)/2, info.numNodes()); } byte[] indices = (byte[]) Whitebox.getInternalState(info, "indices"); Assert.assertEquals(totalBlocks, info.getCapacity()); Assert.assertEquals(totalBlocks, indices.length); i = 0; for (DatanodeStorageInfo storage : storageInfos) { int index = info.findStorageInfo(storage); Assert.assertEquals(i++, index); Assert.assertEquals(index, indices[index]); } i = 0; for (DatanodeStorageInfo storage : storageInfos) { Assert.assertTrue(info.addStorage(storage, blocks[i++])); } Assert.assertEquals(totalBlocks, info.getCapacity()); Assert.assertEquals(totalBlocks, info.numNodes()); Assert.assertEquals(totalBlocks, indices.length); i = 0; for (DatanodeStorageInfo storage : storageInfos) { int index = info.findStorageInfo(storage); Assert.assertEquals(i++, index); Assert.assertEquals(index, indices[index]); } DatanodeStorageInfo[] storageInfos2 = DFSTestUtil.createDatanodeStorageInfos(totalBlocks * 2); for (i = totalBlocks; i < storageInfos2.length; i++) { info.addStorage(storageInfos2[i], blocks[i % totalBlocks]); Assert.assertEquals(i + 1, info.getCapacity()); Assert.assertEquals(i + 1, info.numNodes()); indices = (byte[]) Whitebox.getInternalState(info, "indices"); Assert.assertEquals(i + 1, indices.length); } for (i = totalBlocks; i < storageInfos2.length; i++) { int index = info.findStorageInfo(storageInfos2[i]); Assert.assertEquals(i++, index); Assert.assertEquals(index - totalBlocks, indices[index]); } }
@Test(expected=IllegalArgumentException.class) public void testAddStorageWithReplicatedBlock() { DatanodeStorageInfo storage = DFSTestUtil.createDatanodeStorageInfo( "storageID", "127.0.0.1"); BlockInfo replica = new BlockInfoContiguous(new Block(1000L), (short) 3); info.addStorage(storage, replica); }
@Test(expected=IllegalArgumentException.class) public void testAddStorageWithDifferentBlockGroup() { DatanodeStorageInfo storage = DFSTestUtil.createDatanodeStorageInfo( "storageID", "127.0.0.1"); BlockInfo diffGroup = new BlockInfoStriped(new Block(BASE_ID + 100), testECPolicy); info.addStorage(storage, diffGroup); }