diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java index 2e7c78a205b..0263f2a347f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java @@ -188,7 +188,7 @@ public class ContentSummaryComputationContext { String ecPolicyName = WritableUtils.readString(din); return dir.getFSNamesystem() .getErasureCodingPolicyManager() - .getByName(ecPolicyName) + .getErasureCodingPolicyByName(ecPolicyName) .getName(); } } else if (inode.getParent() != null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java index 57fa9583a09..1649f93b87d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java @@ -238,6 +238,22 @@ public final class ErasureCodingPolicyManager { return ecpi.getPolicy(); } + /** + * Get a {@link ErasureCodingPolicy} by policy name, including system + * policy, user defined policy and Replication policy. + * @return ecPolicy, or null if not found + */ + public ErasureCodingPolicy getErasureCodingPolicyByName(String name) { + final ErasureCodingPolicyInfo ecpi = getPolicyInfoByName(name); + if (ecpi == null) { + if (name.equalsIgnoreCase(ErasureCodeConstants.REPLICATION_POLICY_NAME)) { + return SystemErasureCodingPolicies.getReplicationPolicy(); + } + return null; + } + return ecpi.getPolicy(); + } + /** * Get a {@link ErasureCodingPolicyInfo} by policy name, including system * policy and user defined policy. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml index c280eca42ac..2cc08f4aa5b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml @@ -1055,5 +1055,24 @@ + + ls: file with replication Policy + + -fs NAMENODE -mkdir -p /ecdir + -fs NAMENODE -setPolicy -path /ecdir -replicate + -fs NAMENODE -touchz /ecdir/file1 + -fs NAMENODE -ls -e / + + + -fs NAMENODE -rmdir /ecdir + + + + RegexpComparator + ^drwxr-xr-x( )*-( )*USERNAME( )*supergroup( )*[A-Za-z0-9-]{1,}( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*/ecdir + + + +