From ab80a572be7c30bc21f6e5329ed02d6e0692d73e Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Fri, 8 May 2015 13:50:51 -0700 Subject: [PATCH] HDFS-8113. Add check for null BlockCollection pointers in BlockInfoContiguous structures (Chengbing Liu via Colin P. McCabe) (cherry picked from commit f523e963e4d88e4e459352387c6efeab59e7a809) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../server/blockmanagement/BlockInfoContiguous.java | 3 ++- .../hdfs/server/blockmanagement/TestBlockInfo.java | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 0d54a0d2df5..6093dd061e2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -200,6 +200,9 @@ Release 2.8.0 - UNRELEASED HDFS-8284. Update documentation about how to use HTrace with HDFS (Masatake Iwasaki via Colin P. McCabe) + HDFS-8113. Add check for null BlockCollection pointers in + BlockInfoContiguous structures (Chengbing Liu via Colin P. McCabe) + OPTIMIZATIONS HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoContiguous.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoContiguous.java index 1039a98f176..695eadff6fe 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoContiguous.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoContiguous.java @@ -77,7 +77,8 @@ public BlockInfoContiguous(Block blk, short replication) { * @param from BlockInfo to copy from. */ protected BlockInfoContiguous(BlockInfoContiguous from) { - this(from, from.bc.getBlockReplication()); + super(from); + this.triplets = new Object[from.triplets.length]; this.bc = from.bc; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockInfo.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockInfo.java index 6cee8b0ef9a..c5662caabaf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockInfo.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockInfo.java @@ -69,6 +69,17 @@ public void testAddStorage() throws Exception { Assert.assertEquals(storage, blockInfo.getStorageInfo(0)); } + @Test + public void testCopyConstructor() { + BlockInfoContiguous old = new BlockInfoContiguous((short) 3); + try { + BlockInfoContiguous copy = new BlockInfoContiguous(old); + assertEquals(old.getBlockCollection(), copy.getBlockCollection()); + assertEquals(old.getCapacity(), copy.getCapacity()); + } catch (Exception e) { + Assert.fail("Copy constructor throws exception: " + e); + } + } @Test public void testReplaceStorage() throws Exception {