From 3bcdff8facffb7f15496aff806dc5042ad96dde3 Mon Sep 17 00:00:00 2001 From: Surendra Singh Lilhore Date: Wed, 13 Feb 2019 23:06:46 +0530 Subject: [PATCH] HDFS-14274. EC: NPE While Listing EC Policy For A Directory Following Replication Policy. Contributed by Ayush Saxena. (cherry picked from commit 35d4f32b32a3ba05332811caf3d245d9c3dcf1a5) --- .../ContentSummaryComputationContext.java | 2 +- .../namenode/ErasureCodingPolicyManager.java | 16 ++++++++++++++++ .../test/resources/testErasureCodingConf.xml | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) 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 d816cb2aca8..f21319b1828 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 b8404805fe1..53732b0a105 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 @@ -237,6 +237,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 1651745c5c9..1a7f2c7d347 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml @@ -1031,5 +1031,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 + + + +