Add optional support for ClickHouse

pull/1175/head
René Cannaò 9 years ago
parent 474dd78dc2
commit 62898623df

@ -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

5
deps/Makefile vendored

@ -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

@ -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"

@ -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 */

@ -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;

@ -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 */

@ -1,3 +1,4 @@
#ifdef PROXYSQLCLICKHOUSE
#include <iostream> // std::cout
#include <algorithm> // std::sort
#include <vector> // std::vector
@ -3025,3 +3026,4 @@ void * waitpid_thread(void *arg) {
return NULL;
}
*/
#endif /* PROXYSQLCLICKHOUSE */

@ -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

@ -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);
}

@ -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;

@ -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;

@ -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;

@ -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)

@ -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 */
}

Loading…
Cancel
Save