HDFS-14274. EC: NPE While Listing EC Policy For A Directory Following Replication...
authorSurendra Singh Lilhore <surendralilhore@apache.org>
Wed, 13 Feb 2019 17:36:46 +0000 (23:06 +0530)
committerSurendra Singh Lilhore <surendralilhore@apache.org>
Wed, 13 Feb 2019 17:36:46 +0000 (23:06 +0530)
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java
hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml

index 2e7c78a..0263f2a 100644 (file)
@@ -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) {
index 327de41..d9f7e9a 100644 (file)
@@ -256,6 +256,22 @@ public final class ErasureCodingPolicyManager {
   }
 
   /**
+   * 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.
    * @return ecPolicy, or null if not found
index c280eca..2cc08f4 100644 (file)
       </comparators>
     </test>
 
+    <test>
+      <description>ls: file with replication Policy</description>
+      <test-commands>
+        <command>-fs NAMENODE -mkdir -p /ecdir</command>
+        <ec-admin-command>-fs NAMENODE -setPolicy -path /ecdir -replicate</ec-admin-command>
+        <command>-fs NAMENODE -touchz /ecdir/file1</command>
+        <command>-fs NAMENODE -ls -e /</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rmdir /ecdir</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>RegexpComparator</type>
+          <expected-output>^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</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+
   </tests>
 </configuration>