Skip to content

Commit 0f0ebf9

Browse files
cndaiminjojochuang
authored andcommitted
HDFS-16430. Add validation to maximum blocks in EC group when adding an EC policy (#3899). Contributed by daimin.
Reviewed-by: tomscut <litao@bigo.sg> Signed-off-by: Ayush Saxena <ayushsaxena@apache.org> (cherry picked from commit 5ef335d) Conflicts: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java (cherry picked from commit 728ed10)
1 parent 0aff874 commit 0f0ebf9

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
@@ -19,6 +19,7 @@
1919

2020
import com.google.common.annotations.VisibleForTesting;
2121
import com.google.common.base.Preconditions;
22+
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
2223
import org.apache.hadoop.HadoopIllegalArgumentException;
2324
import org.apache.hadoop.classification.InterfaceAudience;
2425
import org.apache.hadoop.conf.Configuration;
@@ -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)