Skip to content

Commit 27df81f

Browse files
haiyang1987Fermi Fei
authored andcommitted
SPDI-102753. Backport HDFS-16879. EC: Fsck -blockId shows number of redundant internal block replicas for EC Blocks (apache#5264)
1 parent 6e459f0 commit 27df81f

File tree

2 files changed

+66
-0
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src

2 files changed

+66
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ public void blockIdCK(String blockId) {
321321
}
322322
out.println("No. of corrupted Replica: " +
323323
numberReplicas.corruptReplicas());
324+
// for striped blocks only and number of redundant internal block replicas.
325+
if (blockInfo.isStriped()) {
326+
out.println("No. of redundant Replica: " + numberReplicas.redundantInternalBlocks());
327+
}
324328
//record datanodes that have corrupted block replica
325329
Collection<DatanodeDescriptor> corruptionRecord = null;
326330
if (blockManager.getCorruptReplicas(block) != null) {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)