MySQL 8.0.31
Source Code Documentation
srv0shutdown.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2020, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/srv0shutdown.h
28 Shutdowns the Innobase database server
29
30 *******************************************************/
31
32#ifndef srv0shutdown_h
33#define srv0shutdown_h
34
35#include "my_compiler.h"
36#include "univ.i"
37
38/** Shut down all InnoDB background tasks that may look up objects in
39the data dictionary. */
41
42/** Shut down the InnoDB database. */
43void srv_shutdown();
44
45/** Shutdown state */
47 /** Database running normally. */
49
50 /** Shutdown has started. Stopping the thread responsible for rollback of
51 recovered transactions. In case of slow shutdown, this implies waiting
52 for completed rollback of all recovered transactions.
53 @remarks Note that user transactions are stopped earlier, when the
54 shutdown state is still equal to SRV_SHUTDOWN_NONE (user transactions
55 are closed when related connections are closed in close_connections()). */
57
58 /** Stopping threads that might use system transactions or DD objects.
59 This is important because we need to ensure that in the next phase no
60 undo records could be produced (we will be stopping purge threads).
61 After next phase DD is shut down, so also no accesses to DD objects
62 are allowed then. List of threads being stopped within this phase:
63 - dict_stats thread,
64 - fts_optimize thread,
65 - ts_alter_encrypt thread.
66 The master thread exits its main loop and finishes its first phase
67 of shutdown (in which it was allowed to touch DD objects). */
69
70 /** Stopping the purge threads. Before we enter this phase, we have
71 the guarantee that no new undo records could be produced. */
73
74 /** Shutting down the DD. */
76
77 /** Stopping remaining InnoDB background threads except:
78 - the master thread,
79 - redo log threads,
80 - page cleaner threads,
81 - archiver threads.
82 List of threads being stopped within this phase:
83 - lock_wait_timeout thread,
84 - error_monitor thread,
85 - monitor thread,
86 - buf_dump thread,
87 - buf_resize thread.
88 @remarks If your thread might touch DD objects or use system transactions
89 it must be stopped within SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS phase.
90*/
92
93 /** Stopping the master thread. */
95
96 /** Once we enter this phase, the page cleaners can clean up the buffer pool
97 and exit. The redo log threads write and flush the log buffer and exit after
98 the page cleaners (and within this phase). */
100
101 /** Last phase after ensuring that all data have been flushed to disk and
102 the flushed_lsn has been updated in the header of system tablespace.
103 During this phase we close all files and ensure archiver has archived all. */
105
106 /** Exit all threads and free resources. We might reach this phase in one
107 of two different ways:
108 - after visiting all previous states (usual shutdown),
109 - or during startup when we failed and we abort the startup. */
112
113/** At a shutdown this value climbs from SRV_SHUTDOWN_NONE
114to SRV_SHUTDOWN_EXIT_THREADS. */
115extern std::atomic<enum srv_shutdown_t> srv_shutdown_state;
116
117/** Call std::quick_exit(3) */
118[[noreturn]] void srv_fatal_error();
119
120/** Attempt to shutdown all background threads created by InnoDB.
121NOTE: Does not guarantee they are actually shut down, only does
122the best effort. Changes state of shutdown to SHUTDOWN_EXIT_THREADS,
123wakes up the background threads and waits a little bit. It might be
124used within startup phase or when fatal error is discovered during
125some IO operation. Therefore you must not assume anything related
126to the state in which it might be used. */
128
129/** Checks if all recovered transactions are supposed to be rolled back
130before shutdown is ended.
131@return value of the check */
133
134/** Allows to safely check value of the current shutdown state.
135Note that the current shutdown state might be changed while the
136check is being executed, but the check is based on a single load
137of the srv_shutdown_state (atomic global variable). */
138template <typename F>
140 const auto state = srv_shutdown_state.load();
141 return std::forward<F>(f)(state);
142}
143
144#endif
Header for compiler-dependent features.
void srv_shutdown_exit_threads()
Attempt to shutdown all background threads created by InnoDB.
Definition: srv0start.cc:1379
std::atomic< enum srv_shutdown_t > srv_shutdown_state
At a shutdown this value climbs from SRV_SHUTDOWN_NONE to SRV_SHUTDOWN_EXIT_THREADS.
Definition: srv0start.cc:166
void srv_pre_dd_shutdown()
Shut down all InnoDB background tasks that may look up objects in the data dictionary.
Definition: srv0start.cc:2763
bool srv_shutdown_state_matches(F &&f)
Allows to safely check value of the current shutdown state.
Definition: srv0shutdown.h:139
void srv_fatal_error()
Call std::quick_exit(3)
Definition: srv0start.cc:3294
void srv_shutdown()
Shut down the InnoDB database.
Definition: srv0start.cc:3121
srv_shutdown_t
Shutdown state.
Definition: srv0shutdown.h:46
@ SRV_SHUTDOWN_CLEANUP
Stopping remaining InnoDB background threads except:
Definition: srv0shutdown.h:91
@ SRV_SHUTDOWN_NONE
Database running normally.
Definition: srv0shutdown.h:48
@ SRV_SHUTDOWN_RECOVERY_ROLLBACK
Shutdown has started.
Definition: srv0shutdown.h:56
@ SRV_SHUTDOWN_LAST_PHASE
Last phase after ensuring that all data have been flushed to disk and the flushed_lsn has been update...
Definition: srv0shutdown.h:104
@ SRV_SHUTDOWN_PURGE
Stopping the purge threads.
Definition: srv0shutdown.h:72
@ SRV_SHUTDOWN_FLUSH_PHASE
Once we enter this phase, the page cleaners can clean up the buffer pool and exit.
Definition: srv0shutdown.h:99
@ SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS
Stopping threads that might use system transactions or DD objects.
Definition: srv0shutdown.h:68
@ SRV_SHUTDOWN_DD
Shutting down the DD.
Definition: srv0shutdown.h:75
@ SRV_SHUTDOWN_EXIT_THREADS
Exit all threads and free resources.
Definition: srv0shutdown.h:110
@ SRV_SHUTDOWN_MASTER_STOP
Stopping the master thread.
Definition: srv0shutdown.h:94
bool srv_shutdown_waits_for_rollback_of_recovered_transactions()
Checks if all recovered transactions are supposed to be rolled back before shutdown is ended.
Definition: srv0start.cc:2757
Version control for database, common definitions, and include files.