MySQL  8.0.23
Source Code Documentation
srv0shutdown.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2020, Oracle and/or its affiliates.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 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
39 the data dictionary. */
40 void srv_pre_dd_shutdown();
41 
42 /** Shut down the InnoDB database. */
43 void 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. */
111 };
112 
113 /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE
114 to SRV_SHUTDOWN_EXIT_THREADS. */
115 extern std::atomic<enum srv_shutdown_t> srv_shutdown_state;
116 
117 /** Call std::quick_exit(3) */
118 void srv_fatal_error() MY_ATTRIBUTE((noreturn));
119 
120 /** Attempt to shutdown all background threads created by InnoDB.
121 NOTE: Does not guarantee they are actually shut down, only does
122 the best effort. Changes state of shutdown to SHUTDOWN_EXIT_THREADS,
123 wakes up the background threads and waits a little bit. It might be
124 used within startup phase or when fatal error is discovered during
125 some IO operation. Therefore you must not assume anything related
126 to the state in which it might be used. */
128 
129 /** Checks if all recovered transactions are supposed to be rolled back
130 before shutdown is ended.
131 @return value of the check */
133 
134 /** Allows to safely check value of the current shutdown state.
135 Note that the current shutdown state might be changed while the
136 check is being executed, but the check is based on a single load
137 of the srv_shutdown_state (atomic global variable). */
138 template <typename F>
140  const auto state = srv_shutdown_state.load();
141  return std::forward<F>(f)(state);
142 }
143 
144 #endif
srv_shutdown_t
srv_shutdown_t
Shutdown state.
Definition: srv0shutdown.h:46
SRV_SHUTDOWN_RECOVERY_ROLLBACK
@ SRV_SHUTDOWN_RECOVERY_ROLLBACK
Shutdown has started.
Definition: srv0shutdown.h:56
my_compiler.h
srv_shutdown_waits_for_rollback_of_recovered_transactions
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:3096
SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS
@ SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS
Stopping threads that might use system transactions or DD objects.
Definition: srv0shutdown.h:68
SRV_SHUTDOWN_EXIT_THREADS
@ SRV_SHUTDOWN_EXIT_THREADS
Exit all threads and free resources.
Definition: srv0shutdown.h:110
SRV_SHUTDOWN_NONE
@ SRV_SHUTDOWN_NONE
Database running normally.
Definition: srv0shutdown.h:48
SRV_SHUTDOWN_CLEANUP
@ SRV_SHUTDOWN_CLEANUP
Stopping remaining InnoDB background threads except:
Definition: srv0shutdown.h:91
srv_shutdown_state_matches
bool srv_shutdown_state_matches(F &&f)
Allows to safely check value of the current shutdown state.
Definition: srv0shutdown.h:139
SRV_SHUTDOWN_LAST_PHASE
@ 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_fatal_error
void srv_fatal_error()
Call std::quick_exit(3)
Definition: srv0start.cc:3684
srv_shutdown_exit_threads
void srv_shutdown_exit_threads()
Attempt to shutdown all background threads created by InnoDB.
Definition: srv0start.cc:1653
SRV_SHUTDOWN_FLUSH_PHASE
@ 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
void srv_shutdown()
Shut down the InnoDB database.
Definition: srv0start.cc:3511
srv_pre_dd_shutdown
void srv_pre_dd_shutdown()
Shut down all InnoDB background tasks that may look up objects in the data dictionary.
Definition: srv0start.cc:3102
SRV_SHUTDOWN_MASTER_STOP
@ SRV_SHUTDOWN_MASTER_STOP
Stopping the master thread.
Definition: srv0shutdown.h:94
SRV_SHUTDOWN_DD
@ SRV_SHUTDOWN_DD
Shutting down the DD.
Definition: srv0shutdown.h:75
SRV_SHUTDOWN_PURGE
@ SRV_SHUTDOWN_PURGE
Stopping the purge threads.
Definition: srv0shutdown.h:72
srv_shutdown_state
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