From 62898623df8103a552d5fbfdc56094613ddaceb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 10 Sep 2017 09:18:07 +0200 Subject: [PATCH] Add optional support for ClickHouse --- Makefile | 34 +++++++++++++++++++++++++++- deps/Makefile | 5 +++++ include/cpp.h | 4 ++++ include/proxysql_admin.h | 5 +++++ include/proxysql_glovars.hpp | 2 ++ lib/ClickHouse_Authentication.cpp | 2 ++ lib/ClickHouse_Server.cpp | 2 ++ lib/Makefile | 9 +++++++- lib/MySQL_Protocol.cpp | 8 +++++++ lib/MySQL_Session.cpp | 8 +++++++ lib/ProxySQL_Admin.cpp | 37 ++++++++++++++++++++++++++++++- lib/ProxySQL_GloVars.cpp | 6 +++++ src/Makefile | 14 +++++++++++- src/main.cpp | 13 ++++++++++- 14 files changed, 144 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 9f14af6e4..259942fad 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ DEBUG=${ALL_DEBUG} #export DEBUG #export OPTZ #export EXTRALINK -CURVER?=1.4.2 +CURVER?=1.4.3 MAKEOPT="-j 4" DISTRO := $(shell gawk -F= '/^NAME/{print $$2}' /etc/os-release) ifeq ($(wildcard /usr/lib/systemd/system), /usr/lib/systemd/system) @@ -25,6 +25,13 @@ default: build_deps build_lib build_src .PHONY: debug debug: build_deps_debug build_lib_debug build_src_debug +.PHONY: clickhouse +default: build_deps_clickhouse build_lib_clickhouse build_src_clickhouse + +.PHONY: debug_clickhouse +debug: build_deps_debug_clickhouse build_lib_debug_clickhouse build_src_debug_clickhouse + + .PHONY: build_deps build_deps: cd deps && OPTZ="${O2} -ggdb" CC=${CC} CXX=${CXX} ${MAKE} @@ -49,6 +56,31 @@ build_lib_debug: build_deps_debug build_src_debug: build_deps build_lib_debug cd src && OPTZ="${O0} -ggdb -DDEBUG" CC=${CC} CXX=${CXX} ${MAKE} +.PHONY: build_deps_clickhouse +build_deps_clickhouse: + cd deps && OPTZ="${O2} -ggdb" PROXYSQLCLICKHOUSE=1 CC=${CC} CXX=${CXX} ${MAKE} + +.PHONY: build_deps_debug_clickhouse +build_deps_debug_clickhouse: + cd deps && OPTZ="${O0} -ggdb -DDEBUG" PROXYSQLCLICKHOUSE=1 PROXYDEBUG=1 CC=${CC} CXX=${CXX} ${MAKE} + +.PHONY: build_lib_clickhouse +build_lib_clickhouse: build_deps_clickhouse + cd lib && OPTZ="${O2} -ggdb" PROXYSQLCLICKHOUSE=1 CC=${CC} CXX=${CXX} ${MAKE} + +.PHONY: build_lib_debug_clickhouse +build_lib_debug_clickhouse: build_deps_debug_clickhouse + cd lib && OPTZ="${O0} -ggdb -DDEBUG" PROXYSQLCLICKHOUSE=1 CC=${CC} CXX=${CXX} ${MAKE} + +.PHONY: build_src_clickhouse +build_src_clickhouse: build_deps build_lib + cd src && OPTZ="${O2} -ggdb" PROXYSQLCLICKHOUSE=1 CC=${CC} CXX=${CXX} ${MAKE} + +.PHONY: build_src_debug_clickhouse +build_src_debug_clickhouse: build_deps build_lib_debug_clickhouse + cd src && OPTZ="${O0} -ggdb -DDEBUG" PROXYSQLCLICKHOUSE=1 CC=${CC} CXX=${CXX} ${MAKE} + + .PHONY: clean clean: cd lib && ${MAKE} clean diff --git a/deps/Makefile b/deps/Makefile index 83e7d2873..a9c5830da 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -9,7 +9,12 @@ MYCFLAGS=-O2 MYJEOPT=--enable-xmalloc --enable-munmap --enable-prof endif +PROXYSQLCLICKHOUSE := $(shell echo $(PROXYSQLCLICKHOUSE)) +ifeq ($(PROXYSQLCLICKHOUSE),1) default: libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre clickhouse-cpp lz4 cityhash +else +default: libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre +endif .PHONY: default diff --git a/include/cpp.h b/include/cpp.h index e4c69ce6d..f23e77b67 100644 --- a/include/cpp.h +++ b/include/cpp.h @@ -10,13 +10,17 @@ #include "MySQL_Monitor.hpp" #include "MySQL_Protocol.h" #include "MySQL_Authentication.hpp" +#ifdef PROXYSQLCLICKHOUSE #include "ClickHouse_Authentication.hpp" +#endif /* PROXYSQLCLICKHOUSE */ #include "fileutils.hpp" #include "configfile.hpp" #include "query_processor.h" #include "proxysql_admin.h" #include "SQLite3_Server.h" +#ifdef PROXYSQLCLICKHOUSE #include "ClickHouse_Server.h" +#endif /* PROXYSQLCLICKHOUSE */ #include "MySQL_HostGroups_Manager.h" #include "MySQL_Logger.hpp" #include "MySQL_PreparedStatement.h" diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 70280284f..1f6cd73c5 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -146,9 +146,12 @@ class ProxySQL_Admin { void delete_credentials(char *credentials); #endif /* DEBUG */ +#ifdef PROXYSQLCLICKHOUSE + // ClickHouse void __refresh_clickhouse_users(); void __add_active_clickhouse_users(char *user=NULL); void __delete_inactive_clickhouse_users(); +#endif /* PROXYSQLCLICKHOUSE */ public: @@ -252,11 +255,13 @@ class ProxySQL_Admin { void save_proxysql_servers_runtime_to_database(bool); void dump_checksums_values_table(); +#ifdef PROXYSQLCLICKHOUSE // ClickHouse void init_clickhouse_users(); void flush_clickhouse_users__from_memory_to_disk(); void flush_clickhouse_users__from_disk_to_memory(); void save_clickhouse_users_runtime_to_database(bool _runtime); +#endif /* PROXYSQLCLICKHOUSE */ }; #endif /* __CLASS_PROXYSQL_ADMIN_H */ diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index 0474b6fab..07cdb60e6 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -77,7 +77,9 @@ class ProxySQL_GlobalVariables { int restart_delay; SSL_CTX *ssl_ctx; bool sqlite3_server; +#ifdef PROXYSQLCLICKHOUSE bool clickhouse_server; +#endif /* PROXYSQLCLICKHOUSE */ } global; struct mysql { char *server_version; diff --git a/lib/ClickHouse_Authentication.cpp b/lib/ClickHouse_Authentication.cpp index 83d784bf9..93493099b 100644 --- a/lib/ClickHouse_Authentication.cpp +++ b/lib/ClickHouse_Authentication.cpp @@ -1,3 +1,4 @@ +#ifdef PROXYSQLCLICKHOUSE #include "btree_map.h" #include "proxysql.h" #include "cpp.h" @@ -433,3 +434,4 @@ bool ClickHouse_Authentication::reset() { _reset(USERNAME_FRONTEND); return true; } +#endif /* PROXYSQLCLICKHOUSE */ diff --git a/lib/ClickHouse_Server.cpp b/lib/ClickHouse_Server.cpp index 5f9aa06d5..c6bd4a335 100644 --- a/lib/ClickHouse_Server.cpp +++ b/lib/ClickHouse_Server.cpp @@ -1,3 +1,4 @@ +#ifdef PROXYSQLCLICKHOUSE #include // std::cout #include // std::sort #include // std::vector @@ -3025,3 +3026,4 @@ void * waitpid_thread(void *arg) { return NULL; } */ +#endif /* PROXYSQLCLICKHOUSE */ diff --git a/lib/Makefile b/lib/Makefile index ec5b0abbc..af5c24027 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -55,8 +55,15 @@ ifeq ($(UNAME_S),Darwin) NOJEM=-DNOJEM endif +PROXYSQLCLICKHOUSE := $(shell echo $(PROXYSQLCLICKHOUSE)) +ifeq ($(PROXYSQLCLICKHOUSE),1) +PSQLCH=-DPROXYSQLCLICKHOUSE +else +PSQLCH= +endif + MYCFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall -DGITVERSION=\"$(GIT_VERSION)\" $(NOJEM) -MYCXXFLAGS=-std=c++11 $(MYCFLAGS) +MYCXXFLAGS=-std=c++11 $(MYCFLAGS) $(PSQLCH) default: libproxysql.a .PHONY: default diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index 6df0763e7..de503808c 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -4,7 +4,9 @@ extern MySQL_Authentication *GloMyAuth; extern MySQL_Threads_Handler *GloMTH; +#ifdef PROXYSQLCLICKHOUSE extern ClickHouse_Authentication *GloClickHouseAuth; +#endif /* PROXYSQLCLICKHOUSE */ #ifdef max_allowed_packet #undef max_allowed_packet @@ -1094,7 +1096,9 @@ bool MySQL_Protocol::process_pkt_auth_swich_response(unsigned char *pkt, unsigne void *sha1_pass=NULL; enum proxysql_session_type session_type = (*myds)->sess->session_type; if (session_type == PROXYSQL_SESSION_CLICKHOUSE) { +#ifdef PROXYSQLCLICKHOUSE password=GloClickHouseAuth->lookup((char *)userinfo->username, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, NULL, NULL, &transaction_persistent, NULL, NULL, &sha1_pass); +#endif /* PROXYSQLCLICKHOUSE */ } else { password=GloMyAuth->lookup((char *)userinfo->username, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, NULL, NULL, &transaction_persistent, NULL, NULL, &sha1_pass); } @@ -1156,7 +1160,9 @@ bool MySQL_Protocol::process_pkt_COM_CHANGE_USER(unsigned char *pkt, unsigned in void *sha1_pass=NULL; enum proxysql_session_type session_type = (*myds)->sess->session_type; if (session_type == PROXYSQL_SESSION_CLICKHOUSE) { +#ifdef PROXYSQLCLICKHOUSE password=GloClickHouseAuth->lookup((char *)user, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, NULL, NULL, &transaction_persistent, NULL, NULL, &sha1_pass); +#endif /* PROXYSQLCLICKHOUSE */ } else { password=GloMyAuth->lookup((char *)user, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, NULL, NULL, &transaction_persistent, NULL, NULL, &sha1_pass); } @@ -1275,7 +1281,9 @@ bool MySQL_Protocol::process_pkt_handshake_response(unsigned char *pkt, unsigned int max_connections; enum proxysql_session_type session_type = (*myds)->sess->session_type; if (session_type == PROXYSQL_SESSION_CLICKHOUSE) { +#ifdef PROXYSQLCLICKHOUSE password=GloClickHouseAuth->lookup((char *)user, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, &default_schema, &schema_locked, &transaction_persistent, &fast_forward, &max_connections, &sha1_pass); +#endif /* PROXYSQLCLICKHOUSE */ } else { password=GloMyAuth->lookup((char *)user, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, &default_schema, &schema_locked, &transaction_persistent, &fast_forward, &max_connections, &sha1_pass); } diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 799362de4..3a72b17e6 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -28,8 +28,10 @@ extern MySQL_STMT_Manager_v14 *GloMyStmt; extern SQLite3_Server *GloSQLite3Server; +#ifdef PROXYSQLCLICKHOUSE extern ClickHouse_Authentication *GloClickHouseAuth; extern ClickHouse_Server *GloClickHouseServer; +#endif /* PROXYSQLCLICKHOUSE */ Session_Regex::Session_Regex(char *p) { s=strdup(p); @@ -321,9 +323,11 @@ MySQL_Session::~MySQL_Session() { if (client_myds) { if (client_authenticated) { switch (session_type) { +#ifdef PROXYSQLCLICKHOUSE case PROXYSQL_SESSION_CLICKHOUSE: GloClickHouseAuth->decrease_frontend_user_connections(client_myds->myconn->userinfo->username); break; +#endif /* PROXYSQLCLICKHOUSE */ default: GloMyAuth->decrease_frontend_user_connections(client_myds->myconn->userinfo->username); break; @@ -2006,10 +2010,12 @@ __get_pkts_from_client: handler_function(this, (void *)GloSQLite3Server, &pkt); l_free(pkt.size,pkt.ptr); break; +#ifdef PROXYSQLCLICKHOUSE case PROXYSQL_SESSION_CLICKHOUSE: handler_function(this, (void *)GloClickHouseServer, &pkt); l_free(pkt.size,pkt.ptr); break; +#endif /* PROXYSQLCLICKHOUSE */ default: assert(0); } @@ -3108,9 +3114,11 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE( case PROXYSQL_SESSION_MYSQL: free_users=GloMyAuth->increase_frontend_user_connections(client_myds->myconn->userinfo->username, &used_users); break; +#ifdef PROXYSQLCLICKHOUSE case PROXYSQL_SESSION_CLICKHOUSE: free_users=GloClickHouseAuth->increase_frontend_user_connections(client_myds->myconn->userinfo->username, &used_users); break; +#endif /* PROXYSQLCLICKHOUSE */ default: assert(0); break; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index e35115f99..ee09e6be8 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -142,8 +142,10 @@ extern MySQL_STMT_Manager_v14 *GloMyStmt; extern MySQL_Monitor *GloMyMon; extern ProxySQL_Cluster *GloProxyCluster; +#ifdef PROXYSQLCLICKHOUSE extern ClickHouse_Authentication *GloClickHouseAuth; extern ClickHouse_Server *GloClickHouseServer; +#endif /* PROXYSQLCLICKHOUSE */ #define PANIC(msg) { perror(msg); exit(EXIT_FAILURE); } @@ -268,6 +270,7 @@ pthread_mutex_t users_mutex = PTHREAD_MUTEX_INITIALIZER; #define STATS_SQLITE_TABLE_PROXYSQL_SERVERS_CHECKSUMS "CREATE TABLE stats_proxysql_servers_checksums (hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 6032 , name VARCHAR NOT NULL , version INT NOT NULL , epoch INT NOT NULL , checksum VARCHAR NOT NULL , changed_at INT NOT NULL , updated_at INT NOT NULL , diff_check INT NOT NULL , PRIMARY KEY (hostname, port, name) )" +#ifdef PROXYSQLCLICKHOUSE // ClickHouse Tables #define ADMIN_SQLITE_TABLE_CLICKHOUSE_USERS_141 "CREATE TABLE clickhouse_users (username VARCHAR NOT NULL , password VARCHAR , active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000 , PRIMARY KEY (username))" @@ -275,6 +278,7 @@ pthread_mutex_t users_mutex = PTHREAD_MUTEX_INITIALIZER; #define ADMIN_SQLITE_TABLE_CLICKHOUSE_USERS ADMIN_SQLITE_TABLE_CLICKHOUSE_USERS_141 #define ADMIN_SQLITE_TABLE_RUNTIME_CLICKHOUSE_USERS "CREATE TABLE runtime_clickhouse_users (username VARCHAR NOT NULL , password VARCHAR , active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000 , PRIMARY KEY (username))" +#endif /* PROXYSQLCLICKHOUSE */ @@ -938,6 +942,7 @@ bool admin_handler_command_load_or_save(char *query_no_space, unsigned int query } } } +#ifdef PROXYSQLCLICKHOUSE if ( ( GloVars.global.clickhouse_server == true ) && (query_no_space_length>22) && ( (!strncasecmp("SAVE CLICKHOUSE USERS ", query_no_space, 22)) || (!strncasecmp("LOAD CLICKHOUSE USERS ", query_no_space, 22))) ) { if ( (query_no_space_length==strlen("LOAD CLICKHOUSE USERS TO MEMORY") && !strncasecmp("LOAD CLICKHOUSE USERS TO MEMORY",query_no_space, query_no_space_length)) @@ -1004,6 +1009,7 @@ bool admin_handler_command_load_or_save(char *query_no_space, unsigned int query } } +#endif /* PROXYSQLCLICKHOUSE */ if ((query_no_space_length>17) && ( (!strncasecmp("SAVE MYSQL USERS ", query_no_space, 17)) || (!strncasecmp("LOAD MYSQL USERS ", query_no_space, 17))) ) { @@ -1594,7 +1600,9 @@ void ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign bool runtime_proxysql_servers=false; bool runtime_checksums_values=false; +#ifdef PROXYSQLCLICKHOUSE bool runtime_clickhouse_users = false; +#endif /* PROXYSQLCLICKHOUSE */ bool monitor_mysql_server_group_replication_log=false; @@ -1666,9 +1674,11 @@ void ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign runtime_checksums_values=true; refresh=true; } +#ifdef PROXYSQLCLICKHOUSE if (( GloVars.global.clickhouse_server == true ) && strstr(query_no_space,"runtime_clickhouse_users")) { runtime_clickhouse_users=true; refresh=true; } +#endif /* PROXYSQLCLICKHOUSE */ } } @@ -1741,10 +1751,11 @@ void ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign if (runtime_checksums_values) { dump_checksums_values_table(); } - +#ifdef PROXYSQLCLICKHOUSE if (runtime_clickhouse_users) { save_clickhouse_users_runtime_to_database(true); } +#endif /* PROXYSQLCLICKHOUSE */ } if (monitor_mysql_server_group_replication_log) { @@ -3048,11 +3059,13 @@ bool ProxySQL_Admin::init() { #ifdef DEBUG insert_into_tables_defs(tables_defs_admin,"debug_levels", ADMIN_SQLITE_TABLE_DEBUG_LEVELS); #endif /* DEBUG */ +#ifdef PROXYSQLCLICKHOUSE // ClickHouse if (GloVars.global.clickhouse_server) { insert_into_tables_defs(tables_defs_admin,"clickhouse_users", ADMIN_SQLITE_TABLE_CLICKHOUSE_USERS); insert_into_tables_defs(tables_defs_admin,"runtime_clickhouse_users", ADMIN_SQLITE_TABLE_RUNTIME_CLICKHOUSE_USERS); } +#endif /* PROXYSQLCLICKHOUSE */ insert_into_tables_defs(tables_defs_config,"mysql_servers", ADMIN_SQLITE_TABLE_MYSQL_SERVERS); insert_into_tables_defs(tables_defs_config,"mysql_users", ADMIN_SQLITE_TABLE_MYSQL_USERS); @@ -3066,10 +3079,12 @@ bool ProxySQL_Admin::init() { #ifdef DEBUG insert_into_tables_defs(tables_defs_config,"debug_levels", ADMIN_SQLITE_TABLE_DEBUG_LEVELS); #endif /* DEBUG */ +#ifdef PROXYSQLCLICKHOUSE // ClickHouse if (GloVars.global.clickhouse_server) { insert_into_tables_defs(tables_defs_config,"clickhouse_users", ADMIN_SQLITE_TABLE_CLICKHOUSE_USERS); } +#endif /* PROXYSQLCLICKHOUSE */ insert_into_tables_defs(tables_defs_stats,"stats_mysql_query_rules", STATS_SQLITE_TABLE_MYSQL_QUERY_RULES); insert_into_tables_defs(tables_defs_stats,"stats_mysql_commands_counters", STATS_SQLITE_TABLE_MYSQL_COMMANDS_COUNTERS); @@ -4720,9 +4735,11 @@ void ProxySQL_Admin::__insert_or_ignore_maintable_select_disktable() { #ifdef DEBUG admindb->execute("INSERT OR IGNORE INTO main.debug_levels SELECT * FROM disk.debug_levels"); #endif /* DEBUG */ +#ifdef PROXYSQLCLICKHOUSE if ( GloVars.global.clickhouse_server == true ) { admindb->execute("INSERT OR IGNORE INTO main.clickhouse_users SELECT * FROM disk.clickhouse_users"); } +#endif /* PROXYSQLCLICKHOUSE */ admindb->execute("PRAGMA foreign_keys = ON"); } @@ -4739,9 +4756,11 @@ void ProxySQL_Admin::__insert_or_replace_maintable_select_disktable() { #ifdef DEBUG admindb->execute("INSERT OR IGNORE INTO main.debug_levels SELECT * FROM disk.debug_levels"); #endif /* DEBUG */ +#ifdef PROXYSQLCLICKHOUSE if ( GloVars.global.clickhouse_server == true ) { admindb->execute("INSERT OR REPLACE INTO main.clickhouse_users SELECT * FROM disk.clickhouse_users"); } +#endif /* PROXYSQLCLICKHOUSE */ admindb->execute("PRAGMA foreign_keys = ON"); } @@ -4756,9 +4775,11 @@ void ProxySQL_Admin::__delete_disktable() { #ifdef DEBUG admindb->execute("DELETE FROM disk.debug_levels"); #endif /* DEBUG */ +#ifdef PROXYSQLCLICKHOUSE if ( GloVars.global.clickhouse_server == true ) { admindb->execute("DELETE FROM disk.clickhouse_users"); } +#endif /* PROXYSQLCLICKHOUSE */ } void ProxySQL_Admin::__insert_or_replace_disktable_select_maintable() { @@ -4774,9 +4795,11 @@ void ProxySQL_Admin::__insert_or_replace_disktable_select_maintable() { #ifdef DEBUG admindb->execute("INSERT OR REPLACE INTO disk.debug_levels SELECT * FROM main.debug_levels"); #endif /* DEBUG */ +#ifdef PROXYSQLCLICKHOUSE if ( GloVars.global.clickhouse_server == true ) { admindb->execute("INSERT OR REPLACE INTO disk.clickhouse_users SELECT * FROM main.clickhouse_users"); } +#endif /* PROXYSQLCLICKHOUSE */ } @@ -4798,6 +4821,7 @@ void ProxySQL_Admin::flush_mysql_users__from_memory_to_disk() { admindb->wrunlock(); } +#ifdef PROXYSQLCLICKHOUSE void ProxySQL_Admin::flush_clickhouse_users__from_disk_to_memory() { admindb->wrlock(); admindb->execute("PRAGMA foreign_keys = OFF"); @@ -4815,6 +4839,7 @@ void ProxySQL_Admin::flush_clickhouse_users__from_memory_to_disk() { admindb->execute("PRAGMA foreign_keys = ON"); admindb->wrunlock(); } +#endif /* PROXYSQLCLICKHOUSE */ void ProxySQL_Admin::flush_scheduler__from_disk_to_memory() { admindb->wrlock(); @@ -4890,11 +4915,13 @@ void ProxySQL_Admin::init_users() { pthread_mutex_unlock(&users_mutex); } +#ifdef PROXYSQLCLICKHOUSE void ProxySQL_Admin::init_clickhouse_users() { pthread_mutex_lock(&users_mutex); __refresh_clickhouse_users(); pthread_mutex_unlock(&users_mutex); } +#endif /* PROXYSQLCLICKHOUSE */ void ProxySQL_Admin::init_mysql_servers() { mysql_servers_wrlock(); @@ -4965,6 +4992,7 @@ void ProxySQL_Admin::__refresh_users() { } } +#ifdef PROXYSQLCLICKHOUSE void ProxySQL_Admin::__refresh_clickhouse_users() { //__delete_inactive_clickhouse_users(USERNAME_BACKEND); __delete_inactive_clickhouse_users(); @@ -4977,6 +5005,7 @@ void ProxySQL_Admin::__refresh_clickhouse_users() { GloClickHouseAuth->remove_inactives(USERNAME_FRONTEND); //set_variable((char *)"admin_credentials",(char *)""); } +#endif /* PROXYSQLCLICKHOUSE */ void ProxySQL_Admin::send_MySQL_OK(MySQL_Protocol *myprot, char *msg, int rows) { assert(myprot); @@ -5015,6 +5044,7 @@ void ProxySQL_Admin::__delete_inactive_users(enum cred_username_type usertype) { free(query); } +#ifdef PROXYSQLCLICKHOUSE void ProxySQL_Admin::__delete_inactive_clickhouse_users() { char *error=NULL; int cols=0; @@ -5035,6 +5065,7 @@ void ProxySQL_Admin::__delete_inactive_clickhouse_users() { if (resultset) delete resultset; //free(query); } +#endif /* PROXYSQLCLICKHOUSE */ #define ADDUSER_STMT_RAW void ProxySQL_Admin::__add_active_users(enum cred_username_type usertype, char *__user, uint64_t *hash1) { @@ -5160,6 +5191,7 @@ void ProxySQL_Admin::__add_active_users(enum cred_username_type usertype, char * free(query); } +#ifdef PROXYSQLCLICKHOUSE void ProxySQL_Admin::__add_active_clickhouse_users(char *__user) { char *error=NULL; int cols=0; @@ -5259,6 +5291,7 @@ void ProxySQL_Admin::__add_active_clickhouse_users(char *__user) { #endif free(query); } +#endif /* PROXYSQLCLICKHOUSE */ void ProxySQL_Admin::dump_checksums_values_table() { @@ -5422,6 +5455,7 @@ void ProxySQL_Admin::save_mysql_users_runtime_to_database(bool _runtime) { free(ads); } +#ifdef PROXYSQLCLICKHOUSE void ProxySQL_Admin::save_clickhouse_users_runtime_to_database(bool _runtime) { char *query=NULL; if (_runtime) { @@ -5524,6 +5558,7 @@ void ProxySQL_Admin::save_clickhouse_users_runtime_to_database(bool _runtime) { } free(ads); } +#endif /* PROXYSQLCLICKHOUSE */ void ProxySQL_Admin::stats___mysql_users() { account_details_t **ads=NULL; diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index b9a3b96a7..2f4d7fbaa 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -75,7 +75,9 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { #endif global.sqlite3_server=false; +#ifdef PROXYSQLCLICKHOUSE global.clickhouse_server=false; +#endif /* PROXYSQLCLICKHOUSE */ opt=new ez::ezOptionParser(); opt->overview="High Performance Advanced Proxy for MySQL"; opt->syntax="proxysql [OPTIONS]"; @@ -105,7 +107,9 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { opt->add((const char *)"",0,1,0,(const char *)"Administration Unix Socket",(const char *)"-S",(const char *)"--admin-socket"); opt->add((const char *)"",0,0,0,(const char *)"Enable SQLite3 Server",(const char *)"--sqlite3-server"); +#ifdef PROXYSQLCLICKHOUSE opt->add((const char *)"",0,0,0,(const char *)"Enable ClickHouse Server",(const char *)"--clickhouse-server"); +#endif /* PROXYSQLCLICKHOUSE */ confFile=new ProxySQL_ConfigFile(); }; @@ -176,9 +180,11 @@ void ProxySQL_GlobalVariables::process_opts_pre() { if (opt->isSet("--sqlite3-server")) { global.sqlite3_server=true; } +#ifdef PROXYSQLCLICKHOUSE if (opt->isSet("--clickhouse-server")) { global.clickhouse_server=true; } +#endif /* PROXYSQLCLICKHOUSE */ config_file=GloVars.__cmd_proxysql_config_file; diff --git a/src/Makefile b/src/Makefile index 7471c2f8d..f55332e5e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -48,7 +48,15 @@ ifeq ($(UNAME_S),Darwin) LDIRS+= -L/usr/local/lib endif -MYCXXFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) +PROXYSQLCLICKHOUSE := $(shell echo $(PROXYSQLCLICKHOUSE)) +ifeq ($(PROXYSQLCLICKHOUSE),1) +PSQLCH=-DPROXYSQLCLICKHOUSE +else +PSQLCH= +endif + +MYCXXFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) $(PSQLCH) + LDFLAGS+= NOJEMALLOC := $(shell echo $(NOJEMALLOC)) ifeq ($(NOJEMALLOC),1) @@ -83,7 +91,11 @@ $(ODIR)/%.o: %.cpp $(CXX) -c -o $@ $< $(MYCXXFLAGS) $(CXXFLAGS) -Wall proxysql: $(ODIR) $(OBJ) $(LIBPROXYSQLAR) +ifeq ($(PROXYSQLCLICKHOUSE),1) $(CXX) -o $@ $(OBJ) $(LIBPROXYSQLAR) $(CLICKHOUSE_CPP_DIR)/clickhouse/libclickhouse-cpp-lib.a $(CITYHASH_DIR)/libcityhash.a $(LZ4_DIR)/liblz4.a $(MYCXXFLAGS) $(CXXFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) +else + $(CXX) -o $@ $(OBJ) $(LIBPROXYSQLAR) $(MYCXXFLAGS) $(CXXFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) +endif $(ODIR): mkdir $(ODIR) diff --git a/src/main.cpp b/src/main.cpp index 715c76ab8..de9fe7af3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -176,7 +176,9 @@ int socket_fd; Query_Cache *GloQC; MySQL_Authentication *GloMyAuth; +#ifdef PROXYSQLCLICKHOUSE ClickHouse_Authentication *GloClickHouseAuth; +#endif /* PROXYSQLCLICKHOUSE */ Query_Processor *GloQPro; ProxySQL_Admin *GloAdmin; MySQL_Threads_Handler *GloMTH; @@ -193,7 +195,9 @@ std::thread *MyMon_thread; MySQL_Logger *GloMyLogger; SQLite3_Server *GloSQLite3Server; +#ifdef PROXYSQLCLICKHOUSE ClickHouse_Server *GloClickHouseServer; +#endif /* PROXYSQLCLICKHOUSE */ ProxySQL_Cluster *GloProxyCluster = NULL; @@ -329,7 +333,9 @@ void ProxySQL_Main_init_main_modules() { GloQPro=NULL; GloMTH=NULL; GloMyAuth=NULL; +#ifdef PROXYSQLCLICKHOUSE GloClickHouseAuth=NULL; +#endif /* PROXYSQLCLICKHOUSE */ GloMyMon=NULL; GloMyLogger=NULL; GloMyStmt=NULL; @@ -406,7 +412,7 @@ void ProxySQL_Main_init_SQLite3Server() { GloSQLite3Server->init(); GloSQLite3Server->print_version(); } - +#ifdef PROXYSQLCLICKHOUSE void ProxySQL_Main_init_ClickHouseServer() { // start SQServer GloClickHouseServer = new ClickHouse_Server(); @@ -416,6 +422,7 @@ void ProxySQL_Main_init_ClickHouseServer() { GloClickHouseAuth->print_version(); GloAdmin->init_clickhouse_users(); } +#endif /* PROXYSQLCLICKHOUSE */ void ProxySQL_Main_join_all_threads() { cpu_timer t; @@ -482,6 +489,7 @@ void ProxySQL_Main_shutdown_all_modules() { std::cerr << "GloQPro shutdown in "; #endif } +#ifdef PROXYSQLCLICKHOUSE if (GloClickHouseAuth) { cpu_timer t; delete GloClickHouseAuth; @@ -498,6 +506,7 @@ void ProxySQL_Main_shutdown_all_modules() { std::cerr << "GloClickHouseServer shutdown in "; #endif } +#endif /* PROXYSQLCLICKHOUSE */ if (GloSQLite3Server) { cpu_timer t; delete GloSQLite3Server; @@ -668,6 +677,7 @@ void ProxySQL_Main_init_phase3___start_all() { std::cerr << "Main phase3 : SQLite3 Server initialized in "; #endif } +#ifdef PROXYSQLCLICKHOUSE if ( GloVars.global.clickhouse_server == true ) { cpu_timer t; ProxySQL_Main_init_ClickHouseServer(); @@ -675,6 +685,7 @@ void ProxySQL_Main_init_phase3___start_all() { std::cerr << "Main phase3 : ClickHouse Server initialized in "; #endif } +#endif /* PROXYSQLCLICKHOUSE */ }