From afd98fe4a7912fcad0a89f16b3110f37cabe33a8 Mon Sep 17 00:00:00 2001 From: Krzysztof Ksiazek Date: Thu, 25 Aug 2016 14:04:09 +0200 Subject: [PATCH 1/2] Add support for handling case where only available nodes are in Donor/Desync state. It's preferred to use Desync/Donor node as reader and writer than to have all nodes in OFFLINE_SOFT --- tools/proxysql_galera_checker.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/proxysql_galera_checker.sh b/tools/proxysql_galera_checker.sh index a119396ee..f2f9e930e 100755 --- a/tools/proxysql_galera_checker.sh +++ b/tools/proxysql_galera_checker.sh @@ -61,6 +61,30 @@ do fi done +NUMBER_WRITERS_ONLINE=$(${PROXYSQL_CMDLINE} "SELECT COUNT(*) FROM mysql_servers WHERE status LIKE 'ONLINE' AND hostgroup_id=${HOSTGROUP_WRITER_ID};") +echo "`date` Number of writers online: ${NUMBER_WRITERS_ONLINE} : hostgroup: ${HOSTGROUP_WRITER_ID}" >> ${ERR_FILE} + +cnt=0 +if [ ${NUMBER_WRITERS_ONLINE} -eq 0 ] +then + echo "`date` Trying to enable last available node of the cluster (in Donor/Desync state)" >> ${ERR_FILE} + $PROXYSQL_CMDLINE "SELECT hostgroup_id, hostname, port, status FROM mysql_servers WHERE hostgroup_id IN ($HOSTGROUP_WRITER_ID) AND status <> 'OFFLINE_HARD'" | while read hostgroup server port stat + do + safety_cnt=0 + while [ ${cnt} -eq 0 -a ${safety_cnt} -lt 5 ] + do + WSREP_STATUS=$($MYSQL_CMDLINE -h $server -P $port -e "SHOW STATUS LIKE 'wsrep_local_state'" 2>>${ERR_FILE} | tail -1 2>>${ERR_FILE}) + echo "`date` Check server $hostgroup:$server:$port for only available node in DONOR state, status $stat , wsrep_local_state $WSREP_STATUS" >> ${ERR_FILE} + if [ "${WSREP_STATUS}" = "2" -a "$stat" != "ONLINE" ] + then + $PROXYSQL_CMDLINE "UPDATE mysql_servers SET status='ONLINE' WHERE hostgroup_id IN ($HOSTGROUP_WRITER_ID, $HOSTGROUP_READER_ID) AND hostname='$server' AND port='$port';" 2>> ${ERR_FILE} + cnt=$(( $cnt + 1 )) + fi + safety_cnt=$(( $safety_cnt + 1 )) + done + done +fi + if [ $NUMBER_WRITERS -gt 0 ] then CONT=0 From abff6a82db42cd126d2b64af56e9acfcd644b771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Tue, 30 Aug 2016 21:39:04 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Add=20connection=20attributes=20for=20proxy?= =?UTF-8?q?sql=E2=86=92mysql=20connections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/MySQL_Monitor.cpp | 1 + lib/MySQL_Session.cpp | 1 + lib/mysql_connection.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index ae4d710b3..b24d91970 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -518,6 +518,7 @@ bool MySQL_Monitor_State_Data::create_new_connection() { mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); // mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, &timeout); // mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, &timeout); + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name", "proxysql_monitor"); MYSQL *myrc=NULL; if (port) { myrc=mysql_real_connect(mysql, hostname, mysql_thread___monitor_username, mysql_thread___monitor_password, NULL, port, NULL, 0); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 5914be64b..83f0f5be9 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -41,6 +41,7 @@ static void * kill_query_thread(void *arg) { KillArgs *ka=(KillArgs *)arg; MYSQL *mysql; mysql=mysql_init(NULL); + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name", "proxysql_killer"); if (!mysql) { goto __exit_kill_query_thread; } diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index a4aaecda7..201f9364a 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -316,6 +316,7 @@ void MySQL_Connection::connect_start() { mysql=mysql_init(NULL); assert(mysql); mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name", "proxysql"); if (parent->use_ssl) { mysql_ssl_set(mysql, mysql_thread___ssl_p2s_key, mysql_thread___ssl_p2s_cert, mysql_thread___ssl_p2s_ca, NULL, mysql_thread___ssl_p2s_cipher); }