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 for spinning up a new cluster.
19 # Argument = -c current_cluster -s current_stores -o output dir
20 # The final cluster is placed in output_dir/
22 # This script uses getopts which means only single character switches are allowed.
23 # Using getopt would allow for multi charcter switch names but would come at a
24 # cost of not being cross compatible.
26 # Function to display usage
34 -c Current cluster that describes the cluster.
35 -s Current stores that describes the store. If you do not have info about the stores yet, look
36 under 'voldemort_home/config/tools/' for some store examples.
37 -o Output dir where all interim and final files will be stored.
38 The directory will be created if it does not exist yet.
43 # initialize variables to an empty string
48 # Figure out voldemort home directory
49 dir
="$( cd "$
( dirname "${BASH_SOURCE[0]}" )" && pwd )"
50 vold_home
="$(dirname "$dir")"
53 while getopts “hc
:s
:o
:” OPTION
61 current_cluster
=$OPTARG
62 echo "[rebalance-new-zoned-cluster] Will rebalance on the cluster described in '$current_cluster'."
65 current_stores
=$OPTARG
66 echo "[rebalance-new-zoned-cluster] Will rebalance on the stores described in '$current_stores'."
71 echo "[rebalance-new-zoned-cluster] Using '$output_dir' for all interim and final files generated."
79 if [[ -z $current_cluster ]] ||
[[ -z $current_stores ]] ||
[[ -z $output_dir ]]
82 echo "[rebalance-new-zoned-cluster] Missing argument. Check again."
87 if [ ! -e $current_cluster ]; then
88 usage_and_exit
"File '$current_cluster' does not exist."
91 if [ ! -e $current_stores ]; then
92 usage_and_exit
"File '$current_stores' does not exist."
95 # The final cluster.xml for new cluster is generated in three steps.
96 # Step 1 : Repartitioner is executed to limit the max contiguous partition. Four such
97 # runs are attempted and the best cluster.xml from this step is piped to step 2.
98 # Step 2: Cluster.xml from step 1 is fed to the repartitioner along with random swap
99 # attempts. The repartitioner randomly swaps the partitions and tries to balance the ring.
100 # Step 3: Similar to step1, to improve the balance.
103 step2_swap_attempts
=1000
104 step2_swap_successes
=1000
107 mkdir
-p $output_dir/step
1/
108 $vold_home/bin
/run-class.sh voldemort.tools.RepartitionerCLI \
109 --current-cluster $current_cluster \
110 --current-stores $current_stores \
111 --max-contiguous-partitions 3 \
113 --output-dir $output_dir/step
1/
115 if [ ! -e $output_dir/step
1/final-cluster.xml
]; then
116 usage_and_exit
"File '$final-cluster.xml' does not exist."
120 mkdir
-p $output_dir/step2
121 $vold_home/bin
/run-class.sh voldemort.tools.RepartitionerCLI \
122 --current-cluster $output_dir/step
1/final-cluster.xml \
123 --current-stores $current_stores \
124 --output-dir $output_dir/step
2/ \
125 --enable-random-swaps \
126 --random-swap-attempts $step2_swap_attempts \
127 --random-swap-successes $step2_swap_successes
129 if [ ! -e $output_dir/step
2/final-cluster.xml
]; then
130 usage_and_exit
"File '$final-cluster.xml' does not exist."
133 mkdir
-p $output_dir/step
3/
135 $vold_home/bin
/run-class.sh voldemort.tools.RepartitionerCLI \
136 --current-cluster $output_dir/step
2/final-cluster.xml \
137 --current-stores $current_stores \
138 --max-contiguous-partitions 3 \
140 --output-dir $output_dir/step
3/ \
142 echo "[rebalance-new-zoned-cluster] Placing final-cluster.xml in '$output_dir'"
143 cp $output_dir/step
3/final-cluster.xml
$output_dir/final-cluster.xml
144 echo "[rebalance-new-zoned-cluster] Placing final-cluster.xml.analysis in '$output_dir'"
145 cp $output_dir/step
2/final-cluster.xml.analysis
$output_dir/final-cluster.xml.analysis