diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index e6022fe85d..f1e6bdc785 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -2655,6 +2655,9 @@ Release 2.7.3 - UNRELEASED HDFS-9661. Deadlock in DN.FsDatasetImpl between moveBlockAcrossStorage and createRbw (ade via vinayakumarb) + HDFS-9625. set replication for empty file failed when set storage policy + (DENG FEI via vinayakumarb) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java index 6ca7a03c05..a00591f6a5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java @@ -811,6 +811,10 @@ public EnumCounters getStorageTypeDeltas(byte storagePolicyID, long dsDelta, short oldRep, short newRep) { EnumCounters typeSpaceDeltas = new EnumCounters(StorageType.class); + // empty file + if(dsDelta == 0){ + return typeSpaceDeltas; + } // Storage type and its quota are only available when storage policy is set if (storagePolicyID != HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED) { BlockStoragePolicy storagePolicy = getBlockManager().getStoragePolicy(storagePolicyID); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetrepIncreasing.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetrepIncreasing.java index 0af1988a59..a055adca35 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetrepIncreasing.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetrepIncreasing.java @@ -83,4 +83,23 @@ public void testSetrepIncreasing() throws IOException { public void testSetrepIncreasingSimulatedStorage() throws IOException { setrep(3, 7, true); } + + @Test + public void testSetRepWithStoragePolicyOnEmptyFile() throws Exception { + Configuration conf = new HdfsConfiguration(); + MiniDFSCluster cluster = + new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); + DistributedFileSystem dfs = cluster.getFileSystem(); + try { + Path d = new Path("/tmp"); + dfs.mkdirs(d); + dfs.setStoragePolicy(d, "HOT"); + Path f = new Path(d, "foo"); + dfs.createNewFile(f); + dfs.setReplication(f, (short) 4); + } finally { + dfs.close(); + cluster.shutdown(); + } + } }