aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEttore Simone <ettore.simone@gmail.com>2016-05-27 16:13:54 +0200
committerEttore Simone <ettore.simone@gmail.com>2016-06-03 01:30:00 +0200
commitb4759b280c6cfad602ad9b4084d4a4f1f5f1ff2f (patch)
treeac99e6508cb48d147a0e3d1bb2e77d3b5ce49f86
parentc51e315523fe37f28dc9b0968191b7e07125c24b (diff)
downloadkolla-b4759b280c6cfad602ad9b4084d4a4f1f5f1ff2f.tar.gz
kolla-b4759b280c6cfad602ad9b4084d4a4f1f5f1ff2f.zip
Enable HAProxy consider MariaDB wsrep_local_state
This patch enable wsrep_notify_cmd to rename haproxy user in haproxy_blocked when the node is not ready to serve and restore it when ready. Change-Id: I4f49960d7ff2fa689d6ea730b2574f16f083edc1 Closes-Bug: 1578752 Closes-Bug: 1587752
-rw-r--r--ansible/roles/mariadb/tasks/config.yml7
-rw-r--r--ansible/roles/mariadb/templates/galera.cnf.j21
-rw-r--r--ansible/roles/mariadb/templates/mariadb.json.j26
-rw-r--r--ansible/roles/mariadb/templates/wsrep_notify.sh.j275
4 files changed, 89 insertions, 0 deletions
diff --git a/ansible/roles/mariadb/tasks/config.yml b/ansible/roles/mariadb/tasks/config.yml
index 39a186c8c..01a911905 100644
--- a/ansible/roles/mariadb/tasks/config.yml
+++ b/ansible/roles/mariadb/tasks/config.yml
@@ -25,3 +25,10 @@
dest: "{{ node_config_directory }}/{{ item }}/galera.cnf"
with_items:
- "mariadb"
+
+- name: Copying over wsrep_notify.sh
+ template:
+ src: "{{ role_path }}/templates/wsrep_notify.sh.j2"
+ dest: "{{ node_config_directory }}/{{ item }}/wsrep_notify.sh"
+ with_items:
+ - "mariadb"
diff --git a/ansible/roles/mariadb/templates/galera.cnf.j2 b/ansible/roles/mariadb/templates/galera.cnf.j2
index 7c426dbf8..23919e2f3 100644
--- a/ansible/roles/mariadb/templates/galera.cnf.j2
+++ b/ansible/roles/mariadb/templates/galera.cnf.j2
@@ -24,6 +24,7 @@ wsrep_node_name={{ ansible_hostname }}
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth={{ database_user }}:{{ database_password }}
wsrep_slave_threads=4
+wsrep_notify_cmd=/usr/local/bin/wsrep_notify.sh
max_connections=10000
diff --git a/ansible/roles/mariadb/templates/mariadb.json.j2 b/ansible/roles/mariadb/templates/mariadb.json.j2
index 7317d996e..d9c1c0b38 100644
--- a/ansible/roles/mariadb/templates/mariadb.json.j2
+++ b/ansible/roles/mariadb/templates/mariadb.json.j2
@@ -7,6 +7,12 @@
"dest": "/etc/{{ mysql_dir }}/my.cnf",
"owner": "mysql",
"perm": "0600"
+ },
+ {
+ "source": "{{ container_config_directory }}/wsrep_notify.sh",
+ "dest": "/usr/local/bin/wsrep_notify.sh",
+ "owner": "mysql",
+ "perm": "0700"
}
]
}
diff --git a/ansible/roles/mariadb/templates/wsrep_notify.sh.j2 b/ansible/roles/mariadb/templates/wsrep_notify.sh.j2
new file mode 100644
index 000000000..babd29e86
--- /dev/null
+++ b/ansible/roles/mariadb/templates/wsrep_notify.sh.j2
@@ -0,0 +1,75 @@
+#!/bin/bash -e
+
+# Edit parameters below to specify the address and login to server.
+USER={{ database_user }}
+PSWD={{ database_password }}
+HOST={{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}
+PORT={{ mariadb_port }}
+LB_USER=haproxy
+
+ENABLE_LB="UPDATE mysql.user SET User='${LB_USER}' WHERE User='${LB_USER}_blocked';"
+DISABLE_LB="UPDATE mysql.user SET User='${LB_USER}_blocked' WHERE User='${LB_USER}';"
+MYSQL_CMD="`type -p mysql` -B -u$USER -p$PSWD -h$HOST -P$PORT"
+
+status_update()
+{
+ echo "SET SESSION wsrep_on=off;"
+ echo "$@"
+ echo "FLUSH PRIVILEGES;"
+}
+
+get_sst_method()
+{
+ $MYSQL_CMD -s -N -e "SHOW VARIABLES LIKE 'wsrep_sst_method';" | awk '{ print $2 }'
+}
+
+while [ $# -gt 0 ]
+do
+ case $1 in
+ --status)
+ STATUS=$2
+ shift
+ ;;
+ --uuid)
+ CLUSTER_UUID=$2
+ shift
+ ;;
+ --primary)
+ [ "$2" = "yes" ] && PRIMARY="1" || PRIMARY="0"
+ shift
+ ;;
+ --index)
+ INDEX=$2
+ shift
+ ;;
+ --members)
+ MEMBERS=$2
+ shift
+ ;;
+ esac
+ shift
+done
+
+case $STATUS in
+Synced)
+ CMD=$ENABLE_LB
+ ;;
+Donor)
+ # enabling donor only if xtrabackup configured
+ SST_METHOD=`get_sst_method`
+ [[ $SST_METHOD =~ 'xtrabackup' ]] && CMD=$ENABLE_LB || CMD=$DISABLE_LB
+ ;;
+Undefined)
+ # shutting down database: do nothing
+ ;;
+*)
+ CMD=$DISABLE_LB
+ ;;
+esac
+
+if [ -n "$CMD" ]
+then
+ status_update "$CMD" | $MYSQL_CMD
+fi
+
+exit 0