|
@@ -75,6 +75,10 @@ import com.google.common.base.Preconditions;
|
|
|
* start the balancer with a default threshold of 10%
|
|
|
* bin/ start-balancer.sh -threshold 5
|
|
|
* start the balancer with a threshold of 5%
|
|
|
+ * bin/ start-balancer.sh -idleiterations 20
|
|
|
+ * start the balancer with maximum 20 consecutive idle iterations
|
|
|
+ * bin/ start-balancer.sh -idleiterations -1
|
|
|
+ * run the balancer with default threshold infinitely
|
|
|
* To stop:
|
|
|
* bin/ stop-balancer.sh
|
|
|
* </pre>
|
|
@@ -137,7 +141,7 @@ import com.google.common.base.Preconditions;
|
|
|
* <ol>
|
|
|
* <li>The cluster is balanced;
|
|
|
* <li>No block can be moved;
|
|
|
- * <li>No block has been moved for five consecutive iterations;
|
|
|
+ * <li>No block has been moved for specified consecutive iterations (5 by default);
|
|
|
* <li>An IOException occurs while communicating with the namenode;
|
|
|
* <li>Another balancer is running.
|
|
|
* </ol>
|
|
@@ -148,7 +152,7 @@ import com.google.common.base.Preconditions;
|
|
|
* <ol>
|
|
|
* <li>The cluster is balanced. Exiting
|
|
|
* <li>No block can be moved. Exiting...
|
|
|
- * <li>No block has been moved for 5 iterations. Exiting...
|
|
|
+ * <li>No block has been moved for specified iterations (5 by default). Exiting...
|
|
|
* <li>Received an IO exception: failure reason. Exiting...
|
|
|
* <li>Another balancer is running. Exiting...
|
|
|
* </ol>
|
|
@@ -176,7 +180,9 @@ public class Balancer {
|
|
|
+ "\n\t[-exclude [-f <hosts-file> | comma-sperated list of hosts]]"
|
|
|
+ "\tExcludes the specified datanodes."
|
|
|
+ "\n\t[-include [-f <hosts-file> | comma-sperated list of hosts]]"
|
|
|
- + "\tIncludes only the specified datanodes.";
|
|
|
+ + "\tIncludes only the specified datanodes."
|
|
|
+ + "\n\t[-idleiterations <idleiterations>]"
|
|
|
+ + "\tNumber of consecutive idle iterations (-1 for Infinite) before exit.";
|
|
|
|
|
|
private final Dispatcher dispatcher;
|
|
|
private final BalancingPolicy policy;
|
|
@@ -573,7 +579,7 @@ public class Balancer {
|
|
|
List<NameNodeConnector> connectors = Collections.emptyList();
|
|
|
try {
|
|
|
connectors = NameNodeConnector.newNameNodeConnectors(namenodes,
|
|
|
- Balancer.class.getSimpleName(), BALANCER_ID_PATH, conf);
|
|
|
+ Balancer.class.getSimpleName(), BALANCER_ID_PATH, conf, p.maxIdleIteration);
|
|
|
|
|
|
boolean done = false;
|
|
|
for(int iteration = 0; !done; iteration++) {
|
|
@@ -629,19 +635,22 @@ public class Balancer {
|
|
|
static class Parameters {
|
|
|
static final Parameters DEFAULT = new Parameters(
|
|
|
BalancingPolicy.Node.INSTANCE, 10.0,
|
|
|
+ NameNodeConnector.DEFAULT_MAX_IDLE_ITERATIONS,
|
|
|
Collections.<String> emptySet(), Collections.<String> emptySet());
|
|
|
|
|
|
final BalancingPolicy policy;
|
|
|
final double threshold;
|
|
|
+ final int maxIdleIteration;
|
|
|
// exclude the nodes in this set from balancing operations
|
|
|
Set<String> nodesToBeExcluded;
|
|
|
//include only these nodes in balancing operations
|
|
|
Set<String> nodesToBeIncluded;
|
|
|
|
|
|
- Parameters(BalancingPolicy policy, double threshold,
|
|
|
+ Parameters(BalancingPolicy policy, double threshold, int maxIdleIteration,
|
|
|
Set<String> nodesToBeExcluded, Set<String> nodesToBeIncluded) {
|
|
|
this.policy = policy;
|
|
|
this.threshold = threshold;
|
|
|
+ this.maxIdleIteration = maxIdleIteration;
|
|
|
this.nodesToBeExcluded = nodesToBeExcluded;
|
|
|
this.nodesToBeIncluded = nodesToBeIncluded;
|
|
|
}
|
|
@@ -650,6 +659,7 @@ public class Balancer {
|
|
|
public String toString() {
|
|
|
return Balancer.class.getSimpleName() + "." + getClass().getSimpleName()
|
|
|
+ "[" + policy + ", threshold=" + threshold +
|
|
|
+ ", max idle iteration = " + maxIdleIteration +
|
|
|
", number of nodes to be excluded = "+ nodesToBeExcluded.size() +
|
|
|
", number of nodes to be included = "+ nodesToBeIncluded.size() +"]";
|
|
|
}
|
|
@@ -688,6 +698,7 @@ public class Balancer {
|
|
|
static Parameters parse(String[] args) {
|
|
|
BalancingPolicy policy = Parameters.DEFAULT.policy;
|
|
|
double threshold = Parameters.DEFAULT.threshold;
|
|
|
+ int maxIdleIteration = Parameters.DEFAULT.maxIdleIteration;
|
|
|
Set<String> nodesTobeExcluded = Parameters.DEFAULT.nodesToBeExcluded;
|
|
|
Set<String> nodesTobeIncluded = Parameters.DEFAULT.nodesToBeIncluded;
|
|
|
|
|
@@ -743,6 +754,11 @@ public class Balancer {
|
|
|
} else {
|
|
|
nodesTobeIncluded = Util.parseHostList(args[i]);
|
|
|
}
|
|
|
+ } else if ("-idleiterations".equalsIgnoreCase(args[i])) {
|
|
|
+ checkArgument(++i < args.length,
|
|
|
+ "idleiterations value is missing: args = " + Arrays.toString(args));
|
|
|
+ maxIdleIteration = Integer.parseInt(args[i]);
|
|
|
+ LOG.info("Using a idleiterations of " + maxIdleIteration);
|
|
|
} else {
|
|
|
throw new IllegalArgumentException("args = "
|
|
|
+ Arrays.toString(args));
|
|
@@ -756,7 +772,7 @@ public class Balancer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return new Parameters(policy, threshold, nodesTobeExcluded, nodesTobeIncluded);
|
|
|
+ return new Parameters(policy, threshold, maxIdleIteration, nodesTobeExcluded, nodesTobeIncluded);
|
|
|
}
|
|
|
|
|
|
private static void printUsage(PrintStream out) {
|