~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/srv/srv0srv.c

  • Committer: Brian Aker
  • Date: 2010-11-06 15:43:10 UTC
  • mfrom: (1908.1.1 merge)
  • Revision ID: brian@tangent.org-20101106154310-g1jpjzwbc53pfc4f
Filesort encapsulation, plus modification to copy contructor

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
4
Copyright (c) 2008, 2009 Google Inc.
5
 
Copyright (c) 2009, Percona Inc.
6
5
 
7
6
Portions of this file contain modifications contributed and copyrighted by
8
7
Google, Inc. Those modifications are gratefully acknowledged and are described
10
9
incorporated with their permission, and subject to the conditions contained in
11
10
the file COPYING.Google.
12
11
 
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
18
 
COPYING.Percona.
19
 
 
20
12
This program is free software; you can redistribute it and/or modify it under
21
13
the terms of the GNU General Public License as published by the Free Software
22
14
Foundation; version 2 of the License.
30
22
St, Fifth Floor, Boston, MA 02110-1301 USA
31
23
 
32
24
*****************************************************************************/
 
25
/***********************************************************************
 
26
 
 
27
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
28
Copyright (c) 2009, Percona Inc.
 
29
 
 
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
 
35
COPYING.Percona.
 
36
 
 
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.
 
40
 
 
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.
 
45
 
 
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
 
49
 
 
50
***********************************************************************/
33
51
 
34
52
/**************************************************//**
35
53
@file srv/srv0srv.c
68
86
#include "sync0sync.h"
69
87
#include "thr0loc.h"
70
88
#include "que0que.h"
 
89
#include "srv0que.h"
71
90
#include "log0recv.h"
72
91
#include "pars0pars.h"
73
92
#include "usr0sess.h"
100
119
in microseconds, in order to reduce the lagging of the purge thread. */
101
120
UNIV_INTERN ulint       srv_dml_needed_delay = 0;
102
121
 
103
 
UNIV_INTERN ibool       srv_lock_timeout_active = FALSE;
104
 
UNIV_INTERN ibool       srv_monitor_active = FALSE;
 
122
UNIV_INTERN ibool       srv_lock_timeout_and_monitor_active = FALSE;
105
123
UNIV_INTERN ibool       srv_error_monitor_active = FALSE;
106
124
 
107
125
UNIV_INTERN const char* srv_main_thread_op_info = "";
127
145
/** Whether to check file format during startup.  A value of
128
146
DICT_TF_FORMAT_MAX + 1 means no checking ie. FALSE.  The default is to
129
147
set it to the highest format we support. */
130
 
UNIV_INTERN ulint       srv_max_file_format_at_startup = DICT_TF_FORMAT_MAX;
 
148
UNIV_INTERN ulint       srv_check_file_format_at_startup = DICT_TF_FORMAT_MAX;
131
149
 
132
150
#if DICT_TF_FORMAT_51
133
151
# error "DICT_TF_FORMAT_51 must be 0!"
136
154
on duplicate key checking and foreign key checking */
137
155
UNIV_INTERN ibool       srv_locks_unsafe_for_binlog = FALSE;
138
156
 
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;
144
 
 
145
157
UNIV_INTERN ulint       srv_n_data_files = 0;
146
158
UNIV_INTERN char**      srv_data_file_names = NULL;
147
159
/* size in database pages */
176
188
the checkpoints. */
177
189
UNIV_INTERN bool        srv_adaptive_flushing   = TRUE;
178
190
 
179
 
/** Maximum number of times allowed to conditionally acquire
180
 
mutex before switching to blocking wait on the mutex */
181
 
#define MAX_MUTEX_NOWAIT        20
182
 
 
183
 
/** Check whether the number of failed nonblocking mutex
184
 
acquisition attempts exceeds maximum allowed value. If so,
185
 
srv_printf_innodb_monitor() will request mutex acquisition
186
 
with mutex_enter(), which will wait until it gets the mutex. */
187
 
#define MUTEX_NOWAIT(mutex_skipped)     ((mutex_skipped) < MAX_MUTEX_NOWAIT)
188
 
 
189
 
/** The sort order table of the MySQL latin1_swedish_ci character set
 
191
/* The sort order table of the MySQL latin1_swedish_ci character set
190
192
collation */
191
193
#if defined(BUILD_DRIZZLE)
192
194
UNIV_INTERN const byte  srv_latin1_ordering[256]        /* The sort order table of the latin1
235
237
UNIV_INTERN my_bool     srv_use_sys_malloc      = TRUE;
236
238
/* requested size in kilobytes */
237
239
UNIV_INTERN ulint       srv_buf_pool_size       = ULINT_MAX;
238
 
/* requested number of buffer pool instances */
239
 
UNIV_INTERN ulint       srv_buf_pool_instances  = 1;
240
240
/* previously requested size */
241
241
UNIV_INTERN ulint       srv_buf_pool_old_size;
242
242
/* current size in kilobytes */
288
288
 
289
289
UNIV_INTERN ulong       srv_max_buf_pool_modified_pct   = 75;
290
290
 
291
 
/* the number of purge threads to use from the worker pool (currently 0 or 1).*/
292
 
UNIV_INTERN ulong srv_n_purge_threads = 0;
293
 
 
294
 
/* the number of records to purge in one batch */
295
 
UNIV_INTERN ulong srv_purge_batch_size = 20;
296
 
 
297
291
/* variable counts amount of data read in total (in bytes) */
298
292
UNIV_INTERN ulint srv_data_read = 0;
299
293
 
471
465
 
472
466
/* Mutex for locking srv_monitor_file */
473
467
UNIV_INTERN mutex_t     srv_monitor_file_mutex;
474
 
 
475
 
#ifdef UNIV_PFS_MUTEX
476
 
/* Key to register kernel_mutex with performance schema */
477
 
UNIV_INTERN mysql_pfs_key_t     kernel_mutex_key;
478
 
/* Key to register srv_innodb_monitor_mutex with performance schema */
479
 
UNIV_INTERN mysql_pfs_key_t     srv_innodb_monitor_mutex_key;
480
 
