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
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
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.
45 # initialize variables to an empty string
52 # Figure out voldemort home directory
53 dir
="$( cd "$
( dirname "${BASH_SOURCE[0]}" )" && pwd )"
54 vold_home
="$(dirname "$dir")"
57 while getopts “hc
:s
:i
:f
:o
:” OPTION
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'."
78 echo "[rebalance-zone-expansion] Will rebalance on the final stores described in '$final_stores'."
82 output_dir
=$
(readlink
-m $output_dir)
84 echo "[rebalance-zone-expansion] Using '$output_dir' for all interim and final files generated."
92 if [[ -z $current_cluster ]] ||
[[ -z $current_stores ]] ||
[[ -z $interim_cluster ]] \
93 ||
[[ -z $final_stores ]] ||
[[ -z $output_dir ]]
96 echo "[rebalance-zone-expansion] Missing argument. Check again."
101 if [ ! -e $current_cluster ]; then
102 usage_and_exit
"File '$current_cluster' does not exist."
105 if [ ! -e $current_stores ]; then
106 usage_and_exit
"File '$current_stores' does not exist."
109 if [ ! -e $interim_cluster ]; then
110 usage_and_exit
"File '$interim_cluster' does not exist."
113 if [ ! -e $final_stores ]; then
114 usage_and_exit
"File '$final_stores' does not exist."
118 # The final cluster.xml for zone expansion is generated in three steps.
119 # Step 1 : In step 1 1000 separate iterations of the repartitioner is executed and the one
120 # with the minimal utility value is chose for step 2.
121 # Step 2: In step 2, the cluster.xml from step 1 is fed to the repartitioner along with random swap
122 # attempts. The repartitioner randomly swaps the partitions only in zone 2
123 # and tries to balance the ring.
124 # Step 3: Finally, a plan is generated on how to reach from the orignal cluster topology to
125 # the one that is generated in step 2.
129 step2_swap_attempts
=1000
130 step2_overall_iterations
=5
136 mkdir
-p $output_dir/step
1/$i
137 $vold_home/bin
/run-class.sh voldemort.tools.RepartitionerCLI \
138 --current-cluster $current_cluster \
139 --current-stores $current_stores \
140 --interim-cluster $interim_cluster \
141 --final-stores $final_stores \
143 --output-dir $output_dir/step
1/$i
146 #find the run with the best (minimal) utility value
147 bestUtil
="$(grep "Utility
" $output_dir/step1/*/final-cluster.xml.analysis | sort -nk 3 | head -n 1 | cut -f1 -d ' ')"
148 remove
=".analysis:Utility"
149 path_to_bestUtil
=${bestUtil%%$remove}
151 if [ ! -e $path_to_bestUtil ]; then
152 usage_and_exit
"final cluster.xml from step1 does not exist"
156 $vold_home/bin
/run-class.sh voldemort.tools.RepartitionerCLI \
157 --current-cluster $path_to_bestUtil \
158 --current-stores $final_stores \
159 --output-dir $output_dir/step2 \
160 --enable-random-swaps \
161 --random-swap-zoneids $step2_zoneid \
162 --attempts $step2_overall_iterations \
163 --random-swap-attempts $step2_swap_attempts \
166 mkdir
-p $output_dir/step
3/
167 $vold_home/bin
/run-class.sh voldemort.tools.RebalancePlanCLI \
168 --current-cluster $current_cluster \
169 --current-stores $current_stores \
170 --final-cluster $output_dir/step
2/final-cluster.xml \
171 --final-stores $final_stores \
172 --output-dir $output_dir/step
3/
174 echo "[rebalance-zone-expansion] Placing final-cluster.xml in '$output_dir'"
175 cp $output_dir/step
3/final-cluster.xml
$output_dir/final-cluster.xml
176 echo "[rebalance-zone-expansion] Placing plan.out in '$output_dir'"
177 cp $output_dir/step
3/plan.out
$output_dir/plan.out
178 echo "[rebalance-zone-expansion] Placing final-cluster.xml.analysis in '$output_dir'"
179 cp $output_dir/step
2/final-cluster.xml
$output_dir/final-cluster.xml.analysis