HDFS-12402. Refactor ErasureCodingPolicyManager and related codes. Contributed by Sammi Chen
This commit is contained in:
parent
6f101e7df1
commit
2adf8bed71
@ -17,6 +17,8 @@
|
||||
*/
|
||||
package org.apache.hadoop.hdfs.protocol;
|
||||
|
||||
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* A response of add an ErasureCoding policy.
|
||||
*/
|
||||
@ -38,7 +40,7 @@ public AddECPolicyResponse(ErasureCodingPolicy policy,
|
||||
}
|
||||
|
||||
public AddECPolicyResponse(ErasureCodingPolicy policy,
|
||||
IllegalECPolicyException e) {
|
||||
HadoopIllegalArgumentException e) {
|
||||
this(policy, e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.hdfs.protocol;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
|
||||
/**
|
||||
* An Exception indicates the error when adding an ErasureCoding policy.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
@InterfaceStability.Evolving
|
||||
public class IllegalECPolicyException extends Exception {
|
||||
static final long serialVersionUID = 1L;
|
||||
|
||||
public IllegalECPolicyException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
@ -19,11 +19,11 @@
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyState;
|
||||
import org.apache.hadoop.hdfs.protocol.IllegalECPolicyException;
|
||||
import org.apache.hadoop.hdfs.protocol.SystemErasureCodingPolicies;
|
||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
||||
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
||||
@ -144,7 +144,7 @@ public void init(Configuration conf) {
|
||||
policyName,
|
||||
DFSConfigKeys.DFS_NAMENODE_EC_POLICIES_ENABLED_KEY,
|
||||
names);
|
||||
throw new IllegalArgumentException(msg);
|
||||
throw new HadoopIllegalArgumentException(msg);
|
||||
}
|
||||
enabledPoliciesByName.put(ecPolicy.getName(), ecPolicy);
|
||||
}
|
||||
@ -230,33 +230,34 @@ public void clear() {
|
||||
* Add an erasure coding policy.
|
||||
* @return the added policy
|
||||
*/
|
||||
public synchronized ErasureCodingPolicy addPolicy(ErasureCodingPolicy policy)
|
||||
throws IllegalECPolicyException {
|
||||
public synchronized ErasureCodingPolicy addPolicy(
|
||||
ErasureCodingPolicy policy) {
|
||||
// Set policy state into DISABLED when adding into Hadoop.
|
||||
policy.setState(ErasureCodingPolicyState.DISABLED);
|
||||
|
||||
if (!CodecUtil.hasCodec(policy.getCodecName())) {
|
||||
throw new IllegalECPolicyException("Codec name "
|
||||
throw new HadoopIllegalArgumentException("Codec name "
|
||||
+ policy.getCodecName() + " is not supported");
|
||||
}
|
||||
|
||||
if (policy.getCellSize() > maxCellSize) {
|
||||
throw new IllegalECPolicyException("Cell size " + policy.getCellSize()
|
||||
+ " should not exceed maximum " + maxCellSize + " byte");
|
||||
throw new HadoopIllegalArgumentException("Cell size " +
|
||||
policy.getCellSize() + " should not exceed maximum " +
|
||||
maxCellSize + " bytes");
|
||||
}
|
||||
|
||||
String assignedNewName = ErasureCodingPolicy.composePolicyName(
|
||||
policy.getSchema(), policy.getCellSize());
|
||||
for (ErasureCodingPolicy p : getPolicies()) {
|
||||
if (p.getName().equals(assignedNewName)) {
|
||||
throw new IllegalECPolicyException("The policy name " + assignedNewName
|
||||
+ " already exists");
|
||||
throw new HadoopIllegalArgumentException("The policy name " +
|
||||
assignedNewName + " already exists");
|
||||
}
|
||||
if (p.getSchema().equals(policy.getSchema()) &&
|
||||
p.getCellSize() == policy.getCellSize()) {
|
||||
throw new IllegalECPolicyException("A policy with same schema "
|
||||
throw new HadoopIllegalArgumentException("A policy with same schema "
|
||||
+ policy.getSchema().toString() + " and cell size "
|
||||
+ p.getCellSize() + " is already exists");
|
||||
+ p.getCellSize() + " already exists");
|
||||
}
|
||||
}
|
||||
policy.setName(assignedNewName);
|
||||
@ -281,12 +282,12 @@ private byte getNextAvailablePolicyID() {
|
||||
public synchronized void removePolicy(String name) {
|
||||
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
||||
if (ecPolicy == null) {
|
||||
throw new IllegalArgumentException("The policy name " +
|
||||
name + " does not exists");
|
||||
throw new HadoopIllegalArgumentException("The policy name " +
|
||||
name + " does not exist");
|
||||
}
|
||||
|
||||
if (ecPolicy.isSystemPolicy()) {
|
||||
throw new IllegalArgumentException("System erasure coding policy " +
|
||||
throw new HadoopIllegalArgumentException("System erasure coding policy " +
|
||||
name + " cannot be removed");
|
||||
}
|
||||
|
||||
@ -317,8 +318,8 @@ public List<ErasureCodingPolicy> getRemovedPolicies() {
|
||||
public synchronized void disablePolicy(String name) {
|
||||
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
||||
if (ecPolicy == null) {
|
||||
throw new IllegalArgumentException("The policy name " +
|
||||
name + " does not exists");
|
||||
throw new HadoopIllegalArgumentException("The policy name " +
|
||||
name + " does not exist");
|
||||
}
|
||||
|
||||
if (enabledPoliciesByName.containsKey(name)) {
|
||||
@ -336,8 +337,8 @@ public synchronized void disablePolicy(String name) {
|
||||
public synchronized void enablePolicy(String name) {
|
||||
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
||||
if (ecPolicy == null) {
|
||||
throw new IllegalArgumentException("The policy name " +
|
||||
name + " does not exists");
|
||||
throw new HadoopIllegalArgumentException("The policy name " +
|
||||
name + " does not exist");
|
||||
}
|
||||
|
||||
enabledPoliciesByName.put(name, ecPolicy);
|
||||
|
@ -27,7 +27,6 @@
|
||||
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||
import org.apache.hadoop.hdfs.XAttrHelper;
|
||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
||||
import org.apache.hadoop.hdfs.protocol.IllegalECPolicyException;
|
||||
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
import org.apache.hadoop.io.WritableUtils;
|
||||
@ -212,7 +211,7 @@ static FileStatus unsetErasureCodingPolicy(final FSNamesystem fsn,
|
||||
}
|
||||
|
||||
static ErasureCodingPolicy addErasureCodePolicy(final FSNamesystem fsn,
|
||||
ErasureCodingPolicy policy) throws IllegalECPolicyException {
|
||||
ErasureCodingPolicy policy) {
|
||||
Preconditions.checkNotNull(policy);
|
||||
return fsn.getErasureCodingPolicyManager().addPolicy(policy);
|
||||
}
|
||||
|
@ -201,7 +201,6 @@
|
||||
import org.apache.hadoop.hdfs.protocol.HdfsConstants.ReencryptAction;
|
||||
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
|
||||
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
||||
import org.apache.hadoop.hdfs.protocol.IllegalECPolicyException;
|
||||
import org.apache.hadoop.hdfs.protocol.LastBlockWithStatus;
|
||||
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
|
||||
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
|
||||
@ -7207,7 +7206,7 @@ AddECPolicyResponse[] addErasureCodingPolicies(ErasureCodingPolicy[] policies)
|
||||
FSDirErasureCodingOp.addErasureCodePolicy(this, policy);
|
||||
addECPolicyName = newPolicy.getName();
|
||||
responses.add(new AddECPolicyResponse(newPolicy));
|
||||
} catch (IllegalECPolicyException e) {
|
||||
} catch (HadoopIllegalArgumentException e) {
|
||||
responses.add(new AddECPolicyResponse(policy, e));
|
||||
}
|
||||
}
|
||||
|
@ -1617,7 +1617,7 @@ public void testEnableAndDisableErasureCodingPolicy() throws Exception {
|
||||
fs.enableErasureCodingPolicy("notExistECName");
|
||||
Assert.fail("enable the policy that doesn't exist should fail");
|
||||
} catch (Exception e) {
|
||||
GenericTestUtils.assertExceptionContains("does not exists", e);
|
||||
GenericTestUtils.assertExceptionContains("does not exist", e);
|
||||
// pass
|
||||
}
|
||||
|
||||
@ -1626,7 +1626,7 @@ public void testEnableAndDisableErasureCodingPolicy() throws Exception {
|
||||
fs.disableErasureCodingPolicy("notExistECName");
|
||||
Assert.fail("disable the policy that doesn't exist should fail");
|
||||
} catch (Exception e) {
|
||||
GenericTestUtils.assertExceptionContains("does not exists", e);
|
||||
GenericTestUtils.assertExceptionContains("does not exist", e);
|
||||
// pass
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user