/* Key to register srv_monitor_file_mutex with performance schema */
481
 
UNIV_INTERN mysql_pfs_key_t     srv_monitor_file_mutex_key;
482
 
/* Key to register srv_dict_tmpfile_mutex with performance schema */
483
 
UNIV_INTERN mysql_pfs_key_t     srv_dict_tmpfile_mutex_key;
484
 
/* Key to register the mutex with performance schema */
485
 
UNIV_INTERN mysql_pfs_key_t     srv_misc_tmpfile_mutex_key;
486
 
#endif /* UNIV_PFS_MUTEX */
487
 
 
488
468
/* Temporary file for innodb monitor output */
489
469
UNIV_INTERN FILE*       srv_monitor_file;
490
470
/* Mutex for locking srv_dict_tmpfile.
745
725
static ulint    srv_meter_foreground[SRV_MASTER + 1];
746
726
#endif
747
727
 
 
728
/* The following values give info about the activity going on in
 
729
the database. They are protected by the server mutex. The arrays
 
730
are indexed by the type of the thread. */
 
731
 
 
732
UNIV_INTERN ulint       srv_n_threads_active[SRV_MASTER + 1];
 
733
UNIV_INTERN ulint       srv_n_threads[SRV_MASTER + 1];
 
734
 
748
735
/***********************************************************************
749
736
Prints counters for work done by srv_master_thread. */
750
737
static
762
749
                      srv_log_writes_and_flush);
763
750
}
764
751
 
765
 
/* The following values give info about the activity going on in
766
 
the database. They are protected by the server mutex. The arrays
767
 
are indexed by the type of the thread. */
768
 
 
769
 
UNIV_INTERN ulint       srv_n_threads_active[SRV_MASTER + 1];
770
 
UNIV_INTERN ulint       srv_n_threads[SRV_MASTER + 1];
771
 
 
772
752
/*********************************************************************//**
773
753
Sets the info describing an i/o thread current state. */
774
754
UNIV_INTERN
1000
980
        srv_sys = mem_alloc(sizeof(srv_sys_t));
1001
981
 
1002
982
        kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
1003
 
        mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
 
983
        mutex_create(&kernel_mutex, SYNC_KERNEL);
1004
984
 
1005
 
        mutex_create(srv_innodb_monitor_mutex_key,
1006
 
                     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
 
985
        mutex_create(&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1007
986
 
1008
987
        srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
1009
988
 
1680
1659
 
1681
1660
                trx->error_state = DB_LOCK_WAIT_TIMEOUT;
1682
1661
        }
1683
 
 
1684
 
        if (trx_is_interrupted(trx)) {
1685
 
 
1686
 
                trx->error_state = DB_INTERRUPTED;
1687
 
        }
1688
1662
}
1689
1663
 
1690
1664
/********************************************************************//**
1736
1710
 
1737
1711
        log_refresh_stats();
1738
1712
 
1739
 
        buf_refresh_io_stats_all();
 
1713
        buf_refresh_io_stats();
1740
1714
 
1741
1715
        srv_n_rows_inserted_old = srv_n_rows_inserted;
1742
1716
        srv_n_rows_updated_old = srv_n_rows_updated;
1747
1721
}
1748
1722
 
1749
1723
/******************************************************************//**
1750
 
Outputs to a file the output of the InnoDB Monitor.
1751
 
@return FALSE if not all information printed
1752
 
due to failure to obtain necessary mutex */
 
1724
Outputs to a file the output of the InnoDB Monitor. */
1753
1725
UNIV_INTERN
1754
 
ibool
 
1726
void
1755
1727
srv_printf_innodb_monitor(
1756
1728
/*======================*/
1757
1729
        FILE*   file,           /*!< in: output stream */
1758
 
        ibool   nowait,         /*!< in: whether to wait for kernel mutex */
1759
1730
        ulint*  trx_start,      /*!< out: file position of the start of
1760
1731
                                the list of active transactions */
1761
1732
        ulint*  trx_end)        /*!< out: file position of the end of
1764
1735
        double  time_elapsed;
1765
1736
        time_t  current_time;
1766
1737
        ulint   n_reserved;
1767
 
        ibool   ret;
1768
1738
 
1769
1739
        mutex_enter(&srv_innodb_monitor_mutex);
1770
1740
 
1788
1758
                "Per second averages calculated from the last %lu seconds\n",
1789
1759
                (ulong)time_elapsed);
1790
1760
 
1791
 
        fputs("-----------------\n"
1792
 
              "BACKGROUND THREAD\n"
1793
 
              "-----------------\n", file);
 
1761
        fputs("----------\n"
 
1762
                "BACKGROUND THREAD\n"
 
1763
                "----------\n", file);
1794
1764
        srv_print_master_thread_info(file);
1795
1765
 
1796
1766
        fputs("----------\n"
1814
1784
 
1815
1785
        mutex_exit(&dict_foreign_err_mutex);
1816
1786
 
1817
 
        /* Only if lock_print_info_summary proceeds correctly,
1818
 
        before we call the lock_print_info_all_transactions
1819
 
        to print all the lock information. */
1820
 
        ret = lock_print_info_summary(file, nowait);
1821
 
 
1822
 
        if (ret) {
1823
 
                if (trx_start) {
1824
 
                        long    t = ftell(file);
1825
 
                        if (t < 0) {
1826
 
                                *trx_start = ULINT_UNDEFINED;
1827
 
                        } else {
1828
 
                                *trx_start = (ulint) t;
1829
 
                        }
1830
 
                }
1831
 
                lock_print_info_all_transactions(file);
1832
 
                if (trx_end) {
1833
 
                        long    t = ftell(file);
1834
 
                        if (t < 0) {
1835
 
                                *trx_end = ULINT_UNDEFINED;
1836
 
                        } else {
1837
 
                                *trx_end = (ulint) t;
1838
 
                        }
1839
 
                }
1840
 
        }
1841
 
 
 
1787
        lock_print_info_summary(file);
 
