Debian Codegraph @

storage/innobase/include/fsp0sysspace.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 2013, 2026, Oracle and/or its affiliates.
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 designed to work 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 either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/fsp0sysspace.h
29 Multi file, shared, system tablespace implementation.
30
31 Created 2013-7-26 by Kevin Lewis
32 *******************************************************/
33
34 #ifndef fsp0sysspace_h
35 #define fsp0sysspace_h
36
37 #include "fsp0space.h"
38 #include "univ.i"
39
40 #ifdef UNIV_HOTBACKUP
41 #include "srv0srv.h"
42 #endif
43
44 /** If the last data file is auto-extended, we add this many pages to it
45 at a time. We have to make this public because it is a config variable. */
46 extern ulong sys_tablespace_auto_extend_increment;
47
48 #ifdef UNIV_DEBUG
49 /** Control if extra debug checks need to be done for temporary tablespace.
50 Default = true that is disable such checks.
51 This variable is not exposed to end-user but still kept as variable for
52 developer to enable it during debug. */
53 extern bool srv_skip_temp_table_checks_debug;
54 #endif /* UNIV_DEBUG */
55
56 /** Data structure that contains the information about shared tablespaces.
57 Currently this can be the system tablespace or a temporary table tablespace */
58 class SysTablespace : public Tablespace {
59 public:
60 SysTablespace()
61 : m_auto_extend_last_file(),
62 m_last_file_size_max(),
63 m_created_new_raw(),
64 m_is_tablespace_full(false),
65 m_sanity_checks_done(false) {
66 /* No op */
67 }
68
69 ~SysTablespace() override { shutdown(); }
70
71 /** Set tablespace full status
72 @param[in] is_full true if full */
73 void set_tablespace_full_status(bool is_full) {
74 m_is_tablespace_full = is_full;
75 }
76
77 /** Get tablespace full status
78 @return true if table is full */
79 bool get_tablespace_full_status() { return (m_is_tablespace_full); }
80
81 /** Set sanity check status
82 @param[in] status true if sanity checks are done */
83 void set_sanity_check_status(bool status) { m_sanity_checks_done = status; }
84
85 /** Get sanity check status
86 @return true if sanity checks are done */
87 bool get_sanity_check_status() { return (m_sanity_checks_done); }
88
89 /** Parse the input params and populate member variables.
90 @param[in] filepath_spec path to data files
91 @param[in] supports_raw true if the tablespace supports raw devices
92 @return true on success parse */
93 bool parse_params(const char *filepath_spec, bool supports_raw);
94
95 /** Check the data file specification.
96 @param[in] create_new_db True if a new database is to be created
97 @param[in] min_expected_size Minimum expected tablespace size in bytes
98 @return DB_SUCCESS if all OK else error code */
99 dberr_t check_file_spec(bool create_new_db, ulint min_expected_size);
100
101 /** Free the memory allocated by parse() */
102 void shutdown();
103
104 /**
105 @return true if a new raw device was created. */
106 bool created_new_raw() const { return (m_created_new_raw); }
107
108 /**
109 @return auto_extend value setting */
110 ulint can_auto_extend_last_file() const { return (m_auto_extend_last_file); }
111
112 /** Set the last file size.
113 @param[in] size the size to set */
114 void set_last_file_size(page_no_t size) {
115 ut_ad(!m_files.empty());
116 m_files.back().m_size = size;
117 }
118
119 /** Get the number of pages in the last data file in the tablespace
120 @return the size of the last data file in the array */
121 page_no_t last_file_size() const {
122 ut_ad(!m_files.empty());
123 return (m_files.back().m_size);
124 }
125
126 /**
127 @return the autoextend increment in pages. */
128 page_no_t get_autoextend_increment() const {
129 return (sys_tablespace_auto_extend_increment *
130 ((1024 * 1024) / UNIV_PAGE_SIZE));
131 }
132
133 /** Round the number of bytes in the file to MegaBytes
134 and then return the number of pages.
135 Note: Only system tablespaces are required to be at least
136 1 megabyte.
137 @return the number of pages in the file. */
138 page_no_t get_pages_from_size(os_offset_t size) {
139 return static_cast<page_no_t>(
140 ((size / (1024 * 1024)) * ((1024 * 1024) / UNIV_PAGE_SIZE)));
141 }
142
143 /**
144 @return next increment size */
145 page_no_t get_increment() const;
146
147 /** Open or create the data files
148 @param[in] is_temp whether this is a temporary tablespace
149 @param[in] create_new_db whether we are creating a new database
150 @param[out] sum_new_sizes sum of sizes of the new files added
151 @param[out] flush_lsn lsn stored at offset FIL_PAGE_FILE_FLUSH_LSN
152 in the system tablespace header; might be
153 nullptr if not interested in having that
154 @return DB_SUCCESS or error code */
155 [[nodiscard]] dberr_t open_or_create(bool is_temp, bool create_new_db,
156 page_no_t *sum_new_sizes,
157 lsn_t *flush_lsn);
158
159 private:
160 /** Check the tablespace header for this tablespace.
161 @param[out] flushed_lsn value stored at offset FIL_PAGE_FILE_FLUSH_LSN
162 @return DB_SUCCESS or error code */
163 dberr_t read_lsn_and_check_flags(lsn_t *flushed_lsn);
164
165 /** Note that the data file was not found.
166 @param[in] file data file object
167 @param[in] create_new_db true if a new instance to be created
168 @return DB_SUCCESS or error code */
169 dberr_t file_not_found(Datafile &file, bool create_new_db);
170
171 /** Note that the data file was found.
172 @param[in,out] file data file object */
173 void file_found(Datafile &file);
174
175 /** Create a data file.
176 @param[in,out] file data file object
177 @return DB_SUCCESS or error code */
178 dberr_t create(Datafile &file);
179
180 /** Create a data file.
181 @param[in,out] file data file object
182 @return DB_SUCCESS or error code */
183 dberr_t create_file(Datafile &file);
184
185 /** Open a data file.
186 @param[in,out] file data file object
187 @return DB_SUCCESS or error code */
188 dberr_t open_file(Datafile &file);
189
190 /** Set the size of the file.
191 @param[in,out] file data file object
192 @return DB_SUCCESS or error code */
193 dberr_t set_size(Datafile &file);
194
195 private:
196 /* Put the pointer to the next byte after a valid file name.
197 Note that we must step over the ':' in a Windows filepath.
198 A Windows path normally looks like C:\ibdata\ibdata1:1G, but
199 a Windows raw partition may have a specification like
200 \\.\C::1Gnewraw or \\.\PHYSICALDRIVE2:1Gnewraw.
201 @param[in] str system tablespace file path spec
202 @return next character in string after the file name */
203 static char *parse_file_name(char *ptr);
204
205 /** Convert a numeric string that optionally ends in upper or lower
206 case G, M, or K, rounding off to the nearest number of megabytes.
207 Then return the number of pages in the file.
208 @param[in,out] ptr Pointer to a numeric string
209 @return the number of pages in the file. */
210 page_no_t parse_units(char *&ptr);
211
212 enum file_status_t {
213 FILE_STATUS_VOID = 0, /** status not set */
214 FILE_STATUS_RW_PERMISSION_ERROR, /** permission error */
215 FILE_STATUS_READ_WRITE_ERROR, /** not readable/writable */
216 FILE_STATUS_NOT_REGULAR_FILE_ERROR /** not a regular file */
217 };
218
219 /** Verify the size of the physical file
220 @param[in] file data file object
221 @return DB_SUCCESS if OK else error code. */
222 dberr_t check_size(Datafile &file);
223
224 /** Check if a file can be opened in the correct mode.
225 @param[in,out] file data file object
226 @param[out] reason exact reason if file_status check failed.
227 @return DB_SUCCESS or error code. */
228 dberr_t check_file_status(const Datafile &file, file_status_t &reason);
229
230 /* DATA MEMBERS */
231
232 /** if true, then we auto-extend the last data file */
233 bool m_auto_extend_last_file;
234
235 /** if != 0, this tells the max size auto-extending may increase the
236 last data file size */
237 page_no_t m_last_file_size_max;
238
239 /** If the following is true we do not allow
240 inserts etc. This protects the user from forgetting
241 the 'newraw' keyword to my.cnf */
242 bool m_created_new_raw;
243
244 /** Tablespace full status */
245 bool m_is_tablespace_full;
246
247 /** if false, then sanity checks are still pending */
248 bool m_sanity_checks_done;
249 };
250
251 /* GLOBAL OBJECTS */
252
253 /** The control info of the system tablespace. */
254 extern SysTablespace srv_sys_space;
255
256 /** The control info of a temporary table shared tablespace. */
257 extern SysTablespace srv_tmp_space;
258 #endif /* fsp0sysspace_h */