MySQL  8.0.19
Source Code Documentation
fsp0sysspace.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2013, 2018, Oracle and/or its affiliates. All Rights Reserved.
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 also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 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 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
44 at 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.
49 Default = true that is disable such checks.
50 This variable is not exposed to end-user but still kept as variable for
51 developer to enable it during debug. */
53 #endif /* UNIV_DEBUG */
54 
55 /** Data structure that contains the information about shared tablespaces.
56 Currently this can be the system tablespace or a temporary table tablespace */
57 class SysTablespace : public Tablespace {
58  public:
65  /* No op */
66  }
67 
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 filepath_spec path to data files
90  @param supports_raw true if it 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
96  is to be created
97  @param[in] min_expected_size expected tablespace
98  size in bytes
99  @return DB_SUCCESS if all OK else error code */
100  dberr_t check_file_spec(bool create_new_db, ulint min_expected_size);
101 
102  /** Free the memory allocated by parse() */
103  void shutdown();
104 
105  /**
106  @return true if a new raw device was created. */
107  bool created_new_raw() const { return (m_created_new_raw); }
108 
109  /**
110  @return auto_extend value setting */
112 
113  /** Set the last file size.
114  @param[in] size the size to set */
116  ut_ad(!m_files.empty());
117  m_files.back().m_size = size;
118  }
119 
120  /** Get the number of pages in the last data file in the tablespace
121  @return the size of the last data file in the array */
123  ut_ad(!m_files.empty());
124  return (m_files.back().m_size);
125  }
126 
127  /**
128  @return the autoextend increment in pages. */
131  ((1024 * 1024) / UNIV_PAGE_SIZE));
132  }
133 
134  /** Round the number of bytes in the file to MegaBytes
135  and then return the number of pages.
136  Note: Only system tablespaces are required to be at least
137  1 megabyte.
138  @return the number of pages in the file. */
140  return static_cast<page_no_t>(
141  ((size / (1024 * 1024)) * ((1024 * 1024) / UNIV_PAGE_SIZE)));
142  }
143 
144  /**
145  @return next increment size */
146  page_no_t get_increment() const;
147 
148  /** Open or create the data files
149  @param[in] is_temp whether this is a temporary tablespace
150  @param[in] create_new_db whether we are creating a new database
151  @param[out] sum_new_sizes sum of sizes of the new files added
152  @param[out] flush_lsn FIL_PAGE_FILE_FLUSH_LSN of first file
153  @return DB_SUCCESS or error code */
154  dberr_t open_or_create(bool is_temp, bool create_new_db,
155  page_no_t *sum_new_sizes, lsn_t *flush_lsn)
156  MY_ATTRIBUTE((warn_unused_result));
157 
158  private:
159  /** Check the tablespace header for this tablespace.
160  @param[out] flushed_lsn the value of FIL_PAGE_FILE_FLUSH_LSN
161  @return DB_SUCCESS or error code */
162  dberr_t read_lsn_and_check_flags(lsn_t *flushed_lsn);
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 */
177  dberr_t create(Datafile &file);
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 */
187  dberr_t open_file(Datafile &file);
188 
189  /** Set the size of the file.
190  @param[in,out] file data file object
191  @return DB_SUCCESS or error code */
192  dberr_t set_size(Datafile &file);
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. */
221  dberr_t check_size(Datafile &file);
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. */
227  dberr_t check_file_status(const Datafile &file, file_status_t &reason);
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 */
SysTablespace::FILE_STATUS_VOID
@ FILE_STATUS_VOID
Definition: fsp0sysspace.h:212
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
SysTablespace::set_tablespace_full_status
void set_tablespace_full_status(bool is_full)
Set tablespace full status.
Definition: fsp0sysspace.h:72
lsn_t
uint64_t lsn_t
Type used for all log sequence number storage and arithmetics.
Definition: log0types.h:59
SysTablespace::can_auto_extend_last_file
ulint can_auto_extend_last_file() const
Definition: fsp0sysspace.h:111
SysTablespace::SysTablespace
SysTablespace()
Definition: fsp0sysspace.h:59
SysTablespace::FILE_STATUS_READ_WRITE_ERROR
@ FILE_STATUS_READ_WRITE_ERROR
permission error
Definition: fsp0sysspace.h:214
srv_tmp_space
SysTablespace srv_tmp_space
The control info of a temporary table shared tablespace.
Definition: fsp0sysspace.cc:60
Tablespace
Data structure that contains the information about shared tablespaces.
Definition: fsp0space.h:46
SysTablespace::set_size
dberr_t set_size(Datafile &file)
Set the size of the file.
Definition: fsp0sysspace.cc:381
ut_ad
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:65
SysTablespace::FILE_STATUS_RW_PERMISSION_ERROR
@ FILE_STATUS_RW_PERMISSION_ERROR
status not set
Definition: fsp0sysspace.h:213
SysTablespace::open_or_create
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:796
SysTablespace::m_last_file_size_max
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
SysTablespace::create_file
dberr_t create_file(Datafile &file)
Create a data file.
Definition: fsp0sysspace.cc:414
SysTablespace::get_sanity_check_status
bool get_sanity_check_status()
Get sanity check status.
Definition: fsp0sysspace.h:86
SysTablespace::file_found
void file_found(Datafile &file)
Note that the data file was found.
Definition: fsp0sysspace.cc:687
srv_skip_temp_table_checks_debug
bool srv_skip_temp_table_checks_debug
Control if extra debug checks need to be done for temporary tablespace.
Definition: fsp0sysspace.cc:71
dberr_t
dberr_t
Definition: db0err.h:38
SysTablespace::get_tablespace_full_status
bool get_tablespace_full_status()
Get tablespace full status.
Definition: fsp0sysspace.h:78
SysTablespace::file_not_found
dberr_t file_not_found(Datafile &file, bool create_new_db)
Note that the data file was not found.
Definition: fsp0sysspace.cc:640
SysTablespace::last_file_size
page_no_t last_file_size() const
Get the number of pages in the last data file in the tablespace.
Definition: fsp0sysspace.h:122
SysTablespace
Data structure that contains the information about shared tablespaces.
Definition: fsp0sysspace.h:57
SysTablespace::get_pages_from_size
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:139
os_offset_t
ib_uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:81
SysTablespace::set_sanity_check_status
void set_sanity_check_status(bool status)
Set sanity check status.
Definition: fsp0sysspace.h:82
srv0srv.h
SysTablespace::shutdown
void shutdown()
Free the memory allocated by parse()
Definition: fsp0sysspace.cc:316
SysTablespace::get_autoextend_increment
page_no_t get_autoextend_increment() const
Definition: fsp0sysspace.h:129
status
static STATUS status
Definition: mysql.cc:197
SysTablespace::check_file_status
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:576
SysTablespace::m_is_tablespace_full
bool m_is_tablespace_full
Tablespace full status.
Definition: fsp0sysspace.h:244
SysTablespace::check_size
dberr_t check_size(Datafile &file)
Verify the size of the physical file.
Definition: fsp0sysspace.cc:329
SysTablespace::open_file
dberr_t open_file(Datafile &file)
Open a data file.
Definition: fsp0sysspace.cc:451
SysTablespace::create
dberr_t create(Datafile &file)
Create a data file.
fsp0space.h
SysTablespace::m_created_new_raw
bool m_created_new_raw
If the following is true we do not allow inserts etc.
Definition: fsp0sysspace.h:241
SysTablespace::check_file_spec
dberr_t check_file_spec(bool create_new_db, ulint min_expected_size)
Check the data file specification.
Definition: fsp0sysspace.cc:710
SysTablespace::get_increment
page_no_t get_increment() const
Definition: fsp0sysspace.cc:914
SysTablespace::read_lsn_and_check_flags
dberr_t read_lsn_and_check_flags(lsn_t *flushed_lsn)
Check the tablespace header for this tablespace.
Definition: fsp0sysspace.cc:515
srv_sys_space
SysTablespace srv_sys_space
The control info of the system tablespace.
Definition: fsp0sysspace.cc:57
SysTablespace::parse_units
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
SysTablespace::~SysTablespace
~SysTablespace()
Definition: fsp0sysspace.h:68
sys_tablespace_auto_extend_increment
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::set_last_file_size
void set_last_file_size(page_no_t size)
Set the last file size.
Definition: fsp0sysspace.h:115
SysTablespace::parse_params
bool parse_params(const char *filepath_spec, bool supports_raw)
Parse the input params and populate member variables.
Definition: fsp0sysspace.cc:135
Tablespace::m_files
files_t m_files
Data file information - each Datafile can be accessed globally.
Definition: fsp0space.h:51
SysTablespace::file_status_t
file_status_t
Definition: fsp0sysspace.h:211
Datafile
Data file control information.
Definition: fsp0file.h:72
SysTablespace::m_auto_extend_last_file
bool m_auto_extend_last_file
if true, then we auto-extend the last data file
Definition: fsp0sysspace.h:232
SysTablespace::parse_file_name
static char * parse_file_name(char *ptr)
Put the pointer to the next byte after a valid file name.
Definition: fsp0sysspace.cc:81
ulong
unsigned long ulong
Definition: my_inttypes.h:48
SysTablespace::FILE_STATUS_NOT_REGULAR_FILE_ERROR
@ FILE_STATUS_NOT_REGULAR_FILE_ERROR
not readable/writable
Definition: fsp0sysspace.h:215
SysTablespace::created_new_raw
bool created_new_raw() const
Definition: fsp0sysspace.h:107
SysTablespace::m_sanity_checks_done
bool m_sanity_checks_done
if false, then sanity checks are still pending
Definition: fsp0sysspace.h:247
false
#define false
Definition: config_static.h:43