|
@@ -56,15 +56,15 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
"For more information, please enable DEBUG log level on "
|
|
|
+ ((Log4JLogger)LOG).getLogger().getName();
|
|
|
|
|
|
- private boolean considerLoad;
|
|
|
+ protected boolean considerLoad;
|
|
|
private boolean preferLocalNode = true;
|
|
|
- private NetworkTopology clusterMap;
|
|
|
+ protected NetworkTopology clusterMap;
|
|
|
private FSClusterStats stats;
|
|
|
- private long heartbeatInterval; // interval for DataNode heartbeats
|
|
|
+ protected long heartbeatInterval; // interval for DataNode heartbeats
|
|
|
/**
|
|
|
* A miss of that many heartbeats is tolerated for replica deletion policy.
|
|
|
*/
|
|
|
- private int tolerateHeartbeatMultiplier;
|
|
|
+ protected int tolerateHeartbeatMultiplier;
|
|
|
|
|
|
BlockPlacementPolicyDefault(Configuration conf, FSClusterStats stats,
|
|
|
NetworkTopology clusterMap) {
|
|
@@ -88,7 +88,7 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
DFSConfigKeys.DFS_NAMENODE_TOLERATE_HEARTBEAT_MULTIPLIER_DEFAULT);
|
|
|
}
|
|
|
|
|
|
- private ThreadLocal<StringBuilder> threadLocalBuilder =
|
|
|
+ protected ThreadLocal<StringBuilder> threadLocalBuilder =
|
|
|
new ThreadLocal<StringBuilder>() {
|
|
|
@Override
|
|
|
protected StringBuilder initialValue() {
|
|
@@ -229,7 +229,7 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
* choose a node on the same rack
|
|
|
* @return the chosen node
|
|
|
*/
|
|
|
- private DatanodeDescriptor chooseLocalNode(
|
|
|
+ protected DatanodeDescriptor chooseLocalNode(
|
|
|
DatanodeDescriptor localMachine,
|
|
|
HashMap<Node, Node> excludedNodes,
|
|
|
long blocksize,
|
|
@@ -263,7 +263,7 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
* in the cluster.
|
|
|
* @return the chosen node
|
|
|
*/
|
|
|
- private DatanodeDescriptor chooseLocalRack(
|
|
|
+ protected DatanodeDescriptor chooseLocalRack(
|
|
|
DatanodeDescriptor localMachine,
|
|
|
HashMap<Node, Node> excludedNodes,
|
|
|
long blocksize,
|
|
@@ -316,7 +316,7 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
* from the local rack
|
|
|
*/
|
|
|
|
|
|
- private void chooseRemoteRack(int numOfReplicas,
|
|
|
+ protected void chooseRemoteRack(int numOfReplicas,
|
|
|
DatanodeDescriptor localMachine,
|
|
|
HashMap<Node, Node> excludedNodes,
|
|
|
long blocksize,
|
|
@@ -338,7 +338,7 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
/* Randomly choose one target from <i>nodes</i>.
|
|
|
* @return the chosen node
|
|
|
*/
|
|
|
- private DatanodeDescriptor chooseRandom(
|
|
|
+ protected DatanodeDescriptor chooseRandom(
|
|
|
String nodes,
|
|
|
HashMap<Node, Node> excludedNodes,
|
|
|
long blocksize,
|
|
@@ -382,7 +382,7 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
|
|
|
/* Randomly choose <i>numOfReplicas</i> targets from <i>nodes</i>.
|
|
|
*/
|
|
|
- private void chooseRandom(int numOfReplicas,
|
|
|
+ protected void chooseRandom(int numOfReplicas,
|
|
|
String nodes,
|
|
|
HashMap<Node, Node> excludedNodes,
|
|
|
long blocksize,
|
|
@@ -438,7 +438,7 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
this.considerLoad, results);
|
|
|
}
|
|
|
|
|
|
- private boolean isGoodTarget(DatanodeDescriptor node,
|
|
|
+ protected boolean isGoodTarget(DatanodeDescriptor node,
|
|
|
long blockSize, int maxTargetPerLoc,
|
|
|
boolean considerLoad,
|
|
|
List<DatanodeDescriptor> results) {
|
|
@@ -574,8 +574,7 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
|
|
|
// pick replica from the first Set. If first is empty, then pick replicas
|
|
|
// from second set.
|
|
|
- Iterator<DatanodeDescriptor> iter =
|
|
|
- first.isEmpty() ? second.iterator() : first.iterator();
|
|
|
+ Iterator<DatanodeDescriptor> iter = pickupReplicaSet(first, second);
|
|
|
|
|
|
// Pick the node with the oldest heartbeat or with the least free space,
|
|
|
// if all hearbeats are within the tolerable heartbeat interval
|
|
@@ -594,6 +593,20 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy {
|
|
|
}
|
|
|
return oldestHeartbeatNode != null ? oldestHeartbeatNode : minSpaceNode;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Pick up replica node set for deleting replica as over-replicated.
|
|
|
+ * First set contains replica nodes on rack with more than one
|
|
|
+ * replica while second set contains remaining replica nodes.
|
|
|
+ * So pick up first set if not empty. If first is empty, then pick second.
|
|
|
+ */
|
|
|
+ protected Iterator<DatanodeDescriptor> pickupReplicaSet(
|
|
|
+ Collection<DatanodeDescriptor> first,
|
|
|
+ Collection<DatanodeDescriptor> second) {
|
|
|
+ Iterator<DatanodeDescriptor> iter =
|
|
|
+ first.isEmpty() ? second.iterator() : first.iterator();
|
|
|
+ return iter;
|
|
|
+ }
|
|
|
|
|
|
@VisibleForTesting
|
|
|
void setPreferLocalNode(boolean prefer) {
|