1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 2013, 2016, Oracle and/or its affiliates. All Rights Reserved. |
4 | Copyright (c) 2017, MariaDB Corporation. |
5 | |
6 | This program is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU General Public License as published by the Free Software |
8 | Foundation; version 2 of the License. |
9 | |
10 | This program is distributed in the hope that it will be useful, but WITHOUT |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License along with |
15 | this program; if not, write to the Free Software Foundation, Inc., |
16 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
17 | |
18 | *****************************************************************************/ |
19 | |
20 | /**************************************************//** |
21 | @file include/fsp0space.h |
22 | Shared tablespace interface |
23 | |
24 | Created 2013-7-26 by Kevin Lewis |
25 | *******************************************************/ |
26 | |
27 | #ifndef fsp0space_h |
28 | #define fsp0space_h |
29 | |
30 | #include "univ.i" |
31 | #include "fsp0file.h" |
32 | #include "fsp0fsp.h" |
33 | #include "fsp0types.h" |
34 | #include "ut0new.h" |
35 | |
36 | #include <vector> |
37 | |
38 | /** Data structure that contains the information about shared tablespaces. |
39 | Currently this can be the system tablespace or a temporary table tablespace */ |
40 | class Tablespace { |
41 | |
42 | public: |
43 | typedef std::vector<Datafile, ut_allocator<Datafile> > files_t; |
44 | |
45 | /** Data file information - each Datafile can be accessed globally */ |
46 | files_t m_files; |
47 | /** Data file iterator */ |
48 | typedef files_t::iterator iterator; |
49 | /** Data file iterator */ |
50 | typedef files_t::const_iterator const_iterator; |
51 | |
52 | Tablespace() |
53 | : |
54 | m_files(), |
55 | m_name(), |
56 | m_space_id(ULINT_UNDEFINED), |
57 | m_path(), |
58 | m_flags(), |
59 | m_ignore_read_only(false) |
60 | { |
61 | /* No op */ |
62 | } |
63 | |
64 | virtual ~Tablespace() |
65 | { |
66 | shutdown(); |
67 | ut_ad(m_files.empty()); |
68 | ut_ad(m_space_id == ULINT_UNDEFINED); |
69 | } |
70 | |
71 | // Disable copying |
72 | Tablespace(const Tablespace&); |
73 | Tablespace& operator=(const Tablespace&); |
74 | |
75 | /** Data file iterator */ |
76 | const_iterator begin() const { return m_files.begin(); } |
77 | /** Data file iterator */ |
78 | const_iterator end() const { return m_files.end(); } |
79 | /** Data file iterator */ |
80 | iterator begin() { return m_files.begin(); } |
81 | /** Data file iterator */ |
82 | iterator end() { return m_files.end(); } |
83 | |
84 | void set_name(const char* name) { m_name = name; } |
85 | const char* name() const { return m_name; } |
86 | |
87 | /** Set tablespace path and filename members. |
88 | @param[in] path where tablespace file(s) resides |
89 | @param[in] len length of the file path */ |
90 | void set_path(const char* path, size_t len) |
91 | { |
92 | ut_ad(m_path == NULL); |
93 | m_path = mem_strdupl(path, len); |
94 | ut_ad(m_path != NULL); |
95 | |
96 | os_normalize_path(m_path); |
97 | } |
98 | |
99 | /** Set tablespace path and filename members. |
100 | @param[in] path where tablespace file(s) resides */ |
101 | void set_path(const char* path) |
102 | { |
103 | set_path(path, strlen(path)); |
104 | } |
105 | |
106 | /** Get tablespace path |
107 | @return tablespace path */ |
108 | const char* path() const |
109 | { |
110 | return(m_path); |
111 | } |
112 | |
113 | /** Set the space id of the tablespace |
114 | @param[in] space_id tablespace ID to set */ |
115 | void set_space_id(ulint space_id) |
116 | { |
117 | ut_ad(m_space_id == ULINT_UNDEFINED); |
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 | ulint space_id() const |
124 | { |
125 | return(m_space_id); |
126 | } |
127 | |
128 | /** Set the tablespace flags |
129 | @param[in] fsp_flags tablespace flags */ |
130 | void set_flags(ulint fsp_flags) |
131 | { |
132 | ut_ad(fsp_flags_is_valid(fsp_flags, false)); |
133 | m_flags = fsp_flags; |
134 | } |
135 | |
136 | /** Get the tablespace flags |
137 | @return m_flags tablespace flags */ |
138 | ulint flags() const |
139 | { |
140 | return(m_flags); |
141 | } |
142 | |
143 | /** Get the tablespace encryption mode |
144 | @return m_mode tablespace encryption mode */ |
145 | fil_encryption_t encryption_mode() const |
146 | { |
147 | return (m_mode); |
148 | } |
149 | |
150 | /** Get the tablespace encryption key_id |
151 | @return m_key_id tablespace encryption key_id */ |
152 | uint32_t key_id() const |
153 | { |
154 | return (m_key_id); |
155 | } |
156 | |
157 | /** Set Ignore Read Only Status for tablespace. |
158 | @param[in] read_only_status read only status indicator */ |
159 | void set_ignore_read_only(bool read_only_status) |
160 | { |
161 | m_ignore_read_only = read_only_status; |
162 | } |
163 | |
164 | /** Free the memory allocated by the Tablespace object */ |
165 | void shutdown(); |
166 | |
167 | /** @return the sum of the file sizes of each Datafile */ |
168 | ulint get_sum_of_sizes() const |
169 | { |
170 | ulint sum = 0; |
171 | |
172 | for (const_iterator it = begin(); it != end(); ++it) { |
173 | sum += it->m_size; |
174 | } |
175 | |
176 | return(sum); |
177 | } |
178 | |
179 | /** Open or Create the data files if they do not exist. |
180 | @param[in] is_temp whether this is a temporary tablespace |
181 | @return DB_SUCCESS or error code */ |
182 | dberr_t open_or_create(bool is_temp) |
183 | MY_ATTRIBUTE((warn_unused_result)); |
184 | |
185 | /** Delete all the data files. */ |
186 | void delete_files(); |
187 | |
188 | /** Check if two tablespaces have common data file names. |
189 | @param[in] other_space Tablespace to check against this. |
190 | @return true if they have the same data filenames and paths */ |
191 | bool intersection(const Tablespace* other_space); |
192 | |
193 | /** Use the ADD DATAFILE path to create a Datafile object and add |
194 | it to the front of m_files. Parse the datafile path into a path |
195 | and a basename with extension 'ibd'. This datafile_path provided |
196 | may be an absolute or relative path, but it must end with the |
197 | extension .ibd and have a basename of at least 1 byte. |
198 | |
199 | Set tablespace m_path member and add a Datafile with the filename. |
200 | @param[in] datafile_path full path of the tablespace file. */ |
201 | dberr_t add_datafile( |
202 | const char* datafile_path); |
203 | |
204 | /* Return a pointer to the first Datafile for this Tablespace |
205 | @return pointer to the first Datafile for this Tablespace*/ |
206 | Datafile* first_datafile() |
207 | { |
208 | ut_a(!m_files.empty()); |
209 | return(&m_files.front()); |
210 | } |
211 | private: |
212 | /** |
213 | @param[in] filename Name to lookup in the data files. |
214 | @return true if the filename exists in the data files */ |
215 | bool find(const char* filename) const; |
216 | |
217 | /** Note that the data file was found. |
218 | @param[in] file data file object */ |
219 | void file_found(Datafile& file); |
220 | |
221 | /* DATA MEMBERS */ |
222 | |
223 | /** Name of the tablespace. */ |
224 | const char* m_name; |
225 | |
226 | /** Tablespace ID */ |
227 | ulint m_space_id; |
228 | |
229 | /** Path where tablespace files will reside, not including a filename.*/ |
230 | char* m_path; |
231 | |
232 | /** Tablespace flags */ |
233 | ulint m_flags; |
234 | |
235 | /** Encryption mode and key_id */ |
236 | fil_encryption_t m_mode; |
237 | uint32_t m_key_id; |
238 | |
239 | protected: |
240 | /** Ignore server read only configuration for this tablespace. */ |
241 | bool m_ignore_read_only; |
242 | }; |
243 | |
244 | #endif /* fsp0space_h */ |
245 | |