Hi Dejan,
here's the patch for Raoul comments. The patch is over git://github.com/ClusterLabs/resource-agents.git commit bc1991fd0e

commit message:

Better reset slave handling and cleanup for get_slave_info


Regards,

Yves

Le 2012-05-18 11:13, Dejan Muhamedagic a écrit :
On Fri, May 18, 2012 at 10:08:54AM -0400, Yves Trudeau wrote:
Hi Raoul and Dejan,
   I completely forgot about this one but I am wondering about the
impacts.  I have many setups in production and none reported any
problem related to this.  The fix pretty easy though, Dejan, is it
too late to submit a patch?

No, if the patch is fine. Up to you. It's very mysql-specific,
cannot offer much help.
_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

--- mysql.bc1991fd0e    2012-05-18 11:30:51.358422574 -0400
+++ resource-agents-prm/heartbeat/mysql 2012-05-18 11:32:38.418420112 -0400
@@ -413,23 +413,27 @@
 
     # Check whether this machine should be slave
     if ! ocf_is_ms || ! get_read_only; then
-        return 1;
+        return 1
     fi
+   
+    get_slave_info
+    rc=$?
 
-    tmpfile=`mktemp ${HA_RSCTMP}/is_slave.${OCF_RESOURCE_INSTANCE}.XXXXXX`
-
-    $MYSQL $MYSQL_OPTIONS_REPL \
-    -e 'SHOW SLAVE STATUS\G' > $tmpfile
-
-    # "SHOW SLAVE STATUS" returns an empty set if instance is not a
-    # replication slave
-    if [ -s $tmpfile ]; then
-        rm -f $tmpfile
-        return 0
+    if [ $rc -eq 0 ]; then
+       # show slave status is not empty
+       # Is there a master_log_file defined?  (master_log_file is deleted 
+       # by reset slave
+       if [ "$master_log_file" ]; then
+          return 0
+       else
+          return 1
+       fi
+    else
+       # "SHOW SLAVE STATUS" returns an empty set if instance is not a
+       # replication slave
+       return 1
     fi
-
-    rm -f $tmpfile
-    return 1
+    
 }
 
 parse_slave_info() {
@@ -440,31 +444,36 @@
 get_slave_info() {
     # Warning: this sets $tmpfile and LEAVE this file! You must delete it 
after use!
     local mysql_options
+            
+    if [ "$master_log_file" -a "$master_host" ]; then
+        # variables are already defined, get_slave_info has been run before
+        return $OCF_SUCCESS
+    else
+        tmpfile=`mktemp 
${HA_RSCTMP}/check_slave.${OCF_RESOURCE_INSTANCE}.XXXXXX`
 
-    tmpfile=`mktemp ${HA_RSCTMP}/check_slave.${OCF_RESOURCE_INSTANCE}.XXXXXX`
+        $MYSQL $MYSQL_OPTIONS_REPL \
+        -e 'SHOW SLAVE STATUS\G' > $tmpfile
 
-    $MYSQL $MYSQL_OPTIONS_REPL \
-    -e 'SHOW SLAVE STATUS\G' > $tmpfile
+        if [ -s $tmpfile ]; then
+            master_host=`parse_slave_info Master_Host $tmpfile`
+            master_user=`parse_slave_info Master_User $tmpfile`
+            master_port=`parse_slave_info Master_Port $tmpfile`
+            master_log_file=`parse_slave_info Master_Log_File $tmpfile`
+            master_log_pos=`parse_slave_info Read_Master_Log_Pos $tmpfile`
+            slave_sql=`parse_slave_info Slave_SQL_Running $tmpfile`
+            slave_io=`parse_slave_info Slave_IO_Running $tmpfile`
+            last_errno=`parse_slave_info Last_Errno $tmpfile`
+            secs_behind=`parse_slave_info Seconds_Behind_Master $tmpfile`
+            ocf_log debug "MySQL instance running as a replication slave"
+        else
+            # Instance produced an empty "SHOW SLAVE STATUS" output --
+            # instance is not a slave
+            ocf_log err "check_slave invoked on an instance that is not a 
replication slave."
+            return $OCF_ERR_GENERIC
+        fi
 
-    if [ -s $tmpfile ]; then
-        master_host=`parse_slave_info Master_Host $tmpfile`
-        master_user=`parse_slave_info Master_User $tmpfile`
-        master_port=`parse_slave_info Master_Port $tmpfile`
-        master_log_file=`parse_slave_info Master_Log_File $tmpfile`
-        master_log_pos=`parse_slave_info Read_Master_Log_Pos $tmpfile`
-        slave_sql=`parse_slave_info Slave_SQL_Running $tmpfile`
-        slave_io=`parse_slave_info Slave_IO_Running $tmpfile`
-        last_errno=`parse_slave_info Last_Errno $tmpfile`
-        secs_behind=`parse_slave_info Seconds_Behind_Master $tmpfile`
-        ocf_log debug "MySQL instance running as a replication slave"
-    else
-        # Instance produced an empty "SHOW SLAVE STATUS" output --
-        # instance is not a slave
-        ocf_log err "check_slave invoked on an instance that is not a 
replication slave."
-        return $OCF_ERR_GENERIC
+        return $OCF_SUCCESS
     fi
-
-    return $OCF_SUCCESS
 }
 
 check_slave() {
@@ -692,7 +701,7 @@
     ocf_run $MYSQL $MYSQL_OPTIONS_REPL \
         -e "RESET SLAVE;"
     if [ $? -gt 0 ]; then
-        ocf_log err "Failed to set master"
+        ocf_log err "Failed to reset slave"
         exit $OCF_ERR_GENERIC
     fi
 }
_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to