@@ -2451,6 +2451,68 @@ public void testFsckMissingECFile() throws Exception {
24512451 assertTrue (outStr .contains ("has 1 CORRUPT blocks" ));
24522452 }
24532453
2454+ @ Test
2455+ public void testFsckECBlockIdRedundantInternalBlocks () throws Exception {
2456+ final int dataBlocks = StripedFileTestUtil .getDefaultECPolicy ().getNumDataUnits ();
2457+ final int parityBlocks = StripedFileTestUtil .getDefaultECPolicy ().getNumParityUnits ();
2458+ final int cellSize = StripedFileTestUtil .getDefaultECPolicy ().getCellSize ();
2459+ final short groupSize = (short ) (dataBlocks + parityBlocks );
2460+ final File builderBaseDir = new File (GenericTestUtils .getRandomizedTempPath ());
2461+ final Path dirPath = new Path ("/ec_dir" );
2462+ final Path filePath = new Path (dirPath , "file" );
2463+
2464+ conf .setInt (DFSConfigKeys .DFS_NAMENODE_REDUNDANCY_INTERVAL_SECONDS_KEY , 1 );
2465+ cluster = new MiniDFSCluster .Builder (conf , builderBaseDir ).numDataNodes (groupSize + 1 ).build ();
2466+ cluster .waitActive ();
2467+
2468+ DistributedFileSystem fs = cluster .getFileSystem ();
2469+ fs .enableErasureCodingPolicy (
2470+ StripedFileTestUtil .getDefaultECPolicy ().getName ());
2471+
2472+ try {
2473+ fs .mkdirs (dirPath );
2474+ fs .setErasureCodingPolicy (dirPath , StripedFileTestUtil .getDefaultECPolicy ().getName ());
2475+ DFSTestUtil .createFile (fs , filePath , cellSize * dataBlocks * 2 , (short ) 1 , 0L );
2476+ LocatedBlocks blks = fs .getClient ().getLocatedBlocks (filePath .toString (), 0 );
2477+ LocatedStripedBlock block = (LocatedStripedBlock ) blks .getLastLocatedBlock ();
2478+ Assert .assertEquals (groupSize , block .getLocations ().length );
2479+
2480+ //general test.
2481+ String runFsckResult = runFsck (conf , 0 , true , "/" ,
2482+ "-blockId" , block .getBlock ().getBlockName ());
2483+ assertTrue (runFsckResult .contains (block .getBlock ().getBlockName ()));
2484+ assertTrue (runFsckResult .contains ("No. of Expected Replica: " + groupSize ));
2485+ assertTrue (runFsckResult .contains ("No. of live Replica: " + groupSize ));
2486+ assertTrue (runFsckResult .contains ("No. of redundant Replica: " + 0 ));
2487+
2488+ // stop a dn.
2489+ DatanodeInfo dnToStop = block .getLocations ()[0 ];
2490+ MiniDFSCluster .DataNodeProperties dnProp = cluster .stopDataNode (dnToStop .getXferAddr ());
2491+ cluster .setDataNodeDead (dnToStop );
2492+
2493+ // wait for reconstruction to happen.
2494+ DFSTestUtil .waitForReplication (fs , filePath , groupSize , 15 * 1000 );
2495+
2496+ // bring the dn back: 10 internal blocks now.
2497+ cluster .restartDataNode (dnProp );
2498+ cluster .waitActive ();
2499+
2500+ blks = fs .getClient ().getLocatedBlocks (filePath .toString (), 0 );
2501+ block = (LocatedStripedBlock ) blks .getLastLocatedBlock ();
2502+ Assert .assertEquals (groupSize + 1 , block .getLocations ().length );
2503+
2504+ //general test, number of redundant internal block replicas.
2505+ runFsckResult = runFsck (conf , 0 , true , "/" ,
2506+ "-blockId" , block .getBlock ().getBlockName ());
2507+ assertTrue (runFsckResult .contains (block .getBlock ().getBlockName ()));
2508+ assertTrue (runFsckResult .contains ("No. of Expected Replica: " + groupSize ));
2509+ assertTrue (runFsckResult .contains ("No. of live Replica: " + groupSize ));
2510+ assertTrue (runFsckResult .contains ("No. of redundant Replica: " + 1 ));
2511+ } finally {
2512+ cluster .shutdown ();
2513+ }
2514+ }
2515+
24542516 private void waitForUnrecoverableBlockGroup (Configuration configuration )
24552517 throws TimeoutException , InterruptedException {
24562518 GenericTestUtils .waitFor (new Supplier <Boolean >() {
0 commit comments