~dbpercona/percona-qa/readme

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/bin/bash
# This script is for PXC Testing ChaosMonkey Style
# Please go through https://github.com/jayjanssen/percona-xtradb-cluster-tutorial 
# to install PXC on your machine and execute this script from node1
# Analyze script_out.log file from workdir to get the PXC testcase output
IFS=$'\n'
WORKDIR="/root"
dbuser="test"
cd $WORKDIR

header="|%-10s |%-25s |%-25s |\n"
rm -rf script_out.log before-node*.log

# PXC Node IPs
nodes=("192.168.70.2" "192.168.70.3" "192.168.70.4")

# Sysbench Prepare run
mysql -utest -e "drop database if exists pxc_test;create database pxc_test"
sysbench --test=sysbench_tests/db/parallel_prepare.lua   --mysql-host=node1  --num-threads=10    --oltp-tables-count=10 --oltp-table-size=50000  --mysql-db=pxc_test --mysql-user=test   --db-driver=mysql run > sysbench_prepare.log

for i in "${nodes[@]}"
do
  echo $i
  sysbench --test=sysbench_tests/db/oltp.lua --mysql-host=$i --mysql-user=$dbuser   --num-threads=10    --oltp-tables-count=10 --mysql-db=pxc_test --oltp-table-size=50000 --report-interval=1 --max-requests=0 --tx-rate=100 run | grep tps > /dev/null 2>&1 &
done

#Get monitoring state of each PXC node
rm -rf node*.log after-node*.log
myq_status -u test -h 192.168.70.2 -t 1 wsrep > node1.log &
echo $! > myq_status_pid.txt
myq_status -u test -h 192.168.70.3 -t 1 wsrep > node2.log &
echo $! >> myq_status_pid.txt
myq_status -u test -h 192.168.70.4 -t 1 wsrep > node3.log &
echo $! >> myq_status_pid.txt
sleep 120 
strt=`eval date +'%H:%M'`
sleep 60
stop=`eval date +'%H:%M'`

sed -n "/$strt/ , /$stop/p" node1.log > before-node1.log
sed -n "/$strt/ , /$stop/p" node2.log > before-node2.log
sed -n "/$strt/ , /$stop/p" node3.log > before-node3.log
bnode1_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024)}' before-node1.log`
bnode2_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024)}' before-node2.log`
bnode3_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024)}' before-node3.log`
bnode1_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024)}' before-node1.log`
bnode2_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024)}' before-node2.log`
bnode3_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024)}' before-node3.log`

#check mysql status on PXC nodes

function checkPXC {
# IFS=$'\n'
 wsrep_cluster_status=()
 wsrep_local_state_comment=()
 status_node1=`mysql -utest -h192.168.70.2 -Bse"show global status like 'wsrep_cluster_status'" | awk '{print $2}'`
 if [ -z $status_node1 ] ;  then   wsrep_cluster_status+=("MySQL is not running!") ;  else wsrep_cluster_status+=($status_node1) ; fi
 status_node2=`mysql -utest -h192.168.70.3 -Bse"show global status like 'wsrep_cluster_status'" | awk '{print $2}'`
 if [ -z $status_node2 ] ;  then   wsrep_cluster_status+=("MySQL is not running!") ;  else wsrep_cluster_status+=($status_node2) ; fi
 status_node3=`mysql -utest -h192.168.70.4 -Bse"show global status like 'wsrep_cluster_status'" | awk '{print $2}'`
 if [ -z $status_node3 ] ;  then   wsrep_cluster_status+=("MySQL is not running!") ;  else wsrep_cluster_status+=($status_node3) ; fi
 comment_node1=`mysql -utest -h192.168.70.2 -Bse"show global status like 'wsrep_local_state_comment'" | awk '{print $2}'`
 if [ -z $comment_node1 ] ;  then wsrep_local_state_comment+=('MySQL is not running!') ; else wsrep_local_state_comment+=($comment_node1) ; fi 
 comment_node2=`mysql -utest -h192.168.70.3 -Bse"show global status like 'wsrep_local_state_comment'" | awk '{print $2}'`
 if [ -z $comment_node2 ] ;  then wsrep_local_state_comment+=('MySQL is not running!') ; else wsrep_local_state_comment+=($comment_node2) ; fi
 comment_node3=`mysql -utest -h192.168.70.4 -Bse"show global status like 'wsrep_local_state_comment'" | awk '{print $2}'`
 if [ -z $comment_node3 ] ;  then wsrep_local_state_comment+=('MySQL is not running!') ; else wsrep_local_state_comment+=($comment_node3) ; fi
 #printf '%s\n' "${wsrep_cluster_status[*]}"
 cluster_status=(${wsrep_cluster_status[@]})
 state_comment=(${wsrep_local_state_comment[@]})
}

