From f99f54b2a003d02abf2eb89db23c40f192823af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 15 May 2015 22:23:05 +0000 Subject: [PATCH] General code cleanup --- lib/Makefile | 59 +------------- src/main.cpp | 221 +-------------------------------------------------- 2 files changed, 2 insertions(+), 278 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 8d1fe306c..86cfc9d89 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -8,21 +8,12 @@ DEPS_PATH=../deps MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client MARIADB_IDIR=$(MARIADB_PATH)/include -#LIBEVENT_PATH=$(DEPS_PATH)/libevent/libevent -#LIBEVENT_IDIR=-I$(LIBEVENT_PATH)/include - - JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc -#GLIB_PATH=$(DEPS_PATH)/glib/glib -#GLIB_IDIRS=-I$(GLIB_PATH) -I$(GLIB_PATH)/glib - - LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9 LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib - INJECTION_PATH=$(DEPS_PATH)/libinjection INJECTION_IDIR=$(INJECTION_PATH) @@ -32,14 +23,12 @@ RE2_IDIR=$(RE2_PATH) IDIR=../include -#IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBEVENT_IDIR) $(GLIB_IDIRS) $(LIBCONFIG_IDIR) IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(RE2_IDIR) LDIRS=-L$(JEMALLOC_PATH)/lib -L$(RE2_PATH)/obj -L$(INJECTION_PATH) LIBS=-rdynamic -Wl,-Bstatic -ljemalloc_pic -lre2 -Wl,-Bdynamic -ldl -lpthread -lm -lz -lrt $(EXTRALINK) - ODIR= obj CC=gcc @@ -49,52 +38,14 @@ CPP=g++ CFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall #-lcrypto CPPFLAGS=-std=c++0x $(CFLAGS) $(LDIRS) $(LIBS) -#default: libproxysql.a -#default: libproxysql.a DYN_LIB libproxysql.so -default: libproxysql.a libproxysql.so +default: libproxysql.a .PHONY: default -#_OBJ = mysql_protocol.o debug.o global_variables.o mysql_data_stream.o network.o proxysql_global.o _OBJ = sqlite3.o c_tokenizer.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) -#_OBJ_CPP = Standard_Query_Cache.oo SpookyV2.oo Standard_MySQL_Thread.oo gen_utils.oo mysql_connection_pool.oo simple_kv.oo advanced_kv.oo sqlite3db.oo mysql_connection.oo global_variables.oo proxysql_mem.oo mysql_protocol.oo mysql_data_stream.oo mysql_session.oo mysql_backend.oo -#_OBJ_CPP = ProxySQL_GloVars.oo network.oo debug.oo proxysql_global.oo configfile.oo Standard_Query_Cache.oo SpookyV2.oo Standard_MySQL_Thread.oo Standard_MySQL_Authentication.oo gen_utils.oo mysql_connection_pool.oo simple_kv.oo advanced_kv.oo sqlite3db.oo mysql_connection.oo global_variables.oo proxysql_mem.oo MySQL_Protocol.oo mysql_data_stream.oo mysql_session.oo mysql_backend.oo -#_OBJ_CPP = ProxySQL_GloVars.oo network.oo debug.oo proxysql_global.oo configfile.oo Standard_Query_Cache.oo SpookyV2.oo Standard_MySQL_Authentication.oo gen_utils.oo mysql_connection_pool.oo simple_kv.oo advanced_kv.oo sqlite3db.oo mysql_connection.oo global_variables.oo proxysql_mem.oo MySQL_Protocol.oo mysql_data_stream.oo mysql_session.oo mysql_backend.oo -#_OBJ_CPP = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Standard_Query_Cache.oo SpookyV2.oo Standard_MySQL_Authentication.oo gen_utils.oo mysql_connection_pool.oo simple_kv.oo advanced_kv.oo sqlite3db.oo mysql_connection.oo global_variables.oo proxysql_mem.oo MySQL_Protocol.oo mysql_data_stream.oo MySQL_Session.oo mysql_backend.oo MySQL_HostGroups_Manager.oo _OBJ_CPP = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo simple_kv.oo sqlite3db.oo global_variables.oo proxysql_mem.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo ProxySQL_Admin.oo OBJ_CPP = $(patsubst %,$(ODIR)/%,$(_OBJ_CPP)) -#_SHARED_OBJ= Standard_Query_Cache.ko Standard_MySQL_Thread.ko - -#Standard_MySQL_Thread.so: Standard_MySQL_Thread.cpp MySQL_Protocol.cpp mysql_data_stream.cpp MySQL_Session.cpp mysql_backend.cpp mysql_connection.cpp MySQL_HostGroups_Manager.cpp libproxysql.a -# $(CPP) -shared -fPIC -o $@ $(CPPFLAGS) Standard_MySQL_Thread.cpp MySQL_Protocol.cpp mysql_data_stream.cpp MySQL_Session.cpp mysql_backend.cpp mysql_connection.cpp MySQL_HostGroups_Manager.cpp libproxysql.a -lcrypto $(LIBS) - -#Standard_ProxySQL_Admin.so: Standard_ProxySQL_Admin.cpp libproxysql.a -# $(CPP) -shared -fPIC -o $@ $(CPPFLAGS) MySQL_Thread.cpp Standard_ProxySQL_Admin.cpp MySQL_Protocol.cpp mysql_data_stream.cpp MySQL_Session.cpp mysql_backend.cpp mysql_connection.cpp MySQL_HostGroups_Manager.cpp libproxysql.a -lcrypto $(LIBS) -# $(CPP) -shared -fPIC -o $@ $(CPPFLAGS) Standard_ProxySQL_Admin.cpp libproxysql.a -lcrypto $(LIBS) - -#Standard_ProxySQL_Admin.so: Standard_ProxySQL_Admin.ko Standard_MySQL_Thread.ko libproxysql.a -# $(CPP) -shared -fPIC -o $@ $(CPPFLAGS) Standard_ProxySQL_Admin.ko Standard_MySQL_Thread.ko libproxysql.a -lcrypto $(LIBS) - -#Standard_Query_Processor.so: Standard_Query_Processor.ko libproxysql.a -# $(CPP) -shared -fPIC -o $@ $(CPPFLAGS) Standard_Query_Processor.ko libproxysql.a -lcrypto $(LIBS) -linjection - -#Standard_MySQL_Authentication.so: Standard_MySQL_Authentication.ko libproxysql.a -# $(CPP) -shared -fPIC -o $@ $(CPPFLAGS) Standard_MySQL_Authentication.ko libproxysql.a -lcrypto $(LIBS) - -#Standard_Query_Cache.so: Standard_Query_Cache.ko libproxysql.a -# $(CPP) -shared -fPIC -o $@ $(CPPFLAGS) Standard_Query_Cache.ko libproxysql.a -lcrypto -linjection $(LIBS) -# $(CC) -shared -fPIC -o $@ $(CPPFLAGS) $(ODIR)/Standard_Query_Cache.oo $(ODIR)/SpookyV2.oo $(ODIR)/gen_utils.oo - -#Standard_MySQL_Thread.so: Standard_MySQL_Thread.ko libproxysql.a -# $(CPP) -shared -fPIC -o $@ $(CPPFLAGS) Standard_MySQL_Thread.ko libproxysql.a -lcrypto $(LIBS) -# $(CC) -shared -fPIC -o $@ $(CPPFLAGS) $(ODIR)/Standard_MySQL_Thread.oo $(ODIR)/mysql_session.oo - -#LOADABLE_LIB = Standard_ProxySQL_Admin.so # Standard_Query_Cache.so - -#DYN_LIB: $(LOADABLE_LIB) -#.PHONY: DYN_LIB - %.ko: %.cpp $(CPP) -fPIC -c -o $@ $< $(CPPFLAGS) @@ -104,23 +55,15 @@ $(ODIR)/%.o: %.c $(ODIR)/%.oo: %.cpp $(CPP) -fPIC -c -o $@ $< $(CPPFLAGS) -#mysql_data_stream.oo: mysql_data_stream.cpp -# g++ -c -o mysql_data_stream.oo mysql_data_stream.cpp $(CFLAGS) -Wall - - libproxysql.a: $(ODIR) $(OBJ) $(OBJ_CPP) $(INJECTION_PATH)/libinjection.a $(RE2_PATH)/obj/libre2.a ar rcs $@ $(OBJ) $(OBJ_CPP) $(INJECTION_PATH)/libinjection.a $(RE2_PATH)/obj/libre2.a -libproxysql.so: $(ODIR) $(OBJ) $(OBJ_CPP) - $(CPP) -shared -fPIC -o $@ $(OBJ) $(OBJ_CPP) - $(ODIR): mkdir $(ODIR) #all: $(EXECUTABLE) - clean: rm -f *.pid $(ODIR)/*.oo $(ODIR)/*.o *.ko *.so *~ core libproxysql.a diff --git a/src/main.cpp b/src/main.cpp index b7d1a6747..3983e005c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,33 +112,6 @@ char * gen_random_string(const int len) { -/* -void diagnostic_myds(MySQL_Data_Stream *myds) { - if (!myds) return; - fprintf(stderr," fd=%d, pkts_sent=%llu, pkts_recv=%llu, bytes_sent=%llu, bytes_recv=%llu\n", myds->fd, myds->pkts_sent, myds->pkts_recv, myds->bytes_info.bytes_sent, myds->bytes_info.bytes_recv); - //struct pollfd *_pollfd; - //_pollfd=&myds->sess->thread->mypolls.fds[myds->poll_fds_idx]; - //fprintf(stderr," poll_fds_idx=%d pollfd={fd=%d, events=%d, revents=%d}\n", myds->poll_fds_idx, _pollfd->fd, _pollfd->events, _pollfd->revents); -} - -void diagnostic_all() { - fprintf(stderr,"Diagnostic\n"); - int i; - for (i=0;imysql_sessions->len; j++) { - MySQL_Session *sess=(MySQL_Session *)thr->mysql_sessions->index(j); - fprintf(stderr," Session=%p\n", sess); - fprintf(stderr," Client Data Stream=%p, fd=%d\n", sess->client_myds, ( sess->client_myds ? sess->client_myds->fd : 0 )); - diagnostic_myds(sess->client_myds); - fprintf(stderr," Server Data Stream=%p, fd=%d\n", sess->server_myds, ( sess->server_myds ? sess->server_myds->fd : 0 )); - diagnostic_myds(sess->server_myds); - } - } -} -*/ void * mysql_worker_thread_func(void *arg) { __thr_sfp=l_mem_init(); @@ -173,7 +146,7 @@ void * mysql_shared_query_cache_funct(void *arg) { int main(int argc, const char * argv[]) { - + unsigned int i; { #ifdef DEBUG glovars.has_debug=true; @@ -284,163 +257,6 @@ int main(int argc, const char * argv[]) { } */ - - - //bool rc; - -// dlerror(); -// char* dlsym_error = NULL; - -/* -{ - void * __memcached = dlopen("../deps/memcached/memcached/proxymemcached.so", RTLD_LAZY); - if (!__memcached) { - cerr << "Cannot load library: " << dlerror() << '\n'; - exit(EXIT_FAILURE); - } else { - dlerror(); - *(void **) (&__memcached_main) = dlsym(__memcached, "memcached_main"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol memcached_main: " << dlsym_error << '\n'; - exit(EXIT_FAILURE); - } - pthread_create(&memcached_pthread, NULL, memcached_main_thread , NULL); - } -} -*/ - -/* - create_QC_t* create_QC = NULL; - -{ - __qc = dlopen("../lib/Standard_Query_Cache.so", RTLD_LAZY); - if (!__qc) { - cerr << "Cannot load library: " << dlerror() << '\n'; - // exit(EXIT_FAILURE); - } else { - dlerror(); - create_QC = (create_QC_t*) dlsym(__qc, "create_QC_func"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol create_QC: " << dlsym_error << '\n'; - //exit(EXIT_FAILURE); - } - } -// if (__qc==NULL || dlsym_error) { -// create_QC=&create_QC_func; -// } -} -*/ -/* -{ - dlerror(); - dlsym_error=NULL; - //void* __mysql_thread = dlopen("../lib/Standard_MySQL_Thread.so", RTLD_LAZY|RTLD_DEEPBIND); - __mysql_thread = dlopen("../lib/Standard_MySQL_Thread.so", RTLD_LAZY); - if (!__mysql_thread) { - cerr << "Cannot load library: " << dlerror() << '\n'; - exit(EXIT_FAILURE); - } else { - dlerror(); - create_MySQL_Threads_Handler = (create_MySQL_Threads_Handler_t *) dlsym(__mysql_thread, "create_MySQL_Threads_Handler_func"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol create_MySQL_Threads_Handler_func: " << dlsym_error << '\n'; - exit(EXIT_FAILURE); - } - dlerror(); - create_MySQL_Thread = (create_MySQL_Thread_t *) dlsym(__mysql_thread, "create_MySQL_Thread_func"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol create_MySQL_Thread_func: " << dlsym_error << '\n'; - exit(EXIT_FAILURE); - } - dlerror(); - destroy_MySQL_Threads_Handler = (destroy_MySQL_Threads_Handler_t *) dlsym(__mysql_thread, "destroy_MySQL_Threads_Handler_func"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol destroy_MySQL_Threads_Handler_func: " << dlsym_error << '\n'; - exit(EXIT_FAILURE); - } - dlerror(); - destroy_MySQL_Thread = (destroy_MySQL_Thread_t *) dlsym(__mysql_thread, "destroy_MySQL_Thread_func"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol destroy_MySQL_Thread_func: " << dlsym_error << '\n'; - exit(EXIT_FAILURE); - } - } -// if (__mysql_thread==NULL || dlsym_error) { -// create_MySQL_Thread=&create_MySQL_Thread_func; -// } -} -*/ -/* -{ - dlerror(); - dlsym_error=NULL; - //void* __mysql_thread = dlopen("../lib/Standard_MySQL_Thread.so", RTLD_LAZY|RTLD_DEEPBIND); - __query_processor = dlopen("../lib/Standard_Query_Processor.so", RTLD_LAZY); - if (!__query_processor) { - cerr << "Cannot load library: " << dlerror() << '\n'; - exit(EXIT_FAILURE); - } else { - dlerror(); - create_Query_Processor = (create_Query_Processor_t *) dlsym(__query_processor, "create_Query_Processor_func"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol &create_Query_Processor_func: " << dlsym_error << '\n'; - exit(EXIT_FAILURE); - } - } -// if (__mysql_thread==NULL || dlsym_error) { -// create_MySQL_Thread=&create_MySQL_Thread_func; -// } -} -*/ -/* -{ - dlerror(); - dlsym_error=NULL; - __mysql_auth = dlopen("../lib/Standard_MySQL_Authentication.so", RTLD_LAZY); - if (!__mysql_auth) { - cerr << "Cannot load library: " << dlerror() << '\n'; - //exit(EXIT_FAILURE); - } else { - dlerror(); - create_MySQL_Authentication = (create_MySQL_Authentication_t *) dlsym(__mysql_auth, "create_MySQL_Authentication_func"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol &create_MySQL_Authentication: " << dlsym_error << '\n'; - //exit(EXIT_FAILURE); - } - } - if (__mysql_auth==NULL || dlsym_error) { - create_MySQL_Authentication=&create_MySQL_Authentication_func; - } -} -*/ - -/* -{ - dlerror(); - dlsym_error=NULL; - __proxysql_admin = dlopen("../lib/Standard_ProxySQL_Admin.so", RTLD_LAZY); - if (!__proxysql_admin) { - cerr << "Cannot load library: " << dlerror() << '\n'; - exit(EXIT_FAILURE); - } else { - dlerror(); - create_ProxySQL_Admin = (create_ProxySQL_Admin_t *) dlsym(__proxysql_admin, "create_ProxySQL_Admin_func"); - dlsym_error = dlerror(); - if (dlsym_error!=NULL) { - cerr << "Cannot load symbol &create_ProxySQL_Admin_func: " << dlsym_error << '\n'; - exit(EXIT_FAILURE); - } - } -} -*/ __start_label: GloQC=NULL; @@ -524,34 +340,12 @@ __start_label: // start all services - //listen_fd=listen_on_port((char *)"127.0.0.1",6033, 50); - //listen_fd=listen_on_port((char *)"0.0.0.0",6033, 50); - //socket_fd=listen_on_unix((char *)"/tmp/proxysql.sock", 50); - //ioctl_FIONBIO(listen_fd, 1); - //ioctl_FIONBIO(socket_fd, 1); - - unsigned int i; - - //GloMTH->init(6, 512*1024); GloMTH->init(); - //mysql_threads=(proxysql_mysql_thread_t *)malloc(sizeof(proxysql_mysql_thread_t)*NUM_THREADS); - //assert(mysql_threads); load_ = GloMTH->num_threads + 1; -/* - pthread_attr_t attr; - - -{ - rc=pthread_attr_init(&attr); - rc=pthread_attr_setstacksize(&attr, 512*1024); - assert(rc==0); - -} -*/ for (i=0; inum_threads; i++) { //pthread_create(&mysql_threads[i].thread_id, &attr, mysql_worker_thread_func , &mysql_threads[i]); GloMTH->create_thread(i,mysql_worker_thread_func); @@ -630,10 +424,6 @@ __shutdown: GloQC->shutdown=1; pthread_join(GloQC->purge_thread_id, NULL); } - //SQC->empty(); - //SQC->flush(); - - //if (GloVars.__cmd_proxysql_nostart) { @@ -672,15 +462,6 @@ __shutdown: goto __start_label; } -/* - if (RUNNING_ON_VALGRIND==0) { - dlclose(__qc); - dlclose(__mysql_thread); - dlclose(__query_processor); - dlclose(__mysql_auth); - dlclose(__proxysql_admin); - } -*/ l_mem_destroy(__thr_sfp);