BlockInfoStriped extends BlockInfo { @Override boolean addStorage(DatanodeStorageInfo storage, Block reportedBlock) { 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(); long spaceConsumed(); @Override final boolean isStriped(); @Override int numNodes();  }
@Test public void testAddStorage() { DatanodeStorageInfo[] storageInfos = DFSTestUtil.createDatanodeStorageInfos( TOTAL_NUM_BLOCKS); Block[] blocks = createReportedBlocks(TOTAL_NUM_BLOCKS); 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(TOTAL_NUM_BLOCKS, info.getCapacity()); Assert.assertEquals(TOTAL_NUM_BLOCKS, 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(TOTAL_NUM_BLOCKS, info.getCapacity()); Assert.assertEquals(TOTAL_NUM_BLOCKS, info.numNodes()); Assert.assertEquals(TOTAL_NUM_BLOCKS, 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( TOTAL_NUM_BLOCKS * 2); for (i = TOTAL_NUM_BLOCKS; i < storageInfos2.length; i++) { info.addStorage(storageInfos2[i], blocks[i % TOTAL_NUM_BLOCKS]); 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 = TOTAL_NUM_BLOCKS; i < storageInfos2.length; i++) { int index = info.findStorageInfo(storageInfos2[i]); Assert.assertEquals(i++, index); Assert.assertEquals(index - TOTAL_NUM_BLOCKS, indices[index]); } }