svn merge -c 1380934 from trunk for HDFS-3887. Remove redundant chooseTarget methods in BlockPlacementPolicy.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1380936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a42a7fccf5
commit
555e93493e
|
@ -239,6 +239,9 @@ Release 2.0.1-alpha - UNRELEASED
|
|||
HDFS-3871. Change NameNodeProxies to use RetryUtils. (Arun C Murthy
|
||||
via szetszwo)
|
||||
|
||||
HDFS-3887. Remove redundant chooseTarget methods in BlockPlacementPolicy.
|
||||
(Jing Zhao via szetszwo)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
HDFS-2982. Startup performance suffers when there are many edit log
|
||||
|
|
|
@ -1316,8 +1316,9 @@ public class BlockManager {
|
|||
final HashMap<Node, Node> excludedNodes,
|
||||
final long blocksize) throws IOException {
|
||||
// choose targets for the new block to be allocated.
|
||||
final DatanodeDescriptor targets[] = blockplacement.chooseTarget(
|
||||
src, numOfReplicas, client, excludedNodes, blocksize);
|
||||
final DatanodeDescriptor targets[] = blockplacement.chooseTarget(src,
|
||||
numOfReplicas, client, new ArrayList<DatanodeDescriptor>(), false,
|
||||
excludedNodes, blocksize);
|
||||
if (targets.length < minReplication) {
|
||||
throw new IOException("File " + src + " could only be replicated to "
|
||||
+ targets.length + " nodes instead of minReplication (="
|
||||
|
|
|
@ -68,21 +68,6 @@ public abstract class BlockPlacementPolicy {
|
|||
List<DatanodeDescriptor> chosenNodes,
|
||||
long blocksize);
|
||||
|
||||
/**
|
||||
* Same as
|
||||
* {{@link #chooseTarget(String, int, DatanodeDescriptor, List, boolean, HashMap, long)}
|
||||
* with returnChosenNodes equal to false.
|
||||
*/
|
||||
final DatanodeDescriptor[] chooseTarget(String srcPath,
|
||||
int numOfReplicas,
|
||||
DatanodeDescriptor writer,
|
||||
List<DatanodeDescriptor> chosenNodes,
|
||||
HashMap<Node, Node> excludedNodes,
|
||||
long blocksize) {
|
||||
return chooseTarget(srcPath, numOfReplicas, writer, chosenNodes, false,
|
||||
excludedNodes, blocksize);
|
||||
}
|
||||
|
||||
/**
|
||||
* choose <i>numOfReplicas</i> data nodes for <i>writer</i>
|
||||
* to re-replicate a block with size <i>blocksize</i>
|
||||
|
@ -129,7 +114,7 @@ public abstract class BlockPlacementPolicy {
|
|||
HashMap<Node, Node> excludedNodes,
|
||||
long blocksize) {
|
||||
return chooseTarget(srcBC.getName(), numOfReplicas, writer,
|
||||
chosenNodes, excludedNodes, blocksize);
|
||||
chosenNodes, false, excludedNodes, blocksize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,49 +182,4 @@ public abstract class BlockPlacementPolicy {
|
|||
return replicator;
|
||||
}
|
||||
|
||||
/**
|
||||
* choose <i>numOfReplicas</i> nodes for <i>writer</i> to replicate
|
||||
* a block with size <i>blocksize</i>
|
||||
* If not, return as many as we can.
|
||||
*
|
||||
* @param srcPath a string representation of the file for which chooseTarget is invoked
|
||||
* @param numOfReplicas number of replicas wanted.
|
||||
* @param writer the writer's machine, null if not in the cluster.
|
||||
* @param blocksize size of the data to be written.
|
||||
* @return array of DatanodeDescriptor instances chosen as targets
|
||||
* and sorted as a pipeline.
|
||||
*/
|
||||
DatanodeDescriptor[] chooseTarget(String srcPath,
|
||||
int numOfReplicas,
|
||||
DatanodeDescriptor writer,
|
||||
long blocksize) {
|
||||
return chooseTarget(srcPath, numOfReplicas, writer,
|
||||
new ArrayList<DatanodeDescriptor>(),
|
||||
blocksize);
|
||||
}
|
||||
|
||||
/**
|
||||
* choose <i>numOfReplicas</i> nodes for <i>writer</i> to replicate
|
||||
* a block with size <i>blocksize</i>
|
||||
* If not, return as many as we can.
|
||||
*
|
||||
* @param srcPath a string representation of the file for which chooseTarget is invoked
|
||||
* @param numOfReplicas number of replicas wanted.
|
||||
* @param writer the writer's machine, null if not in the cluster.
|
||||
* @param blocksize size of the data to be written.
|
||||
* @param excludedNodes datanodes that should not be considered as targets.
|
||||
* @return array of DatanodeDescriptor instances chosen as targets
|
||||
* and sorted as a pipeline.
|
||||
*/
|
||||
public DatanodeDescriptor[] chooseTarget(String srcPath,
|
||||
int numOfReplicas,
|
||||
DatanodeDescriptor writer,
|
||||
HashMap<Node, Node> excludedNodes,
|
||||
long blocksize) {
|
||||
return chooseTarget(srcPath, numOfReplicas, writer,
|
||||
new ArrayList<DatanodeDescriptor>(),
|
||||
excludedNodes,
|
||||
blocksize);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.net.InetAddress;
|
|||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
@ -163,8 +164,9 @@ public class NamenodeWebHdfsMethods {
|
|||
final DatanodeDescriptor clientNode = bm.getDatanodeManager(
|
||||
).getDatanodeByHost(getRemoteAddress());
|
||||
if (clientNode != null) {
|
||||
final DatanodeDescriptor[] datanodes = bm.getBlockPlacementPolicy(
|
||||
).chooseTarget(path, 1, clientNode, null, blocksize);
|
||||
final DatanodeDescriptor[] datanodes = bm.getBlockPlacementPolicy()
|
||||
.chooseTarget(path, 1, clientNode,
|
||||
new ArrayList<DatanodeDescriptor>(), false, null, blocksize);
|
||||
if (datanodes.length > 0) {
|
||||
return datanodes[0];
|
||||
}
|
||||
|
|
|
@ -110,30 +110,30 @@ public class TestReplicationPolicy {
|
|||
HdfsConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L, 4, 0); // overloaded
|
||||
|
||||
DatanodeDescriptor[] targets;
|
||||
targets = replicator.chooseTarget(filename,
|
||||
0, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 0, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 0);
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
1, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 1, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 1);
|
||||
assertEquals(targets[0], dataNodes[0]);
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
2, dataNodes[0], BLOCK_SIZE);
|
||||
2, dataNodes[0], new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 2);
|
||||
assertEquals(targets[0], dataNodes[0]);
|
||||
assertFalse(cluster.isOnSameRack(targets[0], targets[1]));
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
3, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 3, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 3);
|
||||
assertEquals(targets[0], dataNodes[0]);
|
||||
assertFalse(cluster.isOnSameRack(targets[0], targets[1]));
|
||||
assertTrue(cluster.isOnSameRack(targets[1], targets[2]));
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
4, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 4, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 4);
|
||||
assertEquals(targets[0], dataNodes[0]);
|
||||
assertTrue(cluster.isOnSameRack(targets[1], targets[2]) ||
|
||||
|
@ -248,30 +248,30 @@ public class TestReplicationPolicy {
|
|||
(HdfsConstants.MIN_BLOCKS_FOR_WRITE-1)*BLOCK_SIZE, 0L, 0, 0); // no space
|
||||
|
||||
DatanodeDescriptor[] targets;
|
||||
targets = replicator.chooseTarget(filename,
|
||||
0, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 0, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 0);
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
1, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 1, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 1);
|
||||
assertEquals(targets[0], dataNodes[1]);
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
2, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 2, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 2);
|
||||
assertEquals(targets[0], dataNodes[1]);
|
||||
assertFalse(cluster.isOnSameRack(targets[0], targets[1]));
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
3, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 3, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 3);
|
||||
assertEquals(targets[0], dataNodes[1]);
|
||||
assertTrue(cluster.isOnSameRack(targets[1], targets[2]));
|
||||
assertFalse(cluster.isOnSameRack(targets[0], targets[1]));
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
4, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 4, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 4);
|
||||
assertEquals(targets[0], dataNodes[1]);
|
||||
for(int i=1; i<4; i++) {
|
||||
|
@ -304,23 +304,23 @@ public class TestReplicationPolicy {
|
|||
}
|
||||
|
||||
DatanodeDescriptor[] targets;
|
||||
targets = replicator.chooseTarget(filename,
|
||||
0, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 0, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 0);
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
1, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 1, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 1);
|
||||
assertFalse(cluster.isOnSameRack(targets[0], dataNodes[0]));
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
2, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 2, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 2);
|
||||
assertFalse(cluster.isOnSameRack(targets[0], dataNodes[0]));
|
||||
assertFalse(cluster.isOnSameRack(targets[0], targets[1]));
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
3, dataNodes[0], BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 3, dataNodes[0],
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 3);
|
||||
for(int i=0; i<3; i++) {
|
||||
assertFalse(cluster.isOnSameRack(targets[i], dataNodes[0]));
|
||||
|
@ -349,21 +349,21 @@ public class TestReplicationPolicy {
|
|||
DFSTestUtil.getDatanodeDescriptor("7.7.7.7", "/d2/r4");
|
||||
|
||||
DatanodeDescriptor[] targets;
|
||||
targets = replicator.chooseTarget(filename,
|
||||
0, writerDesc, BLOCK_SIZE);
|
||||
targets = replicator.chooseTarget(filename, 0, writerDesc,
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 0);
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
1, writerDesc, BLOCK_SIZE);
|
||||
|
||||
targets = replicator.chooseTarget(filename, 1, writerDesc,
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 1);
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
2, writerDesc, BLOCK_SIZE);
|
||||
|
||||
targets = replicator.chooseTarget(filename, 2, writerDesc,
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 2);
|
||||
assertFalse(cluster.isOnSameRack(targets[0], targets[1]));
|
||||
|
||||
targets = replicator.chooseTarget(filename,
|
||||
3, writerDesc, BLOCK_SIZE);
|
||||
|
||||
targets = replicator.chooseTarget(filename, 3, writerDesc,
|
||||
new ArrayList<DatanodeDescriptor>(), BLOCK_SIZE);
|
||||
assertEquals(targets.length, 3);
|
||||
assertTrue(cluster.isOnSameRack(targets[1], targets[2]));
|
||||
assertFalse(cluster.isOnSameRack(targets[0], targets[1]));
|
||||
|
|
Loading…
Reference in New Issue