1788
        if (trx_start) {
 
1789
                long    t = ftell(file);
 
1790
                if (t < 0) {
 
1791
                        *trx_start = ULINT_UNDEFINED;
 
1792
                } else {
 
1793
                        *trx_start = (ulint) t;
 
1794
                }
 
1795
        }
 
1796
        lock_print_info_all_transactions(file);
 
1797
        if (trx_end) {
 
1798
                long    t = ftell(file);
 
1799
                if (t < 0) {
 
1800
                        *trx_end = ULINT_UNDEFINED;
 
1801
                } else {
 
1802
                        *trx_end = (ulint) t;
 
1803
                }
 
1804
        }
1842
1805
        fputs("--------\n"
1843
1806
              "FILE I/O\n"
1844
1807
              "--------\n", file);
1936
1899
              "============================\n", file);
1937
1900
        mutex_exit(&srv_innodb_monitor_mutex);
1938
1901
        fflush(file);
1939
 
 
1940
 
        return(ret);
1941
1902
}
1942
1903
 
1943
1904
/******************************************************************//**
1947
1908
srv_export_innodb_status(void)
1948
1909
/*==========================*/
1949
1910
{
1950
 
        buf_pool_stat_t stat;
1951
 
        ulint           LRU_len;
1952
 
        ulint           free_len;
1953
 
        ulint           flush_list_len;
1954
 
 
1955
 
        buf_get_total_stat(&stat);
1956
 
        buf_get_total_list_len(&LRU_len, &free_len, &flush_list_len);
1957
 
 
1958
1911
        mutex_enter(&srv_innodb_monitor_mutex);
1959
1912
 
1960
1913
        export_vars.innodb_data_pending_reads
1969
1922
        export_vars.innodb_data_reads = os_n_file_reads;
1970
1923
        export_vars.innodb_data_writes = os_n_file_writes;
1971
1924
        export_vars.innodb_data_written = srv_data_written;
1972
 
        export_vars.innodb_buffer_pool_read_requests = stat.n_page_gets;
 
1925
        export_vars.innodb_buffer_pool_read_requests = buf_pool->stat.n_page_gets;
1973
1926
        export_vars.innodb_buffer_pool_write_requests
1974
1927
                = srv_buf_pool_write_requests;
1975
1928
        export_vars.innodb_buffer_pool_wait_free = srv_buf_pool_wait_free;
1976
1929
        export_vars.innodb_buffer_pool_pages_flushed = srv_buf_pool_flushed;
1977
1930
        export_vars.innodb_buffer_pool_reads = srv_buf_pool_reads;
1978
1931
        export_vars.innodb_buffer_pool_read_ahead
1979
 
                = stat.n_ra_pages_read;
 
1932
                = buf_pool->stat.n_ra_pages_read;
1980
1933
        export_vars.innodb_buffer_pool_read_ahead_evicted
1981
 
                = stat.n_ra_pages_evicted;
1982
 
        export_vars.innodb_buffer_pool_pages_data = LRU_len;
1983
 
        export_vars.innodb_buffer_pool_pages_dirty = flush_list_len;
1984
 
        export_vars.innodb_buffer_pool_pages_free = free_len;
 
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);
1985
1941
#ifdef UNIV_DEBUG
1986
1942
        export_vars.innodb_buffer_pool_pages_latched
1987
1943
                = buf_get_latched_pages_number();
1988
1944
#endif /* UNIV_DEBUG */
1989
 
        export_vars.innodb_buffer_pool_pages_total = buf_pool_get_n_pages();
 
1945
        export_vars.innodb_buffer_pool_pages_total = buf_pool->curr_size;
1990
1946
 
1991
 
        export_vars.innodb_buffer_pool_pages_misc
1992
 
                = buf_pool_get_n_pages() - LRU_len - free_len;
 
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);
1993
1950
#ifdef HAVE_ATOMIC_BUILTINS
1994
1951
        export_vars.innodb_have_atomic_builtins = 1;
1995
1952
#else
2005
1962
        export_vars.innodb_log_writes = srv_log_writes;
2006
1963
        export_vars.innodb_dblwr_pages_written = srv_dblwr_pages_written;
2007
1964
        export_vars.innodb_dblwr_writes = srv_dblwr_writes;
2008
 
        export_vars.innodb_pages_created = stat.n_pages_created;
2009
 
        export_vars.innodb_pages_read = stat.n_pages_read;
2010
 
        export_vars.innodb_pages_written = stat.n_pages_written;
 
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;
2011
1968
        export_vars.innodb_row_lock_waits = srv_n_lock_wait_count;
2012
1969
        export_vars.innodb_row_lock_current_waits
2013
1970
                = srv_n_lock_wait_current_count;
2029
1986
}
2030
1987
 
2031
1988
/*********************************************************************//**
2032
 
A thread which prints the info output by various InnoDB monitors.
 
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.
2033
1991
@return a dummy parameter */
2034
1992
UNIV_INTERN
2035
1993
os_thread_ret_t
2036
 