#Function for Network delay
function NWdelay {
 ms="$1ms"
 for i in "${nodes[@]}"
 do
  check=`ssh $i "/etc/init.d/mysql status"`
  node=`ssh $i "hostname"`
  status=`echo $check | awk '{print $1}'`
  if [ $status == "ERROR!" ] ; then
   ssh $i 'rm -rf /var/lib/mysql/node*.pid;/etc/init.d/mysql start' 
   sysbench --test=sysbench_tests/db/oltp.lua --mysql-host=$i --mysql-user=$dbuser   --num-threads=10    --oltp-tables-count=10 --mysql-db=pxc_test --oltp-table-size=50000 --report-interval=1 --max-requests=0 --tx-rate=100 run | grep tps > /dev/null 2>&1 &
   rm -rf $node.log
   myq_status -u test -h $i -t 1 wsrep > $node.log &
   echo $! >> myq_status_pid.txt
  fi
 done
 
 tc qdisc add dev eth1 root netem delay $ms
 sleep 120
 strt=`eval date +'%H:%M'`
 sleep 60
 stop=`eval date +'%H:%M'`
 
 sed -n "/$strt/ , /$stop/p" node1.log > after-node1.log
 sed -n "/$strt/ , /$stop/p" node2.log > after-node2.log
 sed -n "/$strt/ , /$stop/p" node3.log > after-node3.log
 
 node1_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024)}' after-node1.log`
 node2_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024)}' after-node2.log`
 node3_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024)}' after-node3.log`
 node1_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024)}' after-node1.log`
 node2_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024)}' after-node2.log`
 node3_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024)}' after-node3.log`

 echo -e "\n\n*************** Network Delay $1 milliseconds (byte transfer rate b/w nodes) ******************\n" >> script_out.log
 printf "|%-10s %-21s *%-20s |%-20s *%-20s |\n" "" "Normal" "" "NW delay($ms)" "" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log 
 header1="|%-10s |%-20s |%-20s |%-20s |%-20s |\n"
 printf "$header1" "Nodes" "Upload Rate(KB)" "Download Rate(KB)" "Upload Rate(KB)" "Download Rate(KB)" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 printf "$header1" "Node 1" $bnode1_up $bnode1_dn $node1_up $node1_dn >> script_out.log
 printf "$header1" "Node 2" $bnode2_up $bnode2_dn $node2_up $node2_dn >> script_out.log
 printf "$header1" "Node 3" $bnode3_up $bnode3_dn $node3_up $node3_dn >> script_out.log
 checkPXC

 tc qdisc delete dev eth1 root
 echo -e "\n\n" >> script_out.log
 printf "$header" "Nodes" "wsrep_cluster_status" "wsrep_local_state" >> script_out.log
 echo -e "--------------------------------------------------------------------------" >> script_out.log
 printf "$header" "Node 1" ${cluster_status[0]} ${state_comment[0]} >> script_out.log
 printf "$header" "Node 2" ${cluster_status[1]} ${state_comment[1]} >> script_out.log
 printf "$header" "Node 3" ${cluster_status[2]} ${state_comment[2]} >> script_out.log
}

