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 BC1B3200B77 for ; Sat, 20 Aug 2016 07:29:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BA84E160ABC; Sat, 20 Aug 2016 05:29:24 +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 0BCA4160AAB for ; Sat, 20 Aug 2016 07:29:23 +0200 (CEST) Received: (qmail 4440 invoked by uid 500); 20 Aug 2016 05:29:23 -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 4428 invoked by uid 99); 20 Aug 2016 05:29:23 -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; Sat, 20 Aug 2016 05:29:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E2FA3DFDCE; Sat, 20 Aug 2016 05:29:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jing9@apache.org To: common-commits@hadoop.apache.org Message-Id: <8e2352fadad24a919f571eacc8be6666@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HDFS-10764. Fix INodeFile#getBlocks to not return null. Contributed by Arpit Agarwal. Date: Sat, 20 Aug 2016 05:29:22 +0000 (UTC) archived-at: Sat, 20 Aug 2016 05:29:24 -0000 Repository: hadoop Updated Branches: refs/heads/branch-2.8 b2efb2040 -> 8628ad079 HDFS-10764. Fix INodeFile#getBlocks to not return null. Contributed by Arpit Agarwal. (cherry picked from commit 0faee62a0c8c1b8fd83227babfd00fbc2b26bddf) (cherry picked from commit fff0418458b23c3096384082f8f387b451efad09) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8628ad07 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8628ad07 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8628ad07 Branch: refs/heads/branch-2.8 Commit: 8628ad07900a9673044074598bcd91997f003e7f Parents: b2efb20 Author: Jing Zhao Authored: Fri Aug 19 22:13:36 2016 -0700 Committer: Jing Zhao Committed: Fri Aug 19 22:27:24 2016 -0700 ---------------------------------------------------------------------- .../hadoop/hdfs/server/namenode/INodeFile.java | 27 +++++++++----------- 1 file changed, 12 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/8628ad07/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 e674c5d..60db457 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 @@ -135,14 +135,14 @@ public class INodeFile extends INodeWithAdditionalFields super(id, name, permissions, mtime, atime); header = HeaderFormat.toLong(preferredBlockSize, replication, storagePolicyID); - this.blocks = blklist; + setBlocks(blklist); } public INodeFile(INodeFile that) { super(that); this.header = that.header; - this.blocks = that.blocks; this.features = that.features; + setBlocks(that.blocks); } public INodeFile(INodeFile that, FileDiffList diffs) { @@ -212,9 +212,6 @@ public class INodeFile extends INodeWithAdditionalFields /** Assert all blocks are complete. */ private void assertAllBlocksComplete(int numCommittedAllowed, short minReplication) { - if (blocks == null) { - return; - } for (int i = 0; i < blocks.length; i++) { final String err = checkBlockComplete(blocks, i, numCommittedAllowed, minReplication); @@ -283,7 +280,7 @@ public class INodeFile extends INodeWithAdditionalFields BlockInfo removeLastBlock(Block oldblock) { Preconditions.checkState(isUnderConstruction(), "file is no longer under construction"); - if (blocks == null || blocks.length == 0) { + if (blocks.length == 0) { return null; } int size_1 = blocks.length - 1; @@ -501,7 +498,7 @@ public class INodeFile extends INodeWithAdditionalFields * add a block to the block list */ void addBlock(BlockInfo newblock) { - if (this.blocks == null) { + if (this.blocks.length == 0) { this.setBlocks(new BlockInfo[]{newblock}); } else { int size = this.blocks.length; @@ -514,12 +511,12 @@ public class INodeFile extends INodeWithAdditionalFields /** Set the blocks. */ private void setBlocks(BlockInfo[] blocks) { - this.blocks = blocks; + this.blocks = (blocks != null ? blocks : BlockInfo.EMPTY_ARRAY); } /** Clear all blocks of the file. */ public void clearBlocks() { - setBlocks(BlockInfo.EMPTY_ARRAY); + this.blocks = BlockInfo.EMPTY_ARRAY; } @Override @@ -704,7 +701,7 @@ public class INodeFile extends INodeWithAdditionalFields */ public final long computeFileSize(boolean includesLastUcBlock, boolean usePreferredBlockSize4LastUcBlock) { - if (blocks == null || blocks.length == 0) { + if (blocks.length == 0) { return 0; } final int last = blocks.length - 1; @@ -769,7 +766,7 @@ public class INodeFile extends INodeWithAdditionalFields * Return the penultimate allocated block for this file. */ BlockInfo getPenultimateBlock() { - if (blocks == null || blocks.length <= 1) { + if (blocks.length <= 1) { return null; } return blocks[blocks.length - 2]; @@ -777,12 +774,12 @@ public class INodeFile extends INodeWithAdditionalFields @Override public BlockInfo getLastBlock() { - return blocks == null || blocks.length == 0? null: blocks[blocks.length-1]; + return blocks.length == 0 ? null: blocks[blocks.length-1]; } @Override public int numBlocks() { - return blocks == null ? 0 : blocks.length; + return blocks.length; } @VisibleForTesting @@ -793,7 +790,7 @@ public class INodeFile extends INodeWithAdditionalFields out.print(", fileSize=" + computeFileSize(snapshotId)); // only compare the first block out.print(", blocks="); - out.print(blocks == null || blocks.length == 0? null: blocks[0]); + out.print(blocks.length == 0 ? null: blocks[0]); out.println(); } @@ -838,7 +835,7 @@ public class INodeFile extends INodeWithAdditionalFields long newLength, BlockStoragePolicy bsps, QuotaCounts delta) { final BlockInfo[] blocks = getBlocks(); - if (blocks == null || blocks.length == 0) { + if (blocks.length == 0) { return; } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org