MySQL 8.0.39
Source Code Documentation
fsp0sysspace.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2013, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 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
45at a time. We have to make this public because it is a config variable. */
47
48#ifdef UNIV_DEBUG
49/** Control if extra debug checks need to be done for temporary tablespace.
50Default = true that is disable such checks.
51This variable is not exposed to end-user but still kept as variable for
52developer to enable it during debug. */
54#endif /* UNIV_DEBUG */
55
56/** Data structure that contains the information about shared tablespaces.
57Currently this can be the system tablespace or a temporary table tablespace */
58class SysTablespace : public Tablespace {
59 public:
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 */
80
81 /** Set sanity check status
82 @param[in] status true if sanity checks are done */
84
85 /** Get sanity check status
86 @return true if sanity checks are 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 */
111
112 /** Set the last file size.
113 @param[in] size the size to set */
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 */
122 ut_ad(!m_files.empty());
123 return (m_files.back().m_size);
124 }
125
126 /**
127 @return the autoextend increment in pages. */
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. */
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 */
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 */
179
180 /** Create a data file.
181 @param[in,out] file data file object
182 @return DB_SUCCESS or error code */
184
185 /** Open a data file.
186 @param[in,out] file data file object
187 @return DB_SUCCESS or error code */
189
190 /** Set the size of the file.
191 @param[in,out] file data file object
192 @return DB_SUCCESS or error code */
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
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. */
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. */
229
230 /* DATA MEMBERS */
231
232 /** if true, then we auto-extend the last data file */
234
235 /** if != 0, this tells the max size auto-extending may increase the
236 last data file size */
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 */
243
244 /** Tablespace full status */
246
247 /** if false, then sanity checks are still pending */
249};
250
251/* GLOBAL OBJECTS */
252
253/** The control info of the system tablespace. */
255
256/** The control info of a temporary table shared tablespace. */
258#endif /* fsp0sysspace_h */
uint32_t page_no_t
Page number.
Definition: api0api.h:49
Data file control information.
Definition: fsp0file.h:72
Data structure that contains the information about shared tablespaces.
Definition: fsp0sysspace.h:58
void file_found(Datafile &file)
Note that the data file was found.
Definition: fsp0sysspace.cc:680
dberr_t open_or_create(bool is_temp, bool create_new_db, page_no_t *sum_new_sizes, lsn_t *flush_lsn)
Open or create the data files.
Definition: fsp0sysspace.cc:784
file_status_t
Definition: fsp0sysspace.h:212
@ FILE_STATUS_RW_PERMISSION_ERROR
status not set
Definition: fsp0sysspace.h:214
@ FILE_STATUS_READ_WRITE_ERROR
permission error
Definition: fsp0sysspace.h:215
@ FILE_STATUS_VOID
Definition: fsp0sysspace.h:213
@ FILE_STATUS_NOT_REGULAR_FILE_ERROR
not readable/writable
Definition: fsp0sysspace.h:216
page_no_t m_last_file_size_max
if != 0, this tells the max size auto-extending may increase the last data file size
Definition: fsp0sysspace.h:237
dberr_t create_file(Datafile &file)
Create a data file.
Definition: fsp0sysspace.cc:414
dberr_t check_size(Datafile &file)
Verify the size of the physical file.
Definition: fsp0sysspace.cc:330
dberr_t open_file(Datafile &file)
Open a data file.
Definition: fsp0sysspace.cc:451
bool m_created_new_raw
If the following is true we do not allow inserts etc.
Definition: fsp0sysspace.h:242
void set_last_file_size(page_no_t size)
Set the last file size.
Definition: fsp0sysspace.h:114
page_no_t get_increment() const
Definition: fsp0sysspace.cc:909
bool m_sanity_checks_done
if false, then sanity checks are still pending
Definition: fsp0sysspace.h:248
dberr_t file_not_found(Datafile &file, bool create_new_db)
Note that the data file was not found.
Definition: fsp0sysspace.cc:633
bool m_is_tablespace_full
Tablespace full status.
Definition: fsp0sysspace.h:245
ulint can_auto_extend_last_file() const
Definition: fsp0sysspace.h:110
bool get_tablespace_full_status()
Get tablespace full status.
Definition: fsp0sysspace.h:79
void set_sanity_check_status(bool status)
Set sanity check status.
Definition: fsp0sysspace.h:83
page_no_t last_file_size() const
Get the number of pages in the last data file in the tablespace.
Definition: fsp0sysspace.h:121
page_no_t parse_units(char *&ptr)
Convert a numeric string that optionally ends in upper or lower case G, M, or K, rounding off to the ...
Definition: fsp0sysspace.cc:100
dberr_t check_file_spec(bool create_new_db, ulint min_expected_size)
Check the data file specification.
Definition: fsp0sysspace.cc:703
SysTablespace()
Definition: fsp0sysspace.h:60
void set_tablespace_full_status(bool is_full)
Set tablespace full status.
Definition: fsp0sysspace.h:73
void shutdown()
Free the memory allocated by parse()
Definition: fsp0sysspace.cc:317
dberr_t set_size(Datafile &file)
Set the size of the file.
Definition: fsp0sysspace.cc:382
page_no_t get_autoextend_increment() const
Definition: fsp0sysspace.h:128
bool get_sanity_check_status()
Get sanity check status.
Definition: fsp0sysspace.h:87
bool created_new_raw() const
Definition: fsp0sysspace.h:106
dberr_t check_file_status(const Datafile &file, file_status_t &reason)
Check if a file can be opened in the correct mode.
Definition: fsp0sysspace.cc:569
static char * parse_file_name(char *ptr)
Put the pointer to the next byte after a valid file name.
Definition: fsp0sysspace.cc:82
dberr_t create(Datafile &file)
Create a data file.
~SysTablespace() override
Definition: fsp0sysspace.h:69
page_no_t get_pages_from_size(os_offset_t size)
Round the number of bytes in the file to MegaBytes and then return the number of pages.
Definition: fsp0sysspace.h:138
bool parse_params(const char *filepath_spec, bool supports_raw)
Parse the input params and populate member variables.
Definition: fsp0sysspace.cc:136
dberr_t read_lsn_and_check_flags(lsn_t *flushed_lsn)
Check the tablespace header for this tablespace.
Definition: fsp0sysspace.cc:513
bool m_auto_extend_last_file
if true, then we auto-extend the last data file
Definition: fsp0sysspace.h:233
Data structure that contains the information about shared tablespaces.
Definition: fsp0space.h:47
files_t m_files
Data file information - each Datafile can be accessed globally.
Definition: fsp0space.h:52
dberr_t
Definition: db0err.h:39
General shared tablespace implementation.
ulong sys_tablespace_auto_extend_increment
If the last data file is auto-extended, we add this many pages to it at a time.
Definition: fsp0sysspace.cc:65
SysTablespace srv_tmp_space
The control info of a temporary table shared tablespace.
Definition: fsp0sysspace.cc:61
SysTablespace srv_sys_space
The control info of the system tablespace.
Definition: fsp0sysspace.cc:58
bool srv_skip_temp_table_checks_debug
Control if extra debug checks need to be done for temporary tablespace.
Definition: fsp0sysspace.cc:72
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
Definition: os0file.h:86
uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:84
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61
The server main program.
Version control for database, common definitions, and include files.
#define UNIV_PAGE_SIZE
The universal page size of the database.
Definition: univ.i:294
unsigned long int ulint
Definition: univ.i:406
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:69