#Function for network packet loss
function NWpacketloss {
 for i in "${nodes[@]}"
 do
  check=`ssh $i "/etc/init.d/mysql status"`
  node=`ssh $i "hostname"`
  status=`echo $check | awk '{print $1}'`
  if [ $status == "ERROR!" ] ; then
   ssh $i 'rm -rf /var/lib/mysql/node*.pid;/etc/init.d/mysql start'
   sysbench --test=sysbench_tests/db/oltp.lua --mysql-host=$i --mysql-user=$dbuser   --num-threads=10    --oltp-tables-count=10 --mysql-db=pxc_test --oltp-table-size=50000 --report-interval=1 --max-requests=0 --tx-rate=100 run | grep tps > /dev/null 2>&1 &
   rm -rf $node.log
   myq_status -u test -h $i -t 1 wsrep > $node.log &
   echo $! >> myq_status_pid.txt
  fi
 done
 perc=$1

 tc qdisc add dev eth1 root netem loss $perc
 sleep 120
 strt=`eval date +'%H:%M'`
 sleep 60
 stop=`eval date +'%H:%M'`
 sed -n "/$strt/ , /$stop/p" node1.log > check-node1.log
 sed -n "/$strt/ , /$stop/p" node2.log > check-node2.log
 sed -n "/$strt/ , /$stop/p" node3.log > check-node3.log


 node1_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node1.log`
 node2_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node2.log`
 node3_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node3.log`
 node1_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node1.log`
 node2_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node2.log`
 node3_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node3.log`

 echo -e "\n\n********************************** Network packet loss $perc ***************************************\n" >> script_out.log
 printf "|%-10s %-21s *%-20s |%-20s *%-20s |\n" "" "Normal" "" "NW packet loss($perc)" "" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 header1="|%-10s |%-20s |%-20s |%-20s |%-20s |\n"
 printf "$header1" "Nodes" "Upload Rate(KB)" "Download Rate(KB)" "Upload Rate(KB)" "Download Rate(KB)" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 printf "$header1" "Node 1" $bnode1_up $bnode1_dn $node1_up $node1_dn >> script_out.log
 printf "$header1" "Node 2" $bnode2_up $bnode2_dn $node2_up $node2_dn >> script_out.log
 printf "$header1" "Node 3" $bnode3_up $bnode3_dn $node3_up $node3_dn >> script_out.log
 
 echo -e "\n\n" >> script_out.log
 checkPXC
 printf "$header" "Nodes" "wsrep_cluster_status" "wsrep_local_state" >> script_out.log
 echo -e "--------------------------------------------------------------------------" >> script_out.log
 printf "$header" "Node 1" ${cluster_status[0]} ${state_comment[0]} >> script_out.log
 printf "$header" "Node 2" ${cluster_status[1]} ${state_comment[1]} >> script_out.log
 printf "$header" "Node 3" ${cluster_status[2]} ${state_comment[2]} >> script_out.log
  
 tc qdisc delete dev eth1 root

}

#Function for network corruption
function NWpkt_corruption {
 for i in "${nodes[@]}"
 do
  check=`ssh $i "/etc/init.d/mysql status"`
  node=`ssh $i "hostname"`
  status=`echo $check | awk '{print $1}'`
  if [ $status == "ERROR!" ] ; then
   ssh $i 'rm -rf /var/lib/mysql/node*.pid;/etc/init.d/mysql start'
   sysbench --test=sysbench_tests/db/oltp.lua --mysql-host=$i --mysql-user=$dbuser   --num-threads=10    --oltp-tables-count=10 --mysql-db=pxc_test --oltp-table-size=50000 --report-interval=1 --max-requests=0 --tx-rate=100 run | grep tps > /dev/null 2>&1 &
   rm -rf $node.log
   myq_status -u test -h $i -t 1 wsrep > $node.log &
   echo $! >> myq_status_pid.txt
  fi
 done
 perc=$1

 tc qdisc add dev eth1 root netem corrupt $perc 
 sleep 120
 strt=`eval date +'%H:%M'`
 sleep 60
 stop=`eval date +'%H:%M'`
 sed -n "/$strt/ , /$stop/p" node1.log > check-node1.log
 sed -n "/$strt/ , /$stop/p" node2.log > check-node2.log
 sed -n "/$strt/ , /$stop/p" node3.log > check-node3.log


 node1_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node1.log`
 node2_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node2.log`
 node3_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node3.log`
 node1_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node1.log`
 node2_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node2.log`
 node3_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node3.log`

 echo -e "\n\n********************************** Network packet corruption $perc ***************************************\n" >> script_out.log
 printf "|%-10s %-21s *%-20s |%-20s *%-20s |\n" "" "Normal" "" "NW pkt corruption($perc)" "" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 header1="|%-10s |%-20s |%-20s |%-20s |%-20s |\n"
 printf "$header1" "Nodes" "Upload Rate(KB)" "Download Rate(KB)" "Upload Rate(KB)" "Download Rate(KB)" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 printf "$header1" "Node 1" $bnode1_up $bnode1_dn $node1_up $node1_dn >> script_out.log
 printf "$header1" "Node 2" $bnode2_up $bnode2_dn $node2_up $node2_dn >> script_out.log
 printf "$header1" "Node 3" $bnode3_up $bnode3_dn $node3_up $node3_dn >> script_out.log

 echo -e "\n\n" >> script_out.log

 checkPXC
 printf "$header" "Nodes" "wsrep_cluster_status" "wsrep_local_state" >> script_out.log
 echo -e "--------------------------------------------------------------------------" >> script_out.log
 printf "$header" "Node 1" ${cluster_status[0]} ${state_comment[0]} >> script_out.log
 printf "$header" "Node 2" ${cluster_status[1]} ${state_comment[1]} >> script_out.log
 printf "$header" "Node 3" ${cluster_status[2]} ${state_comment[2]} >> script_out.log
  
 tc qdisc delete dev eth1 root
}

