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 2e7c78a205..0263f2a347 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 String getErasureCodingPolicyName(INode inode) { 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 327de41ecd..d9f7e9afdc 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 @@ -255,6 +255,22 @@ public ErasureCodingPolicy getByName(String name) { 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 c280eca42a..2cc08f4aa5 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 + + + +