From 59507675e5ffc56f5c57b64bbe5e86871bf72093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 12 May 2015 14:29:05 +0000 Subject: [PATCH] MySQL_Thread, MySQL_Threads_Handler and MySQL_Authentication are no longer modules --- .gitignore | 1 + include/MySQL_Authentication.hpp | 55 ++- ...ysql_data_stream.h => MySQL_Data_Stream.h} | 0 include/{mysql_session.h => MySQL_Session.h} | 0 include/MySQL_Thread.h | 288 ++++++++++++ include/Standard_MySQL_Thread.h | 38 -- include/cpp.h | 6 +- include/mysql_thread.h | 410 ------------------ lib/Makefile | 17 +- lib/MySQL_Authentication.cpp | 184 ++++++++ lib/MySQL_Protocol.cpp | 1 - lib/MySQL_Session.cpp | 1 - ...dard_MySQL_Thread.cpp => MySQL_Thread.cpp} | 122 +++--- lib/Standard_MySQL_Authentication.cpp | 195 --------- lib/Standard_ProxySQL_Admin.cpp | 3 +- src/main.cpp | 21 +- src/proxysql.cfg | 12 +- 17 files changed, 595 insertions(+), 759 deletions(-) rename include/{mysql_data_stream.h => MySQL_Data_Stream.h} (100%) rename include/{mysql_session.h => MySQL_Session.h} (100%) create mode 100644 include/MySQL_Thread.h delete mode 100644 include/Standard_MySQL_Thread.h delete mode 100644 include/mysql_thread.h create mode 100644 lib/MySQL_Authentication.cpp rename lib/{Standard_MySQL_Thread.cpp => MySQL_Thread.cpp} (89%) delete mode 100644 lib/Standard_MySQL_Authentication.cpp diff --git a/.gitignore b/.gitignore index bf3d9443b..6ecf39937 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ deps/libdaemon/libdaemon-0.14/ deps/mariadb-client-library/mariadb_client-2.0.0-Linux-x86/ deps/mariadb-client-library/mariadb_client-2.0.0-Linux-x86_64/ deps/mariadb-client-library/mariadb_client-2.0.0-src/ +deps/mariadb-client-library/mariadb-connector-c-2.1.0-src/ #glib deps/glib/glib-2.40.0/ diff --git a/include/MySQL_Authentication.hpp b/include/MySQL_Authentication.hpp index c2b4437b9..9fe177f64 100644 --- a/include/MySQL_Authentication.hpp +++ b/include/MySQL_Authentication.hpp @@ -1,27 +1,54 @@ #ifndef __CLASS_MYSQL_AUTHENTICATION_H #define __CLASS_MYSQL_AUTHENTICATION_H +#include "btree_map.h" #include "proxysql.h" #include "cpp.h" + +typedef struct _account_details_t { + char *username; + char *password; + bool use_ssl; + int default_hostgroup; + char *default_schema; + bool schema_locked; + bool transaction_persistent; + bool fast_forward; +} account_details_t; + +#ifdef DEBUG +#define DEB "_DEBUG" +#else +#define DEB "" +#endif /* DEBUG */ +#define MYSQL_AUTHENTICATION_VERSION "0.1.0706" DEB + +typedef btree::btree_map BtMap_auth; + +class PtrArray; + +typedef struct _creds_group_t { + rwlock_t lock; + BtMap_auth bt_map; + PtrArray *cred_array; +} creds_group_t; + enum cred_username_type { USERNAME_BACKEND, USERNAME_FRONTEND }; class MySQL_Authentication { + private: + creds_group_t creds_backends; + creds_group_t creds_frontends; + bool _reset(enum cred_username_type usertype); public: - MySQL_Authentication() {}; - virtual ~MySQL_Authentication() {}; - //virtual bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl) { return false; }; - virtual bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward) { return false; }; - virtual bool del(char *username, enum cred_username_type usertype) { return false; }; -// virtual bool reset(unsigned char *) { return false; }; - virtual bool reset() { return false; }; -// virtual bool refresh() { return false; }; - virtual void print_version() {}; -// virtual char * lookup(char *username, enum cred_username_type usertype, bool *use_ssl) {return NULL; }; - virtual char * lookup(char *username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward) {return NULL; }; + MySQL_Authentication(); + ~MySQL_Authentication(); + bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward); + bool del(char *username, enum cred_username_type usertype); + bool reset(); + void print_version(); + char * lookup(char *username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward); }; -typedef MySQL_Authentication * create_MySQL_Authentication_t(); -typedef void destroy_MyAuth_t(MySQL_Authentication *); - #endif /* __CLASS_MYSQL_AUTHENTICATION_H */ diff --git a/include/mysql_data_stream.h b/include/MySQL_Data_Stream.h similarity index 100% rename from include/mysql_data_stream.h rename to include/MySQL_Data_Stream.h diff --git a/include/mysql_session.h b/include/MySQL_Session.h similarity index 100% rename from include/mysql_session.h rename to include/MySQL_Session.h diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h new file mode 100644 index 000000000..d09396f57 --- /dev/null +++ b/include/MySQL_Thread.h @@ -0,0 +1,288 @@ +#ifndef __CLASS_MYSQL_THREAD_H +#define __CLASS_MYSQL_THREAD_H +#define ____CLASS_STANDARD_MYSQL_THREAD_H +#include "proxysql.h" +#include "cpp.h" + + +#define MIN_POLL_LEN 8 +#define MIN_POLL_DELETE_RATIO 8 + + +#define ADMIN_HOSTGROUP -2 +#define STATS_HOSTGROUP -3 + + +static unsigned int near_pow_2 (unsigned int n) { + unsigned int i = 1; + while (i < n) i <<= 1; + return i ? i : n; +} + +class ProxySQL_Poll { + + private: + void shrink() { + unsigned int new_size=near_pow_2(len+1); + fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd)); + myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *)); + last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long)); + last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long)); + size=new_size; + }; + void expand(unsigned int more) { + if ( (len+more) > size ) { + unsigned int new_size=near_pow_2(len+more); + fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd)); + myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *)); + last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long)); + last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long)); + size=new_size; + } + }; + + public: + int poll_timeout; + unsigned long loops; + StatCounters *loop_counters; + unsigned int len; + unsigned int size; + struct pollfd *fds; + MySQL_Data_Stream **myds; + unsigned long long *last_recv; + unsigned long long *last_sent; + volatile int pending_listener_add; + volatile int pending_listener_del; + + ProxySQL_Poll() { + loop_counters=new StatCounters(15,10,false); + poll_timeout=0; + loops=0; + len=0; + pending_listener_add=0; + pending_listener_del=0; + size=MIN_POLL_LEN; + fds=(struct pollfd *)malloc(size*sizeof(struct pollfd)); + myds=(MySQL_Data_Stream **)malloc(size*sizeof(MySQL_Data_Stream *)); + last_recv=(unsigned long long *)malloc(size*sizeof(unsigned long long)); + last_sent=(unsigned long long *)malloc(size*sizeof(unsigned long long)); + }; + + ~ProxySQL_Poll() { + unsigned int i; + for (i=0;imyds_type==MYDS_LISTENER) { + delete myds[i]; + } + } + free(myds); + free(fds); + free(last_recv); + free(last_sent); + delete loop_counters; + }; + + + + void add(uint32_t _events, int _fd, MySQL_Data_Stream *_myds, unsigned long long sent_time) { + if (len==size) { + expand(1); + } + myds[len]=_myds; + fds[len].fd=_fd; + fds[len].events=_events; + fds[len].revents=0; + if (_myds) { + _myds->mypolls=this; + _myds->poll_fds_idx=len; // fix a serious bug + } + last_recv[len]=monotonic_time(); + last_sent[len]=sent_time; + len++; + }; + + void remove_index_fast(unsigned int i) { + if ((int)i==-1) return; + myds[i]->poll_fds_idx=-1; // this prevents further delete + if (i != (len-1)) { + myds[i]=myds[len-1]; + fds[i].fd=fds[len-1].fd; + fds[i].events=fds[len-1].events; + fds[i].revents=fds[len-1].revents; + myds[i]->poll_fds_idx=i; // fix a serious bug + last_recv[i]=last_recv[len-1]; + last_sent[i]=last_sent[len-1]; + } + len--; + if ( ( len>MIN_POLL_LEN ) && ( size > len*MIN_POLL_DELETE_RATIO ) ) { + shrink(); + } + }; + + int find_index(int fd) { + unsigned int i; + for (i=0; i size ) { - unsigned int new_size=near_pow_2(len+more); - fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd)); - myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *)); -// status=(unsigned char *)realloc(status,new_size*sizeof(unsigned char)); - size=new_size; - } - }; - - public: - unsigned int len=0; - unsigned int size=0; - struct pollfd *fds=NULL; - MySQL_Data_Stream **myds=NULL; -// unsigned char *status=NULL; // this should be moved within the Data Stream - ProxySQL_Poll() { - size=MIN_POLL_LEN; - // preallocate MIN_POLL_LEN slots - fds=(struct pollfd *)malloc(size*sizeof(struct pollfd)); - myds=(MySQL_Data_Stream **)malloc(size*sizeof(MySQL_Data_Stream *)); - //status=(unsigned char *)malloc(size*sizeof(unsigned char)); - }; - - ~ProxySQL_Poll() { - unsigned int i; - for (i=0;imyds_type==MYDS_LISTENER) { - delete myds[i]; - } - } - free(myds); - free(fds); - } - - void add(uint32_t _events, int _fd, MySQL_Data_Stream *_myds) { - if (len==size) { - expand(1); - } - myds[len]=_myds; - fds[len].fd=_fd; - fds[len].events=_events; - fds[len].revents=0; - len++; - }; - - void remove_index_fast(unsigned int i) { - if (i != (len-1)) { - myds[i]=myds[len-1]; - fds[i].fd=fds[len-1].fd; - fds[i].events=fds[len-1].events; - fds[i].revents=fds[len-1].revents; - //status[i]=status[len-1]; - } - len--; - if ( ( len>MIN_POLL_LEN ) && ( size > len*MIN_POLL_DELETE_RATIO ) ) { - shrink(); - } - }; -}; -*/ - - -/* -class ProxySQL_Poll; -*/ - -class ProxySQL_Poll { - - private: - void shrink() { - unsigned int new_size=near_pow_2(len+1); - fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd)); - myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *)); -// status=(unsigned char *)realloc(status,new_size*sizeof(unsigned char)); - last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long)); - last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long)); - size=new_size; - }; - void expand(unsigned int more) { - if ( (len+more) > size ) { - unsigned int new_size=near_pow_2(len+more); - fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd)); - myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *)); -// status=(unsigned char *)realloc(status,new_size*sizeof(unsigned char)); - last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long)); - last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long)); - size=new_size; - } - }; - - public: - int poll_timeout; - unsigned long loops; - StatCounters *loop_counters; - unsigned int len; - unsigned int size; - struct pollfd *fds; - MySQL_Data_Stream **myds; - unsigned long long *last_recv; - unsigned long long *last_sent; - volatile int pending_listener_add; - volatile int pending_listener_del; -// unsigned char *status=NULL; // this should be moved within the Data Stream - ProxySQL_Poll() { - loop_counters=new StatCounters(15,10,false); - poll_timeout=0; - loops=0; - len=0; - pending_listener_add=0; - pending_listener_del=0; - size=MIN_POLL_LEN; - // preallocate MIN_POLL_LEN slots - fds=(struct pollfd *)malloc(size*sizeof(struct pollfd)); - myds=(MySQL_Data_Stream **)malloc(size*sizeof(MySQL_Data_Stream *)); - //status=(unsigned char *)malloc(size*sizeof(unsigned char)); - last_recv=(unsigned long long *)malloc(size*sizeof(unsigned long long)); - last_sent=(unsigned long long *)malloc(size*sizeof(unsigned long long)); - }; - - ~ProxySQL_Poll() { - unsigned int i; - for (i=0;imyds_type==MYDS_LISTENER) { - delete myds[i]; - } - } - free(myds); - free(fds); - free(last_recv); - free(last_sent); - delete loop_counters; - }; - - - - void add(uint32_t _events, int _fd, MySQL_Data_Stream *_myds, unsigned long long sent_time) { - //fprintf(stderr,"ProxySQL_Poll: Adding fd %d\n",_fd); - if (len==size) { - expand(1); - } - myds[len]=_myds; - fds[len].fd=_fd; - fds[len].events=_events; - fds[len].revents=0; - if (_myds) { - _myds->mypolls=this; - _myds->poll_fds_idx=len; // fix a serious bug - } - last_recv[len]=monotonic_time(); - last_sent[len]=sent_time; - len++; - }; - - void remove_index_fast(unsigned int i) { - //fprintf(stderr,"ProxySQL_Poll: Removing fd %d\n",fds[i].fd); - if ((int)i==-1) return; - myds[i]->poll_fds_idx=-1; // this prevents further delete - if (i != (len-1)) { - myds[i]=myds[len-1]; - fds[i].fd=fds[len-1].fd; - fds[i].events=fds[len-1].events; - fds[i].revents=fds[len-1].revents; - myds[i]->poll_fds_idx=i; // fix a serious bug - //status[i]=status[len-1]; - last_recv[i]=last_recv[len-1]; - last_sent[i]=last_sent[len-1]; - } - len--; - if ( ( len>MIN_POLL_LEN ) && ( size > len*MIN_POLL_DELETE_RATIO ) ) { - shrink(); - } - }; - - int find_index(int fd) { - unsigned int i; - for (i=0; i BtMap; + +typedef struct _creds_group_t { + rwlock_t lock; + BtMap bt_map; + PtrArray cred_array; +} creds_group_t; +*/ + + +MySQL_Authentication::MySQL_Authentication() { +#ifdef DEBUG + if (glovars.has_debug==false) { +#else + if (glovars.has_debug==true) { +#endif /* DEBUG */ + perror("Incompatible debagging version"); + exit(EXIT_FAILURE); + } + spinlock_rwlock_init(&creds_backends.lock); + spinlock_rwlock_init(&creds_frontends.lock); + creds_backends.cred_array = new PtrArray(); + creds_frontends.cred_array = new PtrArray(); +}; + +MySQL_Authentication::~MySQL_Authentication() { + reset(); +}; + +void MySQL_Authentication::print_version() { + fprintf(stderr,"Standard MySQL Authentication rev. %s -- %s -- %s\n", MYSQL_AUTHENTICATION_VERSION, __FILE__, __TIMESTAMP__); + }; + +bool MySQL_Authentication::add(char * username, char * password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward) { + uint64_t hash1, hash2; + SpookyHash *myhash=new SpookyHash(); + myhash->Init(1,2); + myhash->Update(username,strlen(username)); + myhash->Final(&hash1,&hash2); + delete myhash; + + creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends); + + spin_wrlock(&cg.lock); + btree::btree_map::iterator lookup; + lookup = cg.bt_map.find(hash1); + if (lookup != cg.bt_map.end()) { + account_details_t *ad=lookup->second; + cg.cred_array->remove_fast(ad); + cg.bt_map.erase(lookup); + free(ad->username); + free(ad->password); + free(ad->default_schema); + free(ad); + } + account_details_t *ad=(account_details_t *)malloc(sizeof(account_details_t)); + ad->username=strdup(username); + ad->password=strdup(password); + ad->use_ssl=use_ssl; + ad->default_hostgroup=default_hostgroup; + ad->default_schema=strdup(default_schema); + ad->schema_locked=schema_locked; + ad->transaction_persistent=transaction_persistent; + ad->fast_forward=fast_forward; + cg.bt_map.insert(std::make_pair(hash1,ad)); + cg.cred_array->add(ad); + spin_wrunlock(&cg.lock); + + return true; +}; + +bool MySQL_Authentication::del(char * username, enum cred_username_type usertype) { + bool ret=false; + uint64_t hash1, hash2; + SpookyHash *myhash=new SpookyHash(); + myhash->Init(1,2); + myhash->Update(username,strlen(username)); + myhash->Final(&hash1,&hash2); + delete myhash; + + creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends); + + spin_wrlock(&cg.lock); + btree::btree_map::iterator lookup; + lookup = cg.bt_map.find(hash1); + if (lookup != cg.bt_map.end()) { + account_details_t *ad=lookup->second; + cg.cred_array->remove_fast(ad); + cg.bt_map.erase(lookup); + free(ad->username); + free(ad->password); + free(ad->default_schema); + free(ad); + ret=true; + } + spin_wrunlock(&cg.lock); + + return ret; +}; + + + +char * MySQL_Authentication::lookup(char * username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward) { + char *ret=NULL; + uint64_t hash1, hash2; + SpookyHash myhash; + myhash.Init(1,2); + myhash.Update(username,strlen(username)); + myhash.Final(&hash1,&hash2); + + creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends); + + spin_rdlock(&cg.lock); + btree::btree_map::iterator lookup; + lookup = cg.bt_map.find(hash1); + if (lookup != cg.bt_map.end()) { + account_details_t *ad=lookup->second; + ret=l_strdup(ad->password); + if (use_ssl) *use_ssl=ad->use_ssl; + if (default_hostgroup) *default_hostgroup=ad->default_hostgroup; + if (default_schema) *default_schema=l_strdup(ad->default_schema); + if (schema_locked) *schema_locked=ad->schema_locked; + if (transaction_persistent) *transaction_persistent=ad->transaction_persistent; + if (fast_forward) *fast_forward=ad->fast_forward; + } + spin_rdunlock(&cg.lock); + return ret; + +} + +bool MySQL_Authentication::_reset(enum cred_username_type usertype) { + creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends); + + spin_wrlock(&cg.lock); + btree::btree_map::iterator lookup; + + while (cg.bt_map.size()) { + lookup = cg.bt_map.begin(); + if ( lookup != cg.bt_map.end() ) { + account_details_t *ad=lookup->second; + cg.cred_array->remove_fast(ad); + cg.bt_map.erase(lookup); + free(ad->username); + free(ad->password); + free(ad); + } + } + spin_wrunlock(&cg.lock); + + return true; +}; + +bool MySQL_Authentication::reset() { + _reset(USERNAME_BACKEND); + _reset(USERNAME_FRONTEND); + return true; +} diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index 0737502eb..3ec3fd537 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1,6 +1,5 @@ #include "proxysql.h" #include "cpp.h" -#include "Standard_MySQL_Thread.h" extern MySQL_Authentication *GloMyAuth; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 1427aba2b..6a77a7b1e 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1,6 +1,5 @@ #include "proxysql.h" #include "cpp.h" -#include "Standard_MySQL_Thread.h" extern Query_Processor *GloQPro; extern Query_Cache *GloQC; diff --git a/lib/Standard_MySQL_Thread.cpp b/lib/MySQL_Thread.cpp similarity index 89% rename from lib/Standard_MySQL_Thread.cpp rename to lib/MySQL_Thread.cpp index 0329729a7..99bd696fb 100644 --- a/lib/Standard_MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2,20 +2,17 @@ #define MYSQL_THREAD_IMPLEMENTATION #include "proxysql.h" #include "cpp.h" -#include "Standard_MySQL_Thread.h" +#include "MySQL_Thread.h" extern Query_Processor *GloQPro; -extern Standard_MySQL_Threads_Handler *GloMTH; +extern MySQL_Threads_Handler *GloMTH; -//class Standard_MySQL_Thread; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -//void mypoll_add(proxy_poll_t *, uint32_t, int, MySQL_Data_Stream *); -//void __mypoll_add(proxy_poll_t *, struct pollfd *, MySQL_Data_Stream *); -//int mypoll_del(proxy_poll_t *_myp, int i); + #ifdef __cplusplus } #endif /* __cplusplus */ @@ -134,7 +131,7 @@ static char * mysql_thread_variables_names[]= { -Standard_MySQL_Threads_Handler::Standard_MySQL_Threads_Handler() { +MySQL_Threads_Handler::MySQL_Threads_Handler() { #ifdef DEBUG if (glovars.has_debug==false) { #else @@ -170,7 +167,7 @@ Standard_MySQL_Threads_Handler::Standard_MySQL_Threads_Handler() { MLM = new MySQL_Listeners_Manager(); } -int Standard_MySQL_Threads_Handler::listener_add(const char *address, int port) { +int MySQL_Threads_Handler::listener_add(const char *address, int port) { char *s=(char *)malloc(strlen(address)+32); sprintf(s,"%s:%d",address,port); int ret=listener_add((const char *)s); @@ -178,13 +175,13 @@ int Standard_MySQL_Threads_Handler::listener_add(const char *address, int port) return ret; } -int Standard_MySQL_Threads_Handler::listener_add(const char *iface) { +int MySQL_Threads_Handler::listener_add(const char *iface) { int rc; rc=MLM->add(iface); if (rc>-1) { unsigned int i; for (i=0;imypolls.pending_listener_add,0,rc)); /* while(!__sync_bool_compare_and_swap(&thr->mypolls.pending_listener_change,0,1)) { cpu_relax_pa(); } @@ -199,18 +196,18 @@ int Standard_MySQL_Threads_Handler::listener_add(const char *iface) { return rc; } -int Standard_MySQL_Threads_Handler::listener_del(const char *iface) { +int MySQL_Threads_Handler::listener_del(const char *iface) { int idx; idx=MLM->find_idx(iface); if (idx>-1) { unsigned int i; int fd=MLM->get_fd(idx); for (i=0;imypolls.pending_listener_del,0,fd)); } for (i=0;imypolls.pending_listener_del,0)); } MLM->del(idx); @@ -221,20 +218,20 @@ int Standard_MySQL_Threads_Handler::listener_del(const char *iface) { return 0; } -void Standard_MySQL_Threads_Handler::wrlock() { +void MySQL_Threads_Handler::wrlock() { spin_wrlock(&rwlock); } -void Standard_MySQL_Threads_Handler::wrunlock() { +void MySQL_Threads_Handler::wrunlock() { spin_wrunlock(&rwlock); } -void Standard_MySQL_Threads_Handler::commit() { +void MySQL_Threads_Handler::commit() { __sync_add_and_fetch(&__global_MySQL_Thread_Variables_version,1); proxy_debug(PROXY_DEBUG_MYSQL_SERVER, 1, "Increasing version number to %d - all threads will notice this and refresh their variables\n", __global_MySQL_Thread_Variables_version); } -char * Standard_MySQL_Threads_Handler::get_variable_string(char *name) { +char * MySQL_Threads_Handler::get_variable_string(char *name) { if (!strcasecmp(name,"connect_timeout_server_error")) return strdup(variables.connect_timeout_server_error); if (!strcasecmp(name,"server_version")) return strdup(variables.server_version); if (!strcasecmp(name,"default_schema")) return strdup(variables.default_schema); @@ -243,19 +240,19 @@ char * Standard_MySQL_Threads_Handler::get_variable_string(char *name) { return NULL; } -uint16_t Standard_MySQL_Threads_Handler::get_variable_uint16(char *name) { +uint16_t MySQL_Threads_Handler::get_variable_uint16(char *name) { if (!strcasecmp(name,"server_capabilities")) return variables.server_capabilities; proxy_error("Not existing variable: %s\n", name); assert(0); return 0; } -uint8_t Standard_MySQL_Threads_Handler::get_variable_uint8(char *name) { +uint8_t MySQL_Threads_Handler::get_variable_uint8(char *name) { if (!strcasecmp(name,"default_charset")) return variables.default_charset; proxy_error("Not existing variable: %s\n", name); assert(0); return 0; } -int Standard_MySQL_Threads_Handler::get_variable_int(char *name) { +int MySQL_Threads_Handler::get_variable_int(char *name) { #ifdef DEBUG if (!strcasecmp(name,"session_debug")) return (int)variables.session_debug; #endif /* DEBUG */ @@ -272,7 +269,7 @@ int Standard_MySQL_Threads_Handler::get_variable_int(char *name) { return 0; } -char * Standard_MySQL_Threads_Handler::get_variable(char *name) { // this is the public function, accessible from admin +char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public function, accessible from admin #define INTBUFSIZE 4096 char intbuf[INTBUFSIZE]; if (!strcasecmp(name,"connect_timeout_server_error")) return strdup(variables.connect_timeout_server_error); @@ -335,7 +332,7 @@ char * Standard_MySQL_Threads_Handler::get_variable(char *name) { // this is the -bool Standard_MySQL_Threads_Handler::set_variable(char *name, char *value) { // this is the public function, accessible from admin +bool MySQL_Threads_Handler::set_variable(char *name, char *value) { // this is the public function, accessible from admin // IN: // name: variable name // value: variable value @@ -513,7 +510,7 @@ bool Standard_MySQL_Threads_Handler::set_variable(char *name, char *value) { // return false; } -char ** Standard_MySQL_Threads_Handler::get_variables_list() { +char ** MySQL_Threads_Handler::get_variables_list() { size_t l=sizeof(mysql_thread_variables_names)/sizeof(char *); unsigned int i; char **ret=(char **)malloc(sizeof(char *)*l); @@ -523,11 +520,11 @@ char ** Standard_MySQL_Threads_Handler::get_variables_list() { return ret; } -void Standard_MySQL_Threads_Handler::print_version() { +void MySQL_Threads_Handler::print_version() { fprintf(stderr,"Standard MySQL Threads Handler rev. %s -- %s -- %s\n", MYSQL_THREAD_VERSION, __FILE__, __TIMESTAMP__); } -void Standard_MySQL_Threads_Handler::init(unsigned int num, size_t stack) { +void MySQL_Threads_Handler::init(unsigned int num, size_t stack) { if (stack) { stacksize=stack; } else { @@ -543,12 +540,12 @@ void Standard_MySQL_Threads_Handler::init(unsigned int num, size_t stack) { mysql_threads=(proxysql_mysql_thread_t *)malloc(sizeof(proxysql_mysql_thread_t)*num_threads); } -proxysql_mysql_thread_t * Standard_MySQL_Threads_Handler::create_thread(unsigned int tn, void *(*start_routine) (void *)) { +proxysql_mysql_thread_t * MySQL_Threads_Handler::create_thread(unsigned int tn, void *(*start_routine) (void *)) { pthread_create(&mysql_threads[tn].thread_id, &attr, start_routine , &mysql_threads[tn]); return NULL; } -void Standard_MySQL_Threads_Handler::shutdown_threads() { +void MySQL_Threads_Handler::shutdown_threads() { unsigned int i; shutdown_=1; for (i=0; iget_variable((char *)"interfaces"); if (strlen(_tmp)==0) { @@ -574,7 +571,7 @@ void Standard_MySQL_Threads_Handler::start_listeners() { free_tokenizer( &tok ); } -Standard_MySQL_Threads_Handler::~Standard_MySQL_Threads_Handler() { +MySQL_Threads_Handler::~MySQL_Threads_Handler() { if (variables.connect_timeout_server_error) free(variables.connect_timeout_server_error); if (variables.default_schema) free(variables.default_schema); if (variables.interfaces) free(variables.interfaces); @@ -585,7 +582,7 @@ Standard_MySQL_Threads_Handler::~Standard_MySQL_Threads_Handler() { MLM=NULL; } -Standard_MySQL_Thread::~Standard_MySQL_Thread() { +MySQL_Thread::~MySQL_Thread() { if (mysql_sessions) { while(mysql_sessions->len) { @@ -621,7 +618,7 @@ Standard_MySQL_Thread::~Standard_MySQL_Thread() { -MySQL_Session * Standard_MySQL_Thread::create_new_session_and_client_data_stream(int _fd) { +MySQL_Session * MySQL_Thread::create_new_session_and_client_data_stream(int _fd) { int arg_on=1; MySQL_Session *sess=new MySQL_Session; register_session(sess); // register session @@ -653,7 +650,7 @@ MySQL_Session * Standard_MySQL_Thread::create_new_session_and_client_data_stream return sess; } -bool Standard_MySQL_Thread::init() { +bool MySQL_Thread::init() { int i; mysql_sessions = new PtrArray(); assert(mysql_sessions); @@ -676,11 +673,11 @@ bool Standard_MySQL_Thread::init() { return true; } -struct pollfd * Standard_MySQL_Thread::get_pollfd(unsigned int i) { +struct pollfd * MySQL_Thread::get_pollfd(unsigned int i) { return &mypolls.fds[i]; } -void Standard_MySQL_Thread::poll_listener_add(int sock) { +void MySQL_Thread::poll_listener_add(int sock) { MySQL_Data_Stream *listener_DS = new MySQL_Data_Stream; listener_DS->myds_type=MYDS_LISTENER; listener_DS->fd=sock; @@ -690,7 +687,7 @@ void Standard_MySQL_Thread::poll_listener_add(int sock) { mypolls.add(POLLIN, sock, listener_DS, monotonic_time()); } -void Standard_MySQL_Thread::poll_listener_del(int sock) { +void MySQL_Thread::poll_listener_del(int sock) { int i=mypolls.find_index(sock); if (i>=0) { MySQL_Data_Stream *myds=mypolls.myds[i]; @@ -700,7 +697,7 @@ void Standard_MySQL_Thread::poll_listener_del(int sock) { } } -void Standard_MySQL_Thread::register_session(MySQL_Session *_sess) { +void MySQL_Thread::register_session(MySQL_Session *_sess) { if (mysql_sessions==NULL) { mysql_sessions = new PtrArray(); } @@ -709,7 +706,7 @@ void Standard_MySQL_Thread::register_session(MySQL_Session *_sess) { proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p -- Registered new session\n", _sess->thread, _sess); } -void Standard_MySQL_Thread::unregister_session(int idx) { +void MySQL_Thread::unregister_session(int idx) { if (mysql_sessions==NULL) return; proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p -- Unregistered session\n", this, mysql_sessions->index(idx)); mysql_sessions->remove_index_fast(idx); @@ -717,7 +714,7 @@ void Standard_MySQL_Thread::unregister_session(int idx) { // main loop -void Standard_MySQL_Thread::run() { +void MySQL_Thread::run() { unsigned int n; int rc; //int arg_on=1; @@ -915,7 +912,7 @@ void Standard_MySQL_Thread::run() { } } -void Standard_MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned int n) { +void MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned int n) { mypolls.last_recv[n]=curtime; myds->revents=mypolls.fds[n].revents; myds->read_from_net(); @@ -981,7 +978,7 @@ void Standard_MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, } -void Standard_MySQL_Thread::process_all_sessions() { +void MySQL_Thread::process_all_sessions() { unsigned int n; int rc; for (n=0; nlen; n++) { @@ -1006,7 +1003,7 @@ void Standard_MySQL_Thread::process_all_sessions() { } } -void Standard_MySQL_Thread::refresh_variables() { +void MySQL_Thread::refresh_variables() { GloMTH->wrlock(); __thread_MySQL_Thread_Variables_version=__global_MySQL_Thread_Variables_version; mysql_thread___ping_interval_server=GloMTH->get_variable_int((char *)"ping_interval_server"); @@ -1031,7 +1028,7 @@ void Standard_MySQL_Thread::refresh_variables() { GloMTH->wrunlock(); } -Standard_MySQL_Thread::Standard_MySQL_Thread() { +MySQL_Thread::MySQL_Thread() { spinlock_rwlock_init(&thread_mutex); mypolls.len=0; mypolls.size=0; @@ -1049,7 +1046,7 @@ Standard_MySQL_Thread::Standard_MySQL_Thread() { } -void Standard_MySQL_Thread::process_all_sessions_connections_handler() { +void MySQL_Thread::process_all_sessions_connections_handler() { unsigned int n; int rc; for (n=0; nlen; n++) { @@ -1071,7 +1068,7 @@ void Standard_MySQL_Thread::process_all_sessions_connections_handler() { } } -void Standard_MySQL_Thread::register_session_connection_handler(MySQL_Session *_sess) { +void MySQL_Thread::register_session_connection_handler(MySQL_Session *_sess) { if (mysql_sessions_connections_handler==NULL) return; mysql_sessions_connections_handler->add(_sess); _sess->thread=this; @@ -1079,14 +1076,14 @@ void Standard_MySQL_Thread::register_session_connection_handler(MySQL_Session *_ proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p -- Registered new session for connection handler\n", _sess->thread, _sess); } -void Standard_MySQL_Thread::unregister_session_connection_handler(int idx) { +void MySQL_Thread::unregister_session_connection_handler(int idx) { if (mysql_sessions_connections_handler==NULL) return; proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p -- Unregistered session\n", this, mysql_sessions_connections_handler->index(idx)); mysql_sessions_connections_handler->remove_index_fast(idx); } -void Standard_MySQL_Thread::myds_backend_set_failed_connect(MySQL_Data_Stream *myds, unsigned int n) { +void MySQL_Thread::myds_backend_set_failed_connect(MySQL_Data_Stream *myds, unsigned int n) { if (curtime>mypolls.last_recv[n]+10000000) { proxy_error("connect() timeout . curtime: %llu , last_recv: %llu , failed after %lluus . fd: %d , myds_type: %s\n", curtime, mypolls.last_recv[n] , (curtime-mypolls.last_recv[n]) , myds->fd, (myds->myds_type==MYDS_BACKEND_PAUSE_CONNECT ? "MYDS_BACKEND_PAUSE_CONNECT" : "MYDS_BACKEND_NOT_CONNECTED" ) ); myds->myds_type=MYDS_BACKEND_FAILED_CONNECT; @@ -1095,14 +1092,14 @@ void Standard_MySQL_Thread::myds_backend_set_failed_connect(MySQL_Data_Stream *m } } -void Standard_MySQL_Thread::myds_backend_pause_connect(MySQL_Data_Stream *myds) { +void MySQL_Thread::myds_backend_pause_connect(MySQL_Data_Stream *myds) { proxy_error("connect() error on fd %d . Pausing ...\n", myds->fd); myds->myds_type=MYDS_BACKEND_PAUSE_CONNECT; myds->sess->pause=curtime+10000000; myds->sess->to_process=1; } -void Standard_MySQL_Thread::myds_backend_first_packet_after_connect(MySQL_Data_Stream *myds, unsigned int n) { +void MySQL_Thread::myds_backend_first_packet_after_connect(MySQL_Data_Stream *myds, unsigned int n) { int optval; socklen_t optlen=sizeof(optval); getsockopt(myds->fd, SOL_SOCKET, SO_ERROR, &optval, &optlen); @@ -1117,7 +1114,7 @@ void Standard_MySQL_Thread::myds_backend_first_packet_after_connect(MySQL_Data_S } } -void Standard_MySQL_Thread::listener_handle_new_connection(MySQL_Data_Stream *myds, unsigned int n) { +void MySQL_Thread::listener_handle_new_connection(MySQL_Data_Stream *myds, unsigned int n) { int c; c=accept(myds->fd, NULL, NULL); if (c>-1) { // accept() succeeded @@ -1136,7 +1133,7 @@ void Standard_MySQL_Thread::listener_handle_new_connection(MySQL_Data_Stream *my } } -SQLite3_result * Standard_MySQL_Thread::SQL3_Thread_status(MySQL_Session *sess) { +SQLite3_result * MySQL_Thread::SQL3_Thread_status(MySQL_Session *sess) { proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 4, "Dumping MySQL Session status\n"); SQLite3_result *result=new SQLite3_result(4); result->add_column_definition(SQLITE_TEXT,"ThreadID"); @@ -1208,19 +1205,19 @@ SQLite3_result * Standard_MySQL_Thread::SQL3_Thread_status(MySQL_Session *sess) return result; } -SQLite3_result * Standard_MySQL_Threads_Handler::SQL3_Threads_status(MySQL_Session *sess) { +SQLite3_result * MySQL_Threads_Handler::SQL3_Threads_status(MySQL_Session *sess) { proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 4, "Dumping MySQL Threads Handler status\n"); SQLite3_result *result=new SQLite3_result(1); result->add_column_definition(SQLITE_TEXT,"Status"); //char buf[1024]; unsigned int i; for (i=0;ithread) spin_wrlock(&thr->thread_mutex); } //sleep(1); for (i=0;ithread) spin_wrunlock(&thr->thread_mutex); } @@ -1237,28 +1234,13 @@ SQLite3_result * Standard_MySQL_Threads_Handler::SQL3_Threads_status(MySQL_Sessi return result; } -void Standard_MySQL_Threads_Handler::signal_all_threads() { +void MySQL_Threads_Handler::signal_all_threads() { unsigned int i; char c; for (i=0;ipipefd[1]; write(fd,&c,1); } } -extern "C" MySQL_Threads_Handler * create_MySQL_Threads_Handler_func() { - return new Standard_MySQL_Threads_Handler(); -} - -extern "C" void destroy_MySQL_Threads_Handler_func(MySQL_Threads_Handler * ms) { - delete ms; -} - -extern "C" MySQL_Thread * create_MySQL_Thread_func() { - return new Standard_MySQL_Thread(); -} - -extern "C" void destroy_MySQL_Thread_func(MySQL_Thread * ms) { - delete ms; -} diff --git a/lib/Standard_MySQL_Authentication.cpp b/lib/Standard_MySQL_Authentication.cpp deleted file mode 100644 index 836e8dcfb..000000000 --- a/lib/Standard_MySQL_Authentication.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include "btree_map.h" -#include "proxysql.h" -#include "cpp.h" -#include "proxysql_atomic.h" -#include "SpookyV2.h" - - -typedef struct _account_details_t { - char *username; - char *password; - bool use_ssl; - int default_hostgroup; - char *default_schema; - bool schema_locked; - bool transaction_persistent; - bool fast_forward; -} account_details_t; - -#ifdef DEBUG -#define DEB "_DEBUG" -#else -#define DEB "" -#endif /* DEBUG */ -#define MYSQL_AUTHENTICATION_VERSION "0.1.0706" DEB - -typedef btree::btree_map BtMap; - -typedef struct _creds_group_t { - rwlock_t lock; - BtMap bt_map; - PtrArray cred_array; -} creds_group_t; - -class Standard_MySQL_Authentication: public MySQL_Authentication { - private: - creds_group_t creds_backends; - creds_group_t creds_frontends; - public: - Standard_MySQL_Authentication() { -#ifdef DEBUG - if (glovars.has_debug==false) { -#else - if (glovars.has_debug==true) { -#endif /* DEBUG */ - perror("Incompatible debagging version"); - exit(EXIT_FAILURE); - } - spinlock_rwlock_init(&creds_backends.lock); - spinlock_rwlock_init(&creds_frontends.lock); - }; - - ~Standard_MySQL_Authentication() { - reset(); - }; - - virtual void print_version() { - fprintf(stderr,"Standard MySQL Authentication rev. %s -- %s -- %s\n", MYSQL_AUTHENTICATION_VERSION, __FILE__, __TIMESTAMP__); - }; - - virtual bool add(char * username, char * password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward) { - uint64_t hash1, hash2; - SpookyHash *myhash=new SpookyHash(); - myhash->Init(1,2); - myhash->Update(username,strlen(username)); - myhash->Final(&hash1,&hash2); - delete myhash; - - creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends); - - spin_wrlock(&cg.lock); - btree::btree_map::iterator lookup; - lookup = cg.bt_map.find(hash1); - if (lookup != cg.bt_map.end()) { - account_details_t *ad=lookup->second; - cg.cred_array.remove_fast(ad); - cg.bt_map.erase(lookup); - free(ad->username); - free(ad->password); - free(ad->default_schema); - free(ad); - } - account_details_t *ad=(account_details_t *)malloc(sizeof(account_details_t)); - ad->username=strdup(username); - ad->password=strdup(password); - ad->use_ssl=use_ssl; - ad->default_hostgroup=default_hostgroup; - ad->default_schema=strdup(default_schema); - ad->schema_locked=schema_locked; - ad->transaction_persistent=transaction_persistent; - ad->fast_forward=fast_forward; - cg.bt_map.insert(std::make_pair(hash1,ad)); - cg.cred_array.add(ad); - spin_wrunlock(&cg.lock); - - return true; - }; - - virtual bool del(char * username, enum cred_username_type usertype) { - bool ret=false; - uint64_t hash1, hash2; - SpookyHash *myhash=new SpookyHash(); - myhash->Init(1,2); - myhash->Update(username,strlen(username)); - myhash->Final(&hash1,&hash2); - delete myhash; - - creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends); - - spin_wrlock(&cg.lock); - btree::btree_map::iterator lookup; - lookup = cg.bt_map.find(hash1); - if (lookup != cg.bt_map.end()) { - account_details_t *ad=lookup->second; - cg.cred_array.remove_fast(ad); - cg.bt_map.erase(lookup); - free(ad->username); - free(ad->password); - free(ad->default_schema); - free(ad); - ret=true; - } - spin_wrunlock(&cg.lock); - - return ret; - }; - - - - virtual char * lookup(char * username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward) { - char *ret=NULL; - uint64_t hash1, hash2; - SpookyHash myhash; - myhash.Init(1,2); - myhash.Update(username,strlen(username)); - myhash.Final(&hash1,&hash2); - - creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends); - - spin_rdlock(&cg.lock); - btree::btree_map::iterator lookup; - lookup = cg.bt_map.find(hash1); - if (lookup != cg.bt_map.end()) { - account_details_t *ad=lookup->second; - ret=l_strdup(ad->password); - if (use_ssl) *use_ssl=ad->use_ssl; - if (default_hostgroup) *default_hostgroup=ad->default_hostgroup; - if (default_schema) *default_schema=l_strdup(ad->default_schema); - if (schema_locked) *schema_locked=ad->schema_locked; - if (transaction_persistent) *transaction_persistent=ad->transaction_persistent; - if (fast_forward) *fast_forward=ad->fast_forward; - } - spin_rdunlock(&cg.lock); - return ret; - - } - - bool _reset(enum cred_username_type usertype) { - - creds_group_t &cg=(usertype==USERNAME_BACKEND ? creds_backends : creds_frontends); - - spin_wrlock(&cg.lock); - btree::btree_map::iterator lookup; - - while (cg.bt_map.size()) { - lookup = cg.bt_map.begin(); - if ( lookup != cg.bt_map.end() ) { - account_details_t *ad=lookup->second; - cg.cred_array.remove_fast(ad); - cg.bt_map.erase(lookup); - free(ad->username); - free(ad->password); - free(ad); - } - } - spin_wrunlock(&cg.lock); - - return true; - }; - - virtual bool reset() { - _reset(USERNAME_BACKEND); - _reset(USERNAME_FRONTEND); - return true; - } -}; - - -extern "C" MySQL_Authentication * create_MySQL_Authentication_func() { - return new Standard_MySQL_Authentication(); -} - -extern "C" void destroy_MyAuth(MySQL_Authentication * myauth) { - delete myauth; -} - diff --git a/lib/Standard_ProxySQL_Admin.cpp b/lib/Standard_ProxySQL_Admin.cpp index fc47d2efa..db1520937 100644 --- a/lib/Standard_ProxySQL_Admin.cpp +++ b/lib/Standard_ProxySQL_Admin.cpp @@ -16,7 +16,6 @@ #include "SpookyV2.h" //#define MYSQL_THREAD_IMPLEMENTATION -#include "Standard_MySQL_Thread.h" static volatile int load_main_=0; @@ -1137,7 +1136,7 @@ void *child_mysql(void *arg) { int rc; pthread_mutex_unlock(&sock_mutex); // MySQL_Thread *mysql_thr=create_MySQL_Thread_func(); - Standard_MySQL_Thread *mysql_thr=new Standard_MySQL_Thread(); + MySQL_Thread *mysql_thr=new MySQL_Thread(); //mysql_thr->mysql_sessions = new PtrArray(); mysql_thr->curtime=monotonic_time(); GloQPro->init_thread(); diff --git a/src/main.cpp b/src/main.cpp index 9b556fa79..1003edefd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,11 +30,6 @@ void * __mysql_auth; void * __proxysql_admin; -create_MySQL_Thread_t * create_MySQL_Thread = NULL; -destroy_MySQL_Thread_t * destroy_MySQL_Thread = NULL; -create_MySQL_Threads_Handler_t * create_MySQL_Threads_Handler = NULL; -destroy_MySQL_Threads_Handler_t * destroy_MySQL_Threads_Handler = NULL; -create_MySQL_Authentication_t * create_MySQL_Authentication = NULL; create_Query_Processor_t * create_Query_Processor = NULL; create_ProxySQL_Admin_t * create_ProxySQL_Admin = NULL; @@ -159,7 +154,7 @@ void * mysql_worker_thread_func(void *arg) { __thr_sfp=l_mem_init(); proxysql_mysql_thread_t *mysql_thread=(proxysql_mysql_thread_t *)arg; //MySQL_Thread *worker = new MySQL_Thread; - MySQL_Thread *worker = create_MySQL_Thread(); + MySQL_Thread *worker = new MySQL_Thread(); mysql_thread->worker=worker; worker->init(); // worker->poll_listener_add(listen_fd); @@ -172,7 +167,7 @@ void * mysql_worker_thread_func(void *arg) { worker->run(); //delete worker; - destroy_MySQL_Thread(worker); + delete worker; l_mem_destroy(__thr_sfp); return NULL; } @@ -346,6 +341,7 @@ int main(int argc, const char * argv[]) { // } } +/* { dlerror(); dlsym_error=NULL; @@ -388,7 +384,7 @@ int main(int argc, const char * argv[]) { // create_MySQL_Thread=&create_MySQL_Thread_func; // } } - +*/ { dlerror(); dlsym_error=NULL; @@ -411,6 +407,7 @@ int main(int argc, const char * argv[]) { // } } +/* { dlerror(); dlsym_error=NULL; @@ -431,6 +428,8 @@ int main(int argc, const char * argv[]) { create_MySQL_Authentication=&create_MySQL_Authentication_func; } } +*/ + { dlerror(); @@ -458,7 +457,7 @@ __start_label: // MyHGH=new MySQL_HostGroups_Handler(); MyHGM=new MySQL_HostGroups_Manager(); - GloMTH=create_MySQL_Threads_Handler(); + GloMTH=new MySQL_Threads_Handler(); GloMTH->print_version(); { @@ -471,7 +470,7 @@ __start_label: GloVars.confFile->CloseFile(); } - GloMyAuth = create_MySQL_Authentication(); + GloMyAuth = new MySQL_Authentication(); GloMyAuth->print_version(); GloAdmin->init_users(); @@ -659,7 +658,7 @@ __shutdown: GloQPro=NULL; } if (GloMyAuth) { - delete GloMyAuth; + delete GloMyAuth; GloMyAuth=NULL; } if (GloMTH) { diff --git a/src/proxysql.cfg b/src/proxysql.cfg index 75c6096ed..18e230fab 100644 --- a/src/proxysql.cfg +++ b/src/proxysql.cfg @@ -18,7 +18,7 @@ admin_variables= mysql_variables= { - threads=1 + threads=4 //threads=32 have_compress=true poll_timeout=2000 @@ -51,13 +51,13 @@ mysql_servers = address="127.0.0.1" port=3306 hostgroup=0 - max_connections=10 + max_connections=100 }, - { address="127.0.0.2" , port=3306 , hostgroup=0, max_connections=5 }, +// { address="127.0.0.2" , port=3306 , hostgroup=0, max_connections=5 }, { address="127.0.0.1" , port=3306 , hostgroup=1 }, - { address="127.0.0.2" , port=3306 , hostgroup=1 }, - { address="127.0.0.3" , port=3306 , hostgroup=1 }, - { address="127.0.0.4" , port=3306 , hostgroup=1 }, +// { address="127.0.0.2" , port=3306 , hostgroup=1 }, +// { address="127.0.0.3" , port=3306 , hostgroup=1 }, +// { address="127.0.0.4" , port=3306 , hostgroup=1 }, { address="/var/lib/mysql/mysql.sock" , port=0 , hostgroup=1 } )