MySQL  8.0.18
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 @param[in] scan_directories Scan directories for .ibd files for
92  recovery "dir1;dir2; ... dirN"
93 @return DB_SUCCESS or error code */
94 dberr_t srv_start(bool create_new_db, const std::string &scan_directories);
95 
96 /** Fix up an undo tablespace if it was in the process of being truncated
97 when the server crashed. This is the second call and is done after the DD
98 is available so now we know the space_name, file_name and previous space_id.
99 @param[in] space_name undo tablespace name
100 @param[in] file_name undo tablespace file name
101 @param[in] space_id undo tablespace ID
102 @return error code */
103 dberr_t srv_undo_tablespace_fixup(const char *space_name, const char *file_name,
104  space_id_t space_id);
105 
106 /** On a restart, initialize the remaining InnoDB subsystems so that
107 any tables (including data dictionary tables) can be accessed. */
109 
110 /** Start up the InnoDB service threads which are independent of DDL recovery
111 @param[in] bootstrap True if this is in bootstrap */
112 void srv_start_threads(bool bootstrap);
113 
114 /** Start the remaining InnoDB service threads which must wait for
115 complete DD recovery(post the DDL recovery) */
117 
118 /** Shut down all InnoDB background tasks that may look up objects in
119 the data dictionary. */
120 void srv_pre_dd_shutdown();
121 
122 /** Shut down the InnoDB database. */
123 void srv_shutdown();
124 
125 /** Shut down all InnoDB background threads. */
127 
128 /** Start purge threads. During upgrade we start
129 purge threads early to apply purge. */
131 
132 /** If early redo/undo log encryption processing is done.
133 @return true if it's done. */
135 
136 /** Copy the file path component of the physical file to parameter. It will
137  copy up to and including the terminating path separator.
138  @return number of bytes copied or ULINT_UNDEFINED if destination buffer
139  is smaller than the path to be copied. */
140 ulint srv_path_copy(char *dest, /*!< out: destination buffer */
141  ulint dest_len, /*!< in: max bytes to copy */
142  const char *basedir, /*!< in: base directory */
143  const char *table_name) /*!< in: source table name */
144  MY_ATTRIBUTE((warn_unused_result));
145 
146 /** Get the encryption-data filename from the table name for a
147 single-table tablespace.
148 @param[in] table table object
149 @param[out] filename filename
150 @param[in] max_len filename max length
151 @param[in] convert convert to lower case */
153  ulint max_len, bool convert = false);
154 #endif /* !UNIV_HOTBACKUP */
155 
156 /** true if the server is being started */
157 extern bool srv_is_being_started;
158 /** true if SYS_TABLESPACES is available for lookups */
159 extern bool srv_sys_tablespaces_open;
160 /** true if the server is being started, before rolling back any
161 incomplete transactions */
163 #ifdef UNIV_DEBUG
164 /** true if srv_pre_dd_shutdown() has been completed */
165 extern bool srv_is_being_shutdown;
166 #endif /* UNIV_DEBUG */
167 
168 /** TRUE if a raw partition is in use */
169 extern ibool srv_start_raw_disk_in_use;
170 
171 /** Shutdown state */
173  /** Database running normally. */
175 
176  /** Stopping all extra background tasks. This includes the purge threads and
177  every other thread in Srv_threads except:
178  - master thread,
179  - redo log threads,
180  - page cleaner threads,
181  - archiver threads.
182  At this phase the purge threads must be stopped. */
184 
185  /** Stopping the master thread. */
187 
188  /** Once we enter this phase the page_cleaners can clean up the buffer pool
189  and exit. Redo log threads write and flush the log buffer and exit after
190  page cleaners (and within this phase). Then we switch to the LAST_PHASE. */
192 
193  /** Last phase after ensuring that all data have been flushed to disk and
194  the flushed_lsn has been updated in the header of system tablespace.
195  During this phase we close all files and ensure archiver has archived all. */
197 
198  /** Exit all threads and free resources. */
200 };
201 
202 /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
203 SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
204 extern std::atomic<enum srv_shutdown_t> srv_shutdown_state;
205 
206 /** Call exit(3) */
207 void srv_fatal_error() MY_ATTRIBUTE((noreturn));
208 /**
209 Shutdown all background threads created by InnoDB. */
211 
212 #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:3440
void srv_dict_recover_on_restart()
On a restart, initialize the remaining InnoDB subsystems so that any tables (including data dictionar...
Definition: srv0start.cc:2863
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:1529
Once we enter this phase the page_cleaners can clean up the buffer pool and exit. ...
Definition: srv0start.h:191
bool srv_parse_temp_data_file_paths_and_sizes(char *str)
Parse temporary tablespace configuration.
Stopping all extra background tasks.
Definition: srv0start.h:183
void srv_start_purge_threads()
Start purge threads.
Definition: srv0start.cc:2891
dberr_t srv_start(bool create_new_db, const std::string &scan_directories)
Start InnoDB.
Definition: srv0start.cc:1874
void srv_get_encryption_data_filename(dict_table_t *table, char *filename, ulint max_len, bool convert=false)
Get the encryption-data filename from the table name for a single-table tablespace.
Definition: srv0start.cc:3593
void srv_pre_dd_shutdown()
Shut down all InnoDB background tasks that may look up objects in the data dictionary.
Definition: srv0start.cc:3060
void srv_start_threads(bool bootstrap)
Start up the InnoDB service threads which are independent of DDL recovery.
Definition: srv0start.cc:2920
bool is_early_redo_undo_encryption_done()
If early redo/undo log encryption processing is done.
Definition: srv0start.cc:2883
bool srv_is_being_shutdown
true if srv_pre_dd_shutdown() has been completed
Definition: srv0start.cc:144
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
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:1339
void srv_fatal_error()
Call exit(3)
Definition: srv0start.cc:3621
ibool srv_start_raw_disk_in_use
TRUE if a raw partition is in use.
Definition: srv0start.cc:131
dberr_t
Definition: db0err.h:38
bool srv_sys_tablespaces_open
true if SYS_TABLESPACES is available for lookups
Definition: srv0start.cc:139
Stopping the master thread.
Definition: srv0start.h:186
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:2995
srv_shutdown_t
Shutdown state.
Definition: srv0start.h:172
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:168
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:199
void srv_shutdown_all_bg_threads()
Shut down all InnoDB background threads.
Definition: srv0start.cc:1669
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:196
bool srv_is_being_started
true if the server is being started
Definition: srv0start.cc:137
Database running normally.
Definition: srv0start.h:174
bool srv_startup_is_before_trx_rollback_phase
true if the server is being started, before rolling back any incomplete transactions ...
Definition: srv0start.cc:142
const char * table_name
Definition: rules_table_service.cc:55