# Function for network re-ordering
function NWpkt_reordering {
 for i in "${nodes[@]}"
 do
  check=`ssh $i "/etc/init.d/mysql status"`
  node=`ssh $i "hostname"`
  status=`echo $check | awk '{print $1}'`
  if [ $status == "ERROR!" ] ; then
   ssh $i 'rm -rf /var/lib/mysql/node*.pid;/etc/init.d/mysql start'
   sysbench --test=sysbench_tests/db/oltp.lua --mysql-host=$i --mysql-user=$dbuser   --num-threads=10    --oltp-tables-count=10 --mysql-db=pxc_test --oltp-table-size=50000 --report-interval=1 --max-requests=0 --tx-rate=100 run | grep tps > /dev/null 2>&1 &
   rm -rf $node.log
   myq_status -u test -h $i -t 1 wsrep > $node.log &
   echo $! >> myq_status_pid.txt
  fi
 done
 perc1=$1
 perc2=$2
 tc qdisc add dev eth1 root netem delay 100ms $perc1 $perc2
 sleep 120
 strt=`eval date +'%H:%M'`
 sleep 60
 stop=`eval date +'%H:%M'`
 sed -n "/$strt/ , /$stop/p" node1.log > check-node1.log
 sed -n "/$strt/ , /$stop/p" node2.log > check-node2.log
 sed -n "/$strt/ , /$stop/p" node3.log > check-node3.log


 node1_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node1.log`
 node2_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node2.log`
 node3_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node3.log`
 node1_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node1.log`
 node2_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node2.log`
 node3_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node3.log`

 echo -e "\n\n********************** Network packet re-ordering (delay 100ms reorder $perc1 $perc2..) ******************\n" >> script_out.log
 printf "|%-10s %-21s *%-20s |%-20s *%-20s |\n" "" "Normal" "" "NW pkt re-ordering" "" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 header1="|%-10s |%-20s |%-20s |%-20s |%-20s |\n"
 printf "$header1" "Nodes" "Upload Rate(KB)" "Download Rate(KB)" "Upload Rate(KB)" "Download Rate(KB)" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 printf "$header1" "Node 1" $bnode1_up $bnode1_dn $node1_up $node1_dn >> script_out.log
 printf "$header1" "Node 2" $bnode2_up $bnode2_dn $node2_up $node2_dn >> script_out.log
 printf "$header1" "Node 3" $bnode3_up $bnode3_dn $node3_up $node3_dn >> script_out.log

 echo -e "\n\n" >> script_out.log
 checkPXC
 printf "$header" "Nodes" "wsrep_cluster_status" "wsrep_local_state" >> script_out.log
 echo -e "--------------------------------------------------------------------------" >> script_out.log
 printf "$header" "Node 1" ${cluster_status[0]} ${state_comment[0]} >> script_out.log
 printf "$header" "Node 2" ${cluster_status[1]} ${state_comment[1]} >> script_out.log
 printf "$header" "Node 3" ${cluster_status[2]} ${state_comment[2]} >> script_out.log 
  
 tc qdisc delete dev eth1 root
}