srv_monitor_thread(
2037
 
/*===============*/
 
1994
srv_lock_timeout_and_monitor_thread(
 
1995
/*================================*/
2038
1996
        void*   arg __attribute__((unused)))
2039
1997
                        /*!< in: a dummy parameter required by
2040
1998
                        os_thread_create */
2041
1999
{
 
2000
        srv_slot_t*     slot;
2042
2001
        double          time_elapsed;
2043
2002
        time_t          current_time;
2044
2003
        time_t          last_table_monitor_time;
2045
2004
        time_t          last_tablespace_monitor_time;
2046
2005
        time_t          last_monitor_time;
2047
 
        ulint           mutex_skipped;
2048
 
        ibool           last_srv_print_monitor;
 
2006
        ibool           some_waits;
 
2007
        double          wait_time;
 
2008
        ulint           i;
2049
2009
 
2050
2010
#ifdef UNIV_DEBUG_THREAD_CREATION
2051
2011
        fprintf(stderr, "Lock timeout thread starts, id %lu\n",
2052
2012
                os_thread_pf(os_thread_get_curr_id()));
2053
2013
#endif
2054
 
 
2055
 
#ifdef UNIV_PFS_THREAD
2056
 
        pfs_register_thread(srv_monitor_thread_key);
2057
 
#endif
2058
 
 
2059
2014
        UT_NOT_USED(arg);
2060
2015
        srv_last_monitor_time = time(NULL);
2061
2016
        last_table_monitor_time = time(NULL);
2062
2017
        last_tablespace_monitor_time = time(NULL);
2063
2018
        last_monitor_time = time(NULL);
2064
 
        mutex_skipped = 0;
2065
 
        last_srv_print_monitor = srv_print_innodb_monitor;
2066
2019
loop:
2067
 
        srv_monitor_active = TRUE;
2068
 
 
2069
 
        /* Wake up every 5 seconds to see if we need to print
2070
 
        monitor information. */
2071
 
 
2072
 
        os_thread_sleep(5000000);
 
2020
        srv_lock_timeout_and_monitor_active = TRUE;
 
2021
 
 
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 */
 
2024
 
 
2025
        os_thread_sleep(1000000);
2073
2026
 
2074
2027
        current_time = time(NULL);
2075
2028
 
2079
2032
                last_monitor_time = time(NULL);
2080
2033
 
2081
2034
                if (srv_print_innodb_monitor) {
2082
 
                        /* Reset mutex_skipped counter everytime
2083
 
                        srv_print_innodb_monitor changes. This is to
2084
 
                        ensure we will not be blocked by kernel_mutex
2085
 
                        for short duration information printing,
2086
 
                        such as requested by sync_array_print_long_waits() */
2087
 
                        if (!last_srv_print_monitor) {
2088
 
                                mutex_skipped = 0;
2089
 
                                last_srv_print_monitor = TRUE;
2090
 
                        }
2091
 
 
2092
 
                        if (!srv_printf_innodb_monitor(stderr,
2093
 
                                                MUTEX_NOWAIT(mutex_skipped),
2094
 
                                                NULL, NULL)) {
2095
 
                                mutex_skipped++;
2096
 
                        } else {
2097
 
                                /* Reset the counter */
2098
 
                                mutex_skipped = 0;
2099
 
                        }
2100
 
                } else {
2101
 
                        last_srv_print_monitor = FALSE;
 
2035
                        srv_printf_innodb_monitor(stderr, NULL, NULL);
2102
2036
                }
2103
2037
 
2104
 
 
2105
2038
                if (srv_innodb_status) {
2106
2039
                        mutex_enter(&srv_monitor_file_mutex);
2107
2040
                        rewind(srv_monitor_file);
2108
 
                        if (!srv_printf_innodb_monitor(srv_monitor_file,
2109
 
                                                MUTEX_NOWAIT(mutex_skipped),
2110
 
                                                NULL, NULL)) {
2111
 
                                mutex_skipped++;
2112
 
                        } else {
2113
 
                                mutex_skipped = 0;
2114
 
                        }
2115
 
 
 
2041
                        srv_printf_innodb_monitor(srv_monitor_file, NULL,
 
2042
                                                  NULL);
2116
2043
                        os_file_set_eof(srv_monitor_file);
2117
2044
                        mutex_exit(&srv_monitor_file_mutex);
2118
2045
                }
2165
2092
                }
2166
2093
        }
2167
2094
 
2168
 
        if (srv_shutdown_state >= SRV_SHUTDOWN_CLEANUP) {
2169
 
                goto exit_func;
2170
 
        }
2171
 
 
2172
 
        if (srv_print_innodb_monitor
2173
 
            || srv_print_innodb_lock_monitor
2174
 
            || srv_print_innodb_tablespace_monitor
2175
 
            || srv_print_innodb_table_monitor) {
2176
 
                goto loop;
2177
 
        }
2178
 
 
2179
 
        srv_monitor_active = FALSE;
2180
 
 
2181
 
        goto loop;
2182
 
 
2183
 
exit_func:
2184
 
        srv_monitor_active = FALSE;
2185
 
 
2186
 
        /* We count the number of threads in os_thread_exit(). A created
2187
 
        thread should always use that to exit and not use return() to exit. */
2188
 
 
2189
 
        os_thread_exit(NULL);
2190
 
 
2191
 
        OS_THREAD_DUMMY_RETURN;
2192
 
}
2193
 
 
2194
 
/*********************************************************************//**
2195
 
A thread which wakes up threads whose lock wait may have lasted too long.
2196
 
@return a dummy parameter */
2197
 
UNIV_INTERN
2198
 
os_thread_ret_t
2199
 
srv_lock_timeout_thread(
2200
 
/*====================*/
2201
 
        void*   arg __attribute__((unused)))
2202
 
                        /* in: a dummy parameter required by
2203
 
                        os_thread_create */
2204
 
