Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a shell script to build targetCluster.xml, more Javadoc.

  • Loading branch information...
commit 7ad319a42b160c54ddbe78cdb3a6c48c3107cf30 1 parent e601a7c
@afeinberg afeinberg authored
View
21 bin/voldemort-rebalance-configure.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+#
+# Copyright 2008-2010 LinkedIn, Inc
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+base_dir=$(dirname $0)/..
+
+$base_dir/bin/run-class.sh voldemort.client.rebalance.RebalanceClusterBuilder $@
View
40 src/java/voldemort/client/rebalance/RebalanceClusterBuilder.java
@@ -19,6 +19,12 @@
import java.util.Set;
/**
+ * Insert a node into the cluster in a way that preserves most of the existing cluster's characteristics
+ * and moves as little data around as possible.
+ *
+ * Most of the logic resides in {@link voldemort.client.rebalance.RebalanceClusterTool}, see that class for
+ * more documentation.
+ *
* @author afeinberg
*/
public class RebalanceClusterBuilder {
@@ -40,6 +46,18 @@ private RebalanceClusterBuilder(Cluster cluster,
this.desiredNumPartitions = desiredNumPartitions;
}
+ /**
+ * Create an instance of <tt>RebalanceClusterBuilder</tt>. Parses the cluster.xml and stores.xml file to
+ * find the store with the highest replication-factor.
+ *
+ * @param clusterXmlFile Path to the original cluster.xml
+ * @param storesXmlFile Path to the stores.xml
+ * @param maxRemappedReplicas Maximum number of partition to replica mappings that can change
+ * @param minNumPartitions Minimum number of partitions that should be moved to new nodes
+ * @param desiredNumPartitions Desired number of partitions to move to the new node
+ * @return Constructed instance of <tt>RebalanceClusterBuilder</tt>
+ * @throws IOException If unable to read from cluster.xml or stores.xml
+ */
public static RebalanceClusterBuilder create(String clusterXmlFile,
String storesXmlFile,
int maxRemappedReplicas,
@@ -61,6 +79,17 @@ public static RebalanceClusterBuilder create(String clusterXmlFile,
desiredNumPartitions);
}
+ /**
+ * Create a targetCluster.xml as a string. If a file is specified, output to that file; otherwise print to
+ * screen. Fail and exit if we're unable to add the new node at all.
+ *
+ * @param targetClusterXmlFile File to write to (will be written to STDOUT if null)
+ * @param host Host name of the new node
+ * @param httpPort Http port for the new node
+ * @param socketPort Socket port for the new node
+ * @param adminPort Admin port for the new node
+ * @throws IOException If we're unable to write the cluster XML to file
+ */
public void build(String targetClusterXmlFile,
String host,
int httpPort,
@@ -122,6 +151,17 @@ public void build(String targetClusterXmlFile,
}
}
+ /**
+ * Main method to run to create a targetCluster.xml. Example usage:
+ * <code>
+ * ./bin/voldemort-rebalance-configure.sh \
+ * --cluster ./test/common/voldemort/config/rebalance-tool-big-cluster.xml \
+ * --stores ./test/common/voldemort/config/rebalance-tool-stores.xml \
+ * --host node6 --http-port 8081 --socket-port 6666 --target-cluster ./targetCluster.xml
+ * </code>
+ * @param args See USAGE for details
+ * @throws IOException If unable to read input files or write to output file
+ */
public static void main(String [] args) throws IOException {
OptionParser parser = new OptionParser();
View
11 src/java/voldemort/client/rebalance/RebalanceClusterTool.java
@@ -61,7 +61,7 @@ public RebalanceClusterTool(Cluster cluster, StoreDefinition storeDefinition) {
}
/**
- * Attempt inserting a node into a cluster the <code>RebalanceClusterTool</tt> was constructed with
+ * Attempt inserting a node into a cluster the <tt>RebalanceClusterTool</tt> was constructed with
* while following these constraints:
* <ul>
* <li>
@@ -75,12 +75,15 @@ public RebalanceClusterTool(Cluster cluster, StoreDefinition storeDefinition) {
* </li>
* </ul>
*
- * @param template A template node: with correct hostname, port, id information but with arbitrary partition ids
+ * @param template A template node: with correct hostname, port, id information but with empty partition id list
+ * @param minPartitions We want to move <b>at least</b> this many partitions to this node
+ * @param desiredPartitions The number of partitions that we'd want <b>ideally</b> to move to the new node
+ * @param maxRemap Maximum number of existing partition to replica mappings that we can remap
* @return If successful, a new cluster containing the template node; otherwise null.
*/
public Cluster insertNode(Node template,
int minPartitions,
- int desiredParitions,
+ int desiredPartitions,
int maxRemap) {
List<Node> nodes = new ArrayList<Node>();
nodes.addAll(cluster.getNodes());
@@ -89,7 +92,7 @@ public Cluster insertNode(Node template,
Cluster targetCluster = null;
boolean foundBest = false;
- for (int i = desiredParitions; i >= minPartitions && !foundBest; i--) {
+ for (int i = desiredPartitions; i >= minPartitions && !foundBest; i--) {
System.out.println("Trying to move " + i + " partitions to the new node");
Cluster candidateCluster = createTargetCluster(templateCluster,
i,
Please sign in to comment.
Something went wrong with that request. Please try again.