From 30dbcc21a88a741dc56f9b913a0622c87b05ceac Mon Sep 17 00:00:00 2001 From: Maxim Bublis Date: Wed, 14 Dec 2016 23:53:38 +0000 Subject: [PATCH] Refactor header includes. * reduce build time by 25%; * remove circular dependency on `cpp.h` and other headers. * fixes issue with `my_global.h` from mariadbclient which redefines `__attribute__`, that leads to broken STL and GCC intrinsics if `` wasn't included prior including this header; * fixes another issue with redefined `__attribute__` which leads to `_conn_exchange_t` not being aligned to cache line size; * removes `pthread_setstacksize` calls as `my_global.h` redefines `pthread_setstacksize` to be `pthread_dummy(0)` which led to stack size being never adjusted; * add missing include guards to some headers; * remove unused proxysql_hash.h header. --- include/MySQL_Authentication.hpp | 6 ++- include/MySQL_Data_Stream.h | 5 +- include/MySQL_HostGroups_Manager.h | 5 +- include/MySQL_Logger.hpp | 3 +- include/MySQL_Monitor.hpp | 5 +- include/MySQL_PreparedStatement.h | 6 ++- include/MySQL_Protocol.h | 3 +- include/MySQL_Session.h | 6 ++- include/MySQL_Thread.h | 8 +++- include/StatCounters.h | 2 + include/configfile.hpp | 2 + include/cpp.h | 25 ---------- include/fileutils.hpp | 6 ++- include/gen_utils.h | 1 + include/mysql_backend.h | 3 +- include/mysql_client.h | 8 ++++ include/mysql_connection.h | 4 +- include/network.h | 10 ++++ include/proxysql.h | 76 ++---------------------------- include/proxysql_admin.h | 4 +- include/proxysql_atomic.h | 7 ++- include/proxysql_debug.h | 16 +++---- include/proxysql_glovars.hpp | 6 +-- include/proxysql_hash.h | 32 ------------- include/proxysql_macros.h | 6 +++ include/proxysql_mem.h | 4 ++ include/proxysql_structs.h | 58 +++++------------------ include/query_cache.hpp | 8 +++- include/query_processor.h | 8 +++- include/sqlite3db.h | 9 +++- lib/MySQL_Authentication.cpp | 6 +-- lib/MySQL_HostGroups_Manager.cpp | 10 ++-- lib/MySQL_Logger.cpp | 8 +++- lib/MySQL_Monitor.cpp | 23 +++------ lib/MySQL_PreparedStatement.cpp | 7 ++- lib/MySQL_Protocol.cpp | 43 +++++++++-------- lib/MySQL_Session.cpp | 16 +++++-- lib/MySQL_Thread.cpp | 17 ++++--- lib/ProxySQL_Admin.cpp | 43 +++++++---------- lib/ProxySQL_GloVars.cpp | 12 +++-- lib/Query_Cache.cpp | 8 ++-- lib/Query_Processor.cpp | 17 ++++--- lib/configfile.cpp | 12 ++--- lib/debug.cpp | 9 +++- lib/gen_utils.cpp | 4 +- lib/mysql_backend.cpp | 6 ++- lib/mysql_connection.cpp | 10 +++- lib/mysql_data_stream.cpp | 22 +++++++-- lib/network.cpp | 16 ++++++- lib/sqlite3db.cpp | 7 ++- src/main.cpp | 18 ++++--- src/proxysql_global.cpp | 3 -- 52 files changed, 304 insertions(+), 355 deletions(-) delete mode 100644 include/cpp.h create mode 100644 include/mysql_client.h create mode 100644 include/network.h delete mode 100644 include/proxysql_hash.h diff --git a/include/MySQL_Authentication.hpp b/include/MySQL_Authentication.hpp index 8146c48dd7..a6e1a91a33 100644 --- a/include/MySQL_Authentication.hpp +++ b/include/MySQL_Authentication.hpp @@ -1,9 +1,11 @@ #ifndef __CLASS_MYSQL_AUTHENTICATION_H #define __CLASS_MYSQL_AUTHENTICATION_H -#include "proxysql.h" -#include "cpp.h" +#include +#include "proxysql.h" +#include "proxysql_atomic.h" +#include "proxysql_mem.h" typedef struct _account_details_t { char *username; diff --git a/include/MySQL_Data_Stream.h b/include/MySQL_Data_Stream.h index eec1d4909a..419024fc92 100644 --- a/include/MySQL_Data_Stream.h +++ b/include/MySQL_Data_Stream.h @@ -1,9 +1,8 @@ #ifndef __CLASS_MYSQL_DATA_STREAM_H #define __CLASS_MYSQL_DATA_STREAM_H -#include "proxysql.h" -#include "cpp.h" - +#include "mysql_connection.h" +#include "proxysql_mem.h" #define QUEUE_T_DEFAULT_SIZE 32768 diff --git a/include/MySQL_HostGroups_Manager.h b/include/MySQL_HostGroups_Manager.h index a987195a19..8d0936c87d 100644 --- a/include/MySQL_HostGroups_Manager.h +++ b/include/MySQL_HostGroups_Manager.h @@ -1,11 +1,10 @@ #ifndef __CLASS_MYSQL_HOSTGROUPS_MANAGER_H #define __CLASS_MYSQL_HOSTGROUPS_MANAGER_H -#include "proxysql.h" -#include "cpp.h" +#include #include -#include "thread.h" +#include "gen_utils.h" #include "wqueue.h" /* diff --git a/include/MySQL_Logger.hpp b/include/MySQL_Logger.hpp index fcf4ef575d..817339a492 100644 --- a/include/MySQL_Logger.hpp +++ b/include/MySQL_Logger.hpp @@ -1,8 +1,7 @@ #ifndef __CLASS_MYSQL_LOGGER_H #define __CLASS_MYSQL_LOGGER_H -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_Session.h" class MySQL_Event { private: diff --git a/include/MySQL_Monitor.hpp b/include/MySQL_Monitor.hpp index 93069e0f44..c73611de9a 100644 --- a/include/MySQL_Monitor.hpp +++ b/include/MySQL_Monitor.hpp @@ -1,8 +1,9 @@ #ifndef __CLASS_MYSQL_MONITOR_H #define __CLASS_MYSQL_MONITOR_H + +#include "mysql_client.h" #include "proxysql.h" -#include "cpp.h" -#include "thread.h" +#include "sqlite3db.h" #include "wqueue.h" diff --git a/include/MySQL_PreparedStatement.h b/include/MySQL_PreparedStatement.h index 960ebb9c11..9a0194bedd 100644 --- a/include/MySQL_PreparedStatement.h +++ b/include/MySQL_PreparedStatement.h @@ -1,8 +1,12 @@ #ifndef CLASS_MYSQL_PREPARED_STATEMENT_H #define CLASS_MYSQL_PREPARED_STATEMENT_H +#include +#include + +#include "mysql_client.h" #include "proxysql.h" -#include "cpp.h" +#include "proxysql_atomic.h" /* One of the main challenge in handling prepared statement (PS) is that a single diff --git a/include/MySQL_Protocol.h b/include/MySQL_Protocol.h index 4f459850c1..9c5b263782 100644 --- a/include/MySQL_Protocol.h +++ b/include/MySQL_Protocol.h @@ -2,7 +2,8 @@ #define __CLASS_MYSQL_PROTOCOL_H #include "proxysql.h" -#include "cpp.h" + +#include "MySQL_PreparedStatement.h" #define RESULTSET_BUFLEN 16300 diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index 51ffd7b45f..a1b7b29125 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -1,7 +1,11 @@ #ifndef __CLASS_MYSQL_SESSION_H #define __CLASS_MYSQL_SESSION_H #include "proxysql.h" -#include "cpp.h" + +#include "mysql_backend.h" +#include "proxysql_admin.h" +#include "query_processor.h" + // these structs will be used for various regex hardcoded // their initial use will be for sql_log_bin , sql_mode and time_zone diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 46d4489f9a..bbc9371b4d 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -1,10 +1,14 @@ #ifndef __CLASS_MYSQL_THREAD_H #define __CLASS_MYSQL_THREAD_H #define ____CLASS_STANDARD_MYSQL_THREAD_H -#include "proxysql.h" -#include "cpp.h" + +#include #include +#include "MySQL_Data_Stream.h" +#include "StatCounters.h" + +#define CACHE_LINE_SIZE 64 #define MIN_POLL_LEN 8 #define MIN_POLL_DELETE_RATIO 8 #define MY_EPOLL_THREAD_MAXEVENTS 128 diff --git a/include/StatCounters.h b/include/StatCounters.h index 7f8e6206de..6e519d6029 100644 --- a/include/StatCounters.h +++ b/include/StatCounters.h @@ -1,6 +1,8 @@ #ifndef __CLASS_STAT_COUNTERS_H #define __CLASS_STAT_COUNTERS_H + #include "proxysql_atomic.h" + class StatCounters { private: bool with_lock; diff --git a/include/configfile.hpp b/include/configfile.hpp index 071f9ea951..b34fc04b29 100644 --- a/include/configfile.hpp +++ b/include/configfile.hpp @@ -1,6 +1,8 @@ #ifndef __CLASS_PROXYSQL_CONFIGFILE_H #define __CLASS_PROXYSQL_CONFIGFILE_H +#include + #include "libconfig.h++" using namespace libconfig; diff --git a/include/cpp.h b/include/cpp.h deleted file mode 100644 index eca55ba03f..0000000000 --- a/include/cpp.h +++ /dev/null @@ -1,25 +0,0 @@ -#include "gen_utils.h" -#include "MySQL_Thread.h" -#include "MySQL_Session.h" -#include "mysql_backend.h" -#include "MySQL_Data_Stream.h" -#include "query_cache.hpp" -#include "mysql_connection.h" -#include "sqlite3db.h" -#include "StatCounters.h" -#include "MySQL_Monitor.hpp" -#include "MySQL_Protocol.h" -#include "MySQL_Authentication.hpp" -#include "fileutils.hpp" -#include "configfile.hpp" -#include "query_processor.h" -#include "proxysql_admin.h" -#include "MySQL_HostGroups_Manager.h" -#include "MySQL_Logger.hpp" -#include "MySQL_PreparedStatement.h" -#undef swap -#undef min -#undef max -#include -#include -#include diff --git a/include/fileutils.hpp b/include/fileutils.hpp index 455b56990c..83ea0cb528 100644 --- a/include/fileutils.hpp +++ b/include/fileutils.hpp @@ -1,7 +1,8 @@ -#include - #ifndef __CLASS_FILEUTILS_H #define __CLASS_FILEUTILS_H + +#include + class FileUtils { public: static bool isReadable(const char *pathname) { @@ -13,4 +14,5 @@ class FileUtils { return false; }; }; + #endif /* __CLASS_FILEUTILS_H */ diff --git a/include/gen_utils.h b/include/gen_utils.h index b8d4794659..9826288893 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -1,5 +1,6 @@ #ifndef __CLASS_PTR_ARRAY_H #define __CLASS_PTR_ARRAY_H + #include "proxysql.h" #define MIN_ARRAY_LEN 8 diff --git a/include/mysql_backend.h b/include/mysql_backend.h index df80ecf74e..70f7c8507b 100644 --- a/include/mysql_backend.h +++ b/include/mysql_backend.h @@ -1,8 +1,7 @@ #ifndef __CLASS_MYSQL_BACKEND_H #define __CLASS_MYSQL_BACKEND_H -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_Data_Stream.h" class MySQL_Backend { diff --git a/include/mysql_client.h b/include/mysql_client.h new file mode 100644 index 0000000000..b963889396 --- /dev/null +++ b/include/mysql_client.h @@ -0,0 +1,8 @@ +#ifndef PROXYSQL_MYSQL_CLIENT_H__ +#define PROXYSQL_MYSQL_CLIENT_H__ + +#define HAVE_BOOL +#include "mysql.h" +#undef max_allowed_packet + +#endif // PROXYSQL_MYSQL_CLIENT_H__ diff --git a/include/mysql_connection.h b/include/mysql_connection.h index d9cf6d02b6..1285c91e5e 100644 --- a/include/mysql_connection.h +++ b/include/mysql_connection.h @@ -1,8 +1,8 @@ #ifndef __CLASS_MYSQL_CONNECTION_H #define __CLASS_MYSQL_CONNECTION_H -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_HostGroups_Manager.h" +#include "MySQL_Protocol.h" #define STATUS_MYSQL_CONNECTION_TRANSACTION 0x00000001 #define STATUS_MYSQL_CONNECTION_COMPRESSION 0x00000002 diff --git a/include/network.h b/include/network.h new file mode 100644 index 0000000000..dcb4412060 --- /dev/null +++ b/include/network.h @@ -0,0 +1,10 @@ +#ifndef PROXYSQL_NETWORK_H__ +#define PROXYSQL_NETWORK_H__ + +#include + +int listen_on_port(char *ip, uint16_t port, int backlog, bool reuseport=false); +int listen_on_unix(char *, int); +int connect_socket(char *, int); + +#endif // PROXYSQL_NETWORK_H__ diff --git a/include/proxysql.h b/include/proxysql.h index c65f588fe9..5a80bdb1df 100644 --- a/include/proxysql.h +++ b/include/proxysql.h @@ -1,66 +1,12 @@ -#ifdef __cplusplus -#include -#include - -#include - -#ifndef EZOPTION -#define EZOPTION -#endif /* EZOPTION */ -#endif -#include -#include -#include -#include -#include -#include -#include +#ifndef PROXYSQL_H__ +#define PROXYSQL_H__ #ifdef NDEBUG #undef NDEBUG #endif -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#define HAVE_BOOL -#include "my_global.h" -#include "my_pthread.h" -#include "mysql.h" - -#include "proxysql_mem.h" #include "proxysql_structs.h" -#include "proxysql_debug.h" #include "proxysql_macros.h" -#include "jemalloc.h" - #ifdef DEBUG //#define VALGRIND_ENABLE_ERROR_REPORTING //#define VALGRIND_DISABLE_ERROR_REPORTING @@ -70,10 +16,6 @@ #define VALGRIND_DISABLE_ERROR_REPORTING #endif /* DEBUG */ -#include "sqlite3.h" - -#include "c_tokenizer.h" - #ifdef DEBUG #define DEB "_DEBUG" #else @@ -85,13 +27,6 @@ #ifndef PROXYSQL_FUNC_DEFS #define PROXYSQL_FUNC_DEFS -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -int listen_on_port(char *ip, uint16_t port, int backlog, bool reuseport=false); -int listen_on_unix(char *, int); -int connect_socket(char *, int); int config_file_is_readable(char *); unsigned int CPY3(unsigned char *); @@ -100,16 +35,11 @@ int pkt_end(unsigned char *, unsigned int); int pkt_com_query(unsigned char *, unsigned int); enum MySQL_response_type mysql_response(unsigned char *, unsigned int); -void proxy_error_func(const char *, ...); - #ifdef DEBUG void init_debug_struct(); void init_debug_struct_from_cmdline(); void proxy_debug_func(enum debug_module, int, int, const char *, int, const char *, const char *, ...); #endif -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /* PROXYSQL_FUNC_DEFS */ +#endif // PROXYSQL_H__ diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 85664bdc4b..9c9de1cc3c 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -1,8 +1,8 @@ #ifndef __CLASS_PROXYSQL_ADMIN_H #define __CLASS_PROXYSQL_ADMIN_H + #include "proxysql.h" -#include "cpp.h" -#include +#include "sqlite3db.h" typedef struct { uint32_t hash; uint32_t key; } t_symstruct; diff --git a/include/proxysql_atomic.h b/include/proxysql_atomic.h index 0996d37477..5a28541202 100644 --- a/include/proxysql_atomic.h +++ b/include/proxysql_atomic.h @@ -1,13 +1,16 @@ #ifndef PROXYSQL_ATOMIC #define PROXYSQL_ATOMIC -/* + +#include +#include + typedef unsigned spinlock; typedef struct _rwlock_t rwlock_t; struct _rwlock_t { spinlock lock; unsigned readers; }; -*/ + #define atomic_inc(P) __sync_add_and_fetch((P), 1) #define atomic_dec(P) __sync_add_and_fetch((P), -1) diff --git a/include/proxysql_debug.h b/include/proxysql_debug.h index 56c7a4d00a..5071f83b86 100644 --- a/include/proxysql_debug.h +++ b/include/proxysql_debug.h @@ -1,13 +1,10 @@ +#ifndef PROXYSQL_DEBUG_H__ +#define PROXYSQL_DEBUG_H__ + +#include + +void proxy_error_func(const char *, ...); -/* -#ifdef DEBUG -#ifndef DEBUG_EXTERN -#define DEBUG_EXTERN -extern debug_level *gdbg_lvl; -extern int gdbg; -#endif -#endif -*/ #ifdef DEBUG #define PROXY_TRACE() { proxy_debug(PROXY_DEBUG_GENERIC,10,"TRACE\n"); } #else @@ -108,3 +105,4 @@ extern int gdbg; #ifdef DEBUG //void *debug_logger(); #endif +#endif //PROXYSQL_DEBUG_H__ diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index cbbd046a55..48e0e9bcb4 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -1,11 +1,11 @@ #ifndef __CLASS_PROXYSQL_GLOVARS_H #define __CLASS_PROXYSQL_GLOVARS_H +#include + #include "configfile.hpp" -namespace ez { -class ezOptionParser; -}; +namespace ez { class ezOptionParser; } class ProxySQL_GlobalVariables { public: diff --git a/include/proxysql_hash.h b/include/proxysql_hash.h deleted file mode 100644 index c9ed00fb24..0000000000 --- a/include/proxysql_hash.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -Use of generic memory structure -set/get function defined by the user - -Ex: -*/ - - - -typedef _hte_ext_t hte_ext_t; - -union _hte_ext_t { - void *ptr; - int i; - uint32_t u32; - uint64_t u64; -}; - -struct __leo_hash_entry_t { - unsigned char *key; - void *self; - hte_ext_t ext0; - hte_ext_t ext1; - hte_ext_t ext2; - hte_ext_t ext3; - hte_ext_t ext4; - hte_ext_t ext5; - hte_ext_t ext6; - hte_ext_t ext7; - hte_ext_t ext8; - hte_ext_t ext9; -}; diff --git a/include/proxysql_macros.h b/include/proxysql_macros.h index 945189b302..9fff810aab 100644 --- a/include/proxysql_macros.h +++ b/include/proxysql_macros.h @@ -1,3 +1,7 @@ +#ifndef PROXYSQL_MACROS_H__ +#define PROXYSQL_MACROS_H__ + +#include #define strdup_null(__c) ( __c ? strdup(__c) : __c ) #define char_malloc (char *)malloc @@ -58,3 +62,5 @@ uint32_t *a=(uint32_t *)x; \ *a=*((uint32_t *)y); \ } while(0) + +#endif // PROXYSQL_MACROS_H__ diff --git a/include/proxysql_mem.h b/include/proxysql_mem.h index 51315b961f..83b13ef1af 100644 --- a/include/proxysql_mem.h +++ b/include/proxysql_mem.h @@ -1,3 +1,6 @@ +#ifndef PROXYSQL_MEM_H__ +#define PROXYSQL_MEM_H__ + #define L_SFC_MIN_ELEM_SIZE 8 #define L_SFC_MID_ELEM_SIZE 128 #define L_SFC_MAX_ELEM_SIZE 2048 @@ -89,3 +92,4 @@ static inline char * l_strdup(const char *s) { #endif /* L_STACK */ +#endif // PROXYSQL_MEM_H__ diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index 8fff2d2b95..6473365ee7 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -1,10 +1,14 @@ -#define PKT_PARSED 0 -#define PKT_ERROR 1 +#ifndef PROXYSQL_STRUCTS_H__ +#define PROXYSQL_STRUCTS_H__ + +#include +#include -#ifdef max_allowed_packet -#undef max_allowed_packet -#endif +#include +#include +#define PKT_PARSED 0 +#define PKT_ERROR 1 #ifndef PROXYSQL_ENUMS @@ -308,11 +312,7 @@ typedef struct _mysql_data_stream_t mysql_data_stream_t; typedef struct _mysql_session_t mysql_session_t; typedef struct _bytes_stats_t bytes_stats_t; typedef struct _mysql_hdr mysql_hdr; -typedef int (*PKT_HANDLER)(u_char *pkt, u_int len); -typedef struct __fdb_hash_t fdb_hash_t; -typedef struct __fdb_hash_entry fdb_hash_entry; -typedef unsigned spinlock; -typedef struct _rwlock_t rwlock_t; +typedef int (*PKT_HANDLER)(uint8_t *pkt, uint32_t len); typedef struct _PtrSize_t PtrSize_t; typedef struct _proxysql_mysql_thread_t proxysql_mysql_thread_t; typedef struct { char * table_name; char * table_def; } table_def_t; @@ -374,37 +374,12 @@ struct _debug_level { }; #endif /* DEBUG */ -struct _rwlock_t { - spinlock lock; - unsigned readers; -}; - // counters for number of bytes received and sent struct _bytes_stats_t { uint64_t bytes_recv; uint64_t bytes_sent; }; -struct __fdb_hash_t { - rwlock_t lock; - uint64_t dataSize; - uint64_t purgeChunkSize; - uint64_t purgeIdx; -}; - -struct __fdb_hash_entry { - unsigned char *key; - unsigned char *value; - fdb_hash_t *hash; - struct __fdb_hash_entry *self; - uint32_t klen; - uint32_t length; - time_t expire; - time_t access; - uint32_t ref_count; -}; - - #define MAX_EVENTS_PER_STATE 15 struct mysql_protocol_events { PKT_HANDLER ha[MAX_EVENTS_PER_STATE]; @@ -433,7 +408,7 @@ struct _global_variable_entry_t { // structure that defines mysql protocol header struct _mysql_hdr { - u_int pkt_length:24, pkt_id:8; + uint32_t pkt_length:24, pkt_id:8; }; struct _proxysql_mysql_thread_t { @@ -559,19 +534,11 @@ struct _mysql_session_t { #include "proxysql_glovars.hpp" //#endif - #ifndef GLOBAL_DEFINED #define GLOBAL_DEFINED EXTERN global_variables glovars; #endif /* GLOBAL_DEFINED */ -//#ifdef __cplusplus -#ifndef GLOVARS -#define GLOVARS -//#include "proxysql_glovars.hpp" -#endif -//#endif - #ifdef PROXYSQL_EXTERN #ifndef GLOBAL_DEFINED_OPTS_ENTRIES #define GLOBAL_DEFINED_OPTS_ENTRIES @@ -756,5 +723,4 @@ extern __thread bool mysql_thread___session_debug; extern __thread unsigned int g_seed; #endif /* PROXYSQL_EXTERN */ - - +#endif // PROXYSQL_STRUCTS_H__ diff --git a/include/query_cache.hpp b/include/query_cache.hpp index f2b53271a7..858464ce5b 100644 --- a/include/query_cache.hpp +++ b/include/query_cache.hpp @@ -1,7 +1,11 @@ #ifndef __CLASS_QUERY_CACHE_H #define __CLASS_QUERY_CACHE_H -#include "proxysql.h" -#include "cpp.h" + +#include + +#include + +#include "sqlite3db.h" #define EXPIRE_DROPIT 0 #define SHARED_QUERY_CACHE_HASH_TABLES 32 diff --git a/include/query_processor.h b/include/query_processor.h index 8b0ab0b343..316718b5dc 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -1,7 +1,11 @@ #ifndef __CLASS_QUERY_PROCESSOR_H #define __CLASS_QUERY_PROCESSOR_H -#include "proxysql.h" -#include "cpp.h" + +#include +#include + +#include "MySQL_PreparedStatement.h" +#include "proxysql_mem.h" typedef std::unordered_map umap_query_digest; diff --git a/include/sqlite3db.h b/include/sqlite3db.h index a9d971a037..c1663823b2 100644 --- a/include/sqlite3db.h +++ b/include/sqlite3db.h @@ -1,8 +1,13 @@ #ifndef __CLASS_SQLITE3DB_H #define __CLASS_SQLITE3DB_H -#include "proxysql.h" -#include "cpp.h" +#include +#include +#include + +#include "sqlite3.h" + +#include "proxysql_atomic.h" class SQLite3_row { public: diff --git a/lib/MySQL_Authentication.cpp b/lib/MySQL_Authentication.cpp index 7e56539ee9..9acfab4519 100644 --- a/lib/MySQL_Authentication.cpp +++ b/lib/MySQL_Authentication.cpp @@ -1,6 +1,6 @@ -#include "btree_map.h" -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_Authentication.hpp" + +#include "gen_utils.h" #include "proxysql_atomic.h" #include "SpookyV2.h" diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 6376536afc..dbe11f7a5d 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -1,12 +1,12 @@ -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_HostGroups_Manager.h" + +#include "MySQL_Thread.h" +#include "proxysql_admin.h" +#include "proxysql_debug.h" #define char_malloc (char *)malloc #define itostr(__s, __i) { __s=char_malloc(32); sprintf(__s, "%lld", __i); } -#include "thread.h" -#include "wqueue.h" - #define SAFE_SQLITE3_STEP(_stmt) do {\ do {\ rc=sqlite3_step(_stmt);\ diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index af18b36746..9139840902 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -1,8 +1,12 @@ +#include "MySQL_Logger.hpp" + #include -#include "proxysql.h" -#include "cpp.h" #include +#include "MySQL_Session.h" +#include "MySQL_Thread.h" +#include "proxysql_debug.h" + static uint8_t mysql_encode_length(uint64_t len, unsigned char *hd) { if (len < 251) return 1; diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index c9abae4e85..5a0988ef23 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -1,20 +1,12 @@ -/* - RECENT CHANGELOG - 1.2.0723 - * almost completely rewritten - * use of blocking call for new connections - * use of Thread Pool instead of a thread per check type - 0.2.0902 - * original implementation -*/ - -#include -#include -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_Monitor.hpp" +#include +#include + +#include "MySQL_Thread.h" +#include "proxysql_admin.h" +#include "proxysql_debug.h" #include "thread.h" -#include "wqueue.h" #ifdef DEBUG #define DEB "_DEBUG" @@ -1458,7 +1450,6 @@ void * MySQL_Monitor::run() { } pthread_attr_t attr; pthread_attr_init(&attr); - pthread_attr_setstacksize (&attr, 64*1024); pthread_t monitor_connect_thread; pthread_create(&monitor_connect_thread, &attr, &monitor_connect_pthread,NULL); pthread_t monitor_ping_thread; diff --git a/lib/MySQL_PreparedStatement.cpp b/lib/MySQL_PreparedStatement.cpp index b3743914e3..db1e4fb238 100644 --- a/lib/MySQL_PreparedStatement.cpp +++ b/lib/MySQL_PreparedStatement.cpp @@ -1,7 +1,10 @@ -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_PreparedStatement.h" +#include + +#include "gen_utils.h" #include "SpookyV2.h" +#include "proxysql_debug.h" extern MySQL_STMT_Manager *GloMyStmt; diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index e03383051b..51e9904f39 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1,16 +1,15 @@ +#include "MySQL_Protocol.h" + #include -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_Authentication.hpp" +#include "MySQL_Session.h" +#include "MySQL_Thread.h" +#include "proxysql_debug.h" extern MySQL_Authentication *GloMyAuth; extern MySQL_Threads_Handler *GloMTH; -#ifdef max_allowed_packet -#undef max_allowed_packet -#endif - -//#define RESULTSET_BUFLEN 16300 #ifdef DEBUG static void __dump_pkt(const char *func, unsigned char *_ptr, unsigned int len) { @@ -73,7 +72,7 @@ static inline int write_encoded_length_and_string(unsigned char *p, uint64_t val return l+val; } -void proxy_compute_sha1_hash_multi(uint8 *digest, const uint8_t *buf1, int len1, const char *buf2, int len2) { +void proxy_compute_sha1_hash_multi(uint8_t *digest, const uint8_t *buf1, int len1, const char *buf2, int len2) { PROXY_TRACE(); SHA_CTX sha1_context; @@ -83,7 +82,7 @@ void proxy_compute_sha1_hash_multi(uint8 *digest, const uint8_t *buf1, int len1, SHA1_Final(digest, &sha1_context); } -void proxy_compute_sha1_hash(uint8 *digest, const char *buf, int len) { +void proxy_compute_sha1_hash(uint8_t *digest, const char *buf, int len) { PROXY_TRACE(); SHA_CTX sha1_context; @@ -92,13 +91,13 @@ void proxy_compute_sha1_hash(uint8 *digest, const char *buf, int len) { SHA1_Final(digest, &sha1_context); } -void proxy_compute_two_stage_sha1_hash(const char *password, size_t pass_len, uint8 *hash_stage1, uint8 *hash_stage2) { +void proxy_compute_two_stage_sha1_hash(const char *password, size_t pass_len, uint8_t *hash_stage1, uint8_t *hash_stage2) { proxy_compute_sha1_hash(hash_stage1, password, pass_len); proxy_compute_sha1_hash(hash_stage2, (const char *) hash_stage1, SHA_DIGEST_LENGTH); } -void proxy_my_crypt(char *to, const uchar *s1, const uchar *s2, uint len) { - const uint8 *s1_end= s1 + len; +void proxy_my_crypt(char *to, const uint8_t *s1, const uint8_t *s2, uint len) { + const uint8_t *s1_end= s1 + len; while (s1 < s1_end) *to++= *s1++ ^ *s2++; } @@ -132,23 +131,23 @@ void unhex_pass(uint8_t *out, const char *in) { void proxy_scramble(char *to, const uint8_t *message, const char *password) { - uint8 hash_stage1[SHA_DIGEST_LENGTH]; - uint8 hash_stage2[SHA_DIGEST_LENGTH]; + uint8_t hash_stage1[SHA_DIGEST_LENGTH]; + uint8_t hash_stage2[SHA_DIGEST_LENGTH]; proxy_compute_two_stage_sha1_hash(password, strlen(password), hash_stage1, hash_stage2); - proxy_compute_sha1_hash_multi((uint8 *) to, message, SCRAMBLE_LENGTH, (const char *) hash_stage2, SHA_DIGEST_LENGTH); - proxy_my_crypt(to, (const uchar *) to, hash_stage1, SCRAMBLE_LENGTH); + proxy_compute_sha1_hash_multi((uint8_t *) to, message, SCRAMBLE_LENGTH, (const char *) hash_stage2, SHA_DIGEST_LENGTH); + proxy_my_crypt(to, (const uint8_t *) to, hash_stage1, SCRAMBLE_LENGTH); return; } bool proxy_scramble_sha1(char *pass_reply, const uint8_t *message, const char *sha1_sha1_pass, char *sha1_pass) { bool ret=false; - uint8 hash_stage1[SHA_DIGEST_LENGTH]; - uint8 hash_stage2[SHA_DIGEST_LENGTH]; - uint8 hash_stage3[SHA_DIGEST_LENGTH]; - uint8 to[SHA_DIGEST_LENGTH]; + uint8_t hash_stage1[SHA_DIGEST_LENGTH]; + uint8_t hash_stage2[SHA_DIGEST_LENGTH]; + uint8_t hash_stage3[SHA_DIGEST_LENGTH]; + uint8_t to[SHA_DIGEST_LENGTH]; unhex_pass(hash_stage2,sha1_sha1_pass); - proxy_compute_sha1_hash_multi((uint8 *) to, message, SCRAMBLE_LENGTH, (const char *) hash_stage2, SHA_DIGEST_LENGTH); - proxy_my_crypt((char *)hash_stage1,(const uchar *) pass_reply, to, SCRAMBLE_LENGTH); + proxy_compute_sha1_hash_multi((uint8_t *) to, message, SCRAMBLE_LENGTH, (const char *) hash_stage2, SHA_DIGEST_LENGTH); + proxy_my_crypt((char *)hash_stage1,(const uint8_t *) pass_reply, to, SCRAMBLE_LENGTH); proxy_compute_sha1_hash(hash_stage3, (const char *) hash_stage1, SHA_DIGEST_LENGTH); if (memcmp(hash_stage2,hash_stage3,SHA_DIGEST_LENGTH)==0) { memcpy(sha1_pass,hash_stage1,SHA_DIGEST_LENGTH); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 67b2c89348..ea95accf96 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1,7 +1,16 @@ -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_Session.h" + +#include +#include + +#include + +#include "MySQL_Authentication.hpp" +#include "MySQL_Logger.hpp" +#include "MySQL_Thread.h" +#include "proxysql_debug.h" +#include "query_cache.hpp" #include "re2/re2.h" -#include "re2/regexp.h" #include "SpookyV2.h" #define SELECT_VERSION_COMMENT "select @@version_comment limit 1" @@ -743,7 +752,6 @@ void MySQL_Session::handler_again___new_thread_to_kill_connection() { pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize (&attr, 256*1024); pthread_t pt; pthread_create(&pt, &attr, &kill_query_thread, ka); } diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 7daef60c94..27b993259c 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1,9 +1,16 @@ -//#define __CLASS_STANDARD_MYSQL_THREAD_H #define MYSQL_THREAD_IMPLEMENTATION -#include "proxysql.h" -#include "cpp.h" #include "MySQL_Thread.h" +#include +#include +#include + +#include "c_tokenizer.h" +#include "MySQL_Logger.hpp" +#include "MySQL_Monitor.hpp" +#include "network.h" +#include "proxysql_debug.h" + #ifdef DEBUG MySQL_Session *sess_stopat; #endif @@ -1680,8 +1687,6 @@ void MySQL_Threads_Handler::init(unsigned int num, size_t stack) { } else { if (num_threads==0) num_threads=DEFAULT_NUM_THREADS; //default } - int rc=pthread_attr_setstacksize(&attr, stacksize); - assert(rc==0); mysql_threads=(proxysql_mysql_thread_t *)malloc(sizeof(proxysql_mysql_thread_t)*num_threads); mysql_threads_idles=(proxysql_mysql_thread_t *)malloc(sizeof(proxysql_mysql_thread_t)*num_threads); } @@ -2475,7 +2480,7 @@ bool MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned } - if (myds->active==FALSE) { + if (myds->active==false) { if (myds->sess->client_myds==myds) { proxy_debug(PROXY_DEBUG_NET,1, "Session=%p, DataStream=%p -- Deleting FD %d\n", myds->sess, myds, myds->fd); myds->sess->set_unhealthy(); diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 0da0b007b1..fcd792e849 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -1,25 +1,19 @@ -#include // std::cout -#include // std::sort -#include // std::vector +#include "proxysql_admin.h" + +#include +#include +#include + +#include "jemalloc.h" #include "re2/re2.h" -#include "re2/regexp.h" -#include "proxysql.h" -#include "cpp.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "SpookyV2.h" -//#define MYSQL_THREAD_IMPLEMENTATION + +#include "c_tokenizer.h" +#include "MySQL_Authentication.hpp" +#include "MySQL_Logger.hpp" +#include "MySQL_Thread.h" +#include "network.h" +#include "proxysql_debug.h" +#include "query_cache.hpp" #define SELECT_VERSION_COMMENT "select @@version_comment limit 1" #define SELECT_VERSION_COMMENT_LEN 32 @@ -2194,7 +2188,6 @@ static void * admin_main_loop(void *arg) pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize (&attr, mystacksize); if(GloVars.global.nostart) { nostart_=true; @@ -2397,7 +2390,6 @@ bool ProxySQL_Admin::init() { pthread_attr_t attr; pthread_attr_init(&attr); - pthread_attr_setstacksize (&attr, mystacksize); admindb=new SQLite3DB(); admindb->open((char *)"file:mem_admindb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX); @@ -3736,8 +3728,8 @@ void ProxySQL_Admin::__add_active_users(enum cred_username_type usertype) { if (r->fields[1][0]=='*') { // the password is already hashed password=strdup(r->fields[1]); } else { // we must hash it - uint8 hash_stage1[SHA_DIGEST_LENGTH]; - uint8 hash_stage2[SHA_DIGEST_LENGTH]; + uint8_t hash_stage1[SHA_DIGEST_LENGTH]; + uint8_t hash_stage2[SHA_DIGEST_LENGTH]; SHA_CTX sha1_context; SHA1_Init(&sha1_context); SHA1_Update(&sha1_context, r->fields[1], strlen(r->fields[1])); @@ -5020,7 +5012,6 @@ unsigned long long ProxySQL_External_Scheduler::run_once() { pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize (&attr, 64*1024); pid_t *cpid_ptr=(pid_t *)malloc(sizeof(pid_t)); *cpid_ptr=cpid; pthread_t thr; diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index 80e41ffe45..3fef5c9978 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -1,8 +1,12 @@ -#include "ezOptionParser.hpp" -#include "proxysql.h" -#include "cpp.h" -#include +#include "proxysql_glovars.hpp" + +#include +#include +#include +#include "ezOptionParser.hpp" +#include "proxysql_debug.h" +#include "gen_utils.h" static void term_handler(int sig) { diff --git a/lib/Query_Cache.cpp b/lib/Query_Cache.cpp index 044c8e8df4..e74881d682 100644 --- a/lib/Query_Cache.cpp +++ b/lib/Query_Cache.cpp @@ -1,9 +1,9 @@ -#include "btree_map.h" -#include "proxysql.h" -#include "cpp.h" #include "query_cache.hpp" -#include "proxysql_atomic.h" + +#include "btree_map.h" +#include "MySQL_Thread.h" #include "SpookyV2.h" +#include "proxysql_debug.h" #define THR_UPDATE_CNT(__a, __b, __c, __d) \ do {\ diff --git a/lib/Query_Processor.cpp b/lib/Query_Processor.cpp index 5c60ad8b02..3da78c1409 100644 --- a/lib/Query_Processor.cpp +++ b/lib/Query_Processor.cpp @@ -1,14 +1,17 @@ -#include // std::cout -#include // std::sort -#include // std::vector +#include "query_processor.h" + +#include + +#include "pcrecpp.h" #include "re2/re2.h" -#include "re2/regexp.h" -#include "proxysql.h" -#include "cpp.h" +#include "c_tokenizer.h" +#include "proxysql_debug.h" + +#include "MySQL_Session.h" +#include "MySQL_Thread.h" #include "SpookyV2.h" -#include "pcrecpp.h" #ifdef DEBUG #define DEB "_DEBUG" diff --git a/lib/configfile.cpp b/lib/configfile.cpp index b09e62f1cf..82bfbc179f 100644 --- a/lib/configfile.cpp +++ b/lib/configfile.cpp @@ -1,14 +1,10 @@ -#include "proxysql.h" -#include "cpp.h" +#include "configfile.hpp" +#include +#include #include -#include -#include -#include - - -#include +#include "fileutils.hpp" using namespace std; using namespace libconfig; diff --git a/lib/debug.cpp b/lib/debug.cpp index ebf856f9ac..7e12de5af7 100644 --- a/lib/debug.cpp +++ b/lib/debug.cpp @@ -1,7 +1,12 @@ -#include "proxysql.h" -#include "proxysql_atomic.h" +#include "proxysql_debug.h" + +#include +#include + #include +#include "proxysql_atomic.h" + #ifdef DEBUG #ifdef DEBUG_EXTERN diff --git a/lib/gen_utils.cpp b/lib/gen_utils.cpp index fe4d089a62..a1f3662e9a 100644 --- a/lib/gen_utils.cpp +++ b/lib/gen_utils.cpp @@ -1,6 +1,6 @@ -#include "proxysql.h" -#include "cpp.h" +#include "gen_utils.h" +#include "proxysql_mem.h" char *escape_string_single_quotes(char *input, bool free_it) { int i,j,l; diff --git a/lib/mysql_backend.cpp b/lib/mysql_backend.cpp index 9b8d0b5c45..936a6e0108 100644 --- a/lib/mysql_backend.cpp +++ b/lib/mysql_backend.cpp @@ -1,5 +1,7 @@ -#include "proxysql.h" -#include "cpp.h" +#include "mysql_backend.h" + +#include "MySQL_Session.h" +#include "MySQL_Thread.h" void * MySQL_Backend::operator new(size_t size) { return l_alloc(size); diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index bf0baf548b..fbe81c94c0 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -1,6 +1,12 @@ -#include "proxysql.h" -#include "cpp.h" +#include "mysql_connection.h" + +#include +#include + +#include "MySQL_Session.h" +#include "MySQL_Thread.h" #include "SpookyV2.h" +#include "proxysql_debug.h" extern const CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr); diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index 9fd4c92543..843009c08d 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -1,6 +1,18 @@ -#include "proxysql.h" -#include "cpp.h" +#include "MySQL_Data_Stream.h" + +#include +#include +#include +#include +#include +#include + #include + +#include "MySQL_Session.h" +#include "MySQL_Thread.h" +#include "proxysql_debug.h" + #ifndef UNIX_PATH_MAX #define UNIX_PATH_MAX 108 #endif @@ -113,7 +125,7 @@ MySQL_Data_Stream::MySQL_Data_Stream() { queue_init(queueIN,QUEUE_T_DEFAULT_SIZE); queue_init(queueOUT,QUEUE_T_DEFAULT_SIZE); mybe=NULL; - active=TRUE; + active=true; mypolls=NULL; myconn=NULL; // 20141011 DSS=STATE_NOT_CONNECTED; @@ -245,7 +257,7 @@ void MySQL_Data_Stream::init(enum MySQL_DS_type _type, MySQL_Session *_sess, int // TODO: should check the status of the data stream, and identify if it is safe to reconnect or if the session should be destroyed void MySQL_Data_Stream::shut_soft() { proxy_debug(PROXY_DEBUG_NET, 4, "Shutdown soft fd=%d. Session=%p, DataStream=%p\n", fd, sess, this); - active=FALSE; + active=false; set_net_failure(); //if (sess) sess->net_failure=1; } @@ -363,7 +375,7 @@ void MySQL_Data_Stream::set_pollout() { int MySQL_Data_Stream::write_to_net_poll() { int rc=0; - if (active==FALSE) return rc; + if (active==false) return rc; proxy_debug(PROXY_DEBUG_NET,1,"Session=%p, DataStream=%p --\n", sess, this); if (queue_data(queueOUT)) { if ((sess->admin==false)) { diff --git a/lib/network.cpp b/lib/network.cpp index ef62022bc3..0bda01d8bd 100644 --- a/lib/network.cpp +++ b/lib/network.cpp @@ -1,4 +1,18 @@ -#include "proxysql.h" +#include "network.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "proxysql_debug.h" /* * create a socket and listen on a specified IP and port diff --git a/lib/sqlite3db.cpp b/lib/sqlite3db.cpp index 7bcafd6197..199afb7b1b 100644 --- a/lib/sqlite3db.cpp +++ b/lib/sqlite3db.cpp @@ -1,5 +1,10 @@ +#include "sqlite3db.h" + +#include + #include "proxysql.h" -#include "cpp.h" +#include "proxysql_atomic.h" +#include "proxysql_debug.h" #include "SpookyV2.h" #define USLEEP_SQLITE_LOCKED 100 diff --git a/src/main.cpp b/src/main.cpp index 5d676b2ce7..8a0fbd45aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,6 @@ #include -#include -#include "btree_map.h" -#include "proxysql.h" - -//#define PROXYSQL_EXTERN -#include "cpp.h" +#include #include #include @@ -13,6 +8,16 @@ #include #include +#include "gen_utils.h" +#include "MySQL_Authentication.hpp" +#include "MySQL_Monitor.hpp" +#include "MySQL_Thread.h" +#include "MySQL_Logger.hpp" +#include "proxysql_admin.h" +#include "proxysql_debug.h" +#include "query_cache.hpp" +#include "query_processor.h" + // MariaDB client library redefines dlerror(), see https://mariadb.atlassian.net/browse/CONC-101 #ifdef dlerror #undef dlerror @@ -782,4 +787,3 @@ int main(int argc, const char * argv[]) { // l_mem_destroy(__thr_sfp); return 0; } - diff --git a/src/proxysql_global.cpp b/src/proxysql_global.cpp index 12e8686960..968cff615b 100644 --- a/src/proxysql_global.cpp +++ b/src/proxysql_global.cpp @@ -1,5 +1,2 @@ #define PROXYSQL_EXTERN #include "proxysql.h" -//#include "proxysql_glovars.hpp" -#include "cpp.h" -//ProxySQL_GlobalVariables GloVars;