mirror of
https://github.com/MariaDB/server.git
synced 2025-06-13 13:01:51 +03:00
Merge 52.0.168.192.in-addr.arpa:/Users/bell/mysql/bk/mysql-5.0
into 52.0.168.192.in-addr.arpa:/Users/bell/mysql/bk/work-repl-5.0
This commit is contained in:
@ -60,6 +60,7 @@
|
||||
extern "C" int gethostname(char *name, int namelen);
|
||||
#endif
|
||||
|
||||
static void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
|
||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||
static int check_for_max_user_connections(THD *thd, USER_CONN *uc);
|
||||
#endif
|
||||
@ -70,6 +71,7 @@ static void remove_escape(char *name);
|
||||
static void refresh_status(void);
|
||||
static bool append_file_to_dir(THD *thd, const char **filename_ptr,
|
||||
const char *table_name);
|
||||
static void log_slow_query(THD *thd);
|
||||
|
||||
const char *any_db="*any*"; // Special symbol for check_access
|
||||
|
||||
@ -486,6 +488,7 @@ static int check_for_max_user_connections(THD *thd, USER_CONN *uc)
|
||||
error=1;
|
||||
goto end;
|
||||
}
|
||||
time_out_user_resource_limits(thd, uc);
|
||||
if (uc->user_resources.user_conn &&
|
||||
uc->user_resources.user_conn < uc->connections)
|
||||
{
|
||||
@ -604,36 +607,56 @@ bool is_update_query(enum enum_sql_command command)
|
||||
}
|
||||
|
||||
/*
|
||||
Check if maximum queries per hour limit has been reached
|
||||
returns 0 if OK.
|
||||
Reset per-hour user resource limits when it has been more than
|
||||
an hour since they were last checked
|
||||
|
||||
In theory we would need a mutex in the USER_CONN structure for this to
|
||||
be 100 % safe, but as the worst scenario is that we would miss counting
|
||||
a couple of queries, this isn't critical.
|
||||
SYNOPSIS:
|
||||
time_out_user_resource_limits()
|
||||
thd Thread handler
|
||||
uc User connection details
|
||||
|
||||
NOTE:
|
||||
This assumes that the LOCK_user_conn mutex has been acquired, so it is
|
||||
safe to test and modify members of the USER_CONN structure.
|
||||
*/
|
||||
|
||||
static void time_out_user_resource_limits(THD *thd, USER_CONN *uc)
|
||||
{
|
||||
bool error= 0;
|
||||
time_t check_time = thd->start_time ? thd->start_time : time(NULL);
|
||||
DBUG_ENTER("time_out_user_resource_limits");
|
||||
|
||||
/* If more than a hour since last check, reset resource checking */
|
||||
if (check_time - uc->intime >= 3600)
|
||||
{
|
||||
uc->questions=1;
|
||||
uc->updates=0;
|
||||
uc->conn_per_hour=0;
|
||||
uc->intime=check_time;
|
||||
}
|
||||
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Check if maximum queries per hour limit has been reached
|
||||
returns 0 if OK.
|
||||
*/
|
||||
|
||||
static bool check_mqh(THD *thd, uint check_command)
|
||||
{
|
||||
#ifdef NO_EMBEDDED_ACCESS_CHECKS
|
||||
return(0);
|
||||
#else
|
||||
bool error=0;
|
||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||
bool error= 0;
|
||||
time_t check_time = thd->start_time ? thd->start_time : time(NULL);
|
||||
USER_CONN *uc=thd->user_connect;
|
||||
DBUG_ENTER("check_mqh");
|
||||
DBUG_ASSERT(uc != 0);
|
||||
|
||||
/* If more than a hour since last check, reset resource checking */
|
||||
if (check_time - uc->intime >= 3600)
|
||||
{
|
||||
(void) pthread_mutex_lock(&LOCK_user_conn);
|
||||
uc->questions=1;
|
||||
uc->updates=0;
|
||||
uc->conn_per_hour=0;
|
||||
uc->intime=check_time;
|
||||
(void) pthread_mutex_unlock(&LOCK_user_conn);
|
||||
}
|
||||
(void) pthread_mutex_lock(&LOCK_user_conn);
|
||||
|
||||
time_out_user_resource_limits(thd, uc);
|
||||
|
||||
/* Check that we have not done too many questions / hour */
|
||||
if (uc->user_resources.questions &&
|
||||
uc->questions++ >= uc->user_resources.questions)
|
||||
@ -656,7 +679,10 @@ static bool check_mqh(THD *thd, uint check_command)
|
||||
}
|
||||
}
|
||||
end:
|
||||
(void) pthread_mutex_unlock(&LOCK_user_conn);
|
||||
DBUG_RETURN(error);
|
||||
#else
|
||||
return (0);
|
||||
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
|
||||
}
|
||||
|
||||
@ -1733,6 +1759,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
||||
#endif
|
||||
ulong length= (ulong)(packet_end-packet);
|
||||
|
||||
log_slow_query(thd);
|
||||
|
||||
/* Remove garbage at start of query */
|
||||
while (my_isspace(thd->charset(), *packet) && length > 0)
|
||||
{
|
||||
@ -1743,6 +1771,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
||||
thd->query_length= length;
|
||||
thd->query= packet;
|
||||
thd->query_id= next_query_id();
|
||||
thd->set_time(); /* Reset the query start time. */
|
||||
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
|
||||
VOID(pthread_mutex_unlock(&LOCK_thread_count));
|
||||
#ifndef EMBEDDED_LIBRARY
|
||||
@ -2082,6 +2111,24 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
||||
if (thd->net.report_error)
|
||||
net_send_error(thd);
|
||||
|
||||
log_slow_query(thd);
|
||||
|
||||
thd->proc_info="cleaning up";
|
||||
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list
|
||||
thd->proc_info=0;
|
||||
thd->command=COM_SLEEP;
|
||||
thd->query=0;
|
||||
thd->query_length=0;
|
||||
thread_running--;
|
||||
VOID(pthread_mutex_unlock(&LOCK_thread_count));
|
||||
thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
|
||||
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
|
||||
static void log_slow_query(THD *thd)
|
||||
{
|
||||
time_t start_of_query=thd->start_time;
|
||||
thd->end_time(); // Set start time
|
||||
|
||||
@ -2100,18 +2147,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
||||
mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query);
|
||||
}
|
||||
}
|
||||
thd->proc_info="cleaning up";
|
||||
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list
|
||||
thd->proc_info=0;
|
||||
thd->command=COM_SLEEP;
|
||||
thd->query=0;
|
||||
thd->query_length=0;
|
||||
thread_running--;
|
||||
VOID(pthread_mutex_unlock(&LOCK_thread_count));
|
||||
thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
|
||||
|
||||
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user