MySQL  8.0.21
Source Code Documentation
srv0start.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2020, Oracle and/or its affiliates. All Rights Reserved.
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/srv0start.h
28  Starts the Innobase database server
29 
30  Created 10/10/1995 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef srv0start_h
34 #define srv0start_h
35 
36 #include "log0types.h"
37 #include "os0thread-create.h"
38 #ifndef UNIV_HOTBACKUP
39 #include "sync0rw.h"
40 #endif /* !UNIV_HOTBACKUP */
41 #include "trx0purge.h"
42 #include "univ.i"
43 #include "ut0byte.h"
44 
45 // Forward declaration
46 struct dict_table_t;
47 
48 #ifndef UNIV_DEBUG
49 #define RECOVERY_CRASH(x) \
50  do { \
51  } while (0)
52 #else
53 #define RECOVERY_CRASH(x) \
54  do { \
55  if (srv_force_recovery_crash == x) { \
56  flush_error_log_messages(); \
57  fprintf(stderr, "innodb_force_recovery_crash=%lu\n", \
58  srv_force_recovery_crash); \
59  fflush(stderr); \
60  _exit(3); \
61  } \
62  } while (0)
63 #endif /* UNIV_DEBUG */
64 
65 /** If buffer pool is less than the size,
66 only one buffer pool instance is used. */
67 #define BUF_POOL_SIZE_THRESHOLD (1024 * 1024 * 1024)
68 
69 /** Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
70  and srv_parse_log_group_home_dirs(). */
71 void srv_free_paths_and_sizes(void);
72 
73 /** Adds a slash or a backslash to the end of a string if it is missing
74  and the string is not empty.
75  @return string which has the separator if the string is not empty */
77  char *str); /*!< in: null-terminated character string */
78 #ifndef UNIV_HOTBACKUP
79 
80 /** Open an undo tablespace.
81 @param[in] undo_space Undo tablespace
82 @return DB_SUCCESS or error code */
84 
85 /** Upgrade undo tablespaces by deleting the old undo tablespaces
86 referenced by the TRX_SYS page.
87 @return error code */
89 
90 /** Start InnoDB.
91 @param[in] create_new_db Whether to create a new database
92 @return DB_SUCCESS or error code */
93 dberr_t srv_start(bool create_new_db) MY_ATTRIBUTE((warn_unused_result));
94 
95 /** Fix up an undo tablespace if it was in the process of being truncated
96 when the server crashed. This is the second call and is done after the DD
97 is available so now we know the space_name, file_name and previous space_id.
98 @param[in] space_name undo tablespace name
99 @param[in] file_name undo tablespace file name
100 @param[in] space_id undo tablespace ID
101 @return error code */
102 dberr_t srv_undo_tablespace_fixup(const char *space_name, const char *file_name,
103  space_id_t space_id);
104 
105 /** On a restart, initialize the remaining InnoDB subsystems so that
106 any tables (including data dictionary tables) can be accessed. */
108 
109 /** Start up the InnoDB service threads which are independent of DDL recovery
110 @param[in] bootstrap True if this is in bootstrap */
111 void srv_start_threads(bool bootstrap);
112 
113 /** Start the remaining InnoDB service threads which must wait for
114 complete DD recovery(post the DDL recovery) */
116 
117 /** Shut down all InnoDB background tasks that may look up objects in
118 the data dictionary. */
119 void srv_pre_dd_shutdown();
120 
121 /** Shut down the InnoDB database. */
122 void srv_shutdown();
123 
124 /** Start purge threads. During upgrade we start
125 purge threads early to apply purge. */
127 
128 /** If early redo/undo log encryption processing is done.
129 @return true if it's done. */
131 
132 /** Copy the file path component of the physical file to parameter. It will
133  copy up to and including the terminating path separator.
134  @return number of bytes copied or ULINT_UNDEFINED if destination buffer
135  is smaller than the path to be copied. */
136 ulint srv_path_copy(char *dest, /*!< out: destination buffer */
137  ulint dest_len, /*!< in: max bytes to copy */
138  const char *basedir, /*!< in: base directory */
139  const char *table_name) /*!< in: source table name */
140  MY_ATTRIBUTE((warn_unused_result));
141 
142 /** Get the encryption-data filename from the table name for a
143 single-table tablespace.
144 @param[in] table table object
145 @param[out] filename filename
146 @param[in] max_len filename max length */
148  ulint max_len);
149 #endif /* !UNIV_HOTBACKUP */
150 
151 /** true if the server is being started */
152 extern bool srv_is_being_started;
153 /** true if SYS_TABLESPACES is available for lookups */
154 extern bool srv_sys_tablespaces_open;
155 /** true if the server is being started, before rolling back any
156 incomplete transactions */
158 
159 /** TRUE if a raw partition is in use */
160 extern ibool srv_start_raw_disk_in_use;
161 
162 /** Shutdown state */
164  /** Database running normally. */
166 
167  /** Shutdown has started. Stopping the thread responsible for rollback of
168  recovered transactions. In case of slow shutdown, this implies waiting
169  for completed rollback of all recovered transactions.
170  @remarks Note that user transactions are stopped earlier, when the
171  shutdown state is still equal to SRV_SHUTDOWN_NONE (user transactions
172  are closed when related connections are closed in close_connections()). */
174 
175  /** Stopping threads that might use system transactions or DD objects.
176  This is important because we need to ensure that in the next phase no
177  undo records could be produced (we will be stopping purge threads).
178  After next phase DD is shut down, so also no accesses to DD objects
179  are allowed then. List of threads being stopped within this phase:
180  - dict_stats thread,
181  - fts_optimize thread,
182  - ts_alter_encrypt thread.
183  The master thread exits its main loop and finishes its first phase
184  of shutdown (in which it was allowed to touch DD objects). */
186 
187  /** Stopping the purge threads. Before we enter this phase, we have
188  the guarantee that no new undo records could be produced. */
190 
191  /** Shutting down the DD. */
193 
194  /** Stopping remaining InnoDB background threads except:
195  - the master thread,
196  - redo log threads,
197  - page cleaner threads,
198  - archiver threads.
199  List of threads being stopped within this phase:
200  - lock_wait_timeout thread,
201  - error_monitor thread,
202  - monitor thread,
203  - buf_dump thread,
204  - buf_resize thread.
205  @remarks If your thread might touch DD objects or use system transactions
206  it must be stopped within SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS phase.
207 */
209 
210  /** Stopping the master thread. */
212 
213  /** Once we enter this phase, the page cleaners can clean up the buffer pool
214  and exit. The redo log threads write and flush the log buffer and exit after
215  the page cleaners (and within this phase). */
217 
218  /** Last phase after ensuring that all data have been flushed to disk and
219  the flushed_lsn has been updated in the header of system tablespace.
220  During this phase we close all files and ensure archiver has archived all. */
222 
223  /** Exit all threads and free resources. We might reach this phase in one
224  of two different ways:
225  - after visiting all previous states (usual shutdown),
226  - or during startup when we failed and we abort the startup. */
228 };
229 
230 /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE
231 to SRV_SHUTDOWN_EXIT_THREADS. */
232 extern std::atomic<enum srv_shutdown_t> srv_shutdown_state;
233 
234 /** Call std::quick_exit(3) */
235 void srv_fatal_error() MY_ATTRIBUTE((noreturn));
236 
237 /** Attempt to shutdown all background threads created by InnoDB.
238 NOTE: Does not guarantee they are actually shut down, only does
239 the best effort. Changes state of shutdown to SHUTDOWN_EXIT_THREADS,
240 wakes up the background threads and waits a little bit. It might be
241 used within startup phase or when fatal error is discovered during
242 some IO operation. Therefore you must not assume anything related
243 to the state in which it might be used. */
245 
246 /** Checks if all recovered transactions are supposed to be rolled back
247 before shutdown is ended.
248 @return value of the check */
250 
251 /** Allows to safely check value of the current shutdown state.
252 Note that the current shutdown state might be changed while the
253 check is being executed, but the check is based on a single load
254 of the srv_shutdown_state (atomic global variable). */
255 template <typename F>
257  const auto state = srv_shutdown_state.load();
258  return std::forward<F>(f)(state);
259 }
260 
261 #endif
ulint srv_path_copy(char *dest, ulint dest_len, const char *basedir, const char *table_name)
Copy the file path component of the physical file to parameter.
void srv_shutdown()
Shut down the InnoDB database.
Definition: srv0start.cc:3513
void srv_shutdown_exit_threads()
Attempt to shutdown all background threads created by InnoDB.
Definition: srv0start.cc:1663
void srv_dict_recover_on_restart()
On a restart, initialize the remaining InnoDB subsystems so that any tables (including data dictionar...
Definition: srv0start.cc:2893
The interface to the threading wrapper.
char * srv_add_path_separator_if_needed(char *str)
Adds a slash or a backslash to the end of a string if it is missing and the string is not empty...
Data structure for a database table.
Definition: dict0mem.h:1524
dberr_t srv_start(bool create_new_db)
Start InnoDB.
Definition: srv0start.cc:1867
Once we enter this phase, the page cleaners can clean up the buffer pool and exit.
Definition: srv0start.h:216
Stopping remaining InnoDB background threads except:
Definition: srv0start.h:208
void srv_start_purge_threads()
Start purge threads.
Definition: srv0start.cc:2921
void srv_pre_dd_shutdown()
Shut down all InnoDB background tasks that may look up objects in the data dictionary.
Definition: srv0start.cc:3106
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:3100
void srv_start_threads(bool bootstrap)
Start up the InnoDB service threads which are independent of DDL recovery.
Definition: srv0start.cc:2949
bool is_early_redo_undo_encryption_done()
If early redo/undo log encryption processing is done.
Definition: srv0start.cc:2913
Stopping threads that might use system transactions or DD objects.
Definition: srv0start.h:185
Redo log types.
Purge old versions.
dberr_t srv_undo_tablespace_fixup(const char *space_name, const char *file_name, space_id_t space_id)
Fix up an undo tablespace if it was in the process of being truncated when the server crashed...
Definition: srv0start.cc:809
Shutdown has started.
Definition: srv0start.h:173
The read-write lock (for threads, not for database transactions)
dberr_t srv_undo_tablespaces_upgrade()
Upgrade undo tablespaces by deleting the old undo tablespaces referenced by the TRX_SYS page...
Definition: srv0start.cc:1338
An undo::Tablespace object is used to easily convert between undo_space_id and undo_space_num and to ...
Definition: trx0purge.h:305
void srv_fatal_error()
Call std::quick_exit(3)
Definition: srv0start.cc:3686
ibool srv_start_raw_disk_in_use
TRUE if a raw partition is in use.
Definition: srv0start.cc:133
dberr_t
Definition: db0err.h:38
bool srv_sys_tablespaces_open
true if SYS_TABLESPACES is available for lookups
Definition: srv0start.cc:141
bool srv_shutdown_state_matches(F &&f)
Allows to safely check value of the current shutdown state.
Definition: srv0start.h:256
Stopping the master thread.
Definition: srv0start.h:211
Utilities for byte operations.
void srv_start_threads_after_ddl_recovery()
Start the remaining InnoDB service threads which must wait for complete DD recovery(post the DDL reco...
Definition: srv0start.cc:3024
srv_shutdown_t
Shutdown state.
Definition: srv0start.h:163
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
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
const char * filename
Definition: pfs_example_component_population.cc:64
Stopping the purge threads.
Definition: srv0start.h:189
void srv_free_paths_and_sizes(void)
Frees the memory allocated by srv_parse_data_file_paths_and_sizes() and srv_parse_log_group_home_dirs...
Exit all threads and free resources.
Definition: srv0start.h:227
Shutting down the DD.
Definition: srv0start.h:192
Definition: bootstrap.cc:68
Last phase after ensuring that all data have been flushed to disk and the flushed_lsn has been update...
Definition: srv0start.h:221
bool srv_is_being_started
true if the server is being started
Definition: srv0start.cc:139
void srv_get_encryption_data_filename(dict_table_t *table, char *filename, ulint max_len)
Get the encryption-data filename from the table name for a single-table tablespace.
Definition: srv0start.cc:3668
Database running normally.
Definition: srv0start.h:165
bool srv_startup_is_before_trx_rollback_phase
true if the server is being started, before rolling back any incomplete transactions ...
Definition: srv0start.cc:144
dberr_t srv_undo_tablespace_open(undo::Tablespace &undo_space)
Open an undo tablespace.
Definition: srv0start.cc:872
const char * table_name
Definition: rules_table_service.cc:55