{
2205
 
        srv_slot_t*     slot;
2206
 
        ibool           some_waits;
2207
 
        double          wait_time;
2208
 
        ulint           i;
2209
 
 
2210
 
#ifdef UNIV_PFS_THREAD
2211
 
        pfs_register_thread(srv_lock_timeout_thread_key);
2212
 
#endif
2213
 
 
2214
 
loop:
2215
 
        /* When someone is waiting for a lock, we wake up every second
2216
 
        and check if a timeout has passed for a lock wait */
2217
 
 
2218
 
        os_thread_sleep(1000000);
2219
 
 
2220
 
        srv_lock_timeout_active = TRUE;
2221
 
 
2222
2095
        mutex_enter(&kernel_mutex);
2223
2096
 
2224
2097
        some_waits = FALSE;
2242
2115
                        lock_wait_timeout = thd_lock_wait_timeout(
2243
2116
                                trx->mysql_thd);
2244
2117
 
2245
 
                        if (trx_is_interrupted(trx)
2246
 
                            || (lock_wait_timeout < 100000000
2247
 
                                && (wait_time > (double) lock_wait_timeout
2248
 
                                    || wait_time < 0))) {
 
2118
                        if (lock_wait_timeout < 100000000
 
2119
                            && (wait_time > (double) lock_wait_timeout
 
2120
                                || wait_time < 0)) {
2249
2121
 
2250
2122
                                /* Timeout exceeded or a wrap-around in system
2251
2123
                                time counter: cancel the lock request queued
2270
2142
                goto exit_func;
2271
2143
        }
2272
2144
 
2273
 
        if (some_waits) {
 
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) {
2274
2149
                goto loop;
2275
2150
        }
2276
2151
 
2277
 
        srv_lock_timeout_active = FALSE;
 
2152
        /* No one was waiting for a lock and no monitor was active:
 
2153
        suspend this thread */
 
2154
 
 
2155
        srv_lock_timeout_and_monitor_active = FALSE;
2278
2156
 
2279
2157
#if 0
2280
2158
        /* The following synchronisation is disabled, since
2284
2162
        goto loop;
2285
2163
 
2286
2164
exit_func:
2287
 
        srv_lock_timeout_active = FALSE;
 
2165
        srv_lock_timeout_and_monitor_active = FALSE;
2288
2166
 
2289
2167
        /* We count the number of threads in os_thread_exit(). A created
2290
2168
        thread should always use that to exit and not use return() to exit. */
2317
2195
        fprintf(stderr, "Error monitor thread starts, id %lu\n",
2318
2196
                os_thread_pf(os_thread_get_curr_id()));
2319
2197
#endif
2320
 
 
2321
 
#ifdef UNIV_PFS_THREAD
2322
 
        pfs_register_thread(srv_error_monitor_thread_key);
2323
 
#endif
2324
 
 
2325
2198
loop:
2326
2199
        srv_error_monitor_active = TRUE;
2327
2200
 
2402
2275
        OS_THREAD_DUMMY_RETURN;
2403
2276
}
2404
2277
 
2405
 
/**********************************************************************//**
2406
 
Check whether any background thread is active.
2407
 
@return FALSE if all are are suspended or have exited. */
2408
 
UNIV_INTERN
2409
 
ibool
2410
 
srv_is_any_background_thread_active(void)
2411
 
/*=====================================*/
2412
 
{
2413
 
        ulint   i;
2414
 
        ibool   ret = FALSE;
2415
 
 
2416
 
        mutex_enter(&kernel_mutex);
2417
 
 
2418
 
        for (i = SRV_COM; i <= SRV_MASTER; ++i) {
2419
 
                if (srv_n_threads_active[i] != 0) {
2420
 
                        ret = TRUE;
2421
 
                        break;
2422
 
                }
2423
 
        }
2424
 
 
2425
 
        mutex_exit(&kernel_mutex);
2426
 
 
2427
 
        return(ret);
2428
 
}
2429
 
 
2430
2278
/*******************************************************************//**
2431
2279
Tells the InnoDB server that there has been activity in the database
2432
2280
and wakes up the master thread if it is suspended (not sleeping). Used
2433
2281
in the MySQL interface. Note that there is a small chance that the master
2434
 
thread stays suspended (we do not protect our operation with the
2435
 
srv_sys_t->mutex, for performance reasons). */
 
2282
thread stays suspended (we do not protect our operation with the kernel
 
2283
mutex, for performace reasons). */
2436
2284
UNIV_INTERN
2437
2285
void
2438
2286
srv_active_wake_master_thread(void)
2451
2299
}
2452
2300
 
2453
2301
/*******************************************************************//**
2454
 
Tells the purge thread that there has been activity in the database
2455
 
and wakes up the purge thread if it is suspended (not sleeping).  Note
2456
 
that there is a small chance that the purge thread stays suspended
2457
 
(we do not protect our operation with the kernel mutex, for
2458
 
performace reasons). */
2459
 
UNIV_INTERN
2460
 
void
2461
 
srv_wake_purge_thread_if_not_active(void)
2462
 
/*=====================================*/
2463
 
{
2464
 
        ut_ad(!mutex_own(&kernel_mutex));
2465
 
 
2466
 
        if (srv_n_purge_threads > 0
2467
 
            && srv_n_threads_active[SRV_WORKER] == 0) {
2468
 
 
2469
 
                mutex_enter(&kernel_mutex);
2470
 
 
2471
 
                srv_release_threads(SRV_WORKER, 1);
2472
 
 
2473
 
                mutex_exit(&kernel_mutex);
2474
 
        }
2475
 
}
2476
 
 
2477
 
/*******************************************************************//**
2478
2302
Wakes up the master thread if it is suspended or being suspended. */
2479
2303
UNIV_INTERN
2480
2304
void
2490
2314
        mutex_exit(&kernel_mutex);
2491
2315
}
2492
2316
 
2493
 
/*******************************************************************//**
2494
 
Wakes up the purge thread if it's not already awake. */
2495
 
UNIV_INTERN
2496
 
void
2497
 
srv_wake_purge_thread(void)
2498
 
/*=======================*/
2499
 
{
2500
 
        ut_ad(!mutex_own(&kernel_mutex));
2501
 
 
2502
 
        if (srv_n_purge_threads > 0) {
2503
 
 
2504
 
                mutex_enter(&kernel_mutex);
2505
 
 
2506
 
                srv_release_threads(SRV_WORKER, 1);
2507
 
 
2508
 
                mutex_exit(&kernel_mutex);
2509
 
        }
2510
 
}
2511
 
 
2512
2317
/**********************************************************************
2513
2318
The master thread is tasked to ensure that flush of log file happens
2514
2319
once every second in the background. This is to ensure that not more
2529
2334
        }
2530
2335
}
2531
2336
 
2532
 
/********************************************************************//**
2533
 
Do a full purge, reconfigure the purge sub-system if a dynamic
2534
 
change is detected. */
2535
 
static
2536
 
void
2537
 
srv_master_do_purge(void)
2538
 
/*=====================*/
2539
 
