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'."
83 echo "[rebalance-zone-expansion] Using '$output_dir' for all interim and final files generated."
91 if [[ -z $current_cluster ]] ||
[[ -z $current_stores ]] ||
[[ -z $interim_cluster ]] \
92 ||
[[ -z $final_stores ]] ||
[[ -z $output_dir ]]
95 echo "[rebalance-zone-expansion] Missing argument. Check again."
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.
128 step2_swap_attempts
=1000
129 step2_overall_iterations
=5
135 mkdir
-p $output_dir/step
1/$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 \
142 --output-dir $output_dir/step
1/$i
145 #find the run with the best (minimal) utility value
146 bestUtil
=$
(grep "Utility" $output_dir/step
1/*/final-cluster.xml.analysis |
sort -nk 3 | cut
-f4 -d / |
head -n 1)
148 if [ ! -e $output_dir/step
1/$bestUtil/final-cluster.xml
]; then
149 usage_and_exit
"final cluster.xml from step1 does not exist"
153 $vold_home/bin
/run-class.sh voldemort.tools.RepartitionerCLI \
154 --current-cluster $output_dir/step
1/$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 \
163 mkdir
-p $output_dir/step
3/
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/step
2/final-cluster.xml \
168 --final-stores $final_stores \
169 --output-dir $output_dir/step
3/
171 echo "[rebalance-zone-expansion] Placing final-cluster.xml in '$output_dir'"
172 cp $output_dir/step
3/final-cluster.xml
$output_dir/final-cluster.xml
173 echo "[rebalance-zone-expansion] Placing plan.out in '$output_dir'"
174 cp $output_dir/step
3/plan.out
$output_dir/plan.out
175 echo "[rebalance-zone-expansion] Placing final-cluster.xml.analysis in '$output_dir'"
176 cp $output_dir/step
2/final-cluster.xml
$output_dir/final-cluster.xml.analysis