From a6c53d0d1240fc339ce5e3d0f590b6fd0f067d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 21 Dec 2016 15:51:24 -0800 Subject: [PATCH] Revert "Refactor header includes." --- 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 | 24 +++++++--- 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, 356 insertions(+), 304 deletions(-) create mode 100644 include/cpp.h delete mode 100644 include/mysql_client.h delete mode 100644 include/network.h create mode 100644 include/proxysql_hash.h diff --git a/include/MySQL_Authentication.hpp b/include/MySQL_Authentication.hpp index a6e1a91a33..8146c48dd7 100644 --- a/include/MySQL_Authentication.hpp +++ b/include/MySQL_Authentication.hpp @@ -1,11 +1,9 @@ #ifndef __CLASS_MYSQL_AUTHENTICATION_H #define __CLASS_MYSQL_AUTHENTICATION_H -#include - #include "proxysql.h" -#include "proxysql_atomic.h" -#include "proxysql_mem.h" +#include "cpp.h" + typedef struct _account_details_t { char *username; diff --git a/include/MySQL_Data_Stream.h b/include/MySQL_Data_Stream.h index 419024fc92..eec1d4909a 100644 --- a/include/MySQL_Data_Stream.h +++ b/include/MySQL_Data_Stream.h @@ -1,8 +1,9 @@ #ifndef __CLASS_MYSQL_DATA_STREAM_H #define __CLASS_MYSQL_DATA_STREAM_H -#include "mysql_connection.h" -#include "proxysql_mem.h" +#include "proxysql.h" +#include "cpp.h" + #define QUEUE_T_DEFAULT_SIZE 32768 diff --git a/include/MySQL_HostGroups_Manager.h b/include/MySQL_HostGroups_Manager.h index 8d0936c87d..a987195a19 100644 --- a/include/MySQL_HostGroups_Manager.h +++ b/include/MySQL_HostGroups_Manager.h @@ -1,10 +1,11 @@ #ifndef __CLASS_MYSQL_HOSTGROUPS_MANAGER_H #define __CLASS_MYSQL_HOSTGROUPS_MANAGER_H +#include "proxysql.h" +#include "cpp.h" -#include #include -#include "gen_utils.h" +#include "thread.h" #include "wqueue.h" /* diff --git a/include/MySQL_Logger.hpp b/include/MySQL_Logger.hpp index 817339a492..fcf4ef575d 100644 --- a/include/MySQL_Logger.hpp +++ b/include/MySQL_Logger.hpp @@ -1,7 +1,8 @@ #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 c73611de9a..93069e0f44 100644 --- a/include/MySQL_Monitor.hpp +++ b/include/MySQL_Monitor.hpp @@ -1,9 +1,8 @@ #ifndef __CLASS_MYSQL_MONITOR_H #define __CLASS_MYSQL_MONITOR_H - -#include "mysql_client.h" #include "proxysql.h" -#include "sqlite3db.h" +#include "cpp.h" +#include "thread.h" #include "wqueue.h" diff --git a/include/MySQL_PreparedStatement.h b/include/MySQL_PreparedStatement.h index 9a0194bedd..960ebb9c11 100644 --- a/include/MySQL_PreparedStatement.h +++ b/include/MySQL_PreparedStatement.h @@ -1,12 +1,8 @@ #ifndef CLASS_MYSQL_PREPARED_STATEMENT_H #define CLASS_MYSQL_PREPARED_STATEMENT_H -#include -#include - -#include "mysql_client.h" #include "proxysql.h" -#include "proxysql_atomic.h" +#include "cpp.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 9c5b263782..4f459850c1 100644 --- a/include/MySQL_Protocol.h +++ b/include/MySQL_Protocol.h @@ -2,8 +2,7 @@ #define __CLASS_MYSQL_PROTOCOL_H #include "proxysql.h" - -#include "MySQL_PreparedStatement.h" +#include "cpp.h" #define RESULTSET_BUFLEN 16300 diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index a1b7b29125..51ffd7b45f 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -1,11 +1,7 @@ #ifndef __CLASS_MYSQL_SESSION_H #define __CLASS_MYSQL_SESSION_H #include "proxysql.h" - -#include "mysql_backend.h" -#include "proxysql_admin.h" -#include "query_processor.h" - +#include "cpp.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 bbc9371b4d..46d4489f9a 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -1,14 +1,10 @@ #ifndef __CLASS_MYSQL_THREAD_H #define __CLASS_MYSQL_THREAD_H #define ____CLASS_STANDARD_MYSQL_THREAD_H - -#include +#include "proxysql.h" +#include "cpp.h" #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 6e519d6029..7f8e6206de 100644 --- a/include/StatCounters.h +++ b/include/StatCounters.h @@ -1,8 +1,6 @@ #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 b34fc04b29..071f9ea951 100644 --- a/include/configfile.hpp +++ b/include/configfile.hpp @@ -1,8 +1,6 @@ #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 new file mode 100644 index 0000000000..eca55ba03f --- /dev/null +++ b/include/cpp.h @@ -0,0 +1,25 @@ +#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 83ea0cb528..455b56990c 100644 --- a/include/fileutils.hpp +++ b/include/fileutils.hpp @@ -1,8 +1,7 @@ -#ifndef __CLASS_FILEUTILS_H -#define __CLASS_FILEUTILS_H - #include +#ifndef __CLASS_FILEUTILS_H +#define __CLASS_FILEUTILS_H class FileUtils { public: static bool isReadable(const char *pathname) { @@ -14,5 +13,4 @@ class FileUtils { return false; }; }; - #endif /* __CLASS_FILEUTILS_H */ diff --git a/include/gen_utils.h b/include/gen_utils.h index 9826288893..b8d4794659 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -1,6 +1,5 @@ #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 70f7c8507b..df80ecf74e 100644 --- a/include/mysql_backend.h +++ b/include/mysql_backend.h @@ -1,7 +1,8 @@ #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 deleted file mode 100644 index b963889396..0000000000 --- a/include/mysql_client.h +++ /dev/null @@ -1,8 +0,0 @@ -#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 1285c91e5e..d9cf6d02b6 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 "MySQL_HostGroups_Manager.h" -#include "MySQL_Protocol.h" +#include "proxysql.h" +#include "cpp.h" #define STATUS_MYSQL_CONNECTION_TRANSACTION 0x00000001 #define STATUS_MYSQL_CONNECTION_COMPRESSION 0x00000002 diff --git a/include/network.h b/include/network.h deleted file mode 100644 index dcb4412060..0000000000 --- a/include/network.h +++ /dev/null @@ -1,10 +0,0 @@ -#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 5a80bdb1df..c65f588fe9 100644 --- a/include/proxysql.h +++ b/include/proxysql.h @@ -1,12 +1,66 @@ -#ifndef PROXYSQL_H__ -#define PROXYSQL_H__ +#ifdef __cplusplus +#include +#include + +#include + +#ifndef EZOPTION +#define EZOPTION +#endif /* EZOPTION */ +#endif +#include +#include +#include +#include +#include +#include +#include #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 @@ -16,6 +70,10 @@ #define VALGRIND_DISABLE_ERROR_REPORTING #endif /* DEBUG */ +#include "sqlite3.h" + +#include "c_tokenizer.h" + #ifdef DEBUG #define DEB "_DEBUG" #else @@ -27,6 +85,13 @@ #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 *); @@ -35,11 +100,16 @@ 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 9c9de1cc3c..85664bdc4b 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 "sqlite3db.h" +#include "cpp.h" +#include typedef struct { uint32_t hash; uint32_t key; } t_symstruct; diff --git a/include/proxysql_atomic.h b/include/proxysql_atomic.h index 5a28541202..0996d37477 100644 --- a/include/proxysql_atomic.h +++ b/include/proxysql_atomic.h @@ -1,16 +1,13 @@ #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 5071f83b86..56c7a4d00a 100644 --- a/include/proxysql_debug.h +++ b/include/proxysql_debug.h @@ -1,10 +1,13 @@ -#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 @@ -105,4 +108,3 @@ void proxy_error_func(const char *, ...); #ifdef DEBUG //void *debug_logger(); #endif -#endif //PROXYSQL_DEBUG_H__ diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index 48e0e9bcb4..cbbd046a55 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 new file mode 100644 index 0000000000..c9ed00fb24 --- /dev/null +++ b/include/proxysql_hash.h @@ -0,0 +1,32 @@ +/* +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 9fff810aab..945189b302 100644 --- a/include/proxysql_macros.h +++ b/include/proxysql_macros.h @@ -1,7 +1,3 @@ -#ifndef PROXYSQL_MACROS_H__ -#define PROXYSQL_MACROS_H__ - -#include #define strdup_null(__c) ( __c ? strdup(__c) : __c ) #define char_malloc (char *)malloc @@ -62,5 +58,3 @@ 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 83b13ef1af..51315b961f 100644 --- a/include/proxysql_mem.h +++ b/include/proxysql_mem.h @@ -1,6 +1,3 @@ -#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 @@ -92,4 +89,3 @@ 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 6473365ee7..8fff2d2b95 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -1,15 +1,11 @@ -#ifndef PROXYSQL_STRUCTS_H__ -#define PROXYSQL_STRUCTS_H__ - -#include -#include - -#include -#include - #define PKT_PARSED 0 #define PKT_ERROR 1 +#ifdef max_allowed_packet +#undef max_allowed_packet +#endif + + #ifndef PROXYSQL_ENUMS #define PROXYSQL_ENUMS @@ -312,7 +308,11 @@ 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)(uint8_t *pkt, uint32_t len); +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 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,12 +374,37 @@ 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]; @@ -408,7 +433,7 @@ struct _global_variable_entry_t { // structure that defines mysql protocol header struct _mysql_hdr { - uint32_t pkt_length:24, pkt_id:8; + u_int pkt_length:24, pkt_id:8; }; struct _proxysql_mysql_thread_t { @@ -534,11 +559,19 @@ 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 @@ -723,4 +756,5 @@ 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 858464ce5b..f2b53271a7 100644 --- a/include/query_cache.hpp +++ b/include/query_cache.hpp @@ -1,11 +1,7 @@ #ifndef __CLASS_QUERY_CACHE_H #define __CLASS_QUERY_CACHE_H - -#include - -#include - -#include "sqlite3db.h" +#include "proxysql.h" +#include "cpp.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 316718b5dc..8b0ab0b343 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -1,11 +1,7 @@ #ifndef __CLASS_QUERY_PROCESSOR_H #define __CLASS_QUERY_PROCESSOR_H - -#include -#include - -#include "MySQL_PreparedStatement.h" -#include "proxysql_mem.h" +#include "proxysql.h" +#include "cpp.h" typedef std::unordered_map umap_query_digest; diff --git a/include/sqlite3db.h b/include/sqlite3db.h index c1663823b2..a9d971a037 100644 --- a/include/sqlite3db.h +++ b/include/sqlite3db.h @@ -1,13 +1,8 @@ #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 9acfab4519..7e56539ee9 100644 --- a/lib/MySQL_Authentication.cpp +++ b/lib/MySQL_Authentication.cpp @@ -1,6 +1,6 @@ -#include "MySQL_Authentication.hpp" - -#include "gen_utils.h" +#include "btree_map.h" +#include "proxysql.h" +#include "cpp.h" #include "proxysql_atomic.h" #include "SpookyV2.h" diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index dbe11f7a5d..6376536afc 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -1,12 +1,12 @@ -#include "MySQL_HostGroups_Manager.h" - -#include "MySQL_Thread.h" -#include "proxysql_admin.h" -#include "proxysql_debug.h" +#include "proxysql.h" +#include "cpp.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 9139840902..af18b36746 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -1,12 +1,8 @@ -#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 45d2e1b550..1c239edd3a 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -1,12 +1,21 @@ -#include "MySQL_Monitor.hpp" +/* + 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 +#include "proxysql.h" +#include "cpp.h" -#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" @@ -1389,6 +1398,7 @@ 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 db1e4fb238..b3743914e3 100644 --- a/lib/MySQL_PreparedStatement.cpp +++ b/lib/MySQL_PreparedStatement.cpp @@ -1,10 +1,7 @@ -#include "MySQL_PreparedStatement.h" +#include "proxysql.h" +#include "cpp.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 51e9904f39..e03383051b 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1,15 +1,16 @@ -#include "MySQL_Protocol.h" - #include -#include "MySQL_Authentication.hpp" -#include "MySQL_Session.h" -#include "MySQL_Thread.h" -#include "proxysql_debug.h" +#include "proxysql.h" +#include "cpp.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) { @@ -72,7 +73,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_t *digest, const uint8_t *buf1, int len1, const char *buf2, int len2) { +void proxy_compute_sha1_hash_multi(uint8 *digest, const uint8_t *buf1, int len1, const char *buf2, int len2) { PROXY_TRACE(); SHA_CTX sha1_context; @@ -82,7 +83,7 @@ void proxy_compute_sha1_hash_multi(uint8_t *digest, const uint8_t *buf1, int len SHA1_Final(digest, &sha1_context); } -void proxy_compute_sha1_hash(uint8_t *digest, const char *buf, int len) { +void proxy_compute_sha1_hash(uint8 *digest, const char *buf, int len) { PROXY_TRACE(); SHA_CTX sha1_context; @@ -91,13 +92,13 @@ void proxy_compute_sha1_hash(uint8_t *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_t *hash_stage1, uint8_t *hash_stage2) { +void proxy_compute_two_stage_sha1_hash(const char *password, size_t pass_len, uint8 *hash_stage1, uint8 *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 uint8_t *s1, const uint8_t *s2, uint len) { - const uint8_t *s1_end= s1 + len; +void proxy_my_crypt(char *to, const uchar *s1, const uchar *s2, uint len) { + const uint8 *s1_end= s1 + len; while (s1 < s1_end) *to++= *s1++ ^ *s2++; } @@ -131,23 +132,23 @@ void unhex_pass(uint8_t *out, const char *in) { void proxy_scramble(char *to, const uint8_t *message, const char *password) { - uint8_t hash_stage1[SHA_DIGEST_LENGTH]; - uint8_t hash_stage2[SHA_DIGEST_LENGTH]; + uint8 hash_stage1[SHA_DIGEST_LENGTH]; + uint8 hash_stage2[SHA_DIGEST_LENGTH]; proxy_compute_two_stage_sha1_hash(password, strlen(password), hash_stage1, hash_stage2); - 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); + 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); return; } bool proxy_scramble_sha1(char *pass_reply, const uint8_t *message, const char *sha1_sha1_pass, char *sha1_pass) { bool ret=false; - 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]; + uint8 hash_stage1[SHA_DIGEST_LENGTH]; + uint8 hash_stage2[SHA_DIGEST_LENGTH]; + uint8 hash_stage3[SHA_DIGEST_LENGTH]; + uint8 to[SHA_DIGEST_LENGTH]; unhex_pass(hash_stage2,sha1_sha1_pass); - 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_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(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 12c23ac4a2..c5e4a7c7f2 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1,16 +1,7 @@ -#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 "proxysql.h" +#include "cpp.h" #include "re2/re2.h" +#include "re2/regexp.h" #include "SpookyV2.h" #define SELECT_VERSION_COMMENT "select @@version_comment limit 1" @@ -752,6 +743,7 @@ 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 27b993259c..7daef60c94 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1,16 +1,9 @@ +//#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 @@ -1687,6 +1680,8 @@ 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); } @@ -2480,7 +2475,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 fcd792e849..0da0b007b1 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -1,19 +1,25 @@ -#include "proxysql_admin.h" - -#include -#include -#include - -#include "jemalloc.h" +#include // std::cout +#include // std::sort +#include // std::vector #include "re2/re2.h" - -#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" +#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 #define SELECT_VERSION_COMMENT "select @@version_comment limit 1" #define SELECT_VERSION_COMMENT_LEN 32 @@ -2188,6 +2194,7 @@ 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; @@ -2390,6 +2397,7 @@ 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); @@ -3728,8 +3736,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_t hash_stage1[SHA_DIGEST_LENGTH]; - uint8_t hash_stage2[SHA_DIGEST_LENGTH]; + uint8 hash_stage1[SHA_DIGEST_LENGTH]; + uint8 hash_stage2[SHA_DIGEST_LENGTH]; SHA_CTX sha1_context; SHA1_Init(&sha1_context); SHA1_Update(&sha1_context, r->fields[1], strlen(r->fields[1])); @@ -5012,6 +5020,7 @@ 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 3fef5c9978..80e41ffe45 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -1,12 +1,8 @@ -#include "proxysql_glovars.hpp" - -#include -#include -#include - #include "ezOptionParser.hpp" -#include "proxysql_debug.h" -#include "gen_utils.h" +#include "proxysql.h" +#include "cpp.h" +#include + static void term_handler(int sig) { diff --git a/lib/Query_Cache.cpp b/lib/Query_Cache.cpp index e74881d682..044c8e8df4 100644 --- a/lib/Query_Cache.cpp +++ b/lib/Query_Cache.cpp @@ -1,9 +1,9 @@ -#include "query_cache.hpp" - #include "btree_map.h" -#include "MySQL_Thread.h" +#include "proxysql.h" +#include "cpp.h" +#include "query_cache.hpp" +#include "proxysql_atomic.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 3da78c1409..5c60ad8b02 100644 --- a/lib/Query_Processor.cpp +++ b/lib/Query_Processor.cpp @@ -1,17 +1,14 @@ -#include "query_processor.h" - -#include - -#include "pcrecpp.h" +#include // std::cout +#include // std::sort +#include // std::vector #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 82bfbc179f..b09e62f1cf 100644 --- a/lib/configfile.cpp +++ b/lib/configfile.cpp @@ -1,10 +1,14 @@ -#include "configfile.hpp" +#include "proxysql.h" +#include "cpp.h" -#include -#include #include -#include "fileutils.hpp" +#include +#include +#include + + +#include using namespace std; using namespace libconfig; diff --git a/lib/debug.cpp b/lib/debug.cpp index 7e12de5af7..ebf856f9ac 100644 --- a/lib/debug.cpp +++ b/lib/debug.cpp @@ -1,11 +1,6 @@ -#include "proxysql_debug.h" - -#include -#include - -#include - +#include "proxysql.h" #include "proxysql_atomic.h" +#include #ifdef DEBUG diff --git a/lib/gen_utils.cpp b/lib/gen_utils.cpp index a1f3662e9a..fe4d089a62 100644 --- a/lib/gen_utils.cpp +++ b/lib/gen_utils.cpp @@ -1,6 +1,6 @@ -#include "gen_utils.h" +#include "proxysql.h" +#include "cpp.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 936a6e0108..9b8d0b5c45 100644 --- a/lib/mysql_backend.cpp +++ b/lib/mysql_backend.cpp @@ -1,7 +1,5 @@ -#include "mysql_backend.h" - -#include "MySQL_Session.h" -#include "MySQL_Thread.h" +#include "proxysql.h" +#include "cpp.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 fbe81c94c0..bf0baf548b 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -1,12 +1,6 @@ -#include "mysql_connection.h" - -#include -#include - -#include "MySQL_Session.h" -#include "MySQL_Thread.h" +#include "proxysql.h" +#include "cpp.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 843009c08d..9fd4c92543 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -1,18 +1,6 @@ -#include "MySQL_Data_Stream.h" - -#include -#include -#include -#include -#include -#include - +#include "proxysql.h" +#include "cpp.h" #include - -#include "MySQL_Session.h" -#include "MySQL_Thread.h" -#include "proxysql_debug.h" - #ifndef UNIX_PATH_MAX #define UNIX_PATH_MAX 108 #endif @@ -125,7 +113,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; @@ -257,7 +245,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; } @@ -375,7 +363,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 0bda01d8bd..ef62022bc3 100644 --- a/lib/network.cpp +++ b/lib/network.cpp @@ -1,18 +1,4 @@ -#include "network.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "proxysql_debug.h" +#include "proxysql.h" /* * create a socket and listen on a specified IP and port diff --git a/lib/sqlite3db.cpp b/lib/sqlite3db.cpp index 199afb7b1b..7bcafd6197 100644 --- a/lib/sqlite3db.cpp +++ b/lib/sqlite3db.cpp @@ -1,10 +1,5 @@ -#include "sqlite3db.h" - -#include - #include "proxysql.h" -#include "proxysql_atomic.h" -#include "proxysql_debug.h" +#include "cpp.h" #include "SpookyV2.h" #define USLEEP_SQLITE_LOCKED 100 diff --git a/src/main.cpp b/src/main.cpp index 8a0fbd45aa..5d676b2ce7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,11 @@ #include +#include +#include "btree_map.h" +#include "proxysql.h" + +//#define PROXYSQL_EXTERN +#include "cpp.h" -#include #include #include @@ -8,16 +13,6 @@ #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 @@ -787,3 +782,4 @@ 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 968cff615b..12e8686960 100644 --- a/src/proxysql_global.cpp +++ b/src/proxysql_global.cpp @@ -1,2 +1,5 @@ #define PROXYSQL_EXTERN #include "proxysql.h" +//#include "proxysql_glovars.hpp" +#include "cpp.h" +//ProxySQL_GlobalVariables GloVars;