From 8e1e152505cf2c4b85fd3ea7c1e478d683073f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 21 Aug 2019 00:55:44 +1000 Subject: [PATCH] Do not send incorrect GTID to client Extract GTID only if no errors, and status changed. GTID is stored both on MySQL_Connection and MySQL_Backend, to better track changes. --- include/mysql_connection.h | 1 + lib/mysql_connection.cpp | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/mysql_connection.h b/include/mysql_connection.h index 336fc6774..a83f9bb3d 100644 --- a/include/mysql_connection.h +++ b/include/mysql_connection.h @@ -111,6 +111,7 @@ class MySQL_Connection { bool multiplex_delayed; bool unknown_transaction_status; void compute_unknown_transaction_status(); + char gtid_uuid[128]; MySQL_Connection(); ~MySQL_Connection(); bool set_autocommit(bool); diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 61cc16f94..eb62c83bb 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -237,7 +237,7 @@ MySQL_Connection::MySQL_Connection() { statuses.questions = 0; statuses.myconnpoll_get = 0; statuses.myconnpoll_put = 0; - + memset(gtid_uuid,0,sizeof(gtid_uuid)); }; MySQL_Connection::~MySQL_Connection() { @@ -2020,15 +2020,22 @@ bool MySQL_Connection::get_gtid(char *buff, uint64_t *trx_id) { return ret; } if (mysql) { - const char *data; - size_t length; - if (mysql_session_track_get_first(mysql, SESSION_TRACK_GTIDS, &data, &length) == 0) { - if (memcmp(buff,data,length)) { - memcpy(buff,data,length); - buff[length]=0; - //fprintf(stderr,"GTID=%s\n",buff); - __sync_fetch_and_add(&myds->sess->thread->status_variables.gtid_session_collected,1); - ret = true; + if (mysql->net.last_errno==0) { // only if there is no error + if (mysql->server_status & SERVER_SESSION_STATE_CHANGED) { // only if status changed + const char *data; + size_t length; + if (mysql_session_track_get_first(mysql, SESSION_TRACK_GTIDS, &data, &length) == 0) { + if (memcmp(gtid_uuid,data,length)) { + // copy to local buffer in MySQL_Connection + memcpy(gtid_uuid,data,length); + gtid_uuid[length]=0; + // copy to external buffer in MySQL_Backend + memcpy(buff,data,length); + buff[length]=0; + __sync_fetch_and_add(&myds->sess->thread->status_variables.gtid_session_collected,1); + ret = true; + } + } } } }