From ecee022e49269bd6612d32695c6b46a95c6bf11e Mon Sep 17 00:00:00 2001 From: zhangshuyan <81411509+zhangshuyan0@users.noreply.github.com> Date: Mon, 25 Sep 2023 13:01:25 +0800 Subject: [PATCH] HDFS-17197. Show file replication when listing corrupt files. (#6095). Contributed by Shuyan Zhang. Signed-off-by: He Xiaoqiao --- .../hdfs/server/namenode/FSNamesystem.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index eb8022dc63..d9b165f96e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -6131,15 +6131,20 @@ void releaseBackupNode(NamenodeRegistration registration) static class CorruptFileBlockInfo { final String path; final Block block; + private final int replication; + private final String ecPolicy; - public CorruptFileBlockInfo(String p, Block b) { + CorruptFileBlockInfo(String p, Block b, int r, String ec) { path = p; block = b; + replication = r; + ecPolicy = ec; } @Override public String toString() { - return block.getBlockName() + "\t" + path; + return block.getBlockName() + "\t" + + (replication == -1 ? ecPolicy : replication) + "\t" + path; } } /** @@ -6195,7 +6200,21 @@ Collection listCorruptFileBlocks(String path, if (inode != null) { String src = inode.getFullPathName(); if (isParentEntry(src, path)) { - corruptFiles.add(new CorruptFileBlockInfo(src, blk)); + int repl = -1; + String ecPolicyName = null; + if (inode.isFile()) { + if (inode.asFile().isStriped()) { + ErasureCodingPolicy ecPolicy = + ErasureCodingPolicyManager.getInstance() + .getByID(inode.asFile().getErasureCodingPolicyID()); + if (ecPolicy != null) { + ecPolicyName = ecPolicy.getName(); + } + } else { + repl = inode.asFile().getFileReplication(); + } + } + corruptFiles.add(new CorruptFileBlockInfo(src, blk, repl, ecPolicyName)); count++; if (count >= maxCorruptFileBlocksReturn) break;