1
1
/*****************************************************************************
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
3
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
4
4
Copyright (c) 2008, 2009 Google Inc.
5
Copyright (c) 2009, Percona Inc.
6
7
Portions of this file contain modifications contributed and copyrighted by
7
8
Google, Inc. Those modifications are gratefully acknowledged and are described
9
10
incorporated with their permission, and subject to the conditions contained in
10
11
the file COPYING.Google.
13
Portions of this file contain modifications contributed and copyrighted
14
by Percona Inc.. Those modifications are
15
gratefully acknowledged and are described briefly in the InnoDB
16
documentation. The contributions by Percona Inc. are incorporated with
17
their permission, and subject to the conditions contained in the file
12
20
This program is free software; you can redistribute it and/or modify it under
13
21
the terms of the GNU General Public License as published by the Free Software
14
22
Foundation; version 2 of the License.
22
30
St, Fifth Floor, Boston, MA 02110-1301 USA
24
32
*****************************************************************************/
25
/***********************************************************************
27
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
28
Copyright (c) 2009, Percona Inc.
30
Portions of this file contain modifications contributed and copyrighted
31
by Percona Inc.. Those modifications are
32
gratefully acknowledged and are described briefly in the InnoDB
33
documentation. The contributions by Percona Inc. are incorporated with
34
their permission, and subject to the conditions contained in the file
37
This program is free software; you can redistribute it and/or modify it
38
under the terms of the GNU General Public License as published by the
39
Free Software Foundation; version 2 of the License.
41
This program is distributed in the hope that it will be useful, but
42
WITHOUT ANY WARRANTY; without even the implied warranty of
43
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
44
Public License for more details.
46
You should have received a copy of the GNU General Public License along
47
with this program; if not, write to the Free Software Foundation, Inc.,
48
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
50
***********************************************************************/
52
34
/**************************************************//**
53
35
@file srv/srv0srv.c
119
101
in microseconds, in order to reduce the lagging of the purge thread. */
120
102
UNIV_INTERN ulint srv_dml_needed_delay = 0;
122
UNIV_INTERN ibool srv_lock_timeout_and_monitor_active = FALSE;
104
UNIV_INTERN ibool srv_lock_timeout_active = FALSE;
105
UNIV_INTERN ibool srv_monitor_active = FALSE;
123
106
UNIV_INTERN ibool srv_error_monitor_active = FALSE;
125
108
UNIV_INTERN const char* srv_main_thread_op_info = "";
188
171
the checkpoints. */
189
172
UNIV_INTERN bool srv_adaptive_flushing = TRUE;
191
/* The sort order table of the MySQL latin1_swedish_ci character set
174
/** Maximum number of times allowed to conditionally acquire
175
mutex before switching to blocking wait on the mutex */
176
#define MAX_MUTEX_NOWAIT 20
178
/** Check whether the number of failed nonblocking mutex
179
acquisition attempts exceeds maximum allowed value. If so,
180
srv_printf_innodb_monitor() will request mutex acquisition
181
with mutex_enter(), which will wait until it gets the mutex. */
182
#define MUTEX_NOWAIT(mutex_skipped) ((mutex_skipped) < MAX_MUTEX_NOWAIT)
184
/** The sort order table of the MySQL latin1_swedish_ci character set
193
186
#if defined(BUILD_DRIZZLE)
194
187
UNIV_INTERN const byte srv_latin1_ordering[256] /* The sort order table of the latin1
1723
1721
/******************************************************************//**
1724
Outputs to a file the output of the InnoDB Monitor. */
1722
Outputs to a file the output of the InnoDB Monitor.
1723
@return FALSE if not all information printed
1724
due to failure to obtain necessary mutex */
1727
1727
srv_printf_innodb_monitor(
1728
1728
/*======================*/
1729
1729
FILE* file, /*!< in: output stream */
1730
ibool nowait, /*!< in: whether to wait for kernel mutex */
1730
1731
ulint* trx_start, /*!< out: file position of the start of
1731
1732
the list of active transactions */
1732
1733
ulint* trx_end) /*!< out: file position of the end of
1758
1760
"Per second averages calculated from the last %lu seconds\n",
1759
1761
(ulong)time_elapsed);
1761
fputs("----------\n"
1762
"BACKGROUND THREAD\n"
1763
"----------\n", file);
1763
fputs("-----------------\n"
1764
"BACKGROUND THREAD\n"
1765
"-----------------\n", file);
1764
1766
srv_print_master_thread_info(file);
1766
1768
fputs("----------\n"
1785
1787
mutex_exit(&dict_foreign_err_mutex);
1787
lock_print_info_summary(file);
1789
long t = ftell(file);
1791
*trx_start = ULINT_UNDEFINED;
1793
*trx_start = (ulint) t;
1796
lock_print_info_all_transactions(file);
1798
long t = ftell(file);
1800
*trx_end = ULINT_UNDEFINED;
1802
*trx_end = (ulint) t;
1789
/* Only if lock_print_info_summary proceeds correctly,
1790
before we call the lock_print_info_all_transactions
1791
to print all the lock information. */
1792
ret = lock_print_info_summary(file, nowait);
1796
long t = ftell(file);
1798
*trx_start = ULINT_UNDEFINED;
1800
*trx_start = (ulint) t;
1803
lock_print_info_all_transactions(file);
1805
long t = ftell(file);
1807
*trx_end = ULINT_UNDEFINED;
1809
*trx_end = (ulint) t;
1805
1814
fputs("--------\n"
1807
1816
"--------\n", file);
1988
1999
/*********************************************************************//**
1989
A thread which wakes up threads whose lock wait may have lasted too long.
1990
This also prints the info output by various InnoDB monitors.
2000
A thread which prints the info output by various InnoDB monitors.
1991
2001
@return a dummy parameter */
1993
2003
os_thread_ret_t
1994
srv_lock_timeout_and_monitor_thread(
1995
/*================================*/
1996
2006
void* arg __attribute__((unused)))
1997
2007
/*!< in: a dummy parameter required by
1998
2008
os_thread_create */
2001
2010
double time_elapsed;
2002
2011
time_t current_time;
2003
2012
time_t last_table_monitor_time;
2004
2013
time_t last_tablespace_monitor_time;
2005
2014
time_t last_monitor_time;
2015
ulint mutex_skipped;
2016
ibool last_srv_print_monitor;
2010
2018
#ifdef UNIV_DEBUG_THREAD_CREATION
2011
2019
fprintf(stderr, "Lock timeout thread starts, id %lu\n",
2016
2024
last_table_monitor_time = time(NULL);
2017
2025
last_tablespace_monitor_time = time(NULL);
2018
2026
last_monitor_time = time(NULL);
2028
last_srv_print_monitor = srv_print_innodb_monitor;
2020
srv_lock_timeout_and_monitor_active = TRUE;
2022
/* When someone is waiting for a lock, we wake up every second
2023
and check if a timeout has passed for a lock wait */
2025
os_thread_sleep(1000000);
2030
srv_monitor_active = TRUE;
2032
/* Wake up every 5 seconds to see if we need to print
2033
monitor information. */
2035
os_thread_sleep(5000000);
2027
2037
current_time = time(NULL);
2032
2042
last_monitor_time = time(NULL);
2034
2044
if (srv_print_innodb_monitor) {
2035
srv_printf_innodb_monitor(stderr, NULL, NULL);
2045
/* Reset mutex_skipped counter everytime
2046
srv_print_innodb_monitor changes. This is to
2047
ensure we will not be blocked by kernel_mutex
2048
for short duration information printing,
2049
such as requested by sync_array_print_long_waits() */
2050
if (!last_srv_print_monitor) {
2052
last_srv_print_monitor = TRUE;
2055
if (!srv_printf_innodb_monitor(stderr,
2056
MUTEX_NOWAIT(mutex_skipped),
2060
/* Reset the counter */
2064
last_srv_print_monitor = FALSE;
2038
2068
if (srv_innodb_status) {
2039
2069
mutex_enter(&srv_monitor_file_mutex);
2040
2070
rewind(srv_monitor_file);
2041
srv_printf_innodb_monitor(srv_monitor_file, NULL,
2071
if (!srv_printf_innodb_monitor(srv_monitor_file,
2072
MUTEX_NOWAIT(mutex_skipped),
2043
2079
os_file_set_eof(srv_monitor_file);
2044
2080
mutex_exit(&srv_monitor_file_mutex);
2131
if (srv_shutdown_state >= SRV_SHUTDOWN_CLEANUP) {
2135
if (srv_print_innodb_monitor
2136
|| srv_print_innodb_lock_monitor
2137
|| srv_print_innodb_tablespace_monitor
2138
|| srv_print_innodb_table_monitor) {
2142
srv_monitor_active = FALSE;
2147
srv_monitor_active = FALSE;
2149
/* We count the number of threads in os_thread_exit(). A created
2150
thread should always use that to exit and not use return() to exit. */
2152
os_thread_exit(NULL);
2154
OS_THREAD_DUMMY_RETURN;
2157
/*********************************************************************//**
2158
A thread which wakes up threads whose lock wait may have lasted too long.
2159
@return a dummy parameter */
2162
srv_lock_timeout_thread(
2163
/*====================*/
2164
void* arg __attribute__((unused)))
2165
/* in: a dummy parameter required by
2174
/* When someone is waiting for a lock, we wake up every second
2175
and check if a timeout has passed for a lock wait */
2177
os_thread_sleep(1000000);
2179
srv_lock_timeout_active = TRUE;
2095
2181
mutex_enter(&kernel_mutex);
2097
2183
some_waits = FALSE;
2115
2201
lock_wait_timeout = thd_lock_wait_timeout(
2116
2202
trx->mysql_thd);
2118
if (lock_wait_timeout < 100000000
2119
&& (wait_time > (double) lock_wait_timeout
2120
|| wait_time < 0)) {
2204
if (trx_is_interrupted(trx)
2205
|| (lock_wait_timeout < 100000000
2206
&& (wait_time > (double) lock_wait_timeout
2207
|| wait_time < 0))) {
2122
2209
/* Timeout exceeded or a wrap-around in system
2123
2210
time counter: cancel the lock request queued
2142
2229
goto exit_func;
2145
if (some_waits || srv_print_innodb_monitor
2146
|| srv_print_innodb_lock_monitor
2147
|| srv_print_innodb_tablespace_monitor
2148
|| srv_print_innodb_table_monitor) {
2152
/* No one was waiting for a lock and no monitor was active:
2153
suspend this thread */
2155
srv_lock_timeout_and_monitor_active = FALSE;
2236
srv_lock_timeout_active = FALSE;
2158
2239
/* The following synchronisation is disabled, since
2165
srv_lock_timeout_and_monitor_active = FALSE;
2246
srv_lock_timeout_active = FALSE;
2167
2248
/* We count the number of threads in os_thread_exit(). A created
2168
2249
thread should always use that to exit and not use return() to exit. */