From e6bc5cc8b8b0e6e421b3535b4543af244e5932bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 23 Aug 2015 09:47:41 +0000 Subject: [PATCH] Converted QP_out_t into a class Query_Processor_Output --- include/MySQL_Session.h | 2 +- include/proxysql_session.hpp | 48 ------------------------------------ include/query_processor.h | 30 +++++++++++++++++----- lib/Query_Processor.cpp | 12 +++++---- 4 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 include/proxysql_session.hpp diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index 9146ebb19..086070967 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -86,7 +86,7 @@ class MySQL_Session MySQL_Thread *thread; uint32_t thread_session_id; // enum session_states sess_states; - QP_out_t *qpo; + Query_Processor_Output *qpo; StatCounters *command_counters; int healthy; bool killed; diff --git a/include/proxysql_session.hpp b/include/proxysql_session.hpp deleted file mode 100644 index 517670a47..000000000 --- a/include/proxysql_session.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __CLASS_SESSION_H -#define __CLASS_SESSION_H -#include "proxysql.h" -#include "cpp.h" - - -class ProxySQL_Session -{ - public: -// virtual void * operator new(size_t) {return NULL;} -// virtual void operator delete(void *) {}; - MySQL_Thread *thread; -// enum session_states sess_states; - QP_out_t *qpo; - int healthy; - int admin; - int client_fd; - int server_fd; - enum session_status status; - int to_process; - unsigned long long pause; - char *username; - char *password; - char *schema_name; -// char *schema_cur; -// char *schema_new; - int net_failure; - MySQL_Data_Stream *client_myds; - MySQL_Data_Stream *server_myds; - - //GPtrArray *mybes; - PtrArray *mybes; - - ProxySQL_Session(); - ProxySQL_Session(int) {}; - virtual ~ProxySQL_Session() {}; - - - MySQL_Protocol prot; - virtual int handler() {return 0;}; - - virtual int find_backend(int) {return 0;}; - virtual void reset_all_backends() {}; - virtual void writeout() {}; - -}; - -#endif /* __CLASS_SESSION_H */ diff --git a/include/query_processor.h b/include/query_processor.h index 30d8321f8..09a8fa1fb 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -77,7 +77,22 @@ struct _Query_Processor_rule_t { }; -struct _Query_Processor_output_t { +//struct _Query_Processor_output_t { +// void *ptr; +// unsigned int size; +// int destination_hostgroup; +// int cache_ttl; +// int reconnect; +// int timeout; +// int delay; +// std::string *new_query; +//}; + +typedef struct _Query_Processor_rule_t QP_rule_t; +//typedef struct _Query_Processor_output_t QP_out_t; + +class Query_Processor_Output { + public: void *ptr; unsigned int size; int destination_hostgroup; @@ -86,11 +101,14 @@ struct _Query_Processor_output_t { int timeout; int delay; std::string *new_query; + void * operator new(size_t size) { + return l_alloc(size); + } + void operator delete(void *ptr) { + l_free(sizeof(Query_Processor_Output),ptr); + } }; -typedef struct _Query_Processor_rule_t QP_rule_t; -typedef struct _Query_Processor_output_t QP_out_t; - static char *commands_counters_desc[MYSQL_COM_QUERY___NONE]; class Command_Counter { @@ -171,8 +189,8 @@ class Query_Processor { void delete_query_rule(QP_rule_t *qr); // destructor //virtual bool remove(int rule_id, bool lock=true) {return false;}; // FIXME: not implemented yet, should be implemented at all ? // virtual bool remove_locked(int rule_id) {return false;}; // call this instead of remove() in case lock was already acquired via wrlock() - QP_out_t * process_mysql_query(MySQL_Session *sess, void *ptr, unsigned int size, bool delete_original); - void delete_QP_out(QP_out_t *o); + Query_Processor_Output * process_mysql_query(MySQL_Session *sess, void *ptr, unsigned int size, bool delete_original); + void delete_QP_out(Query_Processor_Output *o); void sort(bool lock=true); diff --git a/lib/Query_Processor.cpp b/lib/Query_Processor.cpp index 8ec1fc111..e730a00c7 100644 --- a/lib/Query_Processor.cpp +++ b/lib/Query_Processor.cpp @@ -590,8 +590,8 @@ SQLite3_result * Query_Processor::get_query_digests_reset() { -QP_out_t * Query_Processor::process_mysql_query(MySQL_Session *sess, void *ptr, unsigned int size, bool delete_original) { - QP_out_t *ret=NULL; +Query_Processor_Output * Query_Processor::process_mysql_query(MySQL_Session *sess, void *ptr, unsigned int size, bool delete_original) { + Query_Processor_Output *ret=NULL; unsigned int len=size-sizeof(mysql_hdr)-1; char *query=(char *)l_alloc(len+1); memcpy(query,(char *)ptr+sizeof(mysql_hdr)+1,len); @@ -661,7 +661,8 @@ QP_out_t * Query_Processor::process_mysql_query(MySQL_Session *sess, void *ptr, if (ret==NULL) { proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "this is the first time we find a match\n"); // create struct - ret=(QP_out_t *)l_alloc(sizeof(QP_out_t)); + //ret=(QP_out_t *)l_alloc(sizeof(QP_out_t)); + ret=new Query_Processor_Output(); // initalized all values ret->ptr=NULL; ret->size=0; @@ -748,8 +749,9 @@ __exit_process_mysql_query: }; // this function is called by mysql_session to free the result generated by process_mysql_query() -void Query_Processor::delete_QP_out(QP_out_t *o) { - l_free(sizeof(QP_out_t),o); +void Query_Processor::delete_QP_out(Query_Processor_Output *o) { + //l_free(sizeof(QP_out_t),o); + delete o; }; void Query_Processor::update_query_processor_stats() {