From 6a7c0306bd9a600a943abb61606aaaf4f9beafee Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Thu, 11 Aug 2011 05:24:55 +0000 Subject: [PATCH] HDFS-2245. Fix a NullPointerException in BlockManager.chooseTarget(..). git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1156490 13f79535-47bb-0310-9956-ffa450edef68 --- hdfs/CHANGES.txt | 3 ++ .../server/blockmanagement/BlockManager.java | 13 ++++---- .../apache/hadoop/hdfs/TestFileCreation.java | 30 +++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/hdfs/CHANGES.txt b/hdfs/CHANGES.txt index 7dba58c063..ff0ba15b05 100644 --- a/hdfs/CHANGES.txt +++ b/hdfs/CHANGES.txt @@ -951,6 +951,9 @@ Trunk (unreleased changes) HDFS-2196. Make ant build system work with hadoop-common JAR generated by Maven. (Alejandro Abdelnur via tomwhite) + HDFS-2245. Fix a NullPointerException in BlockManager.chooseTarget(..). + (szetszwo) + BREAKDOWN OF HDFS-1073 SUBTASKS HDFS-1521. Persist transaction ID on disk between NN restarts. diff --git a/hdfs/src/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hdfs/src/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java index e552ccdeab..f60530b4cc 100644 --- a/hdfs/src/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java +++ b/hdfs/src/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java @@ -1221,12 +1221,13 @@ public DatanodeDescriptor[] chooseTarget(final String src, final DatanodeDescriptor targets[] = blockplacement.chooseTarget( src, numOfReplicas, client, excludedNodes, blocksize); if (targets.length < minReplication) { - throw new IOException("File " + src + " could only be replicated to " + - targets.length + " nodes, instead of " + - minReplication + ". There are " - + getDatanodeManager().getNetworkTopology().getNumOfLeaves() - + " datanode(s) running but "+excludedNodes.size() + - " node(s) are excluded in this operation."); + throw new IOException("File " + src + " could only be replicated to " + + targets.length + " nodes instead of minReplication (=" + + minReplication + "). There are " + + getDatanodeManager().getNetworkTopology().getNumOfLeaves() + + " datanode(s) running and " + + (excludedNodes == null? "no": excludedNodes.size()) + + " node(s) are excluded in this operation."); } return targets; } diff --git a/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java b/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java index 6a2792198f..d2dfd7fc65 100644 --- a/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java +++ b/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java @@ -404,6 +404,36 @@ public void testFileCreationError2() throws IOException { } } + /** test addBlock(..) when replication