#Function for single node failure
function singleNodefailure {
 for i in "${nodes[@]}"
 do
  check=`ssh $i "/etc/init.d/mysql status"`
  node=`ssh $i "hostname"`
  status=`echo $check | awk '{print $1}'`
  if [ $status == "ERROR!" ] ; then
   ssh $i 'rm -rf /var/lib/mysql/node*.pid;/etc/init.d/mysql start'
   sysbench --test=sysbench_tests/db/oltp.lua --mysql-host=$i --mysql-user=$dbuser   --num-threads=10    --oltp-tables-count=10 --mysql-db=pxc_test --oltp-table-size=50000 --report-interval=1 --max-requests=0 --tx-rate=100 run | grep tps > /dev/null 2>&1 &
   rm -rf $node.log
   myq_status -u test -h $i -t 1 wsrep > $node.log &
   echo $! >> myq_status_pid.txt
  fi
 done
 ssh root@${nodes[1]} '/etc/init.d/mysql stop'
 sleep 120
 strt=`eval date +'%H:%M'`
 sleep 60
 stop=`eval date +'%H:%M'`
 sed -n "/$strt/ , /$stop/p" node1.log > check-node1.log
 sed -n "/$strt/ , /$stop/p" node2.log > check-node2.log
 sed -n "/$strt/ , /$stop/p" node3.log > check-node3.log


 node1_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node1.log`
 node2_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node2.log`
 node3_up=`awk '{ if ( substr($11,length($11),1) == "K" )  sum += $11 * 1024 ;else if (substr($11,length($11),1) == "M")  sum += $11 * 1024 * 1024 ; else if ($11 ~ /[0-9]/) sum += $11 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node3.log`
 node1_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node1.log`
 node2_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node2.log`
 node3_dn=`awk '{ if ( substr($12,length($12),1) == "K" )  sum += $12 * 1024 ;else if (substr($12,length($12),1) == "M")  sum += $12 * 1024 * 1024 ; else if ($12 ~ /[0-9]/) sum += $12 fi } END {printf ("%0.2f\n",sum /1024/1024)}' check-node3.log`

 echo -e "\n\n****************************** PXC Single node failure status  *****************************************\n" >> script_out.log
 printf "|%-10s %-21s *%-20s |%-20s *%-20s |\n" "" "Normal" "" "NW pkt re-ordering" "" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 header1="|%-10s |%-20s |%-20s |%-20s |%-20s |\n"
 printf "$header1" "Nodes" "Upload Rate(KB)" "Download Rate(KB)" "Upload Rate(KB)" "Download Rate(KB)" >> script_out.log
 echo -e "----------------------------------------------------------------------------------------------------------" >> script_out.log
 printf "$header1" "Node 1" $bnode1_up $bnode1_dn $node1_up $node1_dn >> script_out.log
 printf "$header1" "Node 2" $bnode2_up $bnode2_dn $node2_up $node2_dn >> script_out.log
 printf "$header1" "Node 3" $bnode3_up $bnode3_dn $node3_up $node3_dn >> script_out.log

 echo -e "\n\n" >> script_out.log
 checkPXC
 printf "$header" "Nodes" "wsrep_cluster_status" "wsrep_local_state" >> script_out.log
 echo -e "--------------------------------------------------------------------------" >> script_out.log
 printf "$header" "Node 1" ${cluster_status[0]} ${state_comment[0]} >> script_out.log
 printf "$header" "Node 2" ${cluster_status[1]} ${state_comment[1]} >> script_out.log
 printf "$header" "Node 3" ${cluster_status[2]} ${state_comment[2]} >> script_out.log 
  
}

singleNodefailure

NWdelay 1000
NWdelay 3000
NWdelay 5000

NWpacketloss 10%
NWpacketloss 20%

NWpkt_corruption 0.5%
NWpkt_corruption 5%
NWpkt_corruption 10%

NWpkt_reordering 10% 25%
NWpkt_reordering 25% 50%

kill -9 `cat myq_status_pid.txt` 2>&1
pkill sysbench