HDFS-12915. Fix findbugs warning in INodeFile$HeaderFormat.getBlockLayoutRedundancy. (Contributed by Chris Douglas)
This commit is contained in:
parent
a55884c68e
commit
6e3e1b8cde
|
@ -33,10 +33,11 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.fs.permission.PermissionStatus;
|
|
||||||
import org.apache.hadoop.fs.StorageType;
|
import org.apache.hadoop.fs.StorageType;
|
||||||
|
import org.apache.hadoop.fs.permission.PermissionStatus;
|
||||||
import org.apache.hadoop.hdfs.protocol.Block;
|
import org.apache.hadoop.hdfs.protocol.Block;
|
||||||
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
|
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
|
||||||
|
import org.apache.hadoop.hdfs.protocol.BlockType;
|
||||||
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;
|
||||||
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
|
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
|
||||||
|
@ -45,7 +46,6 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoStriped;
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoStriped;
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite;
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite;
|
||||||
import org.apache.hadoop.hdfs.protocol.BlockType;
|
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
|
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
|
||||||
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.snapshot.FileDiff;
|
import org.apache.hadoop.hdfs.server.namenode.snapshot.FileDiff;
|
||||||
|
@ -53,11 +53,11 @@ import org.apache.hadoop.hdfs.server.namenode.snapshot.FileDiffList;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.snapshot.FileWithSnapshotFeature;
|
import org.apache.hadoop.hdfs.server.namenode.snapshot.FileWithSnapshotFeature;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
|
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
|
||||||
import org.apache.hadoop.hdfs.util.LongBitFormat;
|
import org.apache.hadoop.hdfs.util.LongBitFormat;
|
||||||
|
import org.apache.hadoop.util.StringUtils;
|
||||||
|
import static org.apache.hadoop.io.erasurecode.ErasureCodeConstants.REPLICATION_POLICY_ID;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import org.apache.hadoop.io.erasurecode.ErasureCodeConstants;
|
|
||||||
import org.apache.hadoop.util.StringUtils;
|
|
||||||
|
|
||||||
/** I-node for closed file. */
|
/** I-node for closed file. */
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
|
@ -186,28 +186,49 @@ public class INodeFile extends INodeWithAdditionalFields
|
||||||
* Construct block layout redundancy based on the given BlockType,
|
* Construct block layout redundancy based on the given BlockType,
|
||||||
* replication factor and EC PolicyID.
|
* replication factor and EC PolicyID.
|
||||||
*/
|
*/
|
||||||
static long getBlockLayoutRedundancy(final BlockType blockType,
|
static long getBlockLayoutRedundancy(BlockType blockType,
|
||||||
final Short replication, final Byte erasureCodingPolicyID) {
|
Short replication, Byte erasureCodingPolicyID) {
|
||||||
long layoutRedundancy = 0;
|
if (null == erasureCodingPolicyID) {
|
||||||
if (blockType == STRIPED) {
|
erasureCodingPolicyID = REPLICATION_POLICY_ID;
|
||||||
Preconditions.checkArgument(replication == null &&
|
}
|
||||||
erasureCodingPolicyID != null);
|
long layoutRedundancy = 0xFF & erasureCodingPolicyID;
|
||||||
Preconditions.checkArgument(ErasureCodingPolicyManager.getInstance()
|
switch (blockType) {
|
||||||
.getByID(erasureCodingPolicyID) != null,
|
case STRIPED:
|
||||||
"Could not find EC policy with ID 0x" + StringUtils
|
if (replication != null) {
|
||||||
.byteToHexString(erasureCodingPolicyID));
|
throw new IllegalArgumentException(
|
||||||
|
"Illegal replication for STRIPED block type");
|
||||||
|
}
|
||||||
|
if (erasureCodingPolicyID == REPLICATION_POLICY_ID) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Illegal REPLICATION policy for STRIPED block type");
|
||||||
|
}
|
||||||
|
if (null == ErasureCodingPolicyManager.getInstance()
|
||||||
|
.getByID(erasureCodingPolicyID)) {
|
||||||
|
throw new IllegalArgumentException(String.format(
|
||||||
|
"Could not find EC policy with ID 0x%02x",
|
||||||
|
erasureCodingPolicyID));
|
||||||
|
}
|
||||||
|
|
||||||
|
// valid parameters for STRIPED
|
||||||
layoutRedundancy |= BLOCK_TYPE_MASK_STRIPED;
|
layoutRedundancy |= BLOCK_TYPE_MASK_STRIPED;
|
||||||
// Following bitwise OR with signed byte erasureCodingPolicyID is safe
|
break;
|
||||||
// as the PolicyID can never be in negative.
|
case CONTIGUOUS:
|
||||||
layoutRedundancy |= erasureCodingPolicyID;
|
if (erasureCodingPolicyID != REPLICATION_POLICY_ID) {
|
||||||
} else {
|
throw new IllegalArgumentException(String.format(
|
||||||
Preconditions.checkArgument(erasureCodingPolicyID == null ||
|
"Illegal EC policy 0x%02x for CONTIGUOUS block type",
|
||||||
erasureCodingPolicyID ==
|
erasureCodingPolicyID));
|
||||||
ErasureCodeConstants.REPLICATION_POLICY_ID);
|
}
|
||||||
Preconditions.checkArgument(replication != null && replication >= 0 &&
|
if (null == replication ||
|
||||||
replication <= MAX_REDUNDANCY,
|
replication < 0 || replication > MAX_REDUNDANCY) {
|
||||||
"Invalid replication value " + replication);
|
throw new IllegalArgumentException("Invalid replication value "
|
||||||
|
+ replication);
|
||||||
|
}
|
||||||
|
|
||||||
|
// valid parameters for CONTIGUOUS
|
||||||
layoutRedundancy |= replication;
|
layoutRedundancy |= replication;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown blockType: " + blockType);
|
||||||
}
|
}
|
||||||
return layoutRedundancy;
|
return layoutRedundancy;
|
||||||
}
|
}
|
||||||
|
@ -599,7 +620,7 @@ public class INodeFile extends INodeWithAdditionalFields
|
||||||
if (isStriped()) {
|
if (isStriped()) {
|
||||||
return HeaderFormat.getECPolicyID(header);
|
return HeaderFormat.getECPolicyID(header);
|
||||||
}
|
}
|
||||||
return ErasureCodeConstants.REPLICATION_POLICY_ID;
|
return REPLICATION_POLICY_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue