1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2017, 2020, MariaDB Corporation.
5 
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
17 
18 *****************************************************************************/
19 
20 /**************************************************//**
21 @file include/srv0start.h
22 Starts the Innobase database server
23 
24 Created 10/10/1995 Heikki Tuuri
25 *******************************************************/
26 
27 #pragma once
28 
29 #include "log0log.h"
30 #include "ut0byte.h"
31 
32 // Forward declaration
33 struct dict_table_t;
34 
35 /** Open the configured number of dedicated undo tablespaces.
36 @param[in]	create_new_db	whether the database is being initialized
37 @return DB_SUCCESS or error code */
38 dberr_t
39 srv_undo_tablespaces_init(bool create_new_db);
40 
41 /** Start InnoDB.
42 @param[in]	create_new_db	whether to create a new database
43 @return DB_SUCCESS or error code */
44 dberr_t srv_start(bool create_new_db);
45 
46 /**
47   Shutdown purge to make sure that there is no possibility that we call any
48   plugin code (e.g., audit) inside virtual column computation.
49 */
50 void innodb_preshutdown();
51 
52 /** Shut down InnoDB. */
53 void innodb_shutdown();
54 
55 /** Shut down background threads that can generate undo log. */
56 void srv_shutdown_bg_undo_sources();
57 
58 /*************************************************************//**
59 Copy the file path component of the physical file to parameter. It will
60 copy up to and including the terminating path separator.
61 @return number of bytes copied or ULINT_UNDEFINED if destination buffer
62 	is smaller than the path to be copied. */
63 ulint
64 srv_path_copy(
65 /*==========*/
66 	char*		dest,		/*!< out: destination buffer */
67 	ulint		dest_len,	/*!< in: max bytes to copy */
68 	const char*	basedir,	/*!< in: base directory */
69 	const char*	table_name)	/*!< in: source table name */
70 	MY_ATTRIBUTE((nonnull, warn_unused_result));
71 
72 /** Get the meta-data filename from the table name for a
73 single-table tablespace.
74 @param[in]	table		table object
75 @param[out]	filename	filename
76 @param[in]	max_len		filename max length */
77 void
78 srv_get_meta_data_filename(
79 	dict_table_t*	table,
80 	char*		filename,
81 	ulint		max_len);
82 
83 /** Get the encryption-data filename from the table name for a
84 single-table tablespace.
85 @param[in]	table		table object
86 @param[out]	filename	filename
87 @param[in]	max_len		filename max length */
88 void
89 srv_get_encryption_data_filename(
90 	dict_table_t*	table,
91 	char*		filename,
92 	ulint		max_len);
93 
94 /** Log sequence number at shutdown */
95 extern	lsn_t	srv_shutdown_lsn;
96 
97 /** TRUE if the server is being started */
98 extern	bool	srv_is_being_started;
99 /** TRUE if SYS_TABLESPACES is available for lookups */
100 extern	bool	srv_sys_tablespaces_open;
101 /** TRUE if the server is being started, before rolling back any
102 incomplete transactions */
103 extern	bool	srv_startup_is_before_trx_rollback_phase;
104 
105 /** TRUE if a raw partition is in use */
106 extern	ibool	srv_start_raw_disk_in_use;
107 
108 /** Shutdown state */
109 enum srv_shutdown_t {
110 	SRV_SHUTDOWN_NONE = 0,	/*!< Database running normally */
111 	/** Shutdown initiated in srv_shutdown_bg_undo_sources() */
112 	SRV_SHUTDOWN_INITIATED,
113 	SRV_SHUTDOWN_CLEANUP,	/*!< Cleaning up in
114 				logs_empty_and_mark_files_at_shutdown() */
115 	SRV_SHUTDOWN_LAST_PHASE,/*!< Last phase after ensuring that
116 				the buffer pool can be freed: flush
117 				all file spaces and close all files */
118 	SRV_SHUTDOWN_EXIT_THREADS/*!< Exit all threads */
119 };
120 
121 /** Whether any undo log records can be generated */
122 extern bool srv_undo_sources;
123 
124 /** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
125 SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
126 extern	enum srv_shutdown_t	srv_shutdown_state;
127 
128 /** Files comprising the system tablespace */
129 extern pfs_os_file_t	files[1000];
130