Blame SOURCES/bz1284526-galera-heuristic-recovered.patch

7a920e
From 4d98bbcdadda60166faf7ccc512b9095b439e2bd Mon Sep 17 00:00:00 2001
7a920e
From: Damien Ciabrini <dciabrin@redhat.com>
7a920e
Date: Tue, 2 Feb 2016 16:29:10 +0100
7a920e
Subject: [PATCH] galera: prevent recovered nodes from bootstrapping cluster
7a920e
 when possible
7a920e
7a920e
---
7a920e
 heartbeat/README.galera | 19 ++++++++++++++++++-
7a920e
 heartbeat/galera        | 41 +++++++++++++++++++++++++++++++++++++++++
7a920e
 2 files changed, 59 insertions(+), 1 deletion(-)
7a920e
7a920e
diff --git a/heartbeat/galera b/heartbeat/galera
7a920e
index ca94c21..84c92fd 100755
7a920e
--- a/heartbeat/galera
7a920e
+++ b/heartbeat/galera
7a920e
@@ -276,6 +276,22 @@ is_bootstrap()
7a920e
 
7a920e
 }
7a920e
 
7a920e
+set_heuristic_recovered()
7a920e
+{
7a920e
+    ${HA_SBIN_DIR}/crm_attribute -N $NODENAME -l reboot --name "${INSTANCE_ATTR_NAME}-heuristic-recovered" -v "true"
7a920e
+}
7a920e
+
7a920e
+clear_heuristic_recovered()
7a920e
+{
7a920e
+    ${HA_SBIN_DIR}/crm_attribute -N $NODENAME -l reboot --name "${INSTANCE_ATTR_NAME}-heuristic-recovered" -D
7a920e
+}
7a920e
+
7a920e
+is_heuristic_recovered()
7a920e
+{
7a920e
+    local node=$1
7a920e
+    ${HA_SBIN_DIR}/crm_attribute -N $node -l reboot --name "${INSTANCE_ATTR_NAME}-heuristic-recovered" -Q 2>/dev/null
7a920e
+}
7a920e
+
7a920e
 clear_last_commit()
7a920e
 {
7a920e
     ${HA_SBIN_DIR}/crm_attribute -N $NODENAME -l reboot --name "${INSTANCE_ATTR_NAME}-last-committed" -D
7a920e
@@ -398,8 +414,19 @@ detect_first_master()
7a920e
     local best_node="$NODENAME"
7a920e
     local last_commit=0
7a920e
     local missing_nodes=0
7a920e
+    local nodes=""
7a920e
+    local nodes_recovered=""
7a920e
 
7a920e
+    # avoid selecting a recovered node as bootstrap if possible
7a920e
     for node in $(echo "$OCF_RESKEY_wsrep_cluster_address" | sed 's/gcomm:\/\///g' | tr -d ' ' | tr -s ',' ' '); do
7a920e
+        if is_heuristic_recovered $node; then
7a920e
+            nodes_recovered="$nodes_recovered $node"
7a920e
+        else
7a920e
+            nodes="$nodes $node"
7a920e
+        fi
7a920e
+    done
7a920e
+
7a920e
+    for node in $nodes_recovered $nodes; do
7a920e
         last_commit=$(get_last_commit $node)
7a920e
 
7a920e
         if [ -z "$last_commit" ]; then
7a920e
@@ -466,6 +493,12 @@ detect_last_commit()
7a920e
                                      --tc-heuristic-recover=rollback > $tmp 2>/dev/null
7a920e
 
7a920e
                 last_commit="$(cat $tmp | sed -n $recovered_position_regex)"
7a920e
+                if [ ! -z "$last_commit" ]; then
7a920e
+                    ocf_log warn "State recovered. force SST at next restart for full resynchronization"
7a920e
+                    rm -f ${OCF_RESKEY_datadir}/grastate.dat
7a920e
+                    # try not to use this node if bootstrap is needed
7a920e
+                    set_heuristic_recovered
7a920e
+                fi
7a920e
             fi
7a920e
         fi
7a920e
         rm -f $tmp $tmperr
7a920e
@@ -549,11 +582,17 @@ galera_promote()
7a920e
     if ocf_is_true $bootstrap; then
7a920e
         promote_everyone
7a920e
         clear_bootstrap_node
7a920e
+        # clear attribute heuristic-recovered. if last shutdown was
7a920e
+        # not clean, we cannot be extra-cautious by requesting a SST
7a920e
+        # since this is the bootstrap node
7a920e
+        clear_heuristic_recovered
7a920e
         ocf_log info "Bootstrap complete, promoting the rest of the galera instances."
7a920e
     else
7a920e
         # if this is not the bootstrap node, make sure this instance
7a920e
         # syncs with the rest of the cluster before promotion returns.
7a920e
         wait_for_sync
7a920e
+        # sync is done, clear info about last recovery
7a920e
+        clear_heuristic_recovered
7a920e
     fi
7a920e
 
7a920e
     ocf_log info "Galera started"