MySQL
9.3.0
Source Code Documentation
srv0srv.h
Go to the documentation of this file.
1
/*****************************************************************************
2
3
Copyright (c) 1995, 2025, Oracle and/or its affiliates.
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
8
Google, Inc. Those modifications are gratefully acknowledged and are described
9
briefly in the InnoDB documentation. The contributions by Google are
10
incorporated with their permission, and subject to the conditions contained in
11
the file COPYING.Google.
12
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
This program is free software; you can redistribute it and/or modify it under
21
the terms of the GNU General Public License, version 2.0, as published by the
22
Free Software Foundation.
23
24
This program is designed to work with certain software (including
25
but not limited to OpenSSL) that is licensed under separate terms,
26
as designated in a particular file or component or in included license
27
documentation. The authors of MySQL hereby grant you an additional
28
permission to link the program and your derivative works with the
29
separately licensed software that they have either included with
30
the program or referenced in the documentation.
31
32
This program is distributed in the hope that it will be useful, but WITHOUT
33
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
35
for more details.
36
37
You should have received a copy of the GNU General Public License along with
38
this program; if not, write to the Free Software Foundation, Inc.,
39
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40
41
*****************************************************************************/
42
43
/** @file include/srv0srv.h
44
The server main program
45
46
Created 10/10/1995 Heikki Tuuri
47
*******************************************************/
48
49
#ifndef srv0srv_h
50
#define srv0srv_h
51
52
#include "
buf0checksum.h
"
53
#include "
fil0fil.h
"
54
#include "
mysql/psi/mysql_stage.h
"
55
#include "
univ.i
"
56
57
#ifndef UNIV_HOTBACKUP
58
#include "
log0ddl.h
"
59
#include "
os0event.h
"
60
#include "
os0file.h
"
61
#include "
os0thread.h
"
62
#include "
que0types.h
"
63
#include "
srv0conc.h
"
64
#include "
trx0types.h
"
65
#include "
ut0counter.h
"
66
67
#include <cstdint>
68
#include <future>
69
70
/* Global counters used inside InnoDB. */
71
struct
srv_stats_t
{
72
typedef
ib_counter_t<ulint, 64>
ulint_ctr_64_t
;
73
typedef
ib_counter_t<lsn_t, 1, single_indexer_t>
lsn_ctr_1_t
;
74
typedef
ib_counter_t<ulint, 1, single_indexer_t>
ulint_ctr_1_t
;
75
typedef
ib_counter_t<lint, 1, single_indexer_t>
lint_ctr_1_t
;
76
typedef
ib_counter_t<int64_t, 1, single_indexer_t>
int64_ctr_1_t
;
77
78
/** Count the amount of data written in total (in bytes) */
79
ulint_ctr_1_t
data_written
;
80
81
/** Number of the log write requests done */
82
ulint_ctr_1_t
log_write_requests
;
83
84
/** Number of physical writes to the log performed */
85
ulint_ctr_1_t
log_writes
;
86
87
/** Amount of data written to the log files in bytes */
88
lsn_ctr_1_t
os_log_written
;
89
90
/** Number of writes being done to the log files */
91
lint_ctr_1_t
os_log_pending_writes
;
92
93
/** We increase this counter, when we don't have enough
94
space in the log buffer and have to flush it */
95
ulint_ctr_1_t
log_waits
;
96
97
/** Count the number of times the doublewrite buffer was flushed */
98
ulint_ctr_1_t
dblwr_writes
;
99
100
/** Store the number of pages that have been flushed to the
101
doublewrite buffer */
102
ulint_ctr_1_t
dblwr_pages_written
;
103
104
/** Store the number of write requests issued */
105
ulint_ctr_1_t
buf_pool_write_requests
;
106
107
/** Store the number of times when we had to wait for a free page
108
in the buffer pool. It happens when the buffer pool is full and we
109
need to make a flush, in order to be able to read or create a page. */
110
ulint_ctr_1_t
buf_pool_wait_free
;
111
112
/** Count the number of pages that were written from buffer
113
pool to the disk */
114
ulint_ctr_1_t
buf_pool_flushed
;
115
116
/** Number of buffer pool reads that led to the reading of
117
a disk page */
118
ulint_ctr_1_t
buf_pool_reads
;
119
120
/** Number of data read in total (in bytes) */
121
ulint_ctr_1_t
data_read
;
122
123
/** Wait time of database locks */
124
int64_ctr_1_t
n_lock_wait_time
;
125
126
/** Number of database lock waits */
127
ulint_ctr_1_t
n_lock_wait_count
;
128
129
/** Number of threads currently waiting on database locks */
130
lint_ctr_1_t
n_lock_wait_current_count
;
131
132
/** Number of rows read. */
133
ulint_ctr_64_t
n_rows_read
;
134
135
/** Number of rows updated */
136
ulint_ctr_64_t
n_rows_updated
;
137
138
/** Number of rows deleted */
139
ulint_ctr_64_t
n_rows_deleted
;
140
141
/** Number of rows inserted */
142
ulint_ctr_64_t
n_rows_inserted
;
143
144
/** Number of system rows read. */
145
ulint_ctr_64_t
n_system_rows_read
;
146
147
/** Number of system rows updated */
148
ulint_ctr_64_t
n_system_rows_updated
;
149
150
/** Number of system rows deleted */
151
ulint_ctr_64_t
n_system_rows_deleted
;
152
153
/** Number of system rows inserted */
154
ulint_ctr_64_t
n_system_rows_inserted
;
155
156
/** Number of sampled pages read */
157
ulint_ctr_64_t
n_sampled_pages_read
;
158
159
/** Number of sampled pages skipped */
160
ulint_ctr_64_t
n_sampled_pages_skipped
;
161
};
162
163
/** Structure which keeps shared future objects for InnoDB background
164
threads. One should use these objects to check if threads exited. */
165
struct
Srv_threads
{
166
/** Monitor thread (prints info). */
167
IB_thread
m_monitor
;
168
169
/** Error monitor thread. */
170
IB_thread
m_error_monitor
;
171
172
/** Redo files governor thread. */
173
IB_thread
m_log_files_governor
;
174
175
/** Redo checkpointer thread. */
176
IB_thread
m_log_checkpointer
;
177
178
/** Redo writer thread. */
179
IB_thread
m_log_writer
;
180
181
/** Redo flusher thread. */
182
IB_thread
m_log_flusher
;
183
184
/** Redo write notifier thread. */
185
IB_thread
m_log_write_notifier
;
186
187
/** Redo flush notifier thread. */
188
IB_thread
m_log_flush_notifier
;
189
190
/** Redo log archiver (used by backup). */
191
IB_thread
m_backup_log_archiver
;
192
193
/** Buffer pool dump thread. */
194
IB_thread
m_buf_dump
;
195
196
/** Buffer pool resize thread. */
197
IB_thread
m_buf_resize
;
198
199
/** Dict stats background thread. */
200
IB_thread
m_dict_stats
;
201
202
/** Thread detecting lock wait timeouts. */
203
IB_thread
m_lock_wait_timeout
;
204
205
/** The master thread. */
206
IB_thread
m_master
;
207
208
/** The ts_alter_encrypt thread. */
209
IB_thread
m_ts_alter_encrypt
;
210
211
/** Thread doing rollbacks during recovery. */
212
IB_thread
m_trx_recovery_rollback
;
213
214
/** Thread writing recovered pages during recovery. */
215
IB_thread
m_recv_writer
;
216
217
/** Purge coordinator (also being a worker) */
218
IB_thread
m_purge_coordinator
;
219
220
/** Number of purge workers and size of array below. */
221
size_t
m_purge_workers_n
;
222
223
/** Purge workers. Note that the m_purge_workers[0] is the same shared
224
state as m_purge_coordinator. */
225
IB_thread
*
m_purge_workers
;
226
227
/** Page cleaner coordinator (also being a worker). */
228
IB_thread
m_page_cleaner_coordinator
;
229
230
/** Number of page cleaner workers and size of array below. */
231
size_t
m_page_cleaner_workers_n
;
232
233
/** Page cleaner workers. Note that m_page_cleaner_workers[0] is the
234
same shared state as m_page_cleaner_coordinator. */
235
IB_thread
*
m_page_cleaner_workers
;
236
237
/** Archiver's log archiver (used by Clone). */
238
IB_thread
m_log_archiver
;
239
240
/** Archiver's page archiver (used by Clone). */
241
IB_thread
m_page_archiver
;
242
243
/** Thread doing optimization for FTS index. */
244
IB_thread
m_fts_optimize
;
245
246
/** Thread for GTID persistence */
247
IB_thread
m_gtid_persister
;
248
249
#ifdef UNIV_DEBUG
250
/** Used in test scenario to delay threads' cleanup until the pre_dd_shutdown
251
is ended and final plugin's shutdown is started (when plugin is DELETED).
252
Note that you may only delay the shutdown for threads for which there is no
253
waiting procedure used in the pre_dd_shutdown. */
254
os_event_t
m_shutdown_cleanup_dbg
;
255
#endif
/* UNIV_DEBUG */
256
257
/** When the master thread notices that shutdown has started (by noticing
258
srv_shutdown_state >= SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS), it exits
259
its main loop. Then the master thread proceeds with actions related to tasks:
260
- which it has been responsible for,
261
- and which might depend on DD objects.
262
After finishing them, the master thread sets this event.
263
@remarks We use this event to wait in srv_pre_dd_shutdown before we enter
264
next phase (SRV_SHUTDOWN_PURGE) in which master thread is not allowed to
265
use system transactions or touch DD objects. */
266
os_event_t
m_master_ready_for_dd_shutdown
;
267
};
268
269
/** Check if given thread is still active. */
270
bool
srv_thread_is_active
(
const
IB_thread
&thread);
271
272
/** Check if given thread is cleaned-up and stopped. */
273
bool
srv_thread_is_stopped
(
const
IB_thread
&thread);
274
275
/** Delay the thread after it discovered that the shutdown_state
276
is greater or equal to SRV_SHUTDOWN_CLEANUP, before it proceeds
277
with further clean up. This is used in the tests to see if such
278
a possible delay does not have impact on the clean shutdown.
279
@param[in] wait_for_signal wait until shutdown phase starts */
280
void
srv_thread_delay_cleanup_if_needed
(
bool
wait_for_signal);
281
282
struct
Srv_cpu_usage
{