MySQL  8.0.20
Source Code Documentation
srv0start.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2019, 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 /** Parse temporary tablespace configuration.
70  @return true if ok, false on parse error */
72  char *str); /*!< in/out: the data file path string */
73 /** Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
74  and srv_parse_log_group_home_dirs(). */
75 void srv_free_paths_and_sizes(void);
76 
77 /** Adds a slash or a backslash to the end of a string if it is missing
78  and the string is not empty.
79  @return string which has the separator if the string is not empty */
81  char *str); /*!< in: null-terminated character string */
82 #ifndef UNIV_HOTBACKUP
83 
84 /** Upgrade undo tablespaces by deleting the old undo tablespaces
85 referenced by the TRX_SYS page.
86 @return error code */
88 
89 /** Start InnoDB.
90 @param[in] create_new_db Whether to create a new database
91 @return DB_SUCCESS or error code */
92 dberr_t srv_start(bool create_new_db) MY_ATTRIBUTE((warn_unused_result));
93 
94 /** Fix up an undo tablespace if it was in the process of being truncated
95 when the server crashed. This is the second call and is done after the DD
96 is available so now we know the space_name, file_name and previous space_id.
97 @param[in] space_name undo tablespace name
98 @param[in] file_name undo tablespace file name
99 @param[in] space_id undo tablespace ID
100 @return error code */
101 dberr_t srv_undo_tablespace_fixup(const char *space_name, const char *file_name,
102  space_id_t space_id);
103 
104 /** On a restart, initialize the remaining InnoDB subsystems so that
105 any tables (including data dictionary tables) can be accessed. */
107 
108 /** Start up the InnoDB service threads which are independent of DDL recovery
109 @param[in] bootstrap True if this is in bootstrap */
110 void srv_start_threads(bool bootstrap);
111 
112 /** Start the remaining InnoDB service threads which must wait for
113 complete DD recovery(post the DDL recovery) */
115 
116 /** Shut down all InnoDB background tasks that may look up objects in
117 the data dictionary. */
118 void srv_pre_dd_shutdown();
119 
120 /** Shut down the InnoDB database. */
121 void srv_shutdown();
122 
123 /** Shut down all InnoDB background threads. */
125 
126 /** Start purge threads. During upgrade we start
127 purge threads early to apply purge. */
129 
130 /** If early redo/undo log encryption processing is done.
131 @return true if it's done. */
133 
134 /** Copy the file path component of the physical file to parameter. It will
135  copy up to and including the terminating path separator.
136  @return number of bytes copied or ULINT_UNDEFINED if destination buffer
137  is smaller than the path to be copied. */
138 ulint srv_path_copy(char *dest, /*!< out: destination buffer */
139  ulint dest_len, /*!< in: max bytes to copy */
140  const char *basedir, /*!< in: base directory */
141  const char *table_name) /*!< in: source table name */
142  MY_ATTRIBUTE((warn_unused_result));
143 
144 /** Get the encryption-data filename from the table name for a
145 single-table tablespace.
146 @param[in] table table object
147 @param[out] filename filename
148 @param[in] max_len filename max length */
150  ulint max_len);
151 #endif /* !UNIV_HOTBACKUP */
152 
153 /** true if the server is being started */
154 extern bool srv_is_being_started;
155 /** true if SYS_TABLESPACES is available for lookups */
156 extern bool srv_sys_tablespaces_open;
157 /** true if the server is being started, before rolling back any
158 incomplete transactions */
160 #ifdef UNIV_DEBUG
161 /** true if srv_pre_dd_shutdown() has been completed */
162 extern bool srv_is_being_shutdown;
163 #endif /* UNIV_DEBUG */
164 
165 /** TRUE if a raw partition is in use */
166 extern ibool srv_start_raw_disk_in_use;
167 
168 /** Shutdown state */
170  /** Database running normally. */
172 
173  /** Stopping all extra background tasks. This includes the purge threads and
174  every other thread in Srv_threads except:
175  - master thread,
176  - redo log threads,
177  - page cleaner threads,
178  - archiver threads.
179  At this phase the purge threads must be stopped. */
181 
182  /** Stopping the master thread. */
184 
185  /** Once we enter this phase the page_cleaners can clean up the buffer pool
186  and exit. Redo log threads write and flush the log buffer and exit after
187  page cleaners (and within this phase). Then we switch to the LAST_PHASE. */
189 
190  /** Last phase after ensuring that all data have been flushed to disk and
191  the flushed_lsn has been updated in the header of system tablespace.
192  During this phase we close all files and ensure archiver has archived all. */
194 
195  /** Exit all threads and free resources. */
197 };
198 
199 /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
200 SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
201 extern std::atomic<enum srv_shutdown_t> srv_shutdown_state;
202 
203 /** Call exit(3) */
204 void srv_fatal_error() MY_ATTRIBUTE((noreturn));
205 /**
206 Shutdown all background threads created by InnoDB. */
208 
209 #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:3464
void srv_dict_recover_on_restart()
On a restart, initialize the remaining InnoDB subsystems so that any tables (including data dictionar...
Definition: srv0start.cc:2890
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:1520
dberr_t srv_start(bool create_new_db)
Start InnoDB.
Definition: srv0start.cc:1873
Once we enter this phase the page_cleaners can clean up the buffer pool and exit. ...
Definition: srv0start.h:188
bool srv_parse_temp_data_file_paths_and_sizes(char *str)
Parse temporary tablespace configuration.
Stopping all extra background tasks.
Definition: srv0start.h:180
void srv_start_purge_threads()
Start purge threads.
Definition: srv0start.cc:2918
void srv_pre_dd_shutdown()
Shut down all InnoDB background tasks that may look up objects in the data dictionary.
Definition: srv0start.cc:3088
void srv_start_threads(bool bootstrap)
Start up the InnoDB service threads which are independent of DDL recovery.
Definition: srv0start.cc:2946
bool is_early_redo_undo_encryption_done()
If early redo/undo log encryption processing is done.
Definition: srv0start.cc:2910
bool srv_is_being_shutdown
true if srv_pre_dd_shutdown() has been completed
Definition: srv0start.cc:146
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:812
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:1341
void srv_fatal_error()
Call exit(3)
Definition: srv0start.cc:3641
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
Stopping the master thread.
Definition: srv0start.h:183
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:3021
srv_shutdown_t
Shutdown state.
Definition: srv0start.h:169
std::atomic< enum srv_shutdown_t > srv_shutdown_state
At a shutdown this value climbs from SRV_SHUTDOWN_NONE to SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDO...
Definition: srv0start.cc:170
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
const char * filename
Definition: pfs_example_component_population.cc:64
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:196
void srv_shutdown_all_bg_threads()
Shut down all InnoDB background threads.
Definition: srv0start.cc:1673
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:193
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:3623
Database running normally.
Definition: srv0start.h:171
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
const char * table_name
Definition: rules_table_service.cc:55