{
2540
 
        ulint   n_pages_purged;
2541
 
 
2542
 
        ut_ad(!mutex_own(&kernel_mutex));
2543
 
 
2544
 
        ut_a(srv_n_purge_threads == 0);
2545
 
 
2546
 
        do {
2547
 
                /* Check for shutdown and change in purge config. */
2548
 
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
2549
 
                        /* Nothing to purge. */
2550
 
                        n_pages_purged = 0;
2551
 
                } else {
2552
 
                        n_pages_purged = trx_purge(srv_purge_batch_size);
2553
 
                }
2554
 
 
2555
 
                srv_sync_log_buffer_in_background();
2556
 
 
2557
 
        } while (n_pages_purged > 0);
2558
 
}
2559
 
 
2560
2337
/*********************************************************************//**
2561
2338
The master thread controlling the server.
2562
2339
@return a dummy parameter */
2568
2345
                        /*!< in: a dummy parameter required by
2569
2346
                        os_thread_create */
2570
2347
{
2571
 
        buf_pool_stat_t buf_stat;
2572
2348
        os_event_t      event;
2573
2349
        ulint           old_activity_count;
2574
2350
        ulint           n_pages_purged  = 0;
2580
2356
        ulint           n_ios_old;
2581
2357
        ulint           n_ios_very_old;
2582
2358
        ulint           n_pend_ios;
2583
 
        ulint           next_itr_time;
 
2359
        ibool           skip_sleep      = FALSE;
2584
2360
        ulint           i;
2585
2361
 
2586
2362
#ifdef UNIV_DEBUG_THREAD_CREATION
2587
2363
        fprintf(stderr, "Master thread starts, id %lu\n",
2588
2364
                os_thread_pf(os_thread_get_curr_id()));
2589
2365
#endif
2590
 
 
2591
 
#ifdef UNIV_PFS_THREAD
2592
 
        pfs_register_thread(srv_master_thread_key);
2593
 
#endif
2594
 
 
2595
2366
        srv_main_thread_process_no = os_proc_get_number();
2596
2367
        srv_main_thread_id = os_thread_pf(os_thread_get_curr_id());
2597
2368
 
2610
2381
 
2611
2382
        srv_main_thread_op_info = "reserving kernel mutex";
2612
2383
 
2613
 
        buf_get_total_stat(&buf_stat);
2614
 
        n_ios_very_old = log_sys->n_log_ios + buf_stat.n_pages_read
2615
 
                + buf_stat.n_pages_written;
 
2384
        n_ios_very_old = log_sys->n_log_ios + buf_pool->stat.n_pages_read
 
2385
                + buf_pool->stat.n_pages_written;
2616
2386
        mutex_enter(&kernel_mutex);
2617
2387
 
2618
2388
        /* Store the user activity counter at the start of this loop */
2629
2399
        when there is database activity */
2630
2400
 
2631
2401
        srv_last_log_flush_time = time(NULL);
2632
 
        next_itr_time = ut_time_ms();
 
2402
        skip_sleep = FALSE;
2633
2403
 
2634
2404
        for (i = 0; i < 10; i++) {
2635
 
                ulint   cur_time = ut_time_ms();
2636
 
 
2637
 
                buf_get_total_stat(&buf_stat);
2638
 
 
2639
 
                n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2640
 
                        + buf_stat.n_pages_written;
2641
 
 
 
2405
                n_ios_old = log_sys->n_log_ios + buf_pool->stat.n_pages_read
 
2406
                        + buf_pool->stat.n_pages_written;
2642
2407
                srv_main_thread_op_info = "sleeping";
2643
2408
                srv_main_1_second_loops++;
2644
2409
 
2645
 
                if (next_itr_time > cur_time) {
 
2410
                if (!skip_sleep) {
2646
2411
 
2647
 
                        /* Get sleep interval in micro seconds. We use
2648
 
                        ut_min() to avoid long sleep in case of
2649
 
                        wrap around. */
2650
 
                        os_thread_sleep(ut_min(1000000,
2651
 
                                        (next_itr_time - cur_time)
2652
 
                                         * 1000));
 
2412
                        os_thread_sleep(1000000);
2653
2413
                        srv_main_sleeps++;
2654
2414
                }
2655
2415
 
2656
 
                /* Each iteration should happen at 1 second interval. */
2657
 
                next_itr_time = ut_time_ms() + 1000;
 
2416
                skip_sleep = FALSE;
2658
2417
 
2659
2418
                /* ALTER TABLE in MySQL requires on Unix that the table handler
2660
2419
                can drop tables lazily after there no longer are SELECT
2678
2437
                log_free_check();
2679
2438
 
2680
2439
                /* If i/os during one second sleep were less than 5% of
2681
 
                capacity, we assume that there is free disk i/o capacity
2682
 
                available, and it makes sense to do an insert buffer merge. */
 
2440
                capacity, we assume that there is free disk i/o capacity
 
2441
                available, and it makes sense to do an insert buffer merge. */
2683
2442
 
2684
 
                buf_get_total_stat(&buf_stat);
2685
2443
                n_pend_ios = buf_get_n_pending_ios()
2686
2444
                        + log_sys->n_pending_writes;
2687
 
                n_ios = log_sys->n_log_ios + buf_stat.n_pages_read
2688
 
                        + buf_stat.n_pages_written;
 
2445
                n_ios = log_sys->n_log_ios + buf_pool->stat.n_pages_read
 
2446
                        + buf_pool->stat.n_pages_written;
2689
2447
                if (n_pend_ios < SRV_PEND_IO_THRESHOLD
2690
2448
                    && (n_ios - n_ios_old < SRV_RECENT_IO_ACTIVITY)) {
2691
2449
                        srv_main_thread_op_info = "doing insert buffer merge";
2703
2461
 
2704
2462
                        srv_main_thread_op_info =
2705
2463
                                "flushing buffer pool pages";
2706
 
                        n_pages_flushed = buf_flush_list(
2707
 
                                PCT_IO(100), IB_ULONGLONG_MAX);
2708
 
 
 
2464
                        n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST,
 
2465
                                                          PCT_IO(100),
 
2466
                                                          IB_ULONGLONG_MAX);
 
2467
 
 
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. */
 
2472
 
 
2473
                        skip_sleep = TRUE;
2709
2474
                } else if (srv_adaptive_flushing) {
2710
2475
 
2711
2476
                        /* Try to keep the rate of flushing of dirty
2718
2483
                                        "flushing buffer pool pages";
2719
2484
                                n_flush = ut_min(PCT_IO(100), n_flush);
2720
2485
                                n_pages_flushed =
2721
 
                                        buf_flush_list(
 
2486
                                        buf_flush_batch(
 
2487
                                                BUF_FLUSH_LIST,
2722
2488
                                                n_flush,
2723
2489
                                                IB_ULONGLONG_MAX);
 
2490
                                skip_sleep = TRUE;
2724
2491
                        }
2725
2492
                }
2726
2493
 
2750
2517
        loop above requests writes for that case. The writes done here
2751
2518
        are not required, and may be disabled. */
2752
2519
 
2753
 
        buf_get_total_stat(&buf_stat);
2754
2520
        n_pend_ios = buf_get_n_pending_ios() + log_sys->n_pending_writes;
2755
 
        n_ios = log_sys->n_log_ios + buf_stat.n_pages_read
2756
 
                + buf_stat.n_pages_written;
 
2521
        n_ios = log_sys->n_log_ios + buf_pool->stat.n_pages_read
 
2522
                + buf_pool->stat.n_pages_written;
2757
2523
 
2758
2524
        srv_main_10_second_loops++;
2759
2525
        if (n_pend_ios < SRV_PEND_IO_THRESHOLD
2760
2526
            && (n_ios - n_ios_very_old < SRV_PAST_IO_ACTIVITY)) {
2761
2527
 
2762
2528
                srv_main_thread_op_info = "flushing buffer pool pages";
2763
 
                buf_flush_list(PCT_IO(100), IB_ULONGLONG_MAX);
 
2529
                buf_flush_batch(BUF_FLUSH_LIST, PCT_IO(100),
 
2530
                                IB_ULONGLONG_MAX);
2764
2531
 
2765
2532
                /* Flush logs if needed */
2766
2533
                srv_sync_log_buffer_in_background();
2775
2542
        /* Flush logs if needed */
2776
2543
        srv_sync_log_buffer_in_background();
2777
2544
 
2778
 
        if (srv_n_purge_threads == 0) {
2779
 
                srv_main_thread_op_info = "master purging";
2780
 
 
2781
 
                srv_master_do_purge();
 
2545
        /* We run a full purge every 10 seconds, even if the server
 
2546
        were active */
 
2547
        do {
2782
2548
 
2783
2549
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
2784
2550
 
2785
2551
                        goto background_loop;
2786
2552
                }
2787
 
        }
 
2553
 
 
2554
                srv_main_thread_op_info = "purging";
 
2555
                n_pages_purged = trx_purge();
 
2556
 
 
2557
                /* Flush logs if needed */
 
2558
                srv_sync_log_buffer_in_background();
 
2559
 
 
2560
        } while (n_pages_purged);
2788
2561
 
2789
2562
        srv_main_thread_op_info = "flushing buffer pool pages";
2790
2563
 
2796
2569
                (> 70 %), we assume we can afford reserving the disk(s) for
2797
2570
                the time it requires to flush 100 pages */
2798
2571
 
2799
 
                n_pages_flushed = buf_flush_list(
2800
 
                        PCT_IO(100), IB_ULONGLONG_MAX);
 
2572
                n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST,
 
2573
                                                  PCT_IO(100),
 
2574
                                                  IB_ULONGLONG_MAX);
2801
2575
        } else {
2802
2576
                /* Otherwise, we only flush a small number of pages so that
2803
2577
                we do not unnecessarily use much disk i/o capacity from
2804
2578
                other work */
2805
2579
 
2806
 
                n_pages_flushed = buf_flush_list(
2807
 
                          PCT_IO(10), IB_ULONGLONG_MAX);
 
2580
                n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST,
 
2581
                                                  PCT_IO(10),
 
2582
                                                  IB_ULONGLONG_MAX);
2808
2583
        }
