Blame SOURCES/bz1391470-galera-last-commit-fix-for-mariadb-10.1.18.patch

15862b
From 4e62e214f560c68f037d7a4730076ddc6ee72301 Mon Sep 17 00:00:00 2001
15862b
From: Damien Ciabrini <dciabrin@redhat.com>
15862b
Date: Thu, 17 Nov 2016 22:19:56 +0100
15862b
Subject: [PATCH] galera: make last commit parsing compatible with mariadb
15862b
 10.1.18+
15862b
15862b
---
15862b
 heartbeat/galera | 39 +++++++++++++++++++++------------------
15862b
 1 file changed, 21 insertions(+), 18 deletions(-)
15862b
15862b
diff --git a/heartbeat/galera b/heartbeat/galera
15862b
index 543200d..44c52a5 100755
15862b
--- a/heartbeat/galera
15862b
+++ b/heartbeat/galera
15862b
@@ -662,13 +662,13 @@ detect_last_commit()
15862b
                         --socket=$OCF_RESKEY_socket \
15862b
                         --datadir=$OCF_RESKEY_datadir \
15862b
                         --user=$OCF_RESKEY_user"
15862b
+    local recovery_file_regex='s/.*WSREP\:.*position\s*recovery.*--log_error='\''\([^'\'']*\)'\''.*/\1/p'
15862b
     local recovered_position_regex='s/.*WSREP\:\s*[R|r]ecovered\s*position.*\:\(.*\)\s*$/\1/p'
15862b
 
15862b
     ocf_log info "attempting to detect last commit version by reading ${OCF_RESKEY_datadir}/grastate.dat"
15862b
     last_commit="$(cat ${OCF_RESKEY_datadir}/grastate.dat | sed -n 's/^seqno.\s*\(.*\)\s*$/\1/p')"
15862b
     if [ -z "$last_commit" ] || [ "$last_commit" = "-1" ]; then
15862b
         local tmp=$(mktemp)
15862b
-        local tmperr=$(mktemp)
15862b
 
15862b
         # if we pass here because grastate.dat doesn't exist,
15862b
         # try not to bootstrap from this node if possible
15862b
@@ -678,33 +678,36 @@ detect_last_commit()
15862b
 
15862b
         ocf_log info "now attempting to detect last commit version using 'mysqld_safe --wsrep-recover'"
15862b
 
15862b
-        ${OCF_RESKEY_binary} $recover_args --wsrep-recover > $tmp 2> $tmperr
15862b
+        ${OCF_RESKEY_binary} $recover_args --wsrep-recover --log-error=$tmp 2>/dev/null
15862b
 
15862b
-        last_commit="$(cat $tmp | sed -n $recovered_position_regex)"
15862b
+        last_commit="$(cat $tmp | sed -n $recovered_position_regex | tail -1)"
15862b
         if [ -z "$last_commit" ]; then
15862b
             # Galera uses InnoDB's 2pc transactions internally. If
15862b
             # server was stopped in the middle of a replication, the
15862b
             # recovery may find a "prepared" XA transaction in the
15862b
             # redo log, and mysql won't recover automatically
15862b
 
15862b
-            cat $tmperr | grep -q -E '\[ERROR\]\s+Found\s+[0-9]+\s+prepared\s+transactions!' 2>/dev/null
15862b
-            if [ $? -eq 0 ]; then
15862b
-                # we can only rollback the transaction, but that's OK
15862b
-                # since the DB will get resynchronized anyway
15862b
-                ocf_log warn "local node <${NODENAME}> was not shutdown properly. Rollback stuck transaction with --tc-heuristic-recover"
15862b
-                ${OCF_RESKEY_binary} $recover_args --wsrep-recover \
15862b
-                                     --tc-heuristic-recover=rollback > $tmp 2>/dev/null
15862b
-
15862b
-                last_commit="$(cat $tmp | sed -n $recovered_position_regex)"
15862b
-                if [ ! -z "$last_commit" ]; then
15862b
-                    ocf_log warn "State recovered. force SST at next restart for full resynchronization"
15862b
-                    rm -f ${OCF_RESKEY_datadir}/grastate.dat
15862b
-                    # try not to bootstrap from this node if possible
15862b
-                    set_no_grastate
15862b
+            local recovery_file="$(cat $tmp | sed -n $recovery_file_regex)"
15862b
+            if [ -e $recovery_file ]; then
15862b
+                cat $recovery_file | grep -q -E '\[ERROR\]\s+Found\s+[0-9]+\s+prepared\s+transactions!' 2>/dev/null
15862b
+                if [ $? -eq 0 ]; then
15862b
+                    # we can only rollback the transaction, but that's OK
15862b
+                    # since the DB will get resynchronized anyway
15862b
+                    ocf_log warn "local node <${NODENAME}> was not shutdown properly. Rollback stuck transaction with --tc-heuristic-recover"
15862b
+                    ${OCF_RESKEY_binary} $recover_args --wsrep-recover \
15862b
+                                         --tc-heuristic-recover=rollback --log-error=$tmp 2>/dev/null
15862b
+
15862b
+                    last_commit="$(cat $tmp | sed -n $recovered_position_regex | tail -1)"
15862b
+                    if [ ! -z "$last_commit" ]; then
15862b
+                        ocf_log warn "State recovered. force SST at next restart for full resynchronization"
15862b
+                        rm -f ${OCF_RESKEY_datadir}/grastate.dat
15862b
+                        # try not to bootstrap from this node if possible
15862b
+                        set_no_grastate
15862b
+                    fi
15862b
                 fi
15862b
             fi
15862b
         fi
15862b
-        rm -f $tmp $tmperr
15862b
+        rm -f $tmp
15862b
     fi
15862b
 
15862b
     if [ ! -z "$last_commit" ]; then