timelog=`date +%Y-%m-%d-%H:%M` count=$1 node=node1 next=node2 logname="kill_primary"_$timelog.log homedir=/home/hzwenzhh/innosqltest1 while true; do ret=`$homedir/mysql/bin/mysql -uroot -S $homedir/node1/mysql.sock -Bse "select count(*) from performance_schema.replication_group_members where MEMBER_STATE = 'ONLINE'"` time=`date +%Y-%m-%d-%H:%M:%S` if [ $ret -eq '3' ]; then $homedir/mysql/bin/mysql -uroot -S $homedir/node1/mysql.sock -Bse "select * from performance_schema.replication_group_members" >> $homedir/log/$logname echo "$time all node are online! start test" >> $homedir/log/$logname break else echo "$time some node still in recovering! waiting" >> $homedir/log/$logname fi sleep 5 done while [ $count -ge 1 ] do port=`$homedir/mysql/bin/mysql -uroot -S $homedir/node1/mysql.sock -Bse "select MEMBER_PORT from performance_schema.replication_group_members where MEMBER_ROLE = 'PRIMARY'"` echo "the primary port is $port" >> $homedir/log/$logname if [ $port -eq '20001' ]; then node=node1 next=node2 fi if [ $port -eq '20002' ]; then node=node2 next=node3 fi if [ $port -eq '20003' ]; then node=node3 next=node1 fi echo "round $count primary node $node--------------------" >> $homedir/log/$logname time=`date +%Y-%m-%d-%H:%M:%S` echo "$time sleep serval times " >> $homedir/log/$logname sleep 300 time=`date +%Y-%m-%d-%H:%M:%S` echo "$time begin kill mysqld" >> $homedir/log/$logname ps aux | grep innosqltest1 | grep node | grep hzwenzhh | grep -v grep >> $homedir/log/$logname time=`date +%Y-%m-%d-%H:%M:%S` # echo "$time set $next weight 60, let it be the next primary" >> $homedir/log/$logname # $homedir/mysql/bin/mysql -uroot -S $homedir/$next/mysql.sock -e "set global group_replication_member_weight=60" kill -9 `ps aux | grep innosqltest1 | grep $node | grep hzwenzhh | grep mysqld | grep -v grep | cut -c 9-15` echo "$time after kill mysqld" >> $homedir/log/$logname ps aux | grep innosqltest1 | grep node | grep hzwenzhh | grep -v grep >> $homedir/log/$logname rm $homedir/$node/data/mysql-err.log $homedir/mysql/bin/mysqld --defaults-file=$homedir/$node/$node.cnf & time=`date +%Y-%m-%d-%H:%M:%S` echo "$time wait mysqld alive" >> $homedir/log/$logname while true; do $homedir/mysql/bin/mysql -uroot -S $homedir/$node/mysql.sock -Bse "SELECT 1" mysql if [[ "$?" -eq 0 ]] then sleep 5 break fi sleep 5 done time=`date +%Y-%m-%d-%H:%M:%S` echo "$time begin start group_replication" >> $homedir/log/$logname $homedir/mysql/bin/mysql -uroot -S $homedir/$node/mysql.sock -e "start group_replication" time=`date +%Y-%m-%d-%H:%M:%S` echo "$time wait until the node online!" >> $homedir/log/$logname while true; do ret=`$homedir/mysql/bin/mysql -uroot -S $homedir/node1/mysql.sock -Bse "select count(*) from performance_schema.replication_group_members where MEMBER_STATE = 'ONLINE'"` time=`date +%Y-%m-%d-%H:%M:%S` if [ $ret -eq '3' ]; then $homedir/mysql/bin/mysql -uroot -S $homedir/node1/mysql.sock -Bse "select * from performance_schema.replication_group_members" >> $homedir/log/$logname echo "$time node $MEMBER_HOST is online!" >> $homedir/log/$logname break else echo "$time the node still in recovering!" >> $homedir/log/$logname fi sleep 5 done count=`expr $count - 1` time=`date +%Y-%m-%d-%H:%M:%S` echo "$time start next test or finish test!" >> $homedir/log/$logname echo "------------------------------" >> $homedir/log/$logname done