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;
|
package org.apache.hadoop.hdfs.protocol;
|
||||||
|
|
||||||
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A response of add an ErasureCoding policy.
|
* A response of add an ErasureCoding policy.
|
||||||
*/
|
*/
|
||||||
@ -38,7 +40,7 @@ public AddECPolicyResponse(ErasureCodingPolicy policy,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AddECPolicyResponse(ErasureCodingPolicy policy,
|
public AddECPolicyResponse(ErasureCodingPolicy policy,
|
||||||
IllegalECPolicyException e) {
|
HadoopIllegalArgumentException e) {
|
||||||
this(policy, e.getMessage());
|
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 com.google.common.annotations.VisibleForTesting;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyState;
|
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.SystemErasureCodingPolicies;
|
||||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
||||||
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
||||||
@ -144,7 +144,7 @@ public void init(Configuration conf) {
|
|||||||
policyName,
|
policyName,
|
||||||
DFSConfigKeys.DFS_NAMENODE_EC_POLICIES_ENABLED_KEY,
|
DFSConfigKeys.DFS_NAMENODE_EC_POLICIES_ENABLED_KEY,
|
||||||
names);
|
names);
|
||||||
throw new IllegalArgumentException(msg);
|
throw new HadoopIllegalArgumentException(msg);
|
||||||
}
|
}
|
||||||
enabledPoliciesByName.put(ecPolicy.getName(), ecPolicy);
|
enabledPoliciesByName.put(ecPolicy.getName(), ecPolicy);
|
||||||
}
|
}
|
||||||
@ -230,33 +230,34 @@ public void clear() {
|
|||||||
* Add an erasure coding policy.
|
* Add an erasure coding policy.
|
||||||
* @return the added policy
|
* @return the added policy
|
||||||
*/
|
*/
|
||||||
public synchronized ErasureCodingPolicy addPolicy(ErasureCodingPolicy policy)
|
public synchronized ErasureCodingPolicy addPolicy(
|
||||||
throws IllegalECPolicyException {
|
ErasureCodingPolicy policy) {
|
||||||
// Set policy state into DISABLED when adding into Hadoop.
|
// Set policy state into DISABLED when adding into Hadoop.
|
||||||
policy.setState(ErasureCodingPolicyState.DISABLED);
|
policy.setState(ErasureCodingPolicyState.DISABLED);
|
||||||
|
|
||||||
if (!CodecUtil.hasCodec(policy.getCodecName())) {
|
if (!CodecUtil.hasCodec(policy.getCodecName())) {
|
||||||
throw new IllegalECPolicyException("Codec name "
|
throw new HadoopIllegalArgumentException("Codec name "
|
||||||
+ policy.getCodecName() + " is not supported");
|
+ policy.getCodecName() + " is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policy.getCellSize() > maxCellSize) {
|
if (policy.getCellSize() > maxCellSize) {
|
||||||
throw new IllegalECPolicyException("Cell size " + policy.getCellSize()
|
throw new HadoopIllegalArgumentException("Cell size " +
|
||||||
+ " should not exceed maximum " + maxCellSize + " byte");
|
policy.getCellSize() + " should not exceed maximum " +
|
||||||
|
maxCellSize + " bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
String assignedNewName = ErasureCodingPolicy.composePolicyName(
|
String assignedNewName = ErasureCodingPolicy.composePolicyName(
|
||||||
policy.getSchema(), policy.getCellSize());
|
policy.getSchema(), policy.getCellSize());
|
||||||
for (ErasureCodingPolicy p : getPolicies()) {
|
for (ErasureCodingPolicy p : getPolicies()) {
|
||||||
if (p.getName().equals(assignedNewName)) {
|
if (p.getName().equals(assignedNewName)) {
|
||||||
throw new IllegalECPolicyException("The policy name " + assignedNewName
|
throw new HadoopIllegalArgumentException("The policy name " +
|
||||||
+ " already exists");
|
assignedNewName + " already exists");
|
||||||
}
|
}
|
||||||
if (p.getSchema().equals(policy.getSchema()) &&
|
if (p.getSchema().equals(policy.getSchema()) &&
|
||||||
p.getCellSize() == policy.getCellSize()) {
|
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 "
|
+ policy.getSchema().toString() + " and cell size "
|
||||||
+ p.getCellSize() + " is already exists");
|
+ p.getCellSize() + " already exists");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
policy.setName(assignedNewName);
|
policy.setName(assignedNewName);
|
||||||
@ -281,12 +282,12 @@ private byte getNextAvailablePolicyID() {
|
|||||||
public synchronized void removePolicy(String name) {
|
public synchronized void removePolicy(String name) {
|
||||||
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
||||||
if (ecPolicy == null) {
|
if (ecPolicy == null) {
|
||||||
throw new IllegalArgumentException("The policy name " +
|
throw new HadoopIllegalArgumentException("The policy name " +
|
||||||
name + " does not exists");
|
name + " does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ecPolicy.isSystemPolicy()) {
|
if (ecPolicy.isSystemPolicy()) {
|
||||||
throw new IllegalArgumentException("System erasure coding policy " +
|
throw new HadoopIllegalArgumentException("System erasure coding policy " +
|
||||||
name + " cannot be removed");
|
name + " cannot be removed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,8 +318,8 @@ public List<ErasureCodingPolicy> getRemovedPolicies() {
|
|||||||
public synchronized void disablePolicy(String name) {
|
public synchronized void disablePolicy(String name) {
|
||||||
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
||||||
if (ecPolicy == null) {
|
if (ecPolicy == null) {
|
||||||
throw new IllegalArgumentException("The policy name " +
|
throw new HadoopIllegalArgumentException("The policy name " +
|
||||||
name + " does not exists");
|
name + " does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enabledPoliciesByName.containsKey(name)) {
|
if (enabledPoliciesByName.containsKey(name)) {
|
||||||
@ -336,8 +337,8 @@ public synchronized void disablePolicy(String name) {
|
|||||||
public synchronized void enablePolicy(String name) {
|
public synchronized void enablePolicy(String name) {
|
||||||
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
ErasureCodingPolicy ecPolicy = policiesByName.get(name);
|
||||||
if (ecPolicy == null) {
|
if (ecPolicy == null) {
|
||||||
throw new IllegalArgumentException("The policy name " +
|
throw new HadoopIllegalArgumentException("The policy name " +
|
||||||
name + " does not exists");
|
name + " does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
enabledPoliciesByName.put(name, ecPolicy);
|
enabledPoliciesByName.put(name, ecPolicy);
|
||||||
@ -346,4 +347,4 @@ public synchronized void enablePolicy(String name) {
|
|||||||
enabledPoliciesByName.values().toArray(new ErasureCodingPolicy[0]);
|
enabledPoliciesByName.values().toArray(new ErasureCodingPolicy[0]);
|
||||||
LOG.info("Enable the erasure coding policy " + name);
|
LOG.info("Enable the erasure coding policy " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,7 +27,6 @@
|
|||||||
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||||
import org.apache.hadoop.hdfs.XAttrHelper;
|
import org.apache.hadoop.hdfs.XAttrHelper;
|
||||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
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.hdfs.server.namenode.FSDirectory.DirOp;
|
||||||
import org.apache.hadoop.io.IOUtils;
|
import org.apache.hadoop.io.IOUtils;
|
||||||
import org.apache.hadoop.io.WritableUtils;
|
import org.apache.hadoop.io.WritableUtils;
|
||||||
@ -212,7 +211,7 @@ static FileStatus unsetErasureCodingPolicy(final FSNamesystem fsn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ErasureCodingPolicy addErasureCodePolicy(final FSNamesystem fsn,
|
static ErasureCodingPolicy addErasureCodePolicy(final FSNamesystem fsn,
|
||||||
ErasureCodingPolicy policy) throws IllegalECPolicyException {
|
ErasureCodingPolicy policy) {
|
||||||
Preconditions.checkNotNull(policy);
|
Preconditions.checkNotNull(policy);
|
||||||
return fsn.getErasureCodingPolicyManager().addPolicy(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.ReencryptAction;
|
||||||
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
|
||||||
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
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.LastBlockWithStatus;
|
||||||
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
|
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
|
||||||
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
|
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
|
||||||
@ -7207,7 +7206,7 @@ AddECPolicyResponse[] addErasureCodingPolicies(ErasureCodingPolicy[] policies)
|
|||||||
FSDirErasureCodingOp.addErasureCodePolicy(this, policy);
|
FSDirErasureCodingOp.addErasureCodePolicy(this, policy);
|
||||||
addECPolicyName = newPolicy.getName();
|
addECPolicyName = newPolicy.getName();
|
||||||
responses.add(new AddECPolicyResponse(newPolicy));
|
responses.add(new AddECPolicyResponse(newPolicy));
|
||||||
} catch (IllegalECPolicyException e) {
|
} catch (HadoopIllegalArgumentException e) {
|
||||||
responses.add(new AddECPolicyResponse(policy, e));
|
responses.add(new AddECPolicyResponse(policy, e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1617,7 +1617,7 @@ public void testEnableAndDisableErasureCodingPolicy() throws Exception {
|
|||||||
fs.enableErasureCodingPolicy("notExistECName");
|
fs.enableErasureCodingPolicy("notExistECName");
|
||||||
Assert.fail("enable the policy that doesn't exist should fail");
|
Assert.fail("enable the policy that doesn't exist should fail");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
GenericTestUtils.assertExceptionContains("does not exists", e);
|
GenericTestUtils.assertExceptionContains("does not exist", e);
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1626,7 +1626,7 @@ public void testEnableAndDisableErasureCodingPolicy() throws Exception {
|
|||||||
fs.disableErasureCodingPolicy("notExistECName");
|
fs.disableErasureCodingPolicy("notExistECName");
|
||||||
Assert.fail("disable the policy that doesn't exist should fail");
|
Assert.fail("disable the policy that doesn't exist should fail");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
GenericTestUtils.assertExceptionContains("does not exists", e);
|
GenericTestUtils.assertExceptionContains("does not exist", e);
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user