Added 'details' option to KeyVersionFetcherCLI
[voldemort/jeffpc.git] / bin / rebalance-zone-expansion.sh
blob604c7d392c003d60ac0cabf4c605df6d65c1abf6
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 cluster.xml and a plan for the zone expansion.
19 # The final cluster is placed in output_dir/
20 # Argument = -c current_cluster -s current_stores -i interim_cluster -f final_stores
21 # -o output dir
23 # This script uses getopts which means only single character switches are allowed.
24 # Using getopt would allow for multi charcter switch names but would come at a
25 # cost of not being cross compatible.
27 # Function to display usage
28 usage_and_exit() {
29 echo "ERROR: $1."
30 cat <<EOF
32 Usage: $0 options
33 OPTIONS:
34 -h Show this message
35 -c Current cluster that describes the cluster
36 -s Current stores that describes the store. If you do not have info about the stores yet, look
37 under 'voldemort_home/config/tools/' for some store examples.
38 -i Interim Cluster that corresponds to zone expansion.
39 -f Final Stores that corresponds to zone expansion.
40 -o Output dir where all interim and final files will be stored.
41 EOF
42 exit 1
45 # initialize variables to an empty string
46 current_cluster=""
47 current_stores=""
48 interim_cluster=""
49 final_stores=""
50 output_dir=""
52 # Figure out voldemort home directory
53 dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
54 vold_home="$(dirname "$dir")"
56 # Parse options
57 while getopts “hc:s:i:f:o:” OPTION
59 case $OPTION in
61 usage_and_exit
62 exit 1
65 current_cluster=$OPTARG
66 echo "[rebalance-zone-expansion] Will rebalance on the cluster described in '$current_cluster'."
69 current_stores=$OPTARG
70 echo "[rebalance-zone-expansion] Will rebalance on the stores described in '$current_stores'."
73 interim_cluster=$OPTARG
74 echo "[rebalance-zone-expansion] Will rebalance on the interim cluster described in '$interim_cluster'."
77 final_stores=$OPTARG
78 echo "[rebalance-zone-expansion] Will rebalance on the final stores described in '$final_stores'."
81 output_dir=$OPTARG
82 mkdir -p $output_dir
83 echo "[rebalance-zone-expansion] Using '$output_dir' for all interim and final files generated."
86 usage_and_exit
88 esac
89 done
91 if [[ -z $current_cluster ]] || [[ -z $current_stores ]] || [[ -z $interim_cluster ]] \
92 || [[ -z $final_stores ]] || [[ -z $output_dir ]]
93 then
94 printf "\n"
95 echo "[rebalance-zone-expansion] Missing argument. Check again."
96 usage_and_exit
97 exit 1
100 if [ ! -e $current_cluster ]; then
101 usage_and_exit "File '$current_cluster' does not exist."
104 if [ ! -e $current_stores ]; then
105 usage_and_exit "File '$current_stores' does not exist."
108 if [ ! -e $interim_cluster ]; then
109 usage_and_exit "File '$interim_cluster' does not exist."
112 if [ ! -e $final_stores ]; then
113 usage_and_exit "File '$final_stores' does not exist."
117 # The final cluster.xml for zone expansion is generated in three steps.
118 # Step 1 : In step 1 1000 separate iterations of the repartitioner is executed and the one
119 # with the minimal utility value is chose for step 2.
120 # Step 2: In step 2, the cluster.xml from step 1 is fed to the repartitioner along with random swap
121 # attempts. The repartitioner randomly swaps the partitions only in zone 2
122 # and tries to balance the ring.
123 # Step 3: Finally, a plan is generated on how to reach from the orignal cluster topology to
124 # the one that is generated in step 2.
127 step2_zoneid=2
128 step2_swap_attempts=1000
129 step2_overall_iterations=5
132 # Step 1
133 for i in {1..1000}
135 mkdir -p $output_dir/step1/$i
136 $vold_home/bin/run-class.sh voldemort.tools.RepartitionerCLI \
137 --current-cluster $current_cluster \
138 --current-stores $current_stores \
139 --interim-cluster $interim_cluster \
140 --final-stores $final_stores \
141 --attempts 1 \
142 --output-dir $output_dir/step1/$i
143 done
145 #find the run with the best (minimal) utility value
146 bestUtil=$(grep "Utility" $output_dir/step1/*/final-cluster.xml.analysis | sort -nk 3 | cut -f4 -d / | head -n 1)
148 if [ ! -e $output_dir/step1/$bestUtil/final-cluster.xml ]; then
149 usage_and_exit "final cluster.xml from step1 does not exist"
152 # Step 2
153 $vold_home/bin/run-class.sh voldemort.tools.RepartitionerCLI \
154 --current-cluster $output_dir/step1/$bestUtil/final-cluster.xml \
155 --current-stores $final_stores \
156 --output-dir $output_dir/step2 \
157 --enable-random-swaps \
158 --random-swap-zoneids $step2_zoneid \
159 --attempts $step2_overall_iterations \
160 --random-swap-attempts $step2_swap_attempts \
162 # Step 3
163 mkdir -p $output_dir/step3/
164 $vold_home/bin/run-class.sh voldemort.tools.RebalancePlanCLI \
165 --current-cluster $current_cluster \
166 --current-stores $current_stores \
167 --final-cluster $output_dir/step2/final-cluster.xml \
168 --final-stores $final_stores \
169 --output-dir $output_dir/step3/
171 echo "[rebalance-zone-expansion] Placing final-cluster.xml in '$output_dir'"
172 cp $output_dir/step3/final-cluster.xml $output_dir/final-cluster.xml
173 echo "[rebalance-zone-expansion] Placing plan.out in '$output_dir'"
174 cp $output_dir/step3/plan.out $output_dir/plan.out
175 echo "[rebalance-zone-expansion] Placing final-cluster.xml.analysis in '$output_dir'"
176 cp $output_dir/step2/final-cluster.xml $output_dir/final-cluster.xml.analysis