Added function close_mysql()

close_mysql() is a replacement for mysql_close()
It tries to avoid blocking while sending the QUIT command
pull/642/head
René Cannaò 10 years ago
parent 4b3d69606e
commit bf0a214e4f

@ -132,5 +132,6 @@ class MySQL_Connection {
bool MultiplexDisabled();
void ProcessQueryAndSetStatusFlags(char *query_digest_text);
void optimize();
void close_mysql();
};
#endif /* __CLASS_MYSQL_CONNECTION_H */

@ -57,6 +57,7 @@ static void * kill_query_thread(void *arg) {
}
char buf[100];
sprintf(buf,"KILL QUERY %lu", ka->id);
// FIXME: these 2 calls are blocking, fortunately on their own thread
mysql_query(mysql,buf);
mysql_close(mysql);
__exit_kill_query_thread:

@ -173,12 +173,7 @@ MySQL_Connection::~MySQL_Connection() {
// always decrease the counter
__sync_fetch_and_sub(&MyHGM->status.server_connections_connected,1);
async_free_result();
if (send_quit) {
mysql_close(mysql);
} else {
mysql_close_no_command(mysql);
shutdown(fd, SHUT_RDWR);
}
close_mysql(); // this take care of closing mysql connection
mysql=NULL;
}
// // FIXME: with the use of mysql client library , this part should be gone.
@ -1096,3 +1091,21 @@ void MySQL_Connection::optimize() {
}
}
}
// close_mysql() is a replacement for mysql_close()
// if avoids that a QUIT command stops forever
// FIXME: currently doesn't support encryption and compression
void MySQL_Connection::close_mysql() {
if (send_quit) {
char buff[5];
mysql_hdr myhdr;
myhdr.pkt_id=0;
myhdr.pkt_length=1;
memcpy(buff, &myhdr, sizeof(mysql_hdr));
buff[4]=0x01;
int fd=mysql->net.fd;
send(fd, buff, 5, MSG_NOSIGNAL);
}
mysql_close_no_command(mysql);
shutdown(fd, SHUT_RDWR);
}

Loading…
Cancel
Save