2809
2584
 
2810
2585
        srv_main_thread_op_info = "making checkpoint";
2851
2626
                os_thread_sleep(100000);
2852
2627
        }
2853
2628
 
2854
 
        if (srv_n_purge_threads == 0) {
2855
 
                srv_main_thread_op_info = "master purging";
2856
 
 
2857
 
                srv_master_do_purge();
2858
 
        }
 
2629
        srv_main_thread_op_info = "purging";
 
2630
 
 
2631
        /* Run a full purge */
 
2632
        do {
 
2633
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
 
2634
 
 
2635
                        break;
 
2636
                }
 
2637
 
 
2638
                srv_main_thread_op_info = "purging";
 
2639
                n_pages_purged = trx_purge();
 
2640
 
 
2641
                /* Flush logs if needed */
 
2642
                srv_sync_log_buffer_in_background();
 
2643
 
 
2644
        } while (n_pages_purged);
2859
2645
 
2860
2646
        srv_main_thread_op_info = "reserving kernel mutex";
2861
2647
 
2873
2659
        } else {
2874
2660
                /* This should do an amount of IO similar to the number of
2875
2661
                dirty pages that will be flushed in the call to
2876
 
                buf_flush_list below. Otherwise, the system favors
 
2662
                buf_flush_batch below. Otherwise, the system favors
2877
2663
                clean pages over cleanup throughput. */
2878
2664
                n_bytes_merged = ibuf_contract_for_n_pages(FALSE,
2879
2665
                                                           PCT_IO(100));
2892
2678
        srv_main_thread_op_info = "flushing buffer pool pages";
2893
2679
        srv_main_flush_loops++;
2894
2680
        if (srv_fast_shutdown < 2) {
2895
 
                n_pages_flushed = buf_flush_list(
2896
 
                          PCT_IO(100), IB_ULONGLONG_MAX);
 
2681
                n_pages_flushed = buf_flush_batch(BUF_FLUSH_LIST,
 
2682
                                                  PCT_IO(100),
 
2683
                                                  IB_ULONGLONG_MAX);
2897
2684
        } else {
2898
2685
                /* In the fastest shutdown we do not flush the buffer pool
2899
2686
                to data files: we set n_pages_flushed to 0 artificially. */
2911
2698
        mutex_exit(&kernel_mutex);
2912
2699
 
2913
2700
        srv_main_thread_op_info = "waiting for buffer pool flush to end";
2914
 
        buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST);
 
2701
        buf_flush_wait_batch_end(BUF_FLUSH_LIST);
2915
2702
 
2916
2703
        /* Flush logs if needed */
2917
2704
        srv_sync_log_buffer_in_background();
2998
2785
                already when the event wait ends */
2999
2786
 
3000
2787
                os_thread_exit(NULL);
3001
 
 
3002
2788
        }
