1
1
/*****************************************************************************
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
Copyright (c) 2008, 2009 Google Inc.
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
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
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
103
in microseconds, in order to reduce the lagging of the purge thread. */
120
104
UNIV_INTERN ulint srv_dml_needed_delay = 0;
122
UNIV_INTERN ibool srv_lock_timeout_and_monitor_active = FALSE;
106
UNIV_INTERN ibool srv_lock_timeout_active = FALSE;
107
UNIV_INTERN ibool srv_monitor_active = FALSE;
123
108
UNIV_INTERN ibool srv_error_monitor_active = FALSE;
125
110
UNIV_INTERN const char* srv_main_thread_op_info = "";
127
/** Prefix used by MySQL to indicate pre-5.1 table name encoding */
128
UNIV_INTERN const char srv_mysql50_table_name_prefix[9] = "#mysql50#";
130
112
/* Server parameters which are read from the initfile */
132
114
/* The following three are dir paths which are catenated before file
154
136
on duplicate key checking and foreign key checking */
155
137
UNIV_INTERN ibool srv_locks_unsafe_for_binlog = FALSE;
139
/* If this flag is TRUE, then we will use the native aio of the
140
OS (provided we compiled Innobase with it in), otherwise we will
141
use simulated aio we build below with threads.
142
Currently we support native aio on windows and linux */
143
UNIV_INTERN my_bool srv_use_native_aio = TRUE;
146
/* Windows native condition variables. We use runtime loading / function
147
pointers, because they are not available on Windows Server 2003 and
150
We use condition for events on Windows if possible, even if os_event
151
resembles Windows kernel event object well API-wise. The reason is
152
performance, kernel objects are heavyweights and WaitForSingleObject() is a
153
performance killer causing calling thread to context switch. Besides, Innodb
154
is preallocating large number (often millions) of os_events. With kernel event
155
objects it takes a big chunk out of non-paged pool, which is better suited
156
for tasks like IO than for storing idle event objects. */
157
UNIV_INTERN ibool srv_use_native_conditions = FALSE;
157
160
UNIV_INTERN ulint srv_n_data_files = 0;
158
161
UNIV_INTERN char** srv_data_file_names = NULL;
159
162
/* size in database pages */
188
191
the checkpoints. */
189
192
UNIV_INTERN bool srv_adaptive_flushing = TRUE;
191
/* The sort order table of the MySQL latin1_swedish_ci character set
194
/** Maximum number of times allowed to conditionally acquire
195
mutex before switching to blocking wait on the mutex */
196
#define MAX_MUTEX_NOWAIT 20
198
/** Check whether the number of failed nonblocking mutex
199
acquisition attempts exceeds maximum allowed value. If so,
200
srv_printf_innodb_monitor() will request mutex acquisition
201
with mutex_enter(), which will wait until it gets the mutex. */
202
#define MUTEX_NOWAIT(mutex_skipped) ((mutex_skipped) < MAX_MUTEX_NOWAIT)
204
/** The sort order table of the MySQL latin1_swedish_ci character set
193
206
#if defined(BUILD_DRIZZLE)
194
UNIV_INTERN const byte srv_latin1_ordering[256] /* The sort order table of the latin1
207
const byte srv_latin1_ordering[256] /* The sort order table of the latin1
195
208
character set. The following table is
196
209
the MySQL order as of Feb 10th, 2002 */
466
488
/* Mutex for locking srv_monitor_file */
467
489
UNIV_INTERN mutex_t srv_monitor_file_mutex;
491
#ifdef UNIV_PFS_MUTEX
492
/* Key to register kernel_mutex with performance schema */
493
UNIV_INTERN mysql_pfs_key_t kernel_mutex_key;
494
/* Key to protect writing the commit_id to the sys header */
495
UNIV_INTERN mysql_pfs_key_t commit_id_mutex_key;
496
/* Key to register srv_innodb_monitor_mutex with performance schema */
497
UNIV_INTERN mysql_pfs_key_t srv_innodb_monitor_mutex_key;
498
/* Key to register srv_monitor_file_mutex with performance schema */
499
UNIV_INTERN mysql_pfs_key_t srv_monitor_file_mutex_key;
500
/* Key to register srv_dict_tmpfile_mutex with performance schema */
501
UNIV_INTERN mysql_pfs_key_t srv_dict_tmpfile_mutex_key;
502
/* Key to register the mutex with performance schema */
503
UNIV_INTERN mysql_pfs_key_t srv_misc_tmpfile_mutex_key;
504
#endif /* UNIV_PFS_MUTEX */
468
506
/* Temporary file for innodb monitor output */
469
507
UNIV_INTERN FILE* srv_monitor_file;
470
508
/* Mutex for locking srv_dict_tmpfile.
977
1026
srv_slot_t* slot;
980
srv_sys = mem_alloc(sizeof(srv_sys_t));
982
kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
983
mutex_create(&kernel_mutex, SYNC_KERNEL);
985
mutex_create(&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
987
srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
1029
srv_sys = static_cast<srv_sys_t *>(mem_alloc(sizeof(srv_sys_t)));
1031
kernel_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
1032
mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1034
commit_id_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
1035
mutex_create(commit_id_mutex_key, &commit_id_mutex, SYNC_COMMIT_ID_LOCK);
1037
mutex_create(srv_innodb_monitor_mutex_key,
1038
&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1040
srv_sys->threads = static_cast<srv_table_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t)));
989
1042
for (i = 0; i < OS_THREAD_MAX_N; i++) {
990
1043
slot = srv_table_get_nth_slot(i);
1583
1645
row_mysql_unfreeze_data_dictionary(trx);
1585
1647
case RW_X_LATCH:
1648
/* There should never be a lock wait when the
1649
dictionary latch is reserved in X mode. Dictionary
1650
transactions should only acquire locks on dictionary
1651
tables, not other tables. All access to dictionary
1652
tables should be covered by dictionary
1654
ut_print_timestamp(stderr);
1655
fputs(" InnoDB: Error: dict X latch held in "
1656
"srv_suspend_mysql_thread\n", stderr);
1657
/* This should never occur. This incorrect handling
1658
was added in the early development of
1659
ha_innobase::add_index() in InnoDB Plugin 1.0. */
1586
1660
/* Release fast index creation latch */
1587
1661
row_mysql_unlock_data_dictionary(trx);
1723
1808
/******************************************************************//**
1724
Outputs to a file the output of the InnoDB Monitor. */
1809
Outputs to a file the output of the InnoDB Monitor.
1810
@return FALSE if not all information printed
1811
due to failure to obtain necessary mutex */
1727
1814
srv_printf_innodb_monitor(
1728
1815
/*======================*/
1729
1816
FILE* file, /*!< in: output stream */
1817
ibool nowait, /*!< in: whether to wait for kernel mutex */
1730
1818
ulint* trx_start, /*!< out: file position of the start of
1731
1819
the list of active transactions */
1732
1820
ulint* trx_end) /*!< out: file position of the end of
1785
1874
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;
1876
/* Only if lock_print_info_summary proceeds correctly,
1877
before we call the lock_print_info_all_transactions
1878
to print all the lock information. */
1879
ret = lock_print_info_summary(file, nowait);
1883
long t = ftell(file);
1885
*trx_start = ULINT_UNDEFINED;
1887
*trx_start = (ulint) t;
1890
lock_print_info_all_transactions(file);
1892
long t = ftell(file);
1894
*trx_end = ULINT_UNDEFINED;
1896
*trx_end = (ulint) t;
1805
1901
fputs("--------\n"
1807
1903
"--------\n", file);
1922
2028
export_vars.innodb_data_reads = os_n_file_reads;
1923
2029
export_vars.innodb_data_writes = os_n_file_writes;
1924
2030
export_vars.innodb_data_written = srv_data_written;
1925
export_vars.innodb_buffer_pool_read_requests = buf_pool->stat.n_page_gets;
2031
export_vars.innodb_buffer_pool_read_requests = stat.n_page_gets;
1926
2032
export_vars.innodb_buffer_pool_write_requests
1927
2033
= srv_buf_pool_write_requests;
1928
2034
export_vars.innodb_buffer_pool_wait_free = srv_buf_pool_wait_free;
1929
2035
export_vars.innodb_buffer_pool_pages_flushed = srv_buf_pool_flushed;
1930
2036
export_vars.innodb_buffer_pool_reads = srv_buf_pool_reads;
1931
2037
export_vars.innodb_buffer_pool_read_ahead
1932
= buf_pool->stat.n_ra_pages_read;
2038
= stat.n_ra_pages_read;
1933
2039
export_vars.innodb_buffer_pool_read_ahead_evicted
1934
= buf_pool->stat.n_ra_pages_evicted;
1935
export_vars.innodb_buffer_pool_pages_data
1936
= UT_LIST_GET_LEN(buf_pool->LRU);
1937
export_vars.innodb_buffer_pool_pages_dirty
1938
= UT_LIST_GET_LEN(buf_pool->flush_list);
1939
export_vars.innodb_buffer_pool_pages_free
1940
= UT_LIST_GET_LEN(buf_pool->free);
2040
= stat.n_ra_pages_evicted;
2041
export_vars.innodb_buffer_pool_pages_data = LRU_len;
2042
export_vars.innodb_buffer_pool_pages_dirty = flush_list_len;
2043
export_vars.innodb_buffer_pool_pages_free = free_len;
1941
2044
#ifdef UNIV_DEBUG
1942
2045
export_vars.innodb_buffer_pool_pages_latched
1943
2046
= buf_get_latched_pages_number();
1944
2047
#endif /* UNIV_DEBUG */
1945
export_vars.innodb_buffer_pool_pages_total = buf_pool->curr_size;
2048
export_vars.innodb_buffer_pool_pages_total = buf_pool_get_n_pages();
1947
export_vars.innodb_buffer_pool_pages_misc = buf_pool->curr_size
1948
- UT_LIST_GET_LEN(buf_pool->LRU)
1949
- UT_LIST_GET_LEN(buf_pool->free);
2050
export_vars.innodb_buffer_pool_pages_misc
2051
= buf_pool_get_n_pages() - LRU_len - free_len;
1950
2052
#ifdef HAVE_ATOMIC_BUILTINS
1951
2053
export_vars.innodb_have_atomic_builtins = 1;
1962
2064
export_vars.innodb_log_writes = srv_log_writes;
1963
2065
export_vars.innodb_dblwr_pages_written = srv_dblwr_pages_written;
1964
2066
export_vars.innodb_dblwr_writes = srv_dblwr_writes;
1965
export_vars.innodb_pages_created = buf_pool->stat.n_pages_created;
1966
export_vars.innodb_pages_read = buf_pool->stat.n_pages_read;
1967
export_vars.innodb_pages_written = buf_pool->stat.n_pages_written;
2067
export_vars.innodb_pages_created = stat.n_pages_created;
2068
export_vars.innodb_pages_read = stat.n_pages_read;
2069
export_vars.innodb_pages_written = stat.n_pages_written;
1968
2070
export_vars.innodb_row_lock_waits = srv_n_lock_wait_count;
1969
2071
export_vars.innodb_row_lock_current_waits
1970
2072
= srv_n_lock_wait_current_count;
1981
2083
export_vars.innodb_rows_inserted = srv_n_rows_inserted;
1982
2084
export_vars.innodb_rows_updated = srv_n_rows_updated;
1983
2085
export_vars.innodb_rows_deleted = srv_n_rows_deleted;
2086
export_vars.innodb_truncated_status_writes = srv_truncated_status_writes;
1985
2088
mutex_exit(&srv_innodb_monitor_mutex);
1988
2091
/*********************************************************************//**
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.
2092
A thread which prints the info output by various InnoDB monitors.
1991
2093
@return a dummy parameter */
1993
2095
os_thread_ret_t
1994
srv_lock_timeout_and_monitor_thread(
1995
/*================================*/
1996
void* arg __attribute__((unused)))
2098
void* /*arg __attribute__((unused))*/)
1997
2099
/*!< in: a dummy parameter required by
1998
2100
os_thread_create */
2102
ib_int64_t sig_count;
2001
2103
double time_elapsed;
2002
2104
time_t current_time;
2003
2105
time_t last_table_monitor_time;
2004
2106
time_t last_tablespace_monitor_time;
2005
2107
time_t last_monitor_time;
2108
ulint mutex_skipped;
2109
ibool last_srv_print_monitor;
2010
2111
#ifdef UNIV_DEBUG_THREAD_CREATION
2011
2112
fprintf(stderr, "Lock timeout thread starts, id %lu\n",
2012
2113
os_thread_pf(os_thread_get_curr_id()));
2015
srv_last_monitor_time = time(NULL);
2016
last_table_monitor_time = time(NULL);
2017
last_tablespace_monitor_time = time(NULL);
2018
last_monitor_time = time(NULL);
2116
#ifdef UNIV_PFS_THREAD
2117
pfs_register_thread(srv_monitor_thread_key);
2120
srv_last_monitor_time = ut_time();
2121
last_table_monitor_time = ut_time();
2122
last_tablespace_monitor_time = ut_time();
2123
last_monitor_time = ut_time();
2125
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);
2027
current_time = time(NULL);
2127
srv_monitor_active = TRUE;
2129
/* Wake up every 5 seconds to see if we need to print
2130
monitor information or if signalled at shutdown. */
2132
sig_count = os_event_reset(srv_monitor_event);
2134
os_event_wait_time_low(srv_monitor_event, 5000000, sig_count);
2136
current_time = ut_time();
2029
2138
time_elapsed = difftime(current_time, last_monitor_time);
2031
2140
if (time_elapsed > 15) {
2032
last_monitor_time = time(NULL);
2141
last_monitor_time = ut_time();
2034
2143
if (srv_print_innodb_monitor) {
2035
srv_printf_innodb_monitor(stderr, NULL, NULL);
2144
/* Reset mutex_skipped counter everytime
2145
srv_print_innodb_monitor changes. This is to
2146
ensure we will not be blocked by kernel_mutex
2147
for short duration information printing,
2148
such as requested by sync_array_print_long_waits() */
2149
if (!last_srv_print_monitor) {
2151
last_srv_print_monitor = TRUE;
2154
if (!srv_printf_innodb_monitor(stderr,
2155
MUTEX_NOWAIT(mutex_skipped),
2159
/* Reset the counter */
2163
last_srv_print_monitor = FALSE;
2038
2167
if (srv_innodb_status) {
2039
2168
mutex_enter(&srv_monitor_file_mutex);
2040
2169
rewind(srv_monitor_file);
2041
srv_printf_innodb_monitor(srv_monitor_file, NULL,
2170
if (!srv_printf_innodb_monitor(srv_monitor_file,
2171
MUTEX_NOWAIT(mutex_skipped),
2043
2178
os_file_set_eof(srv_monitor_file);
2044
2179
mutex_exit(&srv_monitor_file_mutex);
2230
if (srv_shutdown_state >= SRV_SHUTDOWN_CLEANUP) {
2234
if (srv_print_innodb_monitor
2235
|| srv_print_innodb_lock_monitor
2236
|| srv_print_innodb_tablespace_monitor
2237
|| srv_print_innodb_table_monitor) {
2241
srv_monitor_active = FALSE;
2246
srv_monitor_active = FALSE;
2248
/* We count the number of threads in os_thread_exit(). A created
2249
thread should always use that to exit and not use return() to exit. */
2251
os_thread_exit(NULL);
2253
OS_THREAD_DUMMY_RETURN;
2256
/*********************************************************************//**
2257
A thread which wakes up threads whose lock wait may have lasted too long.
2258
@return a dummy parameter */
2261
srv_lock_timeout_thread(
2262
/*====================*/
2263
void* /*arg __attribute__((unused))*/)
2264
/* in: a dummy parameter required by
2271
ib_int64_t sig_count;
2273
#ifdef UNIV_PFS_THREAD
2274
pfs_register_thread(srv_lock_timeout_thread_key);
2279
/* When someone is waiting for a lock, we wake up every second
2280
and check if a timeout has passed for a lock wait */
2282
sig_count = os_event_reset(srv_timeout_event);
2284
os_event_wait_time_low(srv_timeout_event, 1000000, sig_count);
2286
srv_lock_timeout_active = TRUE;
2095
2288
mutex_enter(&kernel_mutex);
2097
2290
some_waits = FALSE;
2275
2467
OS_THREAD_DUMMY_RETURN;
2470
/**********************************************************************//**
2471
Check whether any background thread is active.
2472
@return FALSE if all are are suspended or have exited. */
2475
srv_is_any_background_thread_active(void)
2476
/*=====================================*/
2481
mutex_enter(&kernel_mutex);
2483
for (i = SRV_COM; i <= SRV_MASTER; ++i) {
2484
if (srv_n_threads_active[i] != 0) {
2490
mutex_exit(&kernel_mutex);
2278
2495
/*******************************************************************//**
2279
2496
Tells the InnoDB server that there has been activity in the database
2280
2497
and wakes up the master thread if it is suspended (not sleeping). Used
2281
2498
in the MySQL interface. Note that there is a small chance that the master
2282
thread stays suspended (we do not protect our operation with the kernel
2283
mutex, for performace reasons). */
2499
thread stays suspended (we do not protect our operation with the
2500
srv_sys_t->mutex, for performance reasons). */
2286
2503
srv_active_wake_master_thread(void)
2301
2518
/*******************************************************************//**
2519
Tells the purge thread that there has been activity in the database
2520
and wakes up the purge thread if it is suspended (not sleeping). Note
2521
that there is a small chance that the purge thread stays suspended
2522
(we do not protect our operation with the kernel mutex, for
2523
performace reasons). */
2526
srv_wake_purge_thread_if_not_active(void)
2527
/*=====================================*/
2529
ut_ad(!mutex_own(&kernel_mutex));
2531
if (srv_n_purge_threads > 0
2532
&& srv_n_threads_active[SRV_WORKER] == 0) {
2534
mutex_enter(&kernel_mutex);
2536
srv_release_threads(SRV_WORKER, 1);
2538
mutex_exit(&kernel_mutex);
2542
/*******************************************************************//**
2302
2543
Wakes up the master thread if it is suspended or being suspended. */
2314
2555
mutex_exit(&kernel_mutex);
2558
/*******************************************************************//**
2559
Wakes up the purge thread if it's not already awake. */
2562
srv_wake_purge_thread(void)
2563
/*=======================*/
2565
ut_ad(!mutex_own(&kernel_mutex));
2567
if (srv_n_purge_threads > 0) {
2569
mutex_enter(&kernel_mutex);
2571
srv_release_threads(SRV_WORKER, 1);
2573
mutex_exit(&kernel_mutex);
2317
2577
/**********************************************************************
2318
2578
The master thread is tasked to ensure that flush of log file happens
2319
2579
once every second in the background. This is to ensure that not more
2597
/********************************************************************//**
2598
Do a full purge, reconfigure the purge sub-system if a dynamic
2599
change is detected. */
2602
srv_master_do_purge(void)
2603
/*=====================*/
2605
ulint n_pages_purged;
2607
ut_ad(!mutex_own(&kernel_mutex));
2609
ut_a(srv_n_purge_threads == 0);
2612
/* Check for shutdown and change in purge config. */
2613
if (srv_fast_shutdown && srv_shutdown_state > 0) {
2614
/* Nothing to purge. */
2617
n_pages_purged = trx_purge(srv_purge_batch_size);
2620
srv_sync_log_buffer_in_background();
2622
} while (n_pages_purged > 0);
2337
2625
/*********************************************************************//**
2338
2626
The master thread controlling the server.
2339
2627
@return a dummy parameter */
2399
2694
when there is database activity */
2401
2696
srv_last_log_flush_time = time(NULL);
2698
/* Sleep for 1 second on entrying the for loop below the first time. */
2699
next_itr_time = ut_time_ms() + 1000;
2404
2701
for (i = 0; i < 10; i++) {
2405
n_ios_old = log_sys->n_log_ios + buf_pool->stat.n_pages_read
2406
+ buf_pool->stat.n_pages_written;
2407
srv_main_thread_op_info = "sleeping";
2408
srv_main_1_second_loops++;
2412
os_thread_sleep(1000000);
2702
ulint cur_time = ut_time_ms();
2418
2704
/* ALTER TABLE in MySQL requires on Unix that the table handler
2419
2705
can drop tables lazily after there no longer are SELECT
2430
2716
goto background_loop;
2719
buf_get_total_stat(&buf_stat);
2721
n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2722
+ buf_stat.n_pages_written;
2724
srv_main_thread_op_info = "sleeping";
2725
srv_main_1_second_loops++;
2727
if (next_itr_time > cur_time
2728
&& srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2730
/* Get sleep interval in micro seconds. We use
2731
ut_min() to avoid long sleep in case of
2733
os_thread_sleep(ut_min(1000000,
2734
(next_itr_time - cur_time)
2739
/* Each iteration should happen at 1 second interval. */
2740
next_itr_time = ut_time_ms() + 1000;
2433
2742
/* Flush logs if needed */
2434
2743
srv_sync_log_buffer_in_background();
2437
2746
log_free_check();
2439
2748
/* If i/os during one second sleep were less than 5% of
2440
capacity, we assume that there is free disk i/o capacity
2441
available, and it makes sense to do an insert buffer merge. */
2749
capacity, we assume that there is free disk i/o capacity
2750
available, and it makes sense to do an insert buffer merge. */
2752
buf_get_total_stat(&buf_stat);
2443
2753
n_pend_ios = buf_get_n_pending_ios()
2444
2754
+ log_sys->n_pending_writes;
2445
n_ios = log_sys->n_log_ios + buf_pool->stat.n_pages_read
2446
+ buf_pool->stat.n_pages_written;
2755
n_ios = log_sys->n_log_ios + buf_stat.n_pages_read
2756
+ buf_stat.n_pages_written;
2447
2757
if (n_pend_ios < SRV_PEND_IO_THRESHOLD
2448
2758
&& (n_ios - n_ios_old < SRV_RECENT_IO_ACTIVITY)) {
2449
2759
srv_main_thread_op_info = "doing insert buffer merge";
2462
2772
srv_main_thread_op_info =
2463
2773
"flushing buffer pool pages";
2464
n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST,
2468
/* If we had to do the flush, it may have taken
2469
even more than 1 second, and also, there may be more
2470
to flush. Do not sleep 1 second during the next
2471
iteration of this loop. */
2774
n_pages_flushed = buf_flush_list(
2775
PCT_IO(100), IB_ULONGLONG_MAX);
2474
2777
} else if (srv_adaptive_flushing) {
2476
2779
/* Try to keep the rate of flushing of dirty
2517
2818
loop above requests writes for that case. The writes done here
2518
2819
are not required, and may be disabled. */
2821
buf_get_total_stat(&buf_stat);
2520
2822
n_pend_ios = buf_get_n_pending_ios() + log_sys->n_pending_writes;
2521
n_ios = log_sys->n_log_ios + buf_pool->stat.n_pages_read
2522
+ buf_pool->stat.n_pages_written;
2823
n_ios = log_sys->n_log_ios + buf_stat.n_pages_read
2824
+ buf_stat.n_pages_written;
2524
2826
srv_main_10_second_loops++;
2525
2827
if (n_pend_ios < SRV_PEND_IO_THRESHOLD
2526
2828
&& (n_ios - n_ios_very_old < SRV_PAST_IO_ACTIVITY)) {
2528
2830
srv_main_thread_op_info = "flushing buffer pool pages";
2529
buf_flush_batch(BUF_FLUSH_LIST, PCT_IO(100),
2831
buf_flush_list(PCT_IO(100), IB_ULONGLONG_MAX);
2532
2833
/* Flush logs if needed */
2533
2834
srv_sync_log_buffer_in_background();
2542
2843
/* Flush logs if needed */
2543
2844
srv_sync_log_buffer_in_background();
2545
/* We run a full purge every 10 seconds, even if the server
2846
if (srv_n_purge_threads == 0) {
2847
srv_main_thread_op_info = "master purging";
2849
srv_master_do_purge();
2549
2851
if (srv_fast_shutdown && srv_shutdown_state > 0) {
2551
2853
goto background_loop;
2554
srv_main_thread_op_info = "purging";
2555
n_pages_purged = trx_purge();
2557
/* Flush logs if needed */
2558
srv_sync_log_buffer_in_background();
2560
} while (n_pages_purged);
2562
2857
srv_main_thread_op_info = "flushing buffer pool pages";
2569
2864
(> 70 %), we assume we can afford reserving the disk(s) for
2570
2865
the time it requires to flush 100 pages */
2572
n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST,
2867
n_pages_flushed = buf_flush_list(
2868
PCT_IO(100), IB_ULONGLONG_MAX);
2576
2870
/* Otherwise, we only flush a small number of pages so that
2577
2871
we do not unnecessarily use much disk i/o capacity from
2580
n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST,
2874
n_pages_flushed = buf_flush_list(
2875
PCT_IO(10), IB_ULONGLONG_MAX);
2585
2878
srv_main_thread_op_info = "making checkpoint";
2623
2916
MySQL tries to drop a table while there are still open handles
2624
2917
to it and we had to put it to the background drop queue.) */
2626
os_thread_sleep(100000);
2629
srv_main_thread_op_info = "purging";
2631
/* Run a full purge */
2633
if (srv_fast_shutdown && srv_shutdown_state > 0) {
2919
if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2920
os_thread_sleep(100000);
2638
srv_main_thread_op_info = "purging";
2639
n_pages_purged = trx_purge();
2641
/* Flush logs if needed */
2642
srv_sync_log_buffer_in_background();
2644
} while (n_pages_purged);
2924
if (srv_n_purge_threads == 0) {
2925
srv_main_thread_op_info = "master purging";
2927
srv_master_do_purge();
2646
2930
srv_main_thread_op_info = "reserving kernel mutex";
2796
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
3080
#if !defined(__SUNPRO_C)
2797
3081
OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3085
/*********************************************************************//**
3086
Asynchronous purge thread.
3087
@return a dummy parameter */
3092
void* /*arg __attribute__((unused))*/) /*!< in: a dummy parameter
3093
required by os_thread_create */
3096
ulint slot_no = ULINT_UNDEFINED;
3097
ulint n_total_purged = ULINT_UNDEFINED;
3099
ut_a(srv_n_purge_threads == 1);
3101
#ifdef UNIV_DEBUG_THREAD_CREATION
3102
fprintf(stderr, "InnoDB: Purge thread running, id %lu\n",
3103
os_thread_pf(os_thread_get_curr_id()));
3104
#endif /* UNIV_DEBUG_THREAD_CREATION */
3106
mutex_enter(&kernel_mutex);
3108
slot_no = srv_table_reserve_slot(SRV_WORKER);
3110
slot = srv_table_get_nth_slot(slot_no);
3112
++srv_n_threads_active[SRV_WORKER];
3114
mutex_exit(&kernel_mutex);
3116
while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
3118
ulint n_pages_purged;
3120
/* If there are very few records to purge or the last
3121
purge didn't purge any records then wait for activity.
3122
We peek at the history len without holding any mutex
3123
because in the worst case we will end up waiting for
3124
the next purge event. */
3125
if (trx_sys->rseg_history_len < srv_purge_batch_size
3126
|| n_total_purged == 0) {
3130
mutex_enter(&kernel_mutex);
3132
event = srv_suspend_thread();
3134
mutex_exit(&kernel_mutex);
3136
os_event_wait(event);
3139
/* Check for shutdown and whether we should do purge at all. */
3140
if (srv_force_recovery >= SRV_FORCE_NO_BACKGROUND
3141
|| srv_shutdown_state != 0
3142
|| srv_fast_shutdown) {
3149
/* Purge until there are no more records to purge and there is
3150
no change in configuration or server state. */
3152
n_pages_purged = trx_purge(srv_purge_batch_size);
3154
n_total_purged += n_pages_purged;
3156
} while (n_pages_purged > 0 && !srv_fast_shutdown);
3158
srv_sync_log_buffer_in_background();
3161
mutex_enter(&kernel_mutex);
3163
ut_ad(srv_table_get_nth_slot(slot_no) == slot);
3165
/* Decrement the active count. */
3166
srv_suspend_thread();
3168
slot->in_use = FALSE;
3170
/* Free the thread local memory. */
3171
thr_local_free(os_thread_get_curr_id());
3173
mutex_exit(&kernel_mutex);
3175
#ifdef UNIV_DEBUG_THREAD_CREATION
3176
fprintf(stderr, "InnoDB: Purge thread exiting, id %lu\n",
3177
os_thread_pf(os_thread_get_curr_id()));
3178
#endif /* UNIV_DEBUG_THREAD_CREATION */
3180
/* We count the number of threads in os_thread_exit(). A created
3181
thread should always use that to exit and not use return() to exit. */
3182
os_thread_exit(NULL);
3184
OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3187
/**********************************************************************//**
3188
Enqueues a task to server task queue and releases a worker thread, if there
3189
is a suspended one. */
3192
srv_que_task_enqueue_low(
3193
/*=====================*/
3194
que_thr_t* thr) /*!< in: query thread */
3198
mutex_enter(&kernel_mutex);
3200
UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr);
3202
srv_release_threads(SRV_WORKER, 1);
3204
mutex_exit(&kernel_mutex);