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.
pull/2213/head
René Cannaò 7 years ago
parent 6e67c21224
commit 8e1e152505

@ -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);

@ -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;
}
}
}
}
}

Loading…
Cancel
Save