HDFS-14274. EC: NPE While Listing EC Policy For A Directory Following Replication Policy. Contributed by Ayush Saxena.

(cherry picked from commit 35d4f32b32)
This commit is contained in:
Surendra Singh Lilhore 2019-02-13 23:06:46 +05:30
parent 49af36b25c
commit e163bf2258
3 changed files with 36 additions and 1 deletions

View 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) {

View File

@ -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.

View File

@ -1055,5 +1055,24 @@
</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>