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