Specify when a mysql_users.max_connections is reached #794

It also fixes:
* bug in deps/Makefile related to cleanall
* crashing bug in HGCU_thread_run()
pull/827/head
René Cannaò 10 years ago
parent 85f4ba6835
commit d0d764533d

4
deps/Makefile vendored

@ -84,13 +84,13 @@ pcre: pcre/pcre/.libs/libpcre.a
cleanpart:
cd mariadb-client-library && rm -rf mariadb-connector-c-2.3.1
cd jemalloc && rm -rf jemalloc-4.1.0
cd jemalloc && rm -rf jemalloc-4.2.1
cd sqlite3/sqlite3 && rm -rf *
.PHONY: cleanpart
cleanall:
cd libdaemon && rm -rf libdaemon-0.14
cd jemalloc && rm -rf jemalloc-4.1.0
cd jemalloc && rm -rf jemalloc-4.2.1
cd mariadb-client-library && rm -rf mariadb-connector-c-2.3.1
cd libconfig && rm -rf libconfig-1.4.9
cd re2 && rm -rf re2

@ -64,7 +64,7 @@ class MySQL_Authentication {
void print_version();
char * lookup(char *username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward, int *max_connections, void **sha1_pass);
int dump_all_users(account_details_t ***);
int increase_frontend_user_connections(char *username);
int increase_frontend_user_connections(char *username, int *mc=NULL);
void decrease_frontend_user_connections(char *username);
void set_all_inactive(enum cred_username_type usertype);
void remove_inactives(enum cred_username_type usertype);

@ -255,7 +255,7 @@ __exit_dump_all_users:
}
int MySQL_Authentication::increase_frontend_user_connections(char *username) {
int MySQL_Authentication::increase_frontend_user_connections(char *username, int *mc) {
uint64_t hash1, hash2;
SpookyHash *myhash=new SpookyHash();
myhash->Init(1,2);
@ -272,6 +272,9 @@ int MySQL_Authentication::increase_frontend_user_connections(char *username) {
account_details_t *ad=it->second;
ad->num_connections_used++;
ret=ad->max_connections-ad->num_connections_used;
if (mc) {
*mc=ad->max_connections;
}
}
spin_wrunlock(&cg.lock);
return ret;

@ -45,7 +45,12 @@ static void * HGCU_thread_run() {
int i;
for (i=0;i<(int)l;i++) {
myconn=(MySQL_Connection *)conn_array->index(i);
statuses[i]=mysql_change_user_start(&ret[i], myconn->mysql, myconn->userinfo->password, myconn->userinfo->password, myconn->userinfo->schemaname);
if (myconn->mysql->net.vio) {
statuses[i]=mysql_change_user_start(&ret[i], myconn->mysql, myconn->userinfo->password, myconn->userinfo->password, myconn->userinfo->schemaname);
} else {
statuses[i]=0;
ret[i]=1;
}
}
for (i=0;i<(int)conn_array->len;i++) {
if (statuses[i]==0) {

@ -2562,15 +2562,25 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(
client_myds->myconn->userinfo->set_schemaname(default_schema,strlen(default_schema));
}
int free_users=0;
int used_users=0;
if (admin==false) {
client_authenticated=true;
free_users=GloMyAuth->increase_frontend_user_connections(client_myds->myconn->userinfo->username);
free_users=GloMyAuth->increase_frontend_user_connections(client_myds->myconn->userinfo->username, &used_users);
}
if (max_connections_reached==true || free_users<0) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Too many connections\n");
*wrong_pass=true;
client_myds->setDSS_STATE_QUERY_SENT_NET();
client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,2,1040,(char *)"#HY000", (char *)"Too many connections");
if (max_connections_reached==true) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Too many connections\n");
client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,2,1040,(char *)"08004", (char *)"Too many connections");
} else { // see issue #794
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "User '%s' has exceeded the 'max_user_connections' resource (current value: %d)\n", client_myds->myconn->userinfo->username, used_users);
char *a=(char *)"User '%s' has exceeded the 'max_user_connections' resource (current value: %d)";
char *b=(char *)malloc(strlen(a)+strlen(client_myds->myconn->userinfo->username)+16);
sprintf(b,a,client_myds->myconn->userinfo->username,used_users);
client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,2,1226,(char *)"42000", b);
free(b);
}
__sync_add_and_fetch(&MyHGM->status.client_connections_aborted,1);
client_myds->DSS=STATE_SLEEP;
} else {

Loading…
Cancel
Save