MySQL 8.0.40
Source Code Documentation
fsp0space.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/fsp0space.h
29 General shared tablespace implementation.
30
31 Created 2013-7-26 by Kevin Lewis
32 *******************************************************/
33
34#ifndef fsp0space_h
35#define fsp0space_h
36
37#include "fsp0file.h"
38#include "fsp0fsp.h"
39#include "fsp0types.h"
40#include "univ.i"
41#include "ut0new.h"
42
43#include <vector>
44
45/** Data structure that contains the information about shared tablespaces.
46Currently this can be the system tablespace or a temporary table tablespace */
48 public:
49 typedef std::vector<Datafile, ut::allocator<Datafile>> files_t;
50
51 /** Data file information - each Datafile can be accessed globally */
53
55 : m_files(),
56 m_name(),
58 m_path(),
59 m_flags(),
61 m_ignore_read_only(false) {
62 /* No op */
63 }
64
65 virtual ~Tablespace() {
66 shutdown();
67 ut_ad(m_files.empty());
69 if (m_name != nullptr) {
71 m_name = nullptr;
72 }
73 if (m_path != nullptr) {
75 m_path = nullptr;
76 }
77 }
78
79 // Disable copying
82
83 /** Set tablespace name
84 @param[in] name tablespace name */
85 void set_name(const char *name) {
86 ut_ad(m_name == nullptr);
88 ut_ad(m_name != nullptr);
89 }
90
91 /** Get tablespace name
92 @return tablespace name */
93 const char *name() const { return (m_name); }
94
95 /** Set tablespace path and filename members.
96 @param[in] path where tablespace file(s) resides
97 @param[in] len length of the file path */
98 void set_path(const char *path, size_t len) {
99 ut_ad(m_path == nullptr);
100 m_path = mem_strdupl(path, len);
101 ut_ad(m_path != nullptr);
102
104 }
105
106 /** Set tablespace path and filename members.
107 @param[in] path where tablespace file(s) resides */
108 void set_path(const char *path) { set_path(path, strlen(path)); }
109
110 /** Get tablespace path
111 @return tablespace path */
112 const char *path() const { return (m_path); }
113
114 /** Set the space id of the tablespace
115 @param[in] space_id tablespace ID to set */
119 }
120
121 /** Get the space id of the tablespace
122 @return m_space_id space id of the tablespace */
123 space_id_t space_id() const { return (m_space_id); }
124
125 /** Set the tablespace flags
126 @param[in] fsp_flags tablespace flags */
127 void set_flags(uint32_t fsp_flags) {
128 ut_ad(fsp_flags_is_valid(fsp_flags));
129 m_flags = fsp_flags;
130 }
131
132 /** Get the tablespace flags
133 @return m_flags tablespace flags */
134 uint32_t flags() const { return (m_flags); }
135
136 /** Set Ignore Read Only Status for tablespace.
137 @param[in] read_only_status read only status indicator */
138 void set_ignore_read_only(bool read_only_status) {
139 m_ignore_read_only = read_only_status;
140 }
141
142 /** Free the memory allocated by the Tablespace object */
143 void shutdown();
144
145 /** @return the sum of the file sizes of each Datafile */
147 page_no_t sum = 0;
148
149 for (files_t::const_iterator it = m_files.begin(); it != m_files.end();
150 ++it) {
151 sum += it->m_size;
152 }
153
154 return (sum);
155 }
156
157 /** Delete all the data files. */
158 void delete_files();
159
160 /** Check if two tablespaces have common data file names.
161 @param[in] other_space Tablespace to check against this.
162 @return true if they have the same data filenames and paths */
163 bool intersection(const Tablespace *other_space);
164
165 /** Use the ADD DATAFILE path to create a Datafile object and add
166 it to the front of m_files. Parse the datafile path into a path
167 and a basename with extension 'ibd'. This datafile_path provided
168 may be an absolute or relative path, but it must end with the
169 extension .ibd and have a basename of at least 1 byte.
170
171 Set tablespace m_path member and add a Datafile with the filename.
172 @param[in] datafile_added full path of the tablespace file. */
173 dberr_t add_datafile(const char *datafile_added);
174
175 /* Return a pointer to the first Datafile for this Tablespace
176 @return pointer to the first Datafile for this Tablespace*/
178 ut_a(!m_files.empty());
179 return (&m_files.front());
180 }
181
182 /* Set the autoextend size for the tablespace */
183 void set_autoextend_size(uint64_t size) { m_autoextend_size = size; }
184
185 /* Get the autoextend size for the tablespace */
186 uint64_t get_autoextend_size() const { return m_autoextend_size; }
187
188 private:
189 /**
190 @param[in] filename Name to lookup in the data files.
191 @return true if the filename exists in the data files */
192 bool find(const char *filename);
193
194 /** Note that the data file was found.
195 @param[in,out] file Data file object to set */
196 void file_found(Datafile &file);
197
198 /* DATA MEMBERS */
199
200 /** Name of the tablespace. */
201 char *m_name;
202
203 /** Tablespace ID */
205
206 /** Path where tablespace files will reside, not including a filename.*/
207 char *m_path;
208
209 /** Tablespace flags */
210 uint32_t m_flags;
211
212 /** Autoextend size */
214
215 protected:
216 /** Ignore server read only configuration for this tablespace. */
218};
219
220#endif /* fsp0space_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:52
uint32_t page_no_t
Page number.
Definition: api0api.h:50
Data file control information.
Definition: fsp0file.h:72
static void normalize(std::string &path)
Normalize a directory path for the current OS: On Windows, we convert '/' to '\', else we convert '\'...
Definition: fil0fil.h:863
Data structure that contains the information about shared tablespaces.
Definition: fsp0space.h:47
uint32_t flags() const
Get the tablespace flags.
Definition: fsp0space.h:134
uint64_t get_autoextend_size() const
Definition: fsp0space.h:186
Datafile * first_datafile()
Definition: fsp0space.h:177
virtual ~Tablespace()
Definition: fsp0space.h:65
void delete_files()
Delete all the data files.
Definition: fsp0space.cc:98
char * m_name
Name of the tablespace.
Definition: fsp0space.h:201
void set_path(const char *path, size_t len)
Set tablespace path and filename members.
Definition: fsp0space.h:98
page_no_t get_sum_of_sizes() const
Definition: fsp0space.h:146
bool m_ignore_read_only
Ignore server read only configuration for this tablespace.
Definition: fsp0space.h:217
Tablespace()
Definition: fsp0space.h:54
void set_ignore_read_only(bool read_only_status)
Set Ignore Read Only Status for tablespace.
Definition: fsp0space.h:138
uint64_t m_autoextend_size
Autoextend size.
Definition: fsp0space.h:213
bool intersection(const Tablespace *other_space)
Check if two tablespaces have common data file names.
Definition: fsp0space.cc:46
void set_autoextend_size(uint64_t size)
Definition: fsp0space.h:183
const char * path() const
Get tablespace path.
Definition: fsp0space.h:112
space_id_t m_space_id
Tablespace ID.
Definition: fsp0space.h:204
Tablespace(const Tablespace &)
void file_found(Datafile &file)
Note that the data file was found.
Definition: fsp0space.cc:74
const char * name() const
Get tablespace name.
Definition: fsp0space.h:93
void set_space_id(space_id_t space_id)
Set the space id of the tablespace.
Definition: fsp0space.h:116
void shutdown()
Free the memory allocated by the Tablespace object.
Definition: fsp0space.cc:60
void set_name(const char *name)
Set tablespace name.
Definition: fsp0space.h:85
uint32_t m_flags
Tablespace flags.
Definition: fsp0space.h:210
space_id_t space_id() const
Get the space id of the tablespace.
Definition: fsp0space.h:123
std::vector< Datafile, ut::allocator< Datafile > > files_t
Definition: fsp0space.h:49
dberr_t add_datafile(const char *datafile_added)
Use the ADD DATAFILE path to create a Datafile object and add it to the front of m_files.
Definition: fsp0space.cc:124
char * m_path
Path where tablespace files will reside, not including a filename.
Definition: fsp0space.h:207
void set_flags(uint32_t fsp_flags)
Set the tablespace flags.
Definition: fsp0space.h:127
Tablespace & operator=(const Tablespace &)
bool find(const char *filename)
Find a filename in the list of Datafiles for a tablespace.
Definition: fsp0space.cc:85
void set_path(const char *path)
Set tablespace path and filename members.
Definition: fsp0space.h:108
files_t m_files
Data file information - each Datafile can be accessed globally.
Definition: fsp0space.h:52
dberr_t
Definition: db0err.h:39
constexpr space_id_t SPACE_UNKNOWN
Unknown space id.
Definition: fil0fil.h:1137
Tablespace data file implementation.
File space management.
bool fsp_flags_is_valid(uint32_t flags)
Validate the tablespace flags.
Definition: fsp0fsp.ic:317
static char * mem_strdup(const char *str)
Duplicates a NUL-terminated string.
static char * mem_strdupl(const char *str, ulint len)
Makes a NUL-terminated copy of a nonterminated string.
Definition: os0file.h:86
void free(void *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::malloc*(),...
Definition: ut0new.h:718
const char * filename
Definition: pfs_example_component_population.cc:67
Version control for database, common definitions, and include files.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:69
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:57
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...