| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2013, 2026, Oracle and/or its affiliates. |
| 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 designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 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. |
| 46 |
Currently this can be the system tablespace or a temporary table tablespace */ |
| 47 |
class Tablespace { |
| 48 |
public: |
| 49 |
typedef std::vector<Datafile, ut::allocator<Datafile>> files_t; |
| 50 |
|
| 51 |
/** Data file information - each Datafile can be accessed globally */ |
| 52 |
files_t m_files; |
| 53 |
|
| 54 |
Tablespace() |
| 55 |
: m_files(), |
| 56 |
m_name(), |
| 57 |
m_space_id(SPACE_UNKNOWN), |
| 58 |
m_path(), |
| 59 |
m_flags(), |
| 60 |
m_autoextend_size(), |
| 61 |
m_ignore_read_only(false) { |
| 62 |
/* No op */ |
| 63 |
} |
| 64 |
|
| 65 |
virtual ~Tablespace() { |
| 66 |
shutdown(); |
| 67 |
ut_ad(m_files.empty()); |
| 68 |
ut_ad(m_space_id == SPACE_UNKNOWN); |
| 69 |
if (m_name != nullptr) { |
| 70 |
ut::free(m_name); |
| 71 |
m_name = nullptr; |
| 72 |
} |
| 73 |
if (m_path != nullptr) { |
| 74 |
ut::free(m_path); |
| 75 |
m_path = nullptr; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
// Disable copying |
| 80 |
Tablespace(const Tablespace &); |
| 81 |
Tablespace &operator=(const Tablespace &); |
| 82 |
|
| 83 |
/** Set tablespace name |
| 84 |
@param[in] name tablespace name */ |
| 85 |
void set_name(const char *name) { |
| 86 |
ut_ad(m_name == nullptr); |
| 87 |
m_name = mem_strdup(name); |
| 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 |
|
| 103 |
Fil_path::normalize(m_path); |
| 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 */ |
| 116 |
void set_space_id(space_id_t space_id) { |
| 117 |
ut_ad(m_space_id == SPACE_UNKNOWN); |
| 118 |
m_space_id = space_id; |
| 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 */ |
| 146 |
page_no_t get_sum_of_sizes() const { |
| 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*/ |
| 177 |
Datafile *first_datafile() { |
| 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 */ |
| 204 |
space_id_t m_space_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 */ |
| 213 |
uint64_t m_autoextend_size; |
| 214 |
|
| 215 |
protected: |
| 216 |
/** Ignore server read only configuration for this tablespace. */ |
| 217 |
bool m_ignore_read_only; |
| 218 |
}; |
| 219 |
|
| 220 |
#endif /* fsp0space_h */ |