HDFS-8853. Erasure Coding: Provide ECSchema validation when setting EC policy. Contributed by J.Andreina.

Change-Id: I9211d9728480225a407d82e6c0bea1a928adfa11
This commit is contained in:
Zhe Zhang 2015-09-10 16:31:37 -07:00
parent f62237bc2f
commit 96d6b516b2
3 changed files with 48 additions and 0 deletions

View File

@ -415,3 +415,6 @@
HDFS-8833. Erasure coding: store EC schema and cell size in INodeFile and HDFS-8833. Erasure coding: store EC schema and cell size in INodeFile and
eliminate notion of EC zones. (zhz) eliminate notion of EC zones. (zhz)
HDFS-8853. Erasure Coding: Provide ECSchema validation when setting EC
policy. (andreina via zhz)

View File

@ -28,6 +28,8 @@
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.fs.XAttr; import org.apache.hadoop.fs.XAttr;
import org.apache.hadoop.fs.XAttrSetFlag; import org.apache.hadoop.fs.XAttrSetFlag;
import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsAction;
@ -105,6 +107,26 @@ static List<XAttr> createErasureCodingPolicyXAttr(final FSNamesystem fsn,
// System default erasure coding policy will be used since no specified. // System default erasure coding policy will be used since no specified.
if (ecPolicy == null) { if (ecPolicy == null) {
ecPolicy = ErasureCodingPolicyManager.getSystemDefaultPolicy(); ecPolicy = ErasureCodingPolicyManager.getSystemDefaultPolicy();
} else {
// If ecPolicy is specified check if it is one among active policies.
boolean validPolicy = false;
ErasureCodingPolicy[] activePolicies =
FSDirErasureCodingOp.getErasureCodingPolicies(fsd.getFSNamesystem());
for (ErasureCodingPolicy activePolicy : activePolicies) {
if (activePolicy.equals(ecPolicy)) {
validPolicy = true;
break;
}
}
if (!validPolicy) {
List<String> ecPolicyNames = new ArrayList<String>();
for (ErasureCodingPolicy activePolicy : activePolicies) {
ecPolicyNames.add(activePolicy.getName());
}
throw new HadoopIllegalArgumentException("Policy [ " +
ecPolicy.getName()+ " ] does not match any of the " +
"supported policies. Please select any one of " + ecPolicyNames);
}
} }
final XAttr ecXAttr; final XAttr ecXAttr;

View File

@ -26,6 +26,7 @@
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.INode; import org.apache.hadoop.hdfs.server.namenode.INode;
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
import org.apache.hadoop.io.erasurecode.ECSchema;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -208,4 +209,26 @@ private void verifyErasureCodingInfo(
assertEquals("Actually used ecPolicy should be equal with target ecPolicy", assertEquals("Actually used ecPolicy should be equal with target ecPolicy",
usingECPolicy, ecPolicy); usingECPolicy, ecPolicy);
} }
@Test
public void testCreationErasureCodingZoneWithInvalidPolicy()
throws IOException {
ECSchema rsSchema = new ECSchema("rs", 4, 2);
String policyName = "RS-4-2-128k";
int cellSize = 128 * 1024;
ErasureCodingPolicy ecPolicy=
new ErasureCodingPolicy(policyName,rsSchema,cellSize);
String src = "/ecZone4-2";
final Path ecDir = new Path(src);
try {
fs.mkdir(ecDir, FsPermission.getDirDefault());
fs.getClient().setErasureCodingPolicy(src, ecPolicy);
fail("HadoopIllegalArgumentException should be thrown for"
+ "setting an invalid erasure coding policy");
} catch (Exception e) {
assertExceptionContains("Policy [ RS-4-2-128k ] does not match " +
"any of the supported policies",e);
}
}
} }