HDFS-10715. NPE when applying AvailableSpaceBlockPlacementPolicy. Contributed by Guangbin Zhu.
(cherry picked from commitef432579a7
) (cherry picked from commit6863866127
)
This commit is contained in:
parent
e8cd1439d3
commit
5758026833
|
@ -76,6 +76,7 @@ public class AvailableSpaceBlockPlacementPolicy extends
|
||||||
(DatanodeDescriptor) clusterMap.chooseRandom(scope, excludedNode);
|
(DatanodeDescriptor) clusterMap.chooseRandom(scope, excludedNode);
|
||||||
DatanodeDescriptor b =
|
DatanodeDescriptor b =
|
||||||
(DatanodeDescriptor) clusterMap.chooseRandom(scope, excludedNode);
|
(DatanodeDescriptor) clusterMap.chooseRandom(scope, excludedNode);
|
||||||
|
if (a != null && b != null){
|
||||||
int ret = compareDataNode(a, b);
|
int ret = compareDataNode(a, b);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
return a;
|
return a;
|
||||||
|
@ -84,6 +85,9 @@ public class AvailableSpaceBlockPlacementPolicy extends
|
||||||
} else {
|
} else {
|
||||||
return (RAND.nextInt(100) < balancedPreference) ? b : a;
|
return (RAND.nextInt(100) < balancedPreference) ? b : a;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return a == null ? b : a;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.hadoop.hdfs.server.blockmanagement;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
|
@ -30,6 +32,7 @@ import org.apache.hadoop.hdfs.TestBlockStoragePolicy;
|
||||||
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
||||||
import org.apache.hadoop.net.NetworkTopology;
|
import org.apache.hadoop.net.NetworkTopology;
|
||||||
|
import org.apache.hadoop.net.Node;
|
||||||
import org.apache.hadoop.test.PathUtils;
|
import org.apache.hadoop.test.PathUtils;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -158,6 +161,21 @@ public class TestAvailableSpaceBlockPlacementPolicy {
|
||||||
Assert.assertTrue(possibility < 0.55);
|
Assert.assertTrue(possibility < 0.55);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChooseDataNode() {
|
||||||
|
try {
|
||||||
|
Collection<Node> allNodes = new ArrayList<>(dataNodes.length);
|
||||||
|
Collections.addAll(allNodes, dataNodes);
|
||||||
|
if (placementPolicy instanceof AvailableSpaceBlockPlacementPolicy){
|
||||||
|
// exclude all datanodes when chooseDataNode, no NPE should be thrown
|
||||||
|
((AvailableSpaceBlockPlacementPolicy)placementPolicy)
|
||||||
|
.chooseDataNode("~", allNodes);
|
||||||
|
}
|
||||||
|
}catch (NullPointerException npe){
|
||||||
|
Assert.fail("NPE should not be thrown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void teardownCluster() {
|
public static void teardownCluster() {
|
||||||
if (namenode != null) {
|
if (namenode != null) {
|
||||||
|
|
Loading…
Reference in New Issue