BlockInfoStriped extends BlockInfo { @Override boolean removeStorage(DatanodeStorageInfo storage) { int dnIndex = findStorageInfoFromEnd(storage); if (dnIndex < 0) { return false; } setStorageInfo(dnIndex, null); indices[dnIndex] = -1; 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 testRemoveStorage() { DatanodeStorageInfo[] storages = DFSTestUtil.createDatanodeStorageInfos( totalBlocks); Block[] blocks = createReportedBlocks(totalBlocks); for (int i = 0; i < storages.length; i++) { info.addStorage(storages[i], blocks[i]); } info.removeStorage(storages[0]); info.removeStorage(storages[2]); Assert.assertEquals(totalBlocks, info.getCapacity()); Assert.assertEquals(totalBlocks - 2, info.numNodes()); byte[] indices = (byte[]) Whitebox.getInternalState(info, "indices"); for (int i = 0; i < storages.length; i++) { int index = info.findStorageInfo(storages[i]); if (i != 0 && i != 2) { Assert.assertEquals(i, index); Assert.assertEquals(index, indices[index]); } else { Assert.assertEquals(-1, index); Assert.assertEquals(-1, indices[i]); } } DatanodeStorageInfo[] storages2 = DFSTestUtil.createDatanodeStorageInfos( totalBlocks * 2); for (int i = totalBlocks; i < storages2.length; i++) { info.addStorage(storages2[i], blocks[i % totalBlocks]); } Assert.assertEquals(totalBlocks * 2 - 2, info.numNodes()); Assert.assertEquals(totalBlocks * 2 - 2, info.getCapacity()); indices = (byte[]) Whitebox.getInternalState(info, "indices"); Assert.assertEquals(totalBlocks * 2 - 2, indices.length); int j = totalBlocks; for (int i = totalBlocks; i < storages2.length; i++) { int index = info.findStorageInfo(storages2[i]); if (i == totalBlocks || i == totalBlocks + 2) { Assert.assertEquals(i - totalBlocks, index); } else { Assert.assertEquals(j++, index); } } for (int i = 0; i < totalBlocks; i++) { info.removeStorage(storages2[i + totalBlocks]); } Assert.assertEquals(totalBlocks - 2, info.numNodes()); Assert.assertEquals(totalBlocks * 2 - 2, info.getCapacity()); indices = (byte[]) Whitebox.getInternalState(info, "indices"); Assert.assertEquals(totalBlocks * 2 - 2, indices.length); for (int i = 0; i < totalBlocks; i++) { if (i == 0 || i == 2) { int index = info.findStorageInfo(storages2[i + totalBlocks]); Assert.assertEquals(-1, index); } else { int index = info.findStorageInfo(storages[i]); Assert.assertEquals(i, index); } } for (int i = totalBlocks; i < totalBlocks * 2 - 2; i++) { Assert.assertEquals(-1, indices[i]); Assert.assertNull(info.getDatanode(i)); } }
@Test public void testGetBlockInfo() throws IllegalArgumentException, Exception { int dataBlocks = testECPolicy.getNumDataUnits(); int parityBlocks = testECPolicy.getNumParityUnits(); int totalSize = dataBlocks + parityBlocks; File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); Configuration conf = new Configuration(); try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, builderBaseDir).numDataNodes(totalSize) .build()) { DistributedFileSystem fs = cluster.getFileSystem(); fs.enableErasureCodingPolicy( StripedFileTestUtil.getDefaultECPolicy().getName()); fs.enableErasureCodingPolicy(testECPolicy.getName()); fs.mkdirs(new Path("/ecDir")); fs.setErasureCodingPolicy(new Path("/ecDir"), testECPolicy.getName()); DFSTestUtil.createFile(fs, new Path("/ecDir/ecFile"), fs.getDefaultBlockSize() * dataBlocks, (short) 1, 1024); ExtendedBlock blk = DFSTestUtil .getAllBlocks(fs, new Path("/ecDir/ecFile")).get(0).getBlock(); String id = "blk_" + Long.toString(blk.getBlockId()); BlockInfo bInfo = cluster.getNameNode().getNamesystem().getBlockManager() .getStoredBlock(blk.getLocalBlock()); DatanodeStorageInfo[] dnStorageInfo = cluster.getNameNode() .getNamesystem().getBlockManager().getStorages(bInfo); bInfo.removeStorage(dnStorageInfo[1]); ByteArrayOutputStream bStream = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bStream, true); assertEquals(0, ToolRunner.run(new DFSck(conf, out), new String[] { new Path("/ecDir/ecFile").toString(), "-blockId", id })); assertFalse(out.toString().contains("null")); } }