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 c81f82cde32..95f3fee34d8 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 @@ -191,6 +191,8 @@ public class ContentSummaryComputationContext { .getEnabledPolicyByName(ecPolicyName) .getName(); } + } else if (inode.getParent() != null) { + return getErasureCodingPolicyName(inode.getParent()); } } catch (IOException ioe) { LOG.warn("Encountered error getting ec policy for " diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java index 0b7d25932d5..5c703c1723b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeys; +import org.apache.hadoop.fs.ContentSummary; import org.apache.hadoop.fs.CreateFlag; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -153,6 +154,19 @@ public class TestErasureCodingPolicies { assertNotNull(files[1].getErasureCodingPolicy()); } + @Test + public void testContentSummaryOfECSubdir() throws IOException { + final Path testDir = new Path("/ec"); + fs.mkdir(testDir, FsPermission.getDirDefault()); + fs.setErasureCodingPolicy(testDir, ecPolicy.getName()); + final Path fPath = new Path("ec/file"); + fs.create(fPath).close(); + final Path subdir = new Path("/ec/sub"); + fs.mkdir(subdir, FsPermission.getDirDefault()); + ContentSummary contentSummary = fs.getContentSummary(subdir); + assertEquals(ecPolicy.getName(),contentSummary.getErasureCodingPolicy()); + } + @Test public void testBasicSetECPolicy() throws IOException, InterruptedException {