Blame SOURCES/bz1451097-2-galera-fix-bootstrap-when-cluster-has-no-data.patch

79554c
From a05eb8673bd1d5d3d41f2ed39df2650b19681d08 Mon Sep 17 00:00:00 2001
79554c
From: Damien Ciabrini <dciabrin@redhat.com>
79554c
Date: Fri, 3 Mar 2017 15:31:30 +0100
79554c
Subject: [PATCH] galera: fix the first bootstrap when cluster has no data
79554c
79554c
The resource agent selects the first node to go into Master state
79554c
based on the biggest commit version found on each node. If case no
79554c
data were written yet into the galera cluster, the current node is
79554c
selected as a "fallback" node to bootstrap the cluster.
79554c
79554c
The way the "fallback" node is selected is wrong because every node
79554c
takes a different decision, and this ultimately yields to 3
79554c
single-node galera clusters being started. To fix that, let the
79554c
"fallback" node be the last one in the wsrep_cluster_address, so that
79554c
the selection algorithm yields coherent results across nodes.
79554c
---
79554c
 heartbeat/galera | 14 ++++++++++++--
79554c
 1 file changed, 12 insertions(+), 2 deletions(-)
79554c
79554c
diff --git a/heartbeat/galera b/heartbeat/galera
79554c
index decbaa2..475a8ba 100755
79554c
--- a/heartbeat/galera
79554c
+++ b/heartbeat/galera
79554c
@@ -451,14 +451,24 @@ pcmk_to_galera_name()
79554c
 detect_first_master()
79554c
 {
79554c
     local best_commit=0
79554c
-    local best_node="$NODENAME"
79554c
     local last_commit=0
79554c
     local missing_nodes=0
79554c
     local nodes=""
79554c
     local nodes_recovered=""
79554c
+    local all_nodes
79554c
+    local best_node_gcomm
79554c
+    local best_node
79554c
+
79554c
+    all_nodes=$(echo "$OCF_RESKEY_wsrep_cluster_address" | sed 's/gcomm:\/\///g' | tr -d ' ' | tr -s ',' ' ')
79554c
+    best_node_gcomm=$(echo "$all_nodes" | sed 's/^.* \(.*\)$/\1/')
79554c
+    best_node=$(galera_to_pcmk_name $best_node_gcomm)
79554c
+    if [ -z "$best_node" ]; then
79554c
+        ocf_log error "Could not determine initial best node from galera name <${best_node_gcomm}>."
79554c
+        return
79554c
+    fi
79554c
 
79554c
     # avoid selecting a recovered node as bootstrap if possible
79554c
-    for node in $(echo "$OCF_RESKEY_wsrep_cluster_address" | sed 's/gcomm:\/\///g' | tr -d ' ' | tr -s ',' ' '); do
79554c
+    for node in $all_nodes; do
79554c
         local pcmk_node=$(galera_to_pcmk_name $node)
79554c
         if [ -z "$pcmk_node" ]; then
79554c
             ocf_log error "Could not determine pacemaker node from galera name <${node}>."