3003
2789
 
3004
2790
        /* When there is user activity, InnoDB will set the event and the
3011
2797
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3012
2798
#endif
3013
2799
}
3014
 
 
3015
 
/*********************************************************************//**
3016
 
Asynchronous purge thread.
3017
 
@return a dummy parameter */
3018
 
UNIV_INTERN
3019
 
os_thread_ret_t
3020
 
srv_purge_thread(
3021
 
/*=============*/
3022
 
        void*   arg __attribute__((unused)))    /*!< in: a dummy parameter
3023
 
                                                required by os_thread_create */
3024
 
{
3025
 
        srv_slot_t*     slot;
3026
 
        ulint           slot_no = ULINT_UNDEFINED;
3027
 
        ulint           n_total_purged = ULINT_UNDEFINED;
3028
 
 
3029
 
        ut_a(srv_n_purge_threads == 1);
3030
 
 
3031
 
#ifdef UNIV_DEBUG_THREAD_CREATION
3032
 
        fprintf(stderr, "InnoDB: Purge thread running, id %lu\n",
3033
 
                os_thread_pf(os_thread_get_curr_id()));
3034
 
#endif /* UNIV_DEBUG_THREAD_CREATION */
3035
 
 
3036
 
        mutex_enter(&kernel_mutex);
3037
 
 
3038
 
        slot_no = srv_table_reserve_slot(SRV_WORKER);
3039
 
 
3040
 
        ++srv_n_threads_active[SRV_WORKER];
3041
 
 
3042
 
        mutex_exit(&kernel_mutex);
3043
 
 
3044
 
        while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
3045
 
 
3046
 
                ulint   n_pages_purged;
3047
 
 
3048
 
                /* If there are very few records to purge or the last
3049
 
                purge didn't purge any records then wait for activity.
3050
 
                We peek at the history len without holding any mutex
3051
 
                because in the worst case we will end up waiting for
3052
 
                the next purge event. */
3053
 
                if (trx_sys->rseg_history_len < srv_purge_batch_size
3054
 
                    || n_total_purged == 0) {
3055
 
 
3056
 
                        os_event_t      event;
3057
 
 
3058
 
                        mutex_enter(&kernel_mutex);
3059
 
 
3060
 
                        event = srv_suspend_thread();
3061
 
 
3062
 
                        mutex_exit(&kernel_mutex);
3063
 
 
3064
 
                        os_event_wait(event);
3065
 
                }
3066
 
 
3067
 
                /* Check for shutdown and whether we should do purge at all. */
3068
 
                if (srv_force_recovery >= SRV_FORCE_NO_BACKGROUND
3069
 
                    || srv_shutdown_state != 0
3070
 
                    || srv_fast_shutdown) {
3071
 
 
3072
 
                        break;
3073
 
                }
3074
 
 
3075
 
                n_total_purged = 0;
3076
 
 
3077
 
                /* Purge until there are no more records to purge and there is
3078
 
                no change in configuration or server state. */
3079
 
                do {
3080
 
                        n_pages_purged = trx_purge(srv_purge_batch_size);
3081
 
 
3082
 
                        n_total_purged += n_pages_purged;
3083
 
 
3084
 
                } while (n_pages_purged > 0 && !srv_fast_shutdown);
3085
 
 
3086
 
                srv_sync_log_buffer_in_background();
3087
 
        }
3088
 
 
3089
 
        mutex_enter(&kernel_mutex);
3090
 
 
3091
 
        /* Decrement the active count. */
3092
 
        srv_suspend_thread();
3093
 
 
3094
 
        mutex_exit(&kernel_mutex);
3095
 
 
3096
 
        /* Free the thread local memory. */
3097
 
        thr_local_free(os_thread_get_curr_id());
3098
 
 
3099
 
        mutex_enter(&kernel_mutex);
3100
 
 
3101
 
        /* Free the slot for reuse. */
3102
 
        slot = srv_table_get_nth_slot(slot_no);
3103
 
        slot->in_use = FALSE;
3104
 
 
3105
 
        mutex_exit(&kernel_mutex);
3106
 
 
3107
 
#ifdef UNIV_DEBUG_THREAD_CREATION
3108
 
        fprintf(stderr, "InnoDB: Purge thread exiting, id %lu\n",
3109
 
                os_thread_pf(os_thread_get_curr_id()));
3110
 
#endif /* UNIV_DEBUG_THREAD_CREATION */
3111
 
 
3112
 
        /* We count the number of threads in os_thread_exit(). A created
3113
 
        thread should always use that to exit and not use return() to exit. */
3114
 
        os_thread_exit(NULL);
3115
 
 
3116
 
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3117
 
}
3118
 
 
3119
 
/**********************************************************************//**
3120
 
Enqueues a task to server task queue and releases a worker thread, if there
3121
 
is a suspended one. */
3122
 
UNIV_INTERN
3123
 
void
3124
 
srv_que_task_enqueue_low(
3125
 
/*=====================*/
3126
 
        que_thr_t*      thr)    /*!< in: query thread */
3127
 
{
3128
 
        ut_ad(thr);
3129
 
 
3130
 
        mutex_enter(&kernel_mutex);
3131
 
 
3132
 
        UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr);
3133
 
 
3134
 
        srv_release_threads(SRV_WORKER, 1);
3135
 
 
3136
 
        mutex_exit(&kernel_mutex);
3137
 
}