[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-ha-dev
Subject:    [Linux-ha-dev] Patch to mysql RA for replication
From:       Yves Trudeau <y.trudeau () videotron ! ca>
Date:       2012-04-18 22:25:39
Message-ID: 4F8F3F63.3080601 () videotron ! ca
[Download RAW message or body]

Hi Dejan,
   here's my patch to the mysql agent in the commit version 4c18035. 
Sorry for being inept with git.

Included here:

- attribute for replication_info
- put in a variable error code 1040
- put in a variable the long call to crm_attribute for replication_info
- cleanup loglevel
- defined a value for DEBUG_LOG

Like I wrote before, I didn't find any solution yet to remove the IP 
attribute for each node.  Using a replication_VIP breaks the operation 
of the agent as it removes the easy way to add new nodes (or rejoin)

Regards,

Yves

["patch.ra.mysql" (text/plain)]

--- mysql.old	2012-04-13 03:19:42.058422681 -0400
+++ mysql	2012-04-18 18:16:46.898421243 -0400
@@ -79,6 +79,7 @@
 OCF_RESKEY_max_slave_lag_default="3600"
 OCF_RESKEY_evict_outdated_slaves_default="false"
 OCF_RESKEY_reader_attribute_default="readable"
+OCF_RESKEY_replication_info_attribute_default="replication_info"
 
 : ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
 MYSQL_BINDIR=`dirname ${OCF_RESKEY_binary}`
@@ -109,7 +110,8 @@
 : ${OCF_RESKEY_max_slave_lag=${OCF_RESKEY_max_slave_lag_default}}
 : ${OCF_RESKEY_evict_outdated_slaves=${OCF_RESKEY_evict_outdated_slaves_default}}
 
-: ${OCF_RESKEY_reader_attribute=${OCF_RESKEY_evict_reader_attribute_default}}
+: ${OCF_RESKEY_reader_attribute=${OCF_RESKEY_reader_attribute_default}}
+: ${OCF_RESKEY_replication_info_attribute=${OCF_RESKEY_replication_info_attribute_default}}
  
 #######################################################################
 
@@ -328,7 +330,19 @@
 </longdesc>
 <shortdesc lang="en">Sets the node attribute that determines
 whether a node is usable for clients to read from.</shortdesc>
-<content type="boolean" default="${OCF_RESKEY_reader_attribute_default}" />
+<content type="string" default="${OCF_RESKEY_reader_attribute_default}" />
+</parameter>
+
+<parameter name="replication_info_attribute" unique="1" required="0">
+<longdesc lang="en">
+An attribute that stores the current master IP, replication file and position. 
+This is queried by the agent in the post-promote notification
+to reconnect the slaves to the new master.
+
+This parameter is only meaningful in master/slave set configurations.
+</longdesc>
+<shortdesc lang="en">Cluster attribute storing replication information</shortdesc>
+<content type="string" default="${OCF_RESKEY_replication_info_attribute_default}" />
 </parameter>
 </parameters>
 
@@ -355,10 +369,12 @@
 MYSQL_OPTIONS_LOCAL="-S $OCF_RESKEY_socket --connect_timeout=10"
 MYSQL_OPTIONS_REPL="$MYSQL_OPTIONS_LOCAL --user=$OCF_RESKEY_replication_user \
--password=$OCF_RESKEY_replication_passwd"  MYSQL_OPTIONS_TEST="$MYSQL_OPTIONS_LOCAL \
--user=$OCF_RESKEY_test_user --password=$OCF_RESKEY_test_passwd" \
+MYSQL_TOO_MANY_CONN_ERR=1040  
 CRM_MASTER="${HA_SBIN_DIR}/crm_master -l reboot "
 HOSTNAME=`uname -n`
 CRM_ATTR="${HA_SBIN_DIR}/crm_attribute -N $HOSTNAME "
+CRM_ATTR_REPL_INFO="${HA_SBIN_DIR}/crm_attribute --type crm_config --name \
${OCF_RESKEY_replication_info_attribute} -s mysql_replication --query  -q"  \
INSTANCE_ATTR_NAME=`echo ${OCF_RESOURCE_INSTANCE}| awk -F : '{print $1}'`  
 #######################################################################
@@ -468,7 +484,7 @@
 
     if [ $rc -eq 0 ]; then
         # Did we receive an error other than max_connections?
-        if [ $last_errno -ne 0 -a $last_errno -ne 1040 ]; then
+        if [ $last_errno -ne 0 -a $last_errno -ne "$MYSQL_TOO_MANY_CONN_ERR" ]; then
             # Whoa. Replication ran into an error. This slave has
             # diverged from its master. Make sure this resource
             # doesn't restart in place.
@@ -484,7 +500,7 @@
         fi
 
         # If we got max_connections, let's remove the vip
-        if [ $last_errno -eq 1040 ]; then
+        if [ $last_errno -eq "$MYSQL_TOO_MANY_CONN_ERR" ]; then
             set_reader_attr 0
             exit $OCF_SUCCESS
         fi
@@ -496,7 +512,7 @@
             ocf_log warn "MySQL Slave IO threads currently not running."
 
             # Sanity check, are we at least on the right master
-            new_master_IP=`${HA_SBIN_DIR}/crm_attribute --type crm_config --name \
replication_info -s mysql_replication --query  -q | cut -d'|' -f1` +            \
new_master_IP=`$CRM_ATTR_REPL_INFO | cut -d'|' -f1`  
             if [ "$master_host" != "$new_master_IP" ]; then
                # Not pointing to the right master, not good, removing the VIPs
@@ -573,7 +589,7 @@
     local new_master_IP master_log_file master_log_pos
     local master_params
 
-    new_master_IP=`${HA_SBIN_DIR}/crm_attribute --type crm_config --name \
replication_info -s mysql_replication --query  -q | cut -d'|' -f1` +    \
new_master_IP=`$CRM_ATTR_REPL_INFO | cut -d'|' -f1`  
     # Keep replication position
     get_slave_info
@@ -585,8 +601,8 @@
         rm -f $tmpfile
         return
     else
-        master_log_file=`${HA_SBIN_DIR}/crm_attribute --type crm_config --name \
                replication_info -s mysql_replication --query  -q | cut -d'|' -f2`
-        master_log_pos=`${HA_SBIN_DIR}/crm_attribute --type crm_config --name \
replication_info -s mysql_replication --query  -q | cut -d'|' -f3` +        \
master_log_file=`$CRM_ATTR_REPL_INFO | cut -d'|' -f2` +        \
master_log_pos=`$CRM_ATTR_REPL_INFO | cut -d'|' -f3`  if [ -n "$master_log_file" -a \
-n "$master_log_pos" ]; then  master_params=", MASTER_LOG_FILE='$master_log_file', \
             MASTER_LOG_POS=$master_log_pos"
@@ -805,14 +821,8 @@
 
 mysql_monitor() {
     local rc
-    local status_loglevel="err"
-
-    # Set loglevel to info during probe
-    if ocf_is_probe; then
-        status_loglevel="info"
-    fi
 
-    mysql_status $status_loglevel
+    mysql_status 
     rc=$?
 
     # TODO: check max connections error
@@ -1053,7 +1063,7 @@
     # Set Master Info in CIB, cluster level attribute
     update_data_master_status
     master_info="$(get_local_ip)|$(get_master_status File)|$(get_master_status \
                Position)"
-    ${HA_SBIN_DIR}/crm_attribute --type crm_config --name replication_info -s \
mysql_replication -v "$master_info" +    ${HA_SBIN_DIR}/crm_attribute --type \
crm_config --name ${OCF_RESKEY_replication_info_attribute} -s mysql_replication -v \
"$master_info"  rm -f $tmpfile
 
     set_read_only off || return $OCF_ERR_GENERIC
@@ -1177,6 +1187,7 @@
 # The log directory must be a directory owned by root, with permissions 0700,
 # and the log must be writable and not a symlink.
 ##########################################################################
+DEBUG_LOG="/tmp/mysql.ocf.ra.debug/log"
 if [ "${DEBUG_LOG}" -a -w "${DEBUG_LOG}" -a ! -L "${DEBUG_LOG}" ]; then
     DEBUG_LOG_DIR="${DEBUG_LOG%/*}"
     if [ -d "${DEBUG_LOG_DIR}" ]; then



_______________________________________________________
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/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic