MySQL 26.7.0
Source Code Documentation
fil0tablespaces_nodes_interface.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2026, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify it under
4the terms of the GNU General Public License, version 2.0, as published by the
5Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
18for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc.,
2251 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#pragma once
26
27#include <cstdlib> /* size_t */
28#include <string>
30#include "page0size.h"
31#include "ut0expected.h" /* ut::Expected */
32#include "ut0new.h" /* ut::unique_ptr */
33
34namespace ib::fil {
35
36/** Manages low-level storage for Tablespaces. */
38 public:
39 /** Type used for giving the tablespaces unique number. */
40 using Tablespace_id = uint32_t;
41
42 /** Performs any clean up. */
43 virtual ~Tablespaces_nodes_interface() = default;
44
45 /*==========================================================
46 Tablespace Service Implementation's Capabilities
47 ==========================================================*/
48 struct Capabilities {
57 };
58
59 /** Query the capabilities of the Page Service implementation.
60 This function can be called even before start().
61 @return the capabilities of this Page Service implementation */
62 [[nodiscard]] virtual Capabilities get_capabilities() = 0;
63
64 enum class Status { SUCCESS = 0, IO_ERROR };
65
66 enum class Create_error {
67 NODE_EXISTS = 1,
72 };
73
74 /* If an API requires an additional hint then evaluate if you need to
75 extend the Node_hints for that API to keep the APIs contract intact. */
76 struct Node_hints {
77 /** Path and filename of the node to process. */
78 const std::string m_path;
79 /** Specifies if the @p m_path is a raw device or disk partition. */
80 const bool m_is_raw_disk = false;
81 /** Specifies if get_node_info() should probe current access permissions.
82 This may open the node storage and can be sharing-sensitive on Windows. */
83 const bool m_check_permissions = false;
84 };
85
88 /** Specifies if the @p m_path is for an explicit undo tablespace. */
89 const bool m_is_explicit_undo = false;
90 };
91
92 /** Creates a low-level storage for a new tablespace node.
93 if storage 'path' already exists, it returns error TABLESPACE_EXISTS.
94 To be used in fil_create_tablespace().
95 @param[in] space_id Tablespace ID to create the node's storage
96 for.
97 @param[in] node_order Number of the node in the tablespace.
98 @param[in] hints Additional information that may be useful for
99 creating the node's storage.
100 @param[in] flags Tablespace flags
101 @param[in] size_in_pages Initial size of the tablespace node in pages,
102 must be >= FIL_IBD_FILE_INITIAL_SIZE
103 @return Pointer to handle to be used for accessing the node's storage if the
104 storage is created successfully, error code otherwise. */
105 [[nodiscard]] virtual ut::Expected<
107 create(Tablespace_id space_id, size_t node_order,
108 const Create_node_hints &hints, uint32_t flags,
109 page_no_t size_in_pages) = 0;
110
111 enum class Open_error {
115 };
116
117 /** Opens an existing tablespace's node storage by @p path, so it is ready to
118 read and write pages, flush and extend the tablespace node. The tablespace
119 must not be opened at the time of this call.
120 To be used in fil_node_t::open().
121 @param[in] space_id Tablespace ID to open the node's storage for.
122 @param[in] node_order Number of the node in the tablespace.
123 @param[in] hints Additional information that may be useful for
124 opening the node's storage.
125 @param[in] page_size Physical page size used in the tablespace,
126 must match one specified when creating the
127 tablespace.
128 @param[in] for_read_only True if the storage should be opened for
129 read-only access.
130 @return Pointer to handle to be used for accessing the node's storage if the
131 storage is opened successfully, error code otherwise. */
132 [[nodiscard]] virtual ut::Expected<
134 open(Tablespace_id space_id, size_t node_order, const Node_hints &hints,
135 size_t page_size, bool for_read_only) = 0;
136
137 /** Rename a tablespace file.
138 @param[in] space_id tablespace_id
139 @param[in] node_order Number of the node in the tablespace.
140 @param[in] old_path old name of the file
141 @param[in] new_path new name of the file
142 @return SUCCESS if renames successfully, error code otherwise */
143 [[nodiscard]] virtual Status rename(space_id_t space_id, size_t node_order,
144 const std::string &old_path,
145 const std::string &new_path) = 0;
146
147 /** Deletes a specified tablespace's node storage by @p path.
148 To be used in Fil_shard::space_delete().
149 @param[in] space_id Tablespace ID
150 @param[in] node_order Number of the node in the tablespace.
151 @param[in] hints Additional information that may be useful for
152 removing the node's storage.
153 @return Status::SUCCESS if tablespace storage is removed successfully, error
154 code otherwise. */
155 [[nodiscard]] virtual Status remove(Tablespace_id space_id, size_t node_order,
156 const Node_hints &hints) = 0;
157
158 /** Errors that can be returned while getting information about a node. */
159 enum class Node_error {
160 /** The specified node does not exist and the hinted path is free to be
161 reserved by any new node. */
163 /** The specified node does not exist, but the hinted path is used by
164 something that is not a node and can't be used to create a new node. */
166 /** A generic error occurred during the operation, the existence of the node
167 could not be determined. */
169 };
170
171 /** Stored general information about the storage node at the time of calling
172 the get_node_info(). */
173 struct Node_info {
174 /** Size of the node in pages. */
176 /** Block size to use for IO in bytes. If transparent page compression is
177 used, the buffer size for write_page()/write_page_async() must be multiple
178 of this value. */
179 uint32_t block_size;
180 /** Actual file size that is, the amount of space allocated on the file
181 system. */
182 uint64_t alloc_size;
183 /** Determines if caller would succeed to open the path if they tried now,
184 with specified access modes. This value is reliable only when
185 Node_hints::m_check_permissions was true. When a `false` permission is
186 reported after an explicit permission check, it may mean that it is a
187 temporary problem which may go away if another thread/process unlocks the
188 file. This temporary problem is more common on Windows as the default
189 setting is to lock the files when opening them. */
191 };
192
193 /** Gets basic information about the node specified, this includes its size
194 (first page offset that is not available for reading and writing) and minimum
195 block size for usage in transparent page compression. If
196 Node_hints::m_check_permissions is true, currently available access modes are
197 also checked; otherwise Node_info::access_permissions is not reliable.
198 The node may not exist, or the path specified may lead to a non-file object or
199 the operation may encounter any other problem in which case a suitable
200 `Node_error` will be returned.
201 @param[in] space_id Tablespace ID. It can be `SPACE_UNKNOWN` to
202 check if the path specified in hints exists
203 and get all info but the size of node in
204 pages.
205 @param[in] node_order Number of the node in the tablespace.
206 @param[in] hints Additional information that may be useful for
207 querying the node's storage.
208 @param[in] page_size Physical page size used in the tablespace,
209 must match one specified when creating the
210 tablespace. However, if the @p space_id is
211 `SPACE_UNKNOWN` or we are not interested in
212 the node size, a value of 0 can be specified.
213 In such case, the returned Node_info::size
214 will be 0. */
216 Tablespace_id space_id, size_t node_order, const Node_hints &hints,
217 size_t page_size) = 0;
218};
219
220constexpr const char *to_string(
222 switch (error) {
223#define CASE_XXX(x) \
224 case ib::fil::Tablespaces_nodes_interface::Node_error::x: \
225 return #x;
226 CASE_XXX(NODE_DOES_NOT_EXIST)
227 CASE_XXX(NOT_A_NODE)
228 CASE_XXX(IO_ERROR)
229#undef CASE_XXX
230 }
231 return "Unknown";
232}
233
234/* Sets the implementation of the Tablespaces_nodes_interface. It can be called
235only once, that is, once set, it is impossible to set other implementation.
236@param[in] new_tablepsaces_nodes New implementation to use. */
238 ut::unique_ptr<Tablespaces_nodes_interface> new_tablepsaces_nodes);
239
240} /* namespace ib::fil */
241
242/** The low-level tablespaces' nodes' storage implementation. */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
uint32_t page_no_t
Page number.
Definition: api0api.h:47
The class error is used to emit error messages.
Definition: ut0log.h:225
Manages low-level storage for Tablespaces.
Definition: fil0tablespaces_nodes_interface.h:37
virtual ut::Expected< ut::unique_ptr< Tablespace_node_handle_interface >, Open_error > open(Tablespace_id space_id, size_t node_order, const Node_hints &hints, size_t page_size, bool for_read_only)=0
Opens an existing tablespace's node storage by path, so it is ready to read and write pages,...
virtual ut::Expected< Node_info, Node_error > get_node_info(Tablespace_id space_id, size_t node_order, const Node_hints &hints, size_t page_size)=0
Gets basic information about the node specified, this includes its size (first page offset that is no...
virtual Status rename(space_id_t space_id, size_t node_order, const std::string &old_path, const std::string &new_path)=0
Rename a tablespace file.
virtual ut::Expected< ut::unique_ptr< Tablespace_node_handle_interface >, Create_error > create(Tablespace_id space_id, size_t node_order, const Create_node_hints &hints, uint32_t flags, page_no_t size_in_pages)=0
Creates a low-level storage for a new tablespace node.
uint32_t Tablespace_id
Type used for giving the tablespaces unique number.
Definition: fil0tablespaces_nodes_interface.h:40
Open_error
Definition: fil0tablespaces_nodes_interface.h:111
Status
Definition: fil0tablespaces_nodes_interface.h:64
virtual Status remove(Tablespace_id space_id, size_t node_order, const Node_hints &hints)=0
Deletes a specified tablespace's node storage by path.
Create_error
Definition: fil0tablespaces_nodes_interface.h:66
virtual Capabilities get_capabilities()=0
Query the capabilities of the Page Service implementation.
virtual ~Tablespaces_nodes_interface()=default
Performs any clean up.
Node_error
Errors that can be returned while getting information about a node.
Definition: fil0tablespaces_nodes_interface.h:159
@ NOT_A_NODE
The specified node does not exist, but the hinted path is used by something that is not a node and ca...
@ IO_ERROR
A generic error occurred during the operation, the existence of the node could not be determined.
@ NODE_DOES_NOT_EXIST
The specified node does not exist and the hinted path is free to be reserved by any new node.
C++23 std::expected.
Definition: ut0expected.h:74
ut::unique_ptr< ib::fil::Tablespaces_nodes_interface > tablespaces_nodes
The low-level tablespaces' nodes' storage implementation.
Definition: fil0fil.cc:1388
#define CASE_XXX(x)
static int flags[50]
Definition: hp_test1.cc:40
Definition: fil0fil.cc:1392
constexpr const char * to_string(ib::fil::Tablespaces_nodes_interface::Node_error error)
Definition: fil0tablespaces_nodes_interface.h:220
void set_tablespaces_nodes(ut::unique_ptr< Tablespaces_nodes_interface > new_tablepsaces_nodes)
Definition: fil0fil.cc:1394
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2284
A class describing a page size.
Stores information about access modes to the resource permitted to the caller at the moment of checki...
Definition: os0file.h:1776
Definition: fil0tablespaces_nodes_interface.h:48
bool supports_transparent_data_encryption
Definition: fil0tablespaces_nodes_interface.h:54
bool supports_bulk_load
Definition: fil0tablespaces_nodes_interface.h:52
bool supports_import_tablespace
Definition: fil0tablespaces_nodes_interface.h:50
bool supports_dblwr
Definition: fil0tablespaces_nodes_interface.h:49
bool supports_discard_tablespace
Definition: fil0tablespaces_nodes_interface.h:51
bool supports_raw_devices
Definition: fil0tablespaces_nodes_interface.h:56
bool supports_clone
Definition: fil0tablespaces_nodes_interface.h:53
bool supports_transparent_page_compression
Definition: fil0tablespaces_nodes_interface.h:55
Definition: fil0tablespaces_nodes_interface.h:86
Node_hints m_base_hints
Definition: fil0tablespaces_nodes_interface.h:87
const bool m_is_explicit_undo
Specifies if the m_path is for an explicit undo tablespace.
Definition: fil0tablespaces_nodes_interface.h:89
Definition: fil0tablespaces_nodes_interface.h:76
const bool m_check_permissions
Specifies if get_node_info() should probe current access permissions.
Definition: fil0tablespaces_nodes_interface.h:83
const std::string m_path
Path and filename of the node to process.
Definition: fil0tablespaces_nodes_interface.h:78
const bool m_is_raw_disk
Specifies if the m_path is a raw device or disk partition.
Definition: fil0tablespaces_nodes_interface.h:80
Stored general information about the storage node at the time of calling the get_node_info().
Definition: fil0tablespaces_nodes_interface.h:173
Access_permissions access_permissions
Determines if caller would succeed to open the path if they tried now, with specified access modes.
Definition: fil0tablespaces_nodes_interface.h:190
uint32_t block_size
Block size to use for IO in bytes.
Definition: fil0tablespaces_nodes_interface.h:179
page_no_t size
Size of the node in pages.
Definition: fil0tablespaces_nodes_interface.h:175
uint64_t alloc_size
Actual file size that is, the amount of space allocated on the file system.
Definition: fil0tablespaces_nodes_interface.h:182
Minimal implementation of C++23 std::expected.
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...