Skip to content

Commit 5ef335d

Browse files
authored
HDFS-16430. Add validation to maximum blocks in EC group when adding an EC policy (#3899). Contributed by daimin.
Reviewed-by: tomscut <[email protected]> Signed-off-by: Ayush Saxena <[email protected]>
1 parent 15b820c commit 5ef335d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.hdfs.server.namenode;
1919

2020
import org.apache.hadoop.classification.VisibleForTesting;
21+
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
2122
import org.apache.hadoop.util.Preconditions;
2223
import org.apache.hadoop.HadoopIllegalArgumentException;
2324
import org.apache.hadoop.classification.InterfaceAudience;
@@ -304,6 +305,12 @@ public synchronized ErasureCodingPolicy addPolicy(
304305
+ policy.getCodecName() + " is not supported");
305306
}
306307

308+
int blocksInGroup = policy.getNumDataUnits() + policy.getNumParityUnits();
309+
if (blocksInGroup > HdfsServerConstants.MAX_BLOCKS_IN_GROUP) {
310+
throw new HadoopIllegalArgumentException("Number of data and parity blocks in an EC group " +
311+
blocksInGroup + " should not exceed maximum " + HdfsServerConstants.MAX_BLOCKS_IN_GROUP);
312+
}
313+
307314
if (policy.getCellSize() > maxCellSize) {
308315
throw new HadoopIllegalArgumentException("Cell size " +
309316
policy.getCellSize() + " should not exceed maximum " +

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,15 @@ public void testAddErasureCodingPolicies() throws Exception {
747747
assertEquals(1, responses.length);
748748
assertFalse(responses[0].isSucceed());
749749

750+
// Test numDataUnits + numParityUnits > 16
751+
toAddSchema = new ECSchema("rs", 14, 4);
752+
newPolicy =
753+
new ErasureCodingPolicy(toAddSchema, 128 * 1024 * 1024);
754+
policyArray = new ErasureCodingPolicy[]{newPolicy};
755+
responses = fs.addErasureCodingPolicies(policyArray);
756+
assertEquals(1, responses.length);
757+
assertFalse(responses[0].isSucceed());
758+
750759
// Test too big cell size
751760
toAddSchema = new ECSchema("rs", 3, 2);
752761
newPolicy =

0 commit comments

Comments
 (0)