Query parsing optional , add variable mysql-commands_stats , issue #258

pull/259/head
René Cannaò 11 years ago
parent 14933cb943
commit 5ccf176c5b

1
deps/Makefile vendored

@ -69,7 +69,6 @@ re2: re2/re2/obj/libre2.a
cleanall:
cd libdaemon && rm -rf libdaemon-0.14
cd memcached && rm -rf memcached-1.4.20
cd jemalloc && rm -rf jemalloc-3.6.0
cd mariadb-client-library && rm -rf mariadb_client-2.0.0-src
cd libconfig && rm -rf libconfig-1.4.9

@ -24,6 +24,7 @@ class Query_Info {
unsigned char *QueryPointer;
int QueryLength;
Query_Info();
~Query_Info();
void init(unsigned char *_p, int len, bool mysql_header=false);
void query_parser_init();
enum MYSQL_COM_QUERY_command query_parser_command_type();

@ -341,6 +341,7 @@ class Standard_MySQL_Threads_Handler: public MySQL_Threads_Handler
char *server_version;
uint8_t default_charset;
bool servers_stats;
bool commands_stats;
bool have_compress;
#ifdef DEBUG
bool session_debug;

@ -624,6 +624,7 @@ __thread int mysql_thread___poll_timeout;
__thread int mysql_thread___poll_timeout_on_failure;
__thread bool mysql_thread___have_compress;
__thread bool mysql_thread___servers_stats;
__thread bool mysql_thread___commands_stats;
#ifdef DEBUG
__thread bool mysql_thread___session_debug;
#endif /* DEBUG */
@ -645,6 +646,7 @@ extern __thread int mysql_thread___poll_timeout;
extern __thread int mysql_thread___poll_timeout_on_failure;
extern __thread bool mysql_thread___have_compress;
extern __thread bool mysql_thread___servers_stats;
extern __thread bool mysql_thread___commands_stats;
#ifdef DEBUG
extern __thread bool mysql_thread___session_debug;
#endif /* DEBUG */

@ -12,6 +12,16 @@ Query_Info::Query_Info() {
MyComQueryCmd=MYSQL_COM_QUERY___NONE;
QueryPointer=NULL;
QueryLength=0;
QueryParserArgs=NULL;
}
Query_Info::~Query_Info() {
if (QueryParserArgs) {
GloQPro->query_parser_free(QueryParserArgs);
}
if (QueryPointer) {
l_free(QueryLength+1,QueryPointer);
}
}
void Query_Info::init(unsigned char *_p, int len, bool mysql_header) {
@ -35,6 +45,7 @@ enum MYSQL_COM_QUERY_command Query_Info::query_parser_command_type() {
void Query_Info::query_parser_free() {
GloQPro->query_parser_free(QueryParserArgs);
QueryParserArgs=NULL;
}
unsigned long long Query_Info::query_parser_update_counters() {
@ -246,26 +257,32 @@ int MySQL_Session::handler() {
#ifdef DEBUG
if (mysql_thread___session_debug) {
if ((pkt.size>9) && strncasecmp("dbg ",(const char *)pkt.ptr+sizeof(mysql_hdr)+1,4)==0) {
CurrentQuery.init((unsigned char *)pkt.ptr,pkt.size,true);
CurrentQuery.start_time=thread->curtime;
CurrentQuery.query_parser_init();
CurrentQuery.query_parser_command_type();
CurrentQuery.query_parser_free();
if (mysql_thread___commands_stats==true) {
CurrentQuery.init((unsigned char *)pkt.ptr,pkt.size,true);
CurrentQuery.start_time=thread->curtime;
CurrentQuery.query_parser_init();
CurrentQuery.query_parser_command_type();
CurrentQuery.query_parser_free();
}
handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_debug(&pkt);
CurrentQuery.end_time=thread->curtime;
CurrentQuery.query_parser_update_counters();
if (mysql_thread___commands_stats==true) {
CurrentQuery.end_time=thread->curtime;
CurrentQuery.query_parser_update_counters();
}
break;
}
}
#endif /* DEBUG */
if (admin==false) {
if (session_fast_forward==false) {
CurrentQuery.init((unsigned char *)pkt.ptr,pkt.size,true);
CurrentQuery.start_time=thread->curtime;
CurrentQuery.query_parser_init();
CurrentQuery.query_parser_command_type();
CurrentQuery.query_parser_free();
client_myds->myprot.process_pkt_COM_QUERY((unsigned char *)pkt.ptr,pkt.size);
if (mysql_thread___commands_stats==true) {
CurrentQuery.init((unsigned char *)pkt.ptr,pkt.size,true);
CurrentQuery.start_time=thread->curtime;
CurrentQuery.query_parser_init();
CurrentQuery.query_parser_command_type();
CurrentQuery.query_parser_free();
//client_myds->myprot.process_pkt_COM_QUERY((unsigned char *)pkt.ptr,pkt.size);
}
}
qpo=GloQPro->process_mysql_query(this,pkt.ptr,pkt.size,false);
if (qpo) {
@ -715,8 +732,10 @@ void MySQL_Session::handler___status_WAITING_SERVER_DATA___STATE_QUERY_SENT(PtrS
status=WAITING_CLIENT_DATA;
client_myds->DSS=STATE_SLEEP;
client_myds->PSarrayOUT->add(pkt->ptr, pkt->size);
CurrentQuery.end_time=thread->curtime;
CurrentQuery.query_parser_update_counters();
if (mysql_thread___commands_stats==true) {
CurrentQuery.end_time=thread->curtime;
CurrentQuery.query_parser_update_counters();
}
} else {
// this should be a result set
if (qpo && qpo->cache_ttl>0) {
@ -868,8 +887,10 @@ void MySQL_Session::handler___status_WAITING_SERVER_DATA___STATE_EOF1(PtrSize_t
GloQPro->delete_QP_out(qpo);
qpo=NULL;
}
CurrentQuery.end_time=thread->curtime;
CurrentQuery.query_parser_update_counters();
if (mysql_thread___commands_stats==true) {
CurrentQuery.end_time=thread->curtime;
CurrentQuery.query_parser_update_counters();
}
}
} else {
if (mybe->server_myds->myconn->processing_prepared_statement_prepare==true) {
@ -1245,8 +1266,10 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
while (client_myds->resultset->len) client_myds->resultset->remove_index(client_myds->resultset->len-1,NULL);
status=WAITING_CLIENT_DATA;
client_myds->DSS=STATE_SLEEP;
CurrentQuery.end_time=thread->curtime;
CurrentQuery.query_parser_update_counters();
if (mysql_thread___commands_stats==true) {
CurrentQuery.end_time=thread->curtime;
CurrentQuery.query_parser_update_counters();
}
GloQPro->delete_QP_out(qpo);
qpo=NULL;
return true;
@ -1455,8 +1478,10 @@ SQLite3_result * MySQL_Session::SQL3_Session_status() {
MySQL_Connection_userinfo *ui=s->client_myds->myconn->userinfo;
sprintf(buf, "session[%d] = %p :\n\tuserinfo={%s,%s} , status=%d , myds={%p,%p} , HG={d:%d,c:%d}\n\tLast query= ", i, s, ui->username, ui->schemaname, s->status, s->client_myds, s->mybe->server_myds, s->default_hostgroup, s->current_hostgroup);
status_str.append(buf);
if (s->CurrentQuery.QueryLength && s->CurrentQuery.MyComQueryCmd!=MYSQL_COM_QUERY___NONE) {
status_str.append((char *)s->CurrentQuery.QueryPointer);
if (mysql_thread___commands_stats==true) {
if (s->CurrentQuery.QueryLength && s->CurrentQuery.MyComQueryCmd!=MYSQL_COM_QUERY___NONE) {
status_str.append((char *)s->CurrentQuery.QueryPointer);
}
}
status_str+= "\n";
}

@ -124,6 +124,7 @@ static char * mysql_thread_variables_names[]= {
(char *)"poll_timeout_on_failure",
(char *)"server_capabilities",
(char *)"server_version",
(char *)"commands_stats",
(char *)"servers_stats",
(char *)"session_debug",
(char *)"stacksize",
@ -160,6 +161,7 @@ Standard_MySQL_Threads_Handler::Standard_MySQL_Threads_Handler() {
variables.poll_timeout=2000;
variables.poll_timeout_on_failure=100;
variables.have_compress=true;
variables.commands_stats=false;
variables.servers_stats=true;
#ifdef DEBUG
variables.session_debug=true;
@ -261,6 +263,7 @@ int Standard_MySQL_Threads_Handler::get_variable_int(char *name) {
if (!strcasecmp(name,"ping_interval_server")) return (int)variables.ping_interval_server;
if (!strcasecmp(name,"ping_timeout_server")) return (int)variables.ping_timeout_server;
if (!strcasecmp(name,"have_compress")) return (int)variables.have_compress;
if (!strcasecmp(name,"commands_stats")) return (int)variables.commands_stats;
if (!strcasecmp(name,"servers_stats")) return (int)variables.servers_stats;
if (!strcasecmp(name,"poll_timeout")) return variables.poll_timeout;
if (!strcasecmp(name,"poll_timeout_on_failure")) return variables.poll_timeout_on_failure;
@ -321,6 +324,9 @@ char * Standard_MySQL_Threads_Handler::get_variable(char *name) { // this is the
if (!strcasecmp(name,"have_compress")) {
return strdup((variables.have_compress ? "true" : "false"));
}
if (!strcasecmp(name,"commands_stats")) {
return strdup((variables.commands_stats ? "true" : "false"));
}
if (!strcasecmp(name,"servers_stats")) {
return strdup((variables.servers_stats ? "true" : "false"));
}
@ -482,6 +488,17 @@ bool Standard_MySQL_Threads_Handler::set_variable(char *name, char *value) { //
}
return false;
}
if (!strcasecmp(name,"commands_stats")) {
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.commands_stats=true;
return true;
}
if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) {
variables.commands_stats=false;
return true;
}
return false;
}
if (!strcasecmp(name,"servers_stats")) {
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.servers_stats=true;
@ -1006,6 +1023,7 @@ void Standard_MySQL_Thread::refresh_variables() {
mysql_thread___poll_timeout=GloMTH->get_variable_int((char *)"poll_timeout");
mysql_thread___poll_timeout_on_failure=GloMTH->get_variable_int((char *)"poll_timeout_on_failure");
mysql_thread___have_compress=(bool)GloMTH->get_variable_int((char *)"have_compress");
mysql_thread___commands_stats=(bool)GloMTH->get_variable_int((char *)"commands_stats");
mysql_thread___servers_stats=(bool)GloMTH->get_variable_int((char *)"servers_stats");
#ifdef DEBUG
mysql_thread___session_debug=(bool)GloMTH->get_variable_int((char *)"session_debug");

Loading…
Cancel
Save