From bf6c93cb166078eeea2fdb1ed9a5d6cc5c23b46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sat, 22 Oct 2016 12:14:35 +0000 Subject: [PATCH] Killed queries now return 1907 #750 --- include/MySQL_Session.h | 2 +- lib/MySQL_Session.cpp | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index a039b5d27..ac389de1c 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -180,7 +180,7 @@ class MySQL_Session MySQL_Backend * find_or_create_backend(int, MySQL_Data_Stream *_myds=NULL); void SQLite3_to_MySQL(SQLite3_result *, char *, int , MySQL_Protocol *); - void MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *MyRS); + void MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *MyRS, MySQL_Data_Stream *_myds=NULL); void MySQL_Stmt_Result_to_MySQL_wire(MYSQL_STMT *stmt, MySQL_Connection *myconn); unsigned int NumActiveTransactions(); int FindOneActiveTransaction(); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index c40f71c5d..fe3f09d7e 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -2183,9 +2183,13 @@ handler_again: bool retry_conn=false; switch (myerr) { case 1317: // Query execution was interrupted - if (killed==true || myds->killed_at) { + if (killed==true) { // this session is being kiled return -1; } + if (myds->killed_at) { + // we intentionally killed the query + break; + } case 1290: // read-only case 1047: // WSREP has not yet prepared node for application use case 1053: // Server shutdown in progress @@ -2225,7 +2229,7 @@ handler_again: switch (status) { case PROCESSING_QUERY: - MySQL_Result_to_MySQL_wire(myconn->mysql, myconn->MyRS); + MySQL_Result_to_MySQL_wire(myconn->mysql, myconn->MyRS, myds); break; case PROCESSING_STMT_PREPARE: //MySQL_Result_to_MySQL_wire(myconn->mysql, myconn->MyRS, true); @@ -2912,7 +2916,7 @@ void MySQL_Session::MySQL_Stmt_Result_to_MySQL_wire(MYSQL_STMT *stmt, MySQL_Conn } } -void MySQL_Session::MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *MyRS) { +void MySQL_Session::MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *MyRS, MySQL_Data_Stream *_myds) { if (MyRS) { assert(MyRS->result); bool transfer_started=MyRS->transfer_started; @@ -2955,8 +2959,12 @@ void MySQL_Session::MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *My } else { // error char sqlstate[10]; - sprintf(sqlstate,"#%s",mysql_sqlstate(mysql)); - client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,mysql_errno(mysql),sqlstate,mysql_error(mysql)); + sprintf(sqlstate,"%s",mysql_sqlstate(mysql)); + if (_myds && _myds->killed_at) { // see case #750 + client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,1907,sqlstate,"Query execution was interrupted, query_timeout exceeded"); + } else { + client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,mysql_errno(mysql),sqlstate,mysql_error(mysql)); + } client_myds->pkt_sid++; } }