aboutsummaryrefslogtreecommitdiffstats
path: root/patches/fuel-library/upstream-backports/0001-Fix-mysql-OCF-race.patch
blob: 3159f53741c6c4d6cbbd69bac908e05d3c4959dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
From: Sergii Golovatiuk <sgolovatiuk@mirantis.com>
Date: Fri, 20 Jan 2017 20:09:13 +0100
Subject: [PATCH] Fix mysql OCF race

- Fix bug
- Fix issues found in bashate

Closes-Bug: #1658144

Change-Id: I93e9ab269d3ad4a285154fafcac6426ef36f6b52
---
 files/fuel-ha-utils/ocf/mysql-wss | 41 +++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/files/fuel-ha-utils/ocf/mysql-wss b/files/fuel-ha-utils/ocf/mysql-wss
index 64d3477..43e7f29 100755
--- a/files/fuel-ha-utils/ocf/mysql-wss
+++ b/files/fuel-ha-utils/ocf/mysql-wss
@@ -72,9 +72,9 @@ MYSQL=$OCF_RESKEY_client_binary
 HOSTNAME=$(uname -n)
 MYSQL_OPTIONS_LOCAL="-S $OCF_RESKEY_socket --connect_timeout=10"
 if [ "${OCF_RESKEY_test_conf}" ]; then
-  MYSQL_OPTIONS_TEST="--defaults-extra-file=${OCF_RESKEY_test_conf} ${MYSQL_OPTIONS_LOCAL}"
+    MYSQL_OPTIONS_TEST="--defaults-extra-file=${OCF_RESKEY_test_conf} ${MYSQL_OPTIONS_LOCAL}"
 else
-  MYSQL_OPTIONS_TEST="$MYSQL_OPTIONS_LOCAL --user=$OCF_RESKEY_test_user --password=$OCF_RESKEY_test_passwd"
+    MYSQL_OPTIONS_TEST="$MYSQL_OPTIONS_LOCAL --user=$OCF_RESKEY_test_user --password=$OCF_RESKEY_test_passwd"
 fi
 #######################################################################
 usage() {
@@ -337,7 +337,8 @@ clear_node_pc()

 get_master_timeout() {
     local LH="${LL} get_master_timeout():"
-    local timeout=$(crm_attribute --quiet --name galera_master_timeout \
+    local timeout
+    timeout=$(crm_attribute --quiet --name galera_master_timeout \
         --query --default=$OCF_RESKEY_master_timeout -q | sed -e '/(null)/d')

     ocf_log info "${LH} Setting timeout $timeout"
@@ -374,8 +375,8 @@ get_node_gtid_with_retry() {

     GTID=$(get_node_gtid $NODE)

-    if [ "$GTID"="0" ]; then
-        sleep $[ ( $RANDOM % 10 ) + 1]
+    if [ "$GTID" = "0" ]; then
+        sleep $(( ( $RANDOM % 10 )  + 1 ))
         GTID=$(get_node_gtid $NODE)
     fi

@@ -384,12 +385,16 @@ get_node_gtid_with_retry() {

 check_if_reelection_needed() {
     local LH="${LL} check_if_reelection_needed()"
-    local PARTITION_WITH_QUORUM=$(crm_node -q | sed -e '/(null)/d')
-    local RESOURCE_NAME=$(echo $OCF_RESOURCE_INSTANCE | cut -f1 -d":")
-    local NODE_COUNT=$(nodes_in_cluster | wc -w)
+    local PARTITION_WITH_QUORUM
+    local RESOURCE_NAME
+    local NODE_COUNT
     local RUNNING_INSTANCES
     local rc

+    PARTITION_WITH_QUORUM=$(crm_node -q | sed -e '/(null)/d')
+    RESOURCE_NAME=$(echo $OCF_RESOURCE_INSTANCE | cut -f1 -d":")
+    NODE_COUNT=$(nodes_in_cluster | wc -w)
+
     if [ $PARTITION_WITH_QUORUM -eq 1 -o $NODE_COUNT -eq 1 ]; then
         RUNNING_INSTANCES=$(crm_resource \
             --quiet --locate --resource $RESOURCE_NAME | sed -e '/(null)/d' | wc -l 2> /dev/null)
@@ -452,8 +457,7 @@ get_master() {
     ocf_log info "${LH} The most seen GTID is: ${MASTER_GTID}"
     for NODE in $NODES; do
         NODE_SCORE=$(crm_simulate -Ls | awk "/${OCF_RESOURCE_INSTANCE}/ && /clone_color/ && ! /${OCF_RESOURCE_INSTANCE}:/ && /${NODE}/ {print \$NF}")
-        if [[ $NODE_SCORE =~ ^-?[0-9]+$ && $NODE_SCORE -le 0 || $NODE_SCORE = "-INFINITY" || -z $NODE_SCORE ]]
-        then
+        if [[ $NODE_SCORE =~ ^-?[0-9]+$ && $NODE_SCORE -le 0 || $NODE_SCORE = "-INFINITY" || -z $NODE_SCORE ]]; then
             ocf_log info "${LH} Skipping node $NODE as it is not eligible for running the resource. Its score is ${NODE_SCORE:-NULL}"
             continue
         fi
@@ -487,11 +491,13 @@ check_if_galera_pc() {
     local LH="${LL} check_if_galera_pc():"
     local NODES
     local MASTER
-    local timeout=$(get_master_timeout)
+    local timeout
     local GTID
     local pid
     local pcnum=0

+    timeout=$(get_master_timeout)
+
     ocf_log info "${LH} Checking if Primary Component"

     while [ $timeout -gt 0 ]; do
@@ -508,15 +514,12 @@ check_if_galera_pc() {
             ocf_log info "${LH} My neighbour is Primary Component with GTID: ${GTID}"
             if check_if_new_cluster
             then
-                for node in ${NODES}
-                do
+                for node in ${NODES}; do
                     is_pc=$(crm_attribute --quiet --node ${node} --lifetime reboot --query --name is_pc | sed -e '/(null)/d')
-                    if [ ${is_pc} == "true" ]
-                    then
-                        let pcnum=pcnum+1
+                    if [ "${is_pc}" = "true" ]; then
+                        pcnum=$((pcnum + 1))
                     fi
-                    if [ ${pcnum} -gt 1 ]
-                    then
+                    if [ ${pcnum} -gt 1 ]; then
                         ocf_log err "${LH} But I'm running a new cluster, PID:${pid}, this is a split-brain!"
                         exit $OCF_ERR_GENERIC
                     fi
@@ -527,7 +530,7 @@ check_if_galera_pc() {
         fi

         sleep 10
-        (( timeout -= 10 ))
+        timeout=$((timeout - 10))
         ocf_log info "${LH} Waiting for master. ${timeout} seconds left"
     done