# HG changeset patch
# User Marian Marinov <[email protected]>
# Date 1268837185 -7200
# Branch mysql-ms
# Node ID 13e001a78d4ae612797024bf8abebe997bb6eed8
# Parent  94532073f46a421cf6ee753ee3d7013b9860ab61
Medium: RA: mysql: fixed bug with missing arguments from mysql show 
master/slave status

The bug was that within a loop you are in a subshell and so the variables are
not reachable from the outside and we can't add their values to the global
variables. This commit fixes this bug by changing the ware the values are
gathered to using "set -- $(command)".

This commit also fixes one portability issue, grep -P was replaced by grep -E.

diff -r 94532073f46a -r 13e001a78d4a heartbeat/mysql
--- a/heartbeat/mysql   Wed Mar 17 13:17:55 2010 +0200
+++ b/heartbeat/mysql   Wed Mar 17 16:46:25 2010 +0200
@@ -135,7 +135,7 @@
 It manages a MySQL Database instance as an HA resource.
 Note: if you use this RA for a MS resource you have to have
 the root password for your mysql configured in /root/.my.cnf.
-This is required, since this is the best secure way of supplying 
+This is required, since this is the best secure way of supplying
 the root password to the mysql cli.
 </longdesc>
 <shortdesc lang="en">Manages a MySQL database instance</shortdesc>
