1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

Merge with 4.0

BitKeeper/etc/logging_ok:
  auto-union
BitKeeper/deleted/.del-apply-patch:
  Delete: netware/BUILD/apply-patch
BitKeeper/deleted/.del-save-patch:
  Delete: netware/BUILD/save-patch
BitKeeper/deleted/.del-mini_client.cc~8677895ec8169183:
  Auto merged
BitKeeper/triggers/post-commit:
  Auto merged
VC++Files/mysys/mysys.dsp:
  Auto merged
client/mysqlbinlog.cc:
  Auto merged
extra/resolveip.c:
  Auto merged
include/config-win.h:
  Auto merged
include/my_global.h:
  Auto merged
include/my_sys.h:
  Auto merged
include/mysql_com.h:
  Auto merged
innobase/include/os0thread.h:
  Auto merged
innobase/os/os0file.c:
  Auto merged
innobase/srv/srv0start.c:
  Auto merged
innobase/thr/thr0loc.c:
  Auto merged
libmysql/manager.c:
  Auto merged
libmysqld/Makefile.am:
  Auto merged
libmysqld/lib_sql.cc:
  Auto merged
myisam/ft_boolean_search.c:
  Auto merged
myisam/mi_extra.c:
  Auto merged
myisam/mi_locking.c:
  Auto merged
mysql-test/mysql-test-run.sh:
  Auto merged
mysql-test/r/fulltext.result:
  Auto merged
mysql-test/r/myisam.result:
  Auto merged
mysql-test/r/select.result:
  Auto merged
mysql-test/t/fulltext.test:
  Auto merged
mysql-test/t/myisam.test:
  Auto merged
mysql-test/t/rpl_reset_slave.test:
  Auto merged
mysql-test/t/rpl_trunc_binlog.test:
  Auto merged
mysys/Makefile.am:
  Auto merged
mysys/errors.c:
  Auto merged
mysys/my_symlink.c:
  Auto merged
mysys/my_thr_init.c:
  Auto merged
scripts/mysql_install_db.sh:
  Auto merged
sql/item_func.cc:
  Auto merged
sql/log_event.h:
  Auto merged
sql/mysqld.cc:
  Auto merged
sql/slave.cc:
  Auto merged
sql/sql_cache.cc:
  Auto merged
sql/sql_class.cc:
  Auto merged
sql/sql_class.h:
  Auto merged
sql/sql_repl.cc:
  Auto merged
sql/sql_test.cc:
  Auto merged
sql/unireg.h:
  Auto merged
client/mysqldump.c:
  merge with 4.0 (quoted names)
configure.in:
  use local file
include/my_pthread.h:
  Use local file
innobase/include/srv0srv.h:
  Use local file
innobase/row/row0sel.c:
  Use local file
innobase/srv/srv0srv.c:
  Use local file
libmysql/libmysql.c:
  Use local file
myisam/myisamchk.c:
  merge fixes
mysql-test/r/func_crypt.result:
  update results
mysql-test/r/order_by.result:
  update results
mysql-test/r/query_cache.result:
  update results
mysql-test/r/range.result:
  update results
mysql-test/r/rpl_reset_slave.result:
  update results
mysql-test/r/rpl_trunc_binlog.result:
  update results
mysql-test/t/func_crypt.test:
  Added disable_warnings/enable warnings
mysql-test/t/query_cache.test:
  merge tests
mysql-test/t/range.test:
  merge tests
mysys/charset.c:
  use local file (will merge patch separately)
sql/ha_innodb.cc:
  use local file
sql/log_event.cc:
  new slave_proxy_id handling
sql/slave.h:
  merge
sql/sql_base.cc:
  merge
sql/sql_parse.cc:
  Fixes for counting user connect resourses
  Added function comments for involved functions
sql/sql_select.cc:
  Fix for not doing sort with LIMIT when OPTION_FOUND_ROWS is used
sql/unireg.cc:
  merge fixes
support-files/mysql.server.sh:
  merge fixes
This commit is contained in:
unknown
2003-11-04 09:40:36 +02:00
67 changed files with 882 additions and 199 deletions

View File

