HDFS-12054. FSNamesystem#addErasureCodingPolicies should call checkNameNodeSafeMode() to ensure Namenode is not in safemode. Contributed by lufei.
This commit is contained in:
parent
2e43c28e01
commit
1040bae6fc
hadoop-hdfs-project/hadoop-hdfs/src
main/java/org/apache/hadoop/hdfs/server/namenode
test/java/org/apache/hadoop/hdfs
@ -7081,6 +7081,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
||||
checkOperation(OperationCategory.WRITE);
|
||||
for (ErasureCodingPolicy policy : policies) {
|
||||
try {
|
||||
checkOperation(OperationCategory.WRITE);
|
||||
checkNameNodeSafeMode("Cannot add erasure coding policy");
|
||||
ErasureCodingPolicy newPolicy =
|
||||
FSDirErasureCodingOp.addErasureCodePolicy(this, policy);
|
||||
addECPolicyName = newPolicy.getName();
|
||||
|
@ -40,6 +40,7 @@ import org.apache.hadoop.fs.permission.AclEntry;
|
||||
import org.apache.hadoop.fs.permission.FsAction;
|
||||
import org.apache.hadoop.fs.permission.FsPermission;
|
||||
import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties;
|
||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
||||
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
|
||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
|
||||
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
|
||||
@ -48,6 +49,7 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
||||
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
|
||||
import org.apache.hadoop.hdfs.server.namenode.SafeModeException;
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
import org.apache.hadoop.io.erasurecode.ECSchema;
|
||||
import org.apache.hadoop.ipc.RemoteException;
|
||||
import org.apache.hadoop.security.AccessControlException;
|
||||
import org.apache.hadoop.security.UserGroupInformation;
|
||||
@ -466,6 +468,20 @@ public class TestSafeMode {
|
||||
// expected
|
||||
}
|
||||
|
||||
ECSchema toAddSchema = new ECSchema("testcodec", 3, 2);
|
||||
ErasureCodingPolicy newPolicy =
|
||||
new ErasureCodingPolicy(toAddSchema, 128 * 1024);
|
||||
ErasureCodingPolicy[] policyArray =
|
||||
new ErasureCodingPolicy[]{newPolicy};
|
||||
try {
|
||||
dfs.addErasureCodingPolicies(policyArray);
|
||||
fail("AddErasureCodingPolicies should have failed.");
|
||||
} catch (IOException ioe) {
|
||||
GenericTestUtils.assertExceptionContains(
|
||||
"Cannot add erasure coding policy", ioe);
|
||||
// expected
|
||||
}
|
||||
|
||||
assertFalse("Could not leave SM",
|
||||
dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user