@@ -336,18 +336,12 @@
 }
 
 is_slave() {
-    master_host=''
-    master_user=''
-    master_port=''
-    slave_sql=''
-    slave_io=''
-    for i in $(mysql -S $OCF_RESKEY_socket -O connect_timeout=1 -e 'SHOW SLAVE 
STATUS\G'|grep -P 'Running|Master_[UHP]'); do
-       if ( echo $i | grep 'Master_Host:' > /dev/null ); then 
master_host=$(echo $i|sed 's/^.*: //'); fi
-       if ( echo $i | grep 'Master_User:' > /dev/null ); then 
master_user=$(echo $i|sed 's/^.*: //'); fi
-       if ( echo $i | grep 'Master_Port:' > /dev/null ); then 
master_port=$(echo $i|sed 's/^.*: //'); fi
-       if ( echo $i | grep 'Slave_IO_Running:' > /dev/null ); then 
slave_io=$(echo $i|sed 's/^.*: //'); fi
-       if ( echo $i | grep 'Slave_SQL_Running:' > /dev/null ); then 
slave_sql=$(echo $i|sed 's/^.*: //'); fi
-    done
+       set -- $(mysql -S $OCF_RESKEY_socket -O connect_timeout=1 -e 'show 
slave status\G'|grep -E 'Running|Master_[UHP]')
+       master_host=$1
+       master_user=$2
+       master_port=$3
+       slave_sql=$4
+       slave_io=$5
 
     if [ -z "$master_host" ] || [ -z "$master_user" ] || [ -z "$master_port" ] 
|| [ -z "$slave_io" ] || [ -z "$slave_sql" ]; then
         ocf_log err "unable to get slave status value"
@@ -516,7 +510,7 @@
        fi
         sleep 2
     done
-       
+
        if ocf_is_ms; then
                mysql -S $OCF_RESKEY_socket -O connect_timeout=1 -e 'SET GLOBAL 
read_only=on';
        fi
@@ -612,21 +606,18 @@
        else
                if [ -z "$master_host" ]; then  return $OCF_ERR_GENERIC; fi
 
-               master_file=''
+               master_log=''
                master_pos=''
-               oldIFS="$IFS"
-               IFS=$'\n'
-               for i in $(mysql -u $OCF_RESKEY_replication_user \
+               set -- $(mysql -B -N
+                       -u $OCF_RESKEY_replication_user \
                        --password=$OCF_RESKEY_replication_passwd \
                        -h $master_host \
                        -O connect_timeout=1 \
-                       -e 'SHOW MASTER STATUS\G'); do
-               if ( echo $i | grep 'File:' > /dev/null ); then 
master_file=$(echo $i|sed 's/^.*: //'); fi
-               if ( echo $i | grep 'Position:' > /dev/null ); then 
master_pos=$(echo $i|sed 's/^.*: //'); fi
-        done
-               IFS="$oldIFS"
+                       -e 'SHOW MASTER STATUS')
+               master_log=$1
+               master_pos=$2
 
-        if [ -z "$master_file" ] || [ -z "$master_pos" ]; then
+        if [ -z "$master_log" ] || [ -z "$master_pos" ]; then
             ocf_log err "unable to find master file or master position"
             return $OCF_ERR_GENERIC;
         fi
@@ -637,7 +628,7 @@
                                MASTER_USER='$OCF_RESKEY_replication_user', \
                                
MASTER_PASSWORD='$OCF_RESKEY_replication_passwd', \
                                MASTER_PORT=$OCF_RESKEY_replication_port, \
-                               MASTER_LOG_FILE='$master_file', \
+                               MASTER_LOG_FILE='$master_log', \
                                MASTER_LOG_POS=$master_pos, \
                                MASTER_CONNECT_RETRY=4"
                mysql --socket=$OCF_RESKEY_socket -O connect_timeout=1 -e 
'START SLAVE';
@@ -654,17 +645,14 @@
        master_log=''
        master_pos=''
 
-       oldIFS="$IFS"
-       IFS=$'\n'
-       for i in $(mysql --password=$OCF_RESKEY_replication_passwd \
+       set -- $(mysql -B -N
+               --password=$OCF_RESKEY_replication_passwd \
                -u $OCF_RESKEY_replication_user \
                -h $master_host \
                -O connect_timeout=1 \
-               -e 'SHOW MASTER STATUS\G'); do
-       if ( echo $i | grep 'File:' > /dev/null ); then master_log=$(echo 
$i|sed 's/^.*: //'); fi
-       if ( echo $i | grep 'Position:' > /dev/null ); then master_pos=$(echo 
$i|sed 's/^.*: //'); break; fi
-       done
-       IFS="$oldIFS"
+               -e 'SHOW MASTER STATUS')
+       master_log=$1
+       master_pos=$2
 
        if [ -z "$master_log" ] || [ -z "$master_pos" ]; then
                ocf_log warn "unable to find master file or master position"
@@ -674,13 +662,20 @@
        local_log=''
        local_pos=''
        exec_pos=''
-       IFS=$'\n'
-       for i in $(mysql -S $OCF_RESKEY_socket -O connect_timeout=1 -e 'SHOW 
SLAVE STATUS\G'|grep Master_Log); do
-       if ( echo $i | grep 'Master_Log_File:' > /dev/null ); then 
local_log=$(echo $i|sed 's/^.*: //'); fi
-           if ( echo $i | grep 'Read_Master_Log_Pos:' > /dev/null ); then 
local_pos=$(echo $i|sed 's/^.*: //'); fi
-           if ( echo $i | grep 'Exec_Master_Log_Pos:' > /dev/null ); then 
exec_pos=$(echo $i|sed 's/^.*: //'); break; fi
-       done
-       IFS="$oldIFS"
+       set -- $(mysql -S $OCF_RESKEY_socket -O connect_timeout=1 -e 'SHOW 
SLAVE STATUS\G'|grep Master_Log)
+       if [ "$1" != 'Master_Log_File:' ] || [ "$3" != 'Read_Master_Log_Pos:' ] 
&& ; then
+               ocf_log warn "unable to get slave status 
values(local_log|local_pos)"
+               return $OCF_SUCCESS
+       else
+               local_log=$2
+               local_pos=$4
+       fi
+       if [ "$6" == 'Exec_Master_Log_Pos:' ]; then
+               exec_pos=$7
+       fi
+       if [ "$7" == 'Exec_Master_Log_Pos:' ]; then
+               exec_pos=$8
+       fi
 
        if [ -z "$local_log" ] || [ -z "$local_pos" ] || [ -z "$exec_pos" ]; 
then
                ocf_log warn "unable to get slave status values"
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to