added unset_zone_id context for clients
[voldemort/jeffpc.git] / bin / rebalance-new-zoned-cluster.sh
blob02a5aa17f8119bcbf157c98ea70ce964683dcf66
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 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
27 usage_and_exit() {
28 echo "ERROR: $1."
29 cat <<EOF
31 Usage: $0 options
32 OPTIONS:
33 -h Show this message
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.
39 EOF
40 exit 1
43 # initialize variables to an empty string
44 current_cluster=""
45 current_stores=""
46 output_dir=""
48 # Figure out voldemort home directory
49 dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
50 vold_home="$(dirname "$dir")"
52 # Parse options
53 while getopts “hc:s:o:” OPTION
55 case $OPTION in
57 usage_and_exit
58 exit 1
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'."
69 output_dir=$OPTARG
70 mkdir -p $output_dir
71 echo "[rebalance-new-zoned-cluster] Using '$output_dir' for all interim and final files generated."
74 usage_and_exit
76 esac
77 done
79 if [[ -z $current_cluster ]] || [[ -z $current_stores ]] || [[ -z $output_dir ]]
80 then
81 printf "\n"
82 echo "[rebalance-new-zoned-cluster] Missing argument. Check again."
83 usage_and_exit
84 exit 1
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
106 # Step 1
107 mkdir -p $output_dir/step1/
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 \
112 --attempts 4 \
113 --output-dir $output_dir/step1/
115 if [ ! -e $output_dir/step1/final-cluster.xml ]; then
116 usage_and_exit "File '$final-cluster.xml' does not exist."
119 # Step 2
120 mkdir -p $output_dir/step2
121 $vold_home/bin/run-class.sh voldemort.tools.RepartitionerCLI \
122 --current-cluster $output_dir/step1/final-cluster.xml \
123 --current-stores $current_stores \
124 --output-dir $output_dir/step2/ \
125 --enable-random-swaps \
126 --random-swap-attempts $step2_swap_attempts \
127 --random-swap-successes $step2_swap_successes
129 if [ ! -e $output_dir/step2/final-cluster.xml ]; then
130 usage_and_exit "File '$final-cluster.xml' does not exist."
133 mkdir -p $output_dir/step3/
134 # Step 3
135 $vold_home/bin/run-class.sh voldemort.tools.RepartitionerCLI \
136 --current-cluster $output_dir/step2/final-cluster.xml \
137 --current-stores $current_stores \
138 --max-contiguous-partitions 3 \
139 --attempts 4 \
140 --output-dir $output_dir/step3/ \
142 echo "[rebalance-new-zoned-cluster] Placing final-cluster.xml in '$output_dir'"
143 cp $output_dir/step3/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/step2/final-cluster.xml.analysis $output_dir/final-cluster.xml.analysis