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