1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2021, Oracle and/or its affiliates.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation.  The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, 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 Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 *****************************************************************************/
26 
27 /**************************************************//**
28 @file include/srv0start.h
29 Starts the Innobase database server
30 
31 Created 10/10/1995 Heikki Tuuri
32 *******************************************************/
33 
34 #ifndef srv0start_h
35 #define srv0start_h
36 
37 #include "univ.i"
38 #include "log0log.h"
39 #include "ut0byte.h"
40 
41 // Forward declaration
42 struct dict_table_t;
43 
44 #ifdef NDEBUG
45 # define RECOVERY_CRASH(x) do {} while(0)
46 #else
47 # define RECOVERY_CRASH(x) do {						\
48 	if (srv_force_recovery_crash == x) {				\
49 		fprintf(stderr, "innodb_force_recovery_crash=%lu\n",	\
50 			srv_force_recovery_crash);			\
51 		fflush(stderr);						\
52 		_exit(3);						\
53 	}								\
54 } while (0)
55 #endif /* NDEBUG */
56 
57 /** Log 'spaces' have id's >= this */
58 #define SRV_LOG_SPACE_FIRST_ID		0xFFFFFFF0UL
59 
60 /** If buffer pool is less than the size,
61 only one buffer pool instance is used. */
62 #define BUF_POOL_SIZE_THRESHOLD		(1024 * 1024 * 1024)
63 
64 /*********************************************************************//**
65 Parse temporary tablespace configuration.
66 @return true if ok, false on parse error */
67 bool
68 srv_parse_temp_data_file_paths_and_sizes(
69 /*=====================================*/
70 	char*	str);	/*!< in/out: the data file path string */
71 /*********************************************************************//**
72 Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
73 and srv_parse_log_group_home_dirs(). */
74 void
75 srv_free_paths_and_sizes(void);
76 /*==========================*/
77 /*********************************************************************//**
78 Adds a slash or a backslash to the end of a string if it is missing
79 and the string is not empty.
80 @return string which has the separator if the string is not empty */
81 char*
82 srv_add_path_separator_if_needed(
83 /*=============================*/
84 	char*	str);	/*!< in: null-terminated character string */
85 #ifndef UNIV_HOTBACKUP
86 /****************************************************************//**
87 Starts Innobase and creates a new database if database files
88 are not found and the user wants.
89 @return DB_SUCCESS or error code */
90 dberr_t
91 innobase_start_or_create_for_mysql(void);
92 /*====================================*/
93 /****************************************************************//**
94 Shuts down the Innobase database.
95 @return DB_SUCCESS or error code */
96 dberr_t
97 innobase_shutdown_for_mysql(void);
98 
99 /********************************************************************
100 Signal all per-table background threads to shutdown, and wait for them to do
101 so. */
102 void
103 srv_shutdown_table_bg_threads(void);
104 /*=============================*/
105 
106 /*************************************************************//**
107 Copy the file path component of the physical file to parameter. It will
108 copy up to and including the terminating path separator.
109 @return number of bytes copied or ULINT_UNDEFINED if destination buffer
110 	is smaller than the path to be copied. */
111 ulint
112 srv_path_copy(
113 /*==========*/
114 	char*		dest,		/*!< out: destination buffer */
115 	ulint		dest_len,	/*!< in: max bytes to copy */
116 	const char*	basedir,	/*!< in: base directory */
117 	const char*	table_name)	/*!< in: source table name */
118 	MY_ATTRIBUTE((nonnull, warn_unused_result));
119 
120 /**
121 Shutdown all background threads created by InnoDB. */
122 void
123 srv_shutdown_all_bg_threads();
124 
125 /** Get the meta-data filename from the table name for a
126 single-table tablespace.
127 @param[in]	table		table object
128 @param[out]	filename	filename
129 @param[in]	max_len		filename max length */
130 void
131 srv_get_meta_data_filename(
132 	dict_table_t*	table,
133 	char*		filename,
134 	ulint		max_len);
135 
136 /** Get the encryption-data filename from the table name for a
137 single-table tablespace.
138 @param[in]	table		table object
139 @param[out]	filename	filename
140 @param[in]	max_len		filename max length */
141 void
142 srv_get_encryption_data_filename(
143 	dict_table_t*	table,
144 	char*		filename,
145 	ulint		max_len);
146 
147 /** Log sequence number at shutdown */
148 extern	lsn_t	srv_shutdown_lsn;
149 /** Log sequence number immediately after startup */
150 extern	lsn_t	srv_start_lsn;
151 
152 /** TRUE if the server is being started */
153 extern	bool	srv_is_being_started;
154 /** TRUE if SYS_TABLESPACES is available for lookups */
155 extern	bool	srv_sys_tablespaces_open;
156 /** TRUE if the server was successfully started */
157 extern	ibool	srv_was_started;
158 /** TRUE if the server is being started, before rolling back any
159 incomplete transactions */
160 extern	bool	srv_startup_is_before_trx_rollback_phase;
161 
162 /** TRUE if a raw partition is in use */
163 extern	ibool	srv_start_raw_disk_in_use;
164 
165 /** UNDO tablespaces starts with space id. */
166 extern	ulint	srv_undo_space_id_start;
167 
168 /** Shutdown state */
169 enum srv_shutdown_t {
170 	SRV_SHUTDOWN_NONE = 0,	/*!< Database running normally */
171 	SRV_SHUTDOWN_CLEANUP,	/*!< Cleaning up in
172 				logs_empty_and_mark_files_at_shutdown() */
173 	SRV_SHUTDOWN_FLUSH_PHASE,/*!< At this phase the master and the
174 				purge threads must have completed their
175 				work. Once we enter this phase the
176 				page_cleaner can clean up the buffer
177 				pool and exit */
178 	SRV_SHUTDOWN_LAST_PHASE,/*!< Last phase after ensuring that
179 				the buffer pool can be freed: flush
180 				all file spaces and close all files */
181 	SRV_SHUTDOWN_EXIT_THREADS/*!< Exit all threads */
182 };
183 
184 /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
185 SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
186 extern	enum srv_shutdown_t	srv_shutdown_state;
187 #endif /* !UNIV_HOTBACKUP */
188 
189 #endif
190