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