Merge pull request #196 from icefury71/quota_per_store_stats_fix
[voldemort/jeffpc.git] / bin / rebalance-cluster-expansion.sh
blob96ecae997d48a35ad732c4f03d66bf6e96c79262
1 #!/bin/bash -e
4 # Copyright 2013 LinkedIn, Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # This script generates a final cluster.xml and a plan for the cluster expansion.
19 # The final cluster is placed in output_dir/
20 # Argument = -c current_cluster -s current_stores -i interim_cluster -o output dir
22 # This script steals partitions from other nodes and assigns them to the new nodes
23 # in the cluster. While stealing partitions, the script doesn't make an effort to balance
24 # the cluster. However, because the repartitioner is invoked multiple distinct times,
25 # the most balanced such expansion is chosen. #To further rebalance the cluster,
26 # use the rebalance-shuffle script.
28 # In a typical workflow one would chain this script with the rebalance-shuffle script.
29 # by running this script first and then the shuffle to achieve better balancing.
31 # This script uses getopts which means only single character switches are allowed.
32 # Using getopt would allow for multi charcter switch names but would come at a
33 # cost of not being cross compatible.
35 # Function to display usage
36 usage_and_exit() {
37 echo "ERROR: $1."
38 cat <<EOF
40 Usage: $0 options
41 OPTIONS:
42 -h Show this message
43 -c Current cluster that describes the cluster
44 -s Current stores that describes the store. If you do not have info about the stores yet, look
45 under 'voldemort_home/config/tools/' for some store examples.
46 -i Interim Cluster that corresponds to cluster expansion.
47 -o Output dir where all interim and final files will be stored.
48 EOF
49 exit 1
52 # initialize variables to an empty string
53 current_cluster=""
54 current_stores=""
55 interim_cluster=""
56 output_dir=""
58 # Figure out voldemort home directory
59 dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
60 vold_home="$(dirname "$dir")"
62 # Parse options
63 while getopts “hc:s:i:o:” OPTION
65 case $OPTION in
67 usage_and_exit
68 exit 1
71 current_cluster=$OPTARG
72 echo "[rebalance-cluster-expansion] Will rebalance on the cluster described in '$current_cluster'."
75 current_stores=$OPTARG
76 echo "[rebalance-cluster-expansion] Will rebalance on the stores described in '$current_stores'."
79 interim_cluster=$OPTARG
80 echo "[rebalance-cluster-expansion] Will rebalance on the interim cluster described in '$interim_cluster'."
83 output_dir=$OPTARG
84 mkdir -p $output_dir
85 echo "[rebalance-cluster-expansion] Using '$output_dir' for all interim and final files generated."
88 usage_and_exit
90 esac
91 done
93 if [[ -z $current_cluster ]] || [[ -z $current_stores ]] \
94 || [[ -z $interim_cluster ]] || [[ -z $output_dir ]]
95 then
96 printf "\n"
97 echo "[rebalance-cluster-expansion] Missing argument. Check again."
98 usage_and_exit
99 exit 1
102 if [ ! -e $current_cluster ]; then
103 usage_and_exit "File '$current_cluster' does not exist."
106 if [ ! -e $current_stores ]; then
107 usage_and_exit "File '$current_stores' does not exist."
110 if [ ! -e $interim_cluster ]; then
111 usage_and_exit "File '$interim_cluster' does not exist."
115 # The final cluster.xml for cluster expansion is generated in two steps.
116 # Step 1: Current cluster.xml is fed to the repartitioner along with the interim cluster xml.
117 # The repartitioner tries to balance the ring by moving the partitions around.
118 # Step 2: A plan is generated on how to reach from the original cluster topology to
119 # the one that is generated in step 1.
122 attempts=50
124 # Step 1
125 mkdir -p $output_dir/step1/
126 $vold_home/bin/run-class.sh voldemort.tools.RepartitionerCLI \
127 --current-cluster $current_cluster \
128 --current-stores $current_stores \
129 --interim-cluster $interim_cluster \
130 --attempts $attempts \
131 --output-dir $output_dir/step1/$i
133 if [ ! -e $output_dir/step1/final-cluster.xml ]; then
134 usage_and_exit "File '$final-cluster.xml' does not exist."
137 # Step 2
138 mkdir -p $output_dir/step2/
139 $vold_home/bin/run-class.sh voldemort.tools.RebalancePlanCLI \
140 --current-cluster $current_cluster \
141 --current-stores $current_stores \
142 --final-cluster $output_dir/step1/final-cluster.xml \
143 --output-dir $output_dir/step2/
145 echo "[rebalance-cluster-expansion] Placing final-cluster.xml in '$output_dir'"
146 cp $output_dir/step2/final-cluster.xml $output_dir/final-cluster.xml
147 echo "[rebalance-cluster-expansion] Placing plan.out in '$output_dir'"
148 cp $output_dir/step2/plan.out $output_dir/plan.out
149 echo "[rebalance-cluster-expansion] Placing final-cluster.xml.analysis in '$output_dir'"
150 cp $output_dir/step1/final-cluster.xml.analysis $output_dir/final-cluster.xml.analysis