Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D9F30200D66 for ; Fri, 29 Dec 2017 21:23:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D83B9160C33; Fri, 29 Dec 2017 20:23:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 02FB1160C16 for ; Fri, 29 Dec 2017 21:23:48 +0100 (CET) Received: (qmail 20901 invoked by uid 500); 29 Dec 2017 20:23:47 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 20891 invoked by uid 99); 29 Dec 2017 20:23:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Dec 2017 20:23:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6A025DFC25; Fri, 29 Dec 2017 20:23:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lei@apache.org To: common-commits@hadoop.apache.org Message-Id: <5194b15f572a4e1fa260f978555138dd@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HDFS-12915. Fix findbugs warning in INodeFile$HeaderFormat.getBlockLayoutRedundancy. (Contributed by Chris Douglas) Date: Fri, 29 Dec 2017 20:23:45 +0000 (UTC) archived-at: Fri, 29 Dec 2017 20:23:50 -0000 Repository: hadoop Updated Branches: refs/heads/branch-3.0 bd4dcc777 -> 8f9603cb9 HDFS-12915. Fix findbugs warning in INodeFile$HeaderFormat.getBlockLayoutRedundancy. (Contributed by Chris Douglas) (cherry picked from commit 6e3e1b8cde737e4c03b0f5279cab0239e7069a72) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8f9603cb Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8f9603cb Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8f9603cb Branch: refs/heads/branch-3.0 Commit: 8f9603cb9daf219ef881843f9340130f66a9a715 Parents: bd4dcc7 Author: Lei Xu Authored: Fri Dec 29 12:21:57 2017 -0800 Committer: Lei Xu Committed: Fri Dec 29 12:23:33 2017 -0800 ---------------------------------------------------------------------- .../hadoop/hdfs/server/namenode/INodeFile.java | 71 +++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/8f9603cb/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java index 3f2fb33..906a940 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java @@ -33,10 +33,11 @@ import java.util.List; import java.util.Set; import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.fs.permission.PermissionStatus; 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.BlockStoragePolicy; +import org.apache.hadoop.hdfs.protocol.BlockType; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; import org.apache.hadoop.hdfs.protocol.HdfsConstants; 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.BlockManager; 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.common.HdfsServerConstants.BlockUCState; 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.Snapshot; 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.base.Preconditions; -import org.apache.hadoop.io.erasurecode.ErasureCodeConstants; -import org.apache.hadoop.util.StringUtils; /** I-node for closed file. */ @InterfaceAudience.Private @@ -186,28 +186,49 @@ public class INodeFile extends INodeWithAdditionalFields * Construct block layout redundancy based on the given BlockType, * replication factor and EC PolicyID. */ - static long getBlockLayoutRedundancy(final BlockType blockType, - final Short replication, final Byte erasureCodingPolicyID) { - long layoutRedundancy = 0; - if (blockType == STRIPED) { - Preconditions.checkArgument(replication == null && - erasureCodingPolicyID != null); - Preconditions.checkArgument(ErasureCodingPolicyManager.getInstance() - .getByID(erasureCodingPolicyID) != null, - "Could not find EC policy with ID 0x" + StringUtils - .byteToHexString(erasureCodingPolicyID)); + static long getBlockLayoutRedundancy(BlockType blockType, + Short replication, Byte erasureCodingPolicyID) { + if (null == erasureCodingPolicyID) { + erasureCodingPolicyID = REPLICATION_POLICY_ID; + } + long layoutRedundancy = 0xFF & erasureCodingPolicyID; + switch (blockType) { + case STRIPED: + if (replication != null) { + 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; - // Following bitwise OR with signed byte erasureCodingPolicyID is safe - // as the PolicyID can never be in negative. - layoutRedundancy |= erasureCodingPolicyID; - } else { - Preconditions.checkArgument(erasureCodingPolicyID == null || - erasureCodingPolicyID == - ErasureCodeConstants.REPLICATION_POLICY_ID); - Preconditions.checkArgument(replication != null && replication >= 0 && - replication <= MAX_REDUNDANCY, - "Invalid replication value " + replication); + break; + case CONTIGUOUS: + if (erasureCodingPolicyID != REPLICATION_POLICY_ID) { + throw new IllegalArgumentException(String.format( + "Illegal EC policy 0x%02x for CONTIGUOUS block type", + erasureCodingPolicyID)); + } + if (null == replication || + replication < 0 || replication > MAX_REDUNDANCY) { + throw new IllegalArgumentException("Invalid replication value " + + replication); + } + + // valid parameters for CONTIGUOUS layoutRedundancy |= replication; + break; + default: + throw new IllegalArgumentException("Unknown blockType: " + blockType); } return layoutRedundancy; } @@ -599,7 +620,7 @@ public class INodeFile extends INodeWithAdditionalFields if (isStriped()) { return HeaderFormat.getECPolicyID(header); } - return ErasureCodeConstants.REPLICATION_POLICY_ID; + return REPLICATION_POLICY_ID; } /** --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org