@@ -172,6 +172,7 @@ static int get_or_create_user_conn(THD *thd, const char *user,
}
}
thd->user_connect=uc;
uc->connections++;
end:
(void) pthread_mutex_unlock(&LOCK_user_conn);
return return_val;
@@ -314,14 +315,15 @@ int check_user(THD *thd, enum enum_server_command command,
thd->db_access=0;
/* Don't allow user to connect if he has done too many queries */
if ((ur.questions || ur.updates ||
ur.connections || max_user_connections) &&
get_or_create_user_conn(thd,thd->user,thd->host_or_ip,&ur))
DBUG_RETURN(-1);
if (thd->user_connect && (thd->user_connect->user_resources.connections ||
max_user_connections) &&
check_for_max_user_connections(thd, thd->user_connect))
DBUG_RETURN(-1);
if ((ur.questions || ur.updates || ur.connections ||
max_user_connections) &&
get_or_create_user_conn(thd,thd->user,thd->host_or_ip,&ur))
DBUG_RETURN(-1);
if (thd->user_connect &&
(thd->user_connect->user_resources.connections ||
max_user_connections) &&
check_for_max_user_connections(thd, thd->user_connect))
DBUG_RETURN(-1);
/* Change database if necessary: OK or FAIL is sent in mysql_change_db */
if (db && db[0])
@@ -386,42 +388,84 @@ void init_max_user_conn(void)
}
/*
check if user has already too many connections
SYNOPSIS
check_for_max_user_connections()
thd Thread handle
uc User connect object
NOTES
If check fails, we decrease user connection count, which means one
shouldn't call decrease_user_connections() after this function.
RETURN
0 ok
1 error
*/
static int check_for_max_user_connections(THD *thd, USER_CONN *uc)
{
int error=0;
DBUG_ENTER("check_for_max_user_connections");
(void) pthread_mutex_lock(&LOCK_user_conn);
if (max_user_connections &&
(max_user_connections < (uint) uc->connections))
max_user_connections < (uint) uc->connections)
{
net_printf(thd,ER_TOO_MANY_USER_CONNECTIONS, uc->user);
error=1;
goto end;
}
uc->connections++;
if (uc->user_resources.connections &&
uc->conn_per_hour++ >= uc->user_resources.connections)
uc->user_resources.connections <= uc->conn_per_hour)
{
net_printf(thd, ER_USER_LIMIT_REACHED, uc->user,
"max_connections",
(long) uc->user_resources.connections);
error=1;
goto end;
}
end:
uc->conn_per_hour++;
end:
if (error)
uc->connections--; // no need for decrease_user_connections() here
(void) pthread_mutex_unlock(&LOCK_user_conn);
DBUG_RETURN(error);
}
/*
Decrease user connection count
SYNOPSIS
decrease_user_connections()
uc User connection object
NOTES
If there is a n user connection object for a connection
(which only happens if 'max_user_connections' is defined or
if someone has created a resource grant for a user), then
the connection count is always incremented on connect.
The user connect object is not freed if some users has
'max connections per hour' defined as we need to be able to hold
count over the lifetime of the connection.
*/
static void decrease_user_connections(USER_CONN *uc)
{
DBUG_ENTER("decrease_user_connections");
if ((uc->connections && !--uc->connections) && !mqh_used)
(void) pthread_mutex_lock(&LOCK_user_conn);
DBUG_ASSERT(uc->connections);
if (!--uc->connections && !mqh_used)
{
/* Last connection for user; Delete it */
(void) pthread_mutex_lock(&LOCK_user_conn);
(void) hash_delete(&hash_user_connections,(byte*) uc);
(void) pthread_mutex_unlock(&LOCK_user_conn);
}
(void) pthread_mutex_unlock(&LOCK_user_conn);
DBUG_VOID_RETURN;
}
@@ -1227,15 +1271,17 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
char *save_user= thd->user;
char *save_priv_user= thd->priv_user;
char *save_db= thd->db;
USER_CONN *save_uc= thd->user_connect;
thd->user= my_strdup(user, MYF(0));
if (!thd->user)
USER_CONN *save_user_connect= thd->user_connect;
if (!(thd->user= my_strdup(user, MYF(0))))
{
thd->user= save_user;
send_error(thd, ER_OUT_OF_RESOURCES);
break;
}
/* Clear variables that are allocated */
thd->user_connect= 0;
int res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
if (res)
@@ -1246,6 +1292,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
x_free(thd->user);
thd->user= save_user;
thd->priv_user= save_priv_user;
thd->user_connect= save_user_connect;
thd->master_access= save_master_access;
thd->db_access= save_db_access;
thd->db= save_db;
@@ -1254,8 +1301,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
else
{
/* we've authenticated new user */
if (max_connections && save_uc)
decrease_user_connections(save_uc);
if (save_user_connect)
decrease_user_connections(save_user_connect);
x_free((gptr) save_db);
x_free((gptr) save_user);
}