From d1e539555a6ac70d3534f21bcc52814e44717a2b Mon Sep 17 00:00:00 2001 From: Sudheer Ponnemkunnath Date: Tue, 10 Nov 2020 21:03:43 +0000 Subject: [PATCH] Add the scripts to execute TPCC parallely across multiple clients. Reviewers: Mihnea --- parallel_execute_scripts/Readme.md | 46 ++++ parallel_execute_scripts/create_tables.sh | 256 ++++++++++++++++++ parallel_execute_scripts/kill_java.sh | 1 + parallel_execute_scripts/limits.conf | 64 +++++ parallel_execute_scripts/output_ips.cpp | 58 ++++ .../run_tpcc_on_clients.cpp | 147 ++++++++++ parallel_execute_scripts/setup_clients.sh | 20 ++ parallel_execute_scripts/setup_regions.sh | 100 +++++++ 8 files changed, 692 insertions(+) create mode 100644 parallel_execute_scripts/Readme.md create mode 100755 parallel_execute_scripts/create_tables.sh create mode 100755 parallel_execute_scripts/kill_java.sh create mode 100644 parallel_execute_scripts/limits.conf create mode 100644 parallel_execute_scripts/output_ips.cpp create mode 100644 parallel_execute_scripts/run_tpcc_on_clients.cpp create mode 100755 parallel_execute_scripts/setup_clients.sh create mode 100755 parallel_execute_scripts/setup_regions.sh diff --git a/parallel_execute_scripts/Readme.md b/parallel_execute_scripts/Readme.md new file mode 100644 index 0000000..3639ac8 --- /dev/null +++ b/parallel_execute_scripts/Readme.md @@ -0,0 +1,46 @@ +## Step 1. Create the Loader and execute scripts. +First create 2 text files for clients and yugabyte nodes. There is a helper program `output_ips.cpp` that can generate these 2 files for us. +Compile and run the `output_scripts.cpp` to generate `loader$i.sh` and `execute$i.sh`. This program uses the `clients.txt` and `yb_nodes.txt` generated by the first program. + +## Step 2. Upload TPCC binaries and scripts to the client nodes. +This can be done as follows. Make sure that the environment has the ssh user +exported to the variable `SSH_USER` and the additional SSH AND SCP arguments +like the pem file or the port exported as `SSH_ARGS` and `SCP_ARGS`. +```sh +for n in $(cat clients.txt); +do +./upload_scripts.sh $(echo $n | cut -d ":" -f 2) $(echo $n | cut -d ":" -f 1); +done +``` + +This step expects the tpcc.tar.gz file to be present in the same directory. + +## Step 3. Create the TPCC tables. +This can be done from one of the clients as: +```sh +./tpccbenchmark --nodes= --create=true +``` + +## Step 4. Load the data. +This can be done by: +```sh +for n in $(cat clients.txt); +do +./run_loader.sh $(echo $n | cut -d ":" -f 2) $(echo $n | cut -d ":" -f 1); +done +``` + +## Step 5. Enable the foreign keys. +This can be done as: +```sh +./tpccbenchmark --nodes= --enable-foreign-keys=true --create-sql-procedures=true +``` + +## Step 6. Execute the program. +This can be done as: +```sh +for n in $(cat clients.txt); +do +./run_execute.sh $(echo $n | cut -d ":" -f 2) $(echo $n | cut -d ":" -f 1); +done +``` diff --git a/parallel_execute_scripts/create_tables.sh b/parallel_execute_scripts/create_tables.sh new file mode 100755 index 0000000..0894135 --- /dev/null +++ b/parallel_execute_scripts/create_tables.sh @@ -0,0 +1,256 @@ +# This script creates the required tables on a cluster. +# Arguments: +# 1. Number warehouses +# 2. IP of the master leader +# 3. Number of splits. This assumes we have split the cluster into (N + 1) +# logical regions with the first one dedicated for the yb-master. The 'item' +# table is pinned here as well. +# 4. Number of tablets per sub-table. +# +# The first sub-table is pinned to $cloud.$region.$zone2, the second to +# $cloud.$region.$zone3 as the first zone is reserved for the yb-master. + + +warehouses=${warehouses:-15000} +splits=${splits:-20} +tablets=${tablets:-24} +cloud=aws +region=us-west-2 +zone=us-west-2c + +wh_per_split=$(expr $warehouses / $splits) + +while [ $# -gt 0 ]; do + if [[ $1 == *"--"* ]]; then + param="${1/--/}" + declare $param="$2" + fi + shift +done + +master_addrs="" +for n in $(cat yb_nodes.txt | head -n3); +do + if [ ! -z "$n" ] + then + master_addrs+="," + fi + master_addrs+="$n:7100" +done +ip=$(head -1 yb_nodes.txt) + +ysqlsh="/mnt/d0/repositories/yugabyte-db/bin/ysqlsh -h $ip" +ybadmin="/mnt/d0/repositories/yugabyte-db/build/debug-gcc-dynamic/bin/yb-admin --master_addresses $master_addrs" + +# $1: table_name +# $2: column list +# $3: primary key +create_simple_table() { + tablezone="${zone}0" + $ybadmin modify_placement_info $cloud.$region.$tablezone 3 + $ysqlsh -d yugabyte -c "DROP TABLE IF EXISTS $1" + $ysqlsh -d yugabyte -c "CREATE TABLE $1 ($2, PRIMARY KEY($3)) SPLIT INTO 3 TABLETS" + $ybadmin modify_table_placement_info ysql.yugabyte $1 $cloud.$region.$tablezone 3 + return +} + +# $1: table_name +# $2: column list +# $3: partition argument +# $4: column list without type +# $5: PRIMARY key list +create_partitioned_table() { + + # create parent table. + $ysqlsh -d yugabyte -c "DROP TABLE IF EXISTS $1" + $ysqlsh -d yugabyte -c "CREATE TABLE $1 ($2) PARTITION BY RANGE($3) SPLIT INTO 1 TABLETS" + + # Only history table does not have a pkey. + pkey=""; + if [[ $# == '5' ]] + then + pkey=", PRIMARY KEY($5)"; + fi + + # create partitions + for i in `seq 1 $splits`; + do + tablezone=$zone$(( i )) + $ybadmin modify_placement_info $cloud.$region.$tablezone 3 + + start=$(( (i-1)*wh_per_split+1 )) + end=$(( (i*wh_per_split)+1 )) + $ysqlsh -d yugabyte -c "CREATE TABLE $1$i PARTITION OF $1($4${pkey}) FOR VALUES FROM ($start) TO ($end) SPLIT INTO $tablets TABLETS"; + + $ybadmin modify_table_placement_info ysql.yugabyte $1$i $cloud.$region.$tablezone 3 + done +} + + +# $1 index name. +# $2 table name. +# $3 indexed colummns. +# $4 is_unique +create_index() { + for i in `seq 1 $splits`; + do + tablezone=$zone$(( i )) + $ybadmin modify_placement_info $cloud.$region.$tablezone 3 + + if [[ $4 == 0 ]] + then + $ysqlsh -d yugabyte -c "CREATE INDEX $1$i ON $2$i ($3)" + else + $ysqlsh -d yugabyte -c "CREATE UNIQUE INDEX $1$i ON $2$i ($3)" + fi + + $ybadmin modify_table_placement_info ysql.yugabyte $1$i $cloud.$region.$tablezone 3 + done +} + +set -x + +$ybadmin set_load_balancer_enabled 0 + +create_simple_table 'item' \ + 'i_id int NOT NULL, + i_name varchar(24) NOT NULL, + i_price decimal(5,2) NOT NULL, + i_data varchar(50) NOT NULL, + i_im_id int NOT NULL' \ + 'i_id' + + +create_partitioned_table 'warehouse' \ + 'w_id int NOT NULL, + w_ytd decimal(12,2) NOT NULL, + w_tax decimal(4,4) NOT NULL, + w_name varchar(10) NOT NULL, + w_street_1 varchar(20) NOT NULL, + w_street_2 varchar(20) NOT NULL, + w_city varchar(20) NOT NULL, + w_state char(2) NOT NULL, + w_zip char(9) NOT NULL' \ + 'w_id'\ + 'w_id, w_ytd, w_tax, w_name, w_street_1, w_street_2, w_city, w_state, w_zip' \ + 'w_id' + +create_partitioned_table 'district' \ + 'd_w_id int NOT NULL, + d_id int NOT NULL, + d_ytd decimal(12,2) NOT NULL, + d_tax decimal(4,4) NOT NULL, + d_next_o_id int NOT NULL, + d_name varchar(10) NOT NULL, + d_street_1 varchar(20) NOT NULL, + d_street_2 varchar(20) NOT NULL, + d_city varchar(20) NOT NULL, + d_state char(2) NOT NULL, + d_zip char(9) NOT NULL' \ + 'd_w_id' \ + 'd_w_id, d_id, d_ytd, d_tax, d_next_o_id, d_name, d_street_1, d_street_2, d_city, d_state, d_zip' \ + '(d_w_id,d_id) HASH' + +create_partitioned_table 'customer' \ + 'c_w_id int NOT NULL, + c_d_id int NOT NULL, + c_id int NOT NULL, + c_discount decimal(4,4) NOT NULL, + c_credit char(2) NOT NULL, + c_last varchar(16) NOT NULL, + c_first varchar(16) NOT NULL, + c_credit_lim decimal(12,2) NOT NULL, + c_balance decimal(12,2) NOT NULL, + c_ytd_payment float NOT NULL, + c_payment_cnt int NOT NULL, + c_delivery_cnt int NOT NULL, + c_street_1 varchar(20) NOT NULL, + c_street_2 varchar(20) NOT NULL, + c_city varchar(20) NOT NULL, + c_state char(2) NOT NULL, + c_zip char(9) NOT NULL, + c_phone char(16) NOT NULL, + c_since timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + c_middle char(2) NOT NULL, + c_data varchar(500) NOT NULL' \ + 'c_w_id' \ + 'c_w_id, c_d_id, c_id, c_discount, c_credit, c_last, c_first, c_credit_lim, c_balance, c_ytd_payment, c_payment_cnt, + c_delivery_cnt, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_since, c_middle, c_data' \ + '(c_w_id,c_d_id) HASH,c_id' \ + +create_partitioned_table 'history' \ + 'h_c_id int NOT NULL, + h_c_d_id int NOT NULL, + h_c_w_id int NOT NULL, + h_d_id int NOT NULL, + h_w_id int NOT NULL, + h_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + h_amount decimal(6,2) NOT NULL, + h_data varchar(24) NOT NULL' \ + 'h_w_id' \ + 'h_c_id, h_c_d_id, h_c_w_id, h_d_id, h_w_id, h_date, h_amount, h_data' + +create_partitioned_table 'oorder' \ + 'o_w_id int NOT NULL, + o_d_id int NOT NULL, + o_id int NOT NULL, + o_c_id int NOT NULL, + o_carrier_id int DEFAULT NULL, + o_ol_cnt decimal(2,0) NOT NULL, + o_all_local decimal(1,0) NOT NULL, + o_entry_d timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP' \ + 'o_w_id' \ + 'o_w_id, o_d_id, o_id, o_c_id, o_carrier_id, o_ol_cnt, o_all_local, o_entry_d' \ + '(o_w_id,o_d_id) HASH,o_id' + +create_partitioned_table 'stock' \ + 's_w_id int NOT NULL, + s_i_id int NOT NULL, + s_quantity decimal(4,0) NOT NULL, + s_ytd decimal(8,2) NOT NULL, + s_order_cnt int NOT NULL, + s_remote_cnt int NOT NULL, + s_data varchar(50) NOT NULL, + s_dist_01 char(24) NOT NULL, + s_dist_02 char(24) NOT NULL, + s_dist_03 char(24) NOT NULL, + s_dist_04 char(24) NOT NULL, + s_dist_05 char(24) NOT NULL, + s_dist_06 char(24) NOT NULL, + s_dist_07 char(24) NOT NULL, + s_dist_08 char(24) NOT NULL, + s_dist_09 char(24) NOT NULL, + s_dist_10 char(24) NOT NULL'\ + 's_w_id' \ + 's_w_id, s_i_id, s_quantity, s_ytd, s_order_cnt, s_remote_cnt, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10' \ + '(s_w_id,s_i_id)HASH' \ + +create_partitioned_table 'new_order' \ + 'no_w_id int NOT NULL, + no_d_id int NOT NULL, + no_o_id int NOT NULL' \ + 'no_w_id' \ + 'no_w_id, no_d_id, no_o_id' \ + '(no_w_id,no_d_id) HASH,no_o_id' + +create_partitioned_table 'order_line' \ + 'ol_w_id int NOT NULL, + ol_d_id int NOT NULL, + ol_o_id int NOT NULL, + ol_number int NOT NULL, + ol_i_id int NOT NULL, + ol_delivery_d timestamp NULL DEFAULT NULL, + ol_amount decimal(6,2) NOT NULL, + ol_supply_w_id int NOT NULL, + ol_quantity decimal(2,0) NOT NULL, + ol_dist_info char(24) NOT NULL' \ + 'ol_w_id' \ + 'ol_w_id, ol_d_id, ol_o_id, ol_number, ol_i_id, ol_delivery_d, ol_amount, ol_supply_w_id, ol_quantity, ol_dist_info' \ + '(ol_w_id,ol_d_id) HASH,ol_o_id,ol_number' + +create_index 'idx_customer_name' 'customer' '(c_w_id,c_d_id) HASH,c_last,c_first' 0 + +create_index 'idx_order' 'oorder' '(o_w_id,o_d_id) HASH,o_c_id,o_id DESC' 1 + +$ybadmin clear_placement_info +$ybadmin set_load_balancer_enabled 1 diff --git a/parallel_execute_scripts/kill_java.sh b/parallel_execute_scripts/kill_java.sh new file mode 100755 index 0000000..19ed770 --- /dev/null +++ b/parallel_execute_scripts/kill_java.sh @@ -0,0 +1 @@ +sudo ssh $SSH_ARGS -ostricthostkeychecking=no $SSH_USER@$1 'pkill java' diff --git a/parallel_execute_scripts/limits.conf b/parallel_execute_scripts/limits.conf new file mode 100644 index 0000000..c688bc1 --- /dev/null +++ b/parallel_execute_scripts/limits.conf @@ -0,0 +1,64 @@ +# /etc/security/limits.conf +# +#This file sets the resource limits for the users logged in via PAM. +#It does not affect resource limits of the system services. +# +#Also note that configuration files in /etc/security/limits.d directory, +#which are read in alphabetical order, override the settings in this +#file in case the domain is the same or more specific. +#That means for example that setting a limit for wildcard domain here +#can be overriden with a wildcard setting in a config file in the +#subdirectory, but a user specific setting here can be overriden only +#with a user specific setting in the subdirectory. +# +#Each line describes a limit for a user in the form: +# +# +# +#Where: +# can be: +# - a user name +# - a group name, with @group syntax +# - the wildcard *, for default entry +# - the wildcard %, can be also used with %group syntax, +# for maxlogin limit +# +# can have the two values: +# - "soft" for enforcing the soft limits +# - "hard" for enforcing hard limits +# +# can be one of the following: +# - core - limits the core file size (KB) +# - data - max data size (KB) +# - fsize - maximum filesize (KB) +# - memlock - max locked-in-memory address space (KB) +# - nofile - max number of open file descriptors +# - rss - max resident set size (KB) +# - stack - max stack size (KB) +# - cpu - max CPU time (MIN) +# - nproc - max number of processes +# - as - address space limit (KB) +# - maxlogins - max number of logins for this user +# - maxsyslogins - max number of logins on the system +# - priority - the priority to run user process with +# - locks - max number of file locks the user can hold +# - sigpending - max number of pending signals +# - msgqueue - max memory used by POSIX message queues (bytes) +# - nice - max nice priority allowed to raise to values: [-20, 19] +# - rtprio - max realtime priority +# +# +# + +#* soft core 0 +#* hard rss 10000 +#@student hard nproc 20 +#@faculty soft nproc 20 +#@faculty hard nproc 50 +#ftp hard nproc 0 +#@student - maxlogins 4 + +# End of file +* - core unlimited +* - nofile 1048576 +* - nproc 30000 diff --git a/parallel_execute_scripts/output_ips.cpp b/parallel_execute_scripts/output_ips.cpp new file mode 100644 index 0000000..ad980af --- /dev/null +++ b/parallel_execute_scripts/output_ips.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +using namespace std; + +void GetIps(const char *ip_string, vector& ips) { + string input(ip_string); + int start = -1; + int count = 0; // count of '.' + for (int i = 0; i < input.size(); ++i) { + if (input.at(i) == ',' || input.at(i) == ':') { + if (count == 3) { + ips.emplace_back(input.substr(start, i - start)); + } + count = 0; + start = -1; + continue; + } + if (input.at(i) == '.') { + ++count; + } + if (start == -1) { + start = i; + } + } + if (start != -1 && count == 3) { + ips.emplace_back(input.substr(start, input.size() - start)); + } + + for (const auto& ip: ips) { + cout << ip << " "; + } + cout << endl; +} + +void OutputToFile(string filename, vector ips, bool should_number) { + ofstream out_file(filename.data()); + int i = 0; + for (const auto& ip: ips) { + out_file << (should_number ? (to_string(i++) + ":") : "") << ip << "\n"; + } +} + +int main(int argc, char **argv) { + if (argc < 3) { + cout << "Usage : ./binary client_ips yb_nodes_ips"; + return 1; + } + vector client_ips; + vector yb_node_ips; + GetIps(argv[1], client_ips); + GetIps(argv[2], yb_node_ips); + + OutputToFile("clients.txt", client_ips, true); + OutputToFile("yb_nodes.txt", yb_node_ips, false); +} diff --git a/parallel_execute_scripts/run_tpcc_on_clients.cpp b/parallel_execute_scripts/run_tpcc_on_clients.cpp new file mode 100644 index 0000000..484e43a --- /dev/null +++ b/parallel_execute_scripts/run_tpcc_on_clients.cpp @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include +#include +#include + +const int total_warehouses = 15000; // 100000 for 12xl +const int num_ips_per_client = 6; // 3 for 12xl +const int client_repeat_count = 1; // 2 for 12xl +const int loader_threads_per_client = 32; // 60 for 12xl +const int num_connections_per_client = 600; // 300 for 12xl +const int delay_per_client = 120; + +using namespace std; + +const string ssh_args = "-i /opt/yugabyte/data/keys/08c0ba0e-3558-40fc-94e5-a87a627de8c5/yb-15-aws-portal-1-key.pem -p 54422 -ostricthostkeychecking=no"; +const string ssh_user = "centos"; + +void ExecOnServer(const string& cmd, string ip, string out_file) { + stringstream ss; + ss << "nohup ssh " << ssh_args << " " << ssh_user << "@" << ip << " \'" << cmd << "\' > /tmp/" << ip << "_" << out_file << " &"; + string ssh_cmd = ss.str(); + + cout << "SSH command " << ssh_cmd << "\n"; + system(ssh_cmd.data()); +} + +void ReadServerIps(vector& ips) { + ifstream nodes("yb_nodes.txt"); + string line; + int i = 0; + while (getline(nodes, line)) { + // skipping masters. + if (i < 3) { + i++; + continue; + } + ips.emplace_back(line); + } +} + +void ReadClientIps(vector& ips) { + ifstream clients("clients.txt"); + string line; + while (getline(clients, line)) { + string ip = line.substr(line.find(":") + 1); + ips.emplace_back(ip); + } +} + +class IpsIterator { + public: + IpsIterator(const vector& ips, int num_ips_per_client, int repeat_count) : + ips_(ips), + num_ips_per_client_(num_ips_per_client), + repeat_count_(repeat_count), + idx_(0), + current_count_(0) { + } + + string GetNext() { + string execute_ips = ""; + int idx = idx_; + for (int j = 0; j < num_ips_per_client_ && idx < ips_.size(); ++j) { + if (j != 0) execute_ips += ","; + execute_ips += ips_.at(idx++); + } + + ++current_count_; + if (current_count_ == repeat_count_) { + current_count_ = 0; + idx_ = idx; + } + + return execute_ips; + } + + int GetNumSplits() { + return (ips_.size() + num_ips_per_client_ - 1) / num_ips_per_client_ * repeat_count_; + } + + private: + const vector& ips_; + const int num_ips_per_client_; + const int repeat_count_; + int idx_; + int current_count_; +}; + +void OutputLoaderScripts(const vector& ips, const vector& client_ips) { + IpsIterator ip_iterator(ips, num_ips_per_client, client_repeat_count); + int load_splits = ip_iterator.GetNumSplits(); + int warehouses_per_split = total_warehouses / load_splits; + + cout << "LOAD SPLITS: " << load_splits << "\nWH per split " << warehouses_per_split << "\n"; + for (int i = 0; i < load_splits; ++i) { + stringstream ss; + ss << "cd tpcc; ~/tpcc/tpccbenchmark --load=true" + << " --nodes=" << ip_iterator.GetNext() + << " --total-warehouses=" << total_warehouses + << " --warehouses=" << warehouses_per_split + << " --start-warehouse-id=" << i * warehouses_per_split + 1 + << " --loaderthreads=" << loader_threads_per_client; + ExecOnServer(ss.str(), client_ips.at(i), "loader.txt"); + } +} + +void OutputExecuteScripts(const vector& ips, const vector& client_ips) { + IpsIterator ip_iterator(ips, num_ips_per_client, client_repeat_count); + int execute_splits = ip_iterator.GetNumSplits(); + int warehouses_per_split = total_warehouses / execute_splits; + int initial_delay_per_client = 0; + int warmup_time = execute_splits * delay_per_client - delay_per_client; + + for (int i = 0; i < execute_splits; ++i) { + stringstream ss; + ss << "cd tpcc; ~/tpcc/tpccbenchmark --execute=true" + << " --nodes=" << ip_iterator.GetNext() + << " --num-connections=" << num_connections_per_client + << " --total-warehouses=" << total_warehouses + << " --warehouses=" << warehouses_per_split + << " --start-warehouse-id=" << i * warehouses_per_split + 1 + << " --warmup-time-secs=" << warmup_time + << " --initial-delay-secs=" << initial_delay_per_client; + + ExecOnServer(ss.str(), client_ips.at(i), "execute.txt"); + + initial_delay_per_client += delay_per_client; + warmup_time -= delay_per_client; + } +} + +int main(int argc, char** argv) { + vector ips; + ReadServerIps(ips); + + vector client_ips; + ReadClientIps(client_ips); + + if (strcmp(argv[1], "load") == 0) { + OutputLoaderScripts(ips, client_ips); + } else if (strcmp(argv[1], "execute") == 0) { + OutputExecuteScripts(ips, client_ips); + } +} diff --git a/parallel_execute_scripts/setup_clients.sh b/parallel_execute_scripts/setup_clients.sh new file mode 100755 index 0000000..658bf96 --- /dev/null +++ b/parallel_execute_scripts/setup_clients.sh @@ -0,0 +1,20 @@ +set -ex + +for n in $(cat clients.txt); +do + IDX=$(echo $n | cut -d ":" -f 1); + IP=$(echo $n | cut -d ":" -f 2); + # Upload new limits.conf. + scp $SCP_ARGS -ostricthostkeychecking=no limits.conf $SSH_USER@$IP:~ + ssh $SSH_ARGS -ostricthostkeychecking=no $SSH_USER@$IP 'sudo cp ~/limits.conf /etc/security/limits.conf' + + # Install TPCC. + ssh $SSH_ARGS -ostricthostkeychecking=no $SSH_USER@$IP 'sudo yum install -y java wget; rm -rf ~/tpcc; rm ~/tpcc.tar.gz; wget https://github.com/yugabyte/tpcc/releases/download/1.4/tpcc.tar.gz; tar -zxvf tpcc.tar.gz' + + # Upload loader and execute scripts. + #scp $SCP_ARGS -ostricthostkeychecking=no loader$IDX.sh $SSH_USER@$IP:~/loader.sh + #scp $SCP_ARGS -ostricthostkeychecking=no execute$IDX.sh $SSH_USER@$IP:~/execute.sh + + # Confirm limits are set correctly. + ssh $SSH_ARGS -ostricthostkeychecking=no $SSH_USER@$IP 'ulimit -a' +done diff --git a/parallel_execute_scripts/setup_regions.sh b/parallel_execute_scripts/setup_regions.sh new file mode 100755 index 0000000..11fd311 --- /dev/null +++ b/parallel_execute_scripts/setup_regions.sh @@ -0,0 +1,100 @@ +set -ex + +BASEZONE="us-west-2c" + +NUMNODES=$(cat yb_nodes.txt | wc -l) +ybcli="/mnt/d0/repositories/yugabyte-db/build/latest/bin/yb-ts-cli" + +shut_down_services() { + for n in $(cat yb_nodes.txt); + do + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n /home/yugabyte/bin/yb-server-ctl.sh tserver stop + done + + for n in $(cat yb_nodes.txt | head -n 3); + do + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n /home/yugabyte/bin/yb-server-ctl.sh master stop + done +} + +startup_services() { + for n in $(cat yb_nodes.txt | head -n 3); + do + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n /home/yugabyte/bin/yb-server-ctl.sh master start + done + + for n in $(cat yb_nodes.txt); + do + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n /home/yugabyte/bin/yb-server-ctl.sh tserver start + done +} + +clear_state() { + for n in $(cat yb_nodes.txt); + do + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n 'rm -rf /mnt/d0/*; rm -rf /mnt/d1/*' + done +} + +set_zones() { + i=0 + ZONEID=0 + + for n in $(cat yb_nodes.txt); + do + ZONEID=$(( $i / 3 )) + i=$(( $i + 1 )) + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n sed -i "s/--placement_zone.*/--placement_zone=${BASEZONE}${ZONEID}/g" tserver/conf/server.conf + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n sed -i "/^--placement_uuid/d" tserver/conf/server.conf + done + + i=0 + ZONEID=0 + #Set the replication factor of the cluster to the number of nodes to make sure that the transaction table has the required number of tablets. + for n in $(cat yb_nodes.txt | head -n 3); + do + ZONEID=$(( $i / 3 )) + i=$(( $i + 1 )) + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n sed -i "s/--placement_zone.*/--placement_zone=${BASEZONE}${ZONEID}/g" master/conf/server.conf + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n sed -i "/^--placement_uuid/d" master/conf/server.conf + done +} + +set_master_replication_factor() { + i=0 + ZONEID=0 + for n in $(cat yb_nodes.txt | head -n 3); + do + ZONEID=$(( $i / 3 )) + i=$(( $i + 1 )) + ssh -i ./ssh/cluster.pem -ostricthostkeychecking=no -p 54422 yugabyte@$n sed -i "s/--replication_factor.*/--replication_factor=$1/g" master/conf/server.conf + done +} + +remove_additional_tablets() { + for n in $(cat yb_nodes.txt | head -n 3); + do + $ybcli --server_address $n:7100 set_flag -force load_balancer_max_concurrent_removals 50 + done + +# sleep 100 +# +# for n in $(cat yb_nodes.txt | head -n 3); +# do +# $ybcli --server_address $n:7100 set_flag -force load_balancer_max_concurrent_removals 1 +# done +} + +#Set the replication factor of the cluster to the number of nodes to make sure that the transaction table has the required number of tablets. +shut_down_services +clear_state +set_zones +set_master_replication_factor $NUMNODES +startup_services + +sleep 30 + +shut_down_services +set_master_replication_factor 3 +startup_services +remove_additional_tablets