MySQL 26.7.0
Source Code Documentation
fil0tablespace_node_handle_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 <functional>
29#include <span>
30#include "os0file.h" /* IORequest */
31
32namespace ib::fil {
33
34/* Interface for handling operations on the opened tablespace node handle. */
36 public:
37 using byte = unsigned char;
38
39 enum class Status { SUCCESS = 0, IO_ERROR };
40
41 /** Type used for numbering the pages in the node. */
42 using Page_number = uint32_t;
43
44 /** Closes the opened node handle */
46
47 /** Returns true if the node must be flushed in general to ensure data
48 durability.
49 @return true if flush is needed, false otherwise. */
50 [[nodiscard]] virtual bool needs_flushes_for_durability() const = 0;
51
52 /** Ensures any data written so far to this tablespace node before this call
53 will be made durable and will survive either software or hardware crash. */
54 [[nodiscard]] virtual Status flush() = 0;
55
56 /** Truncate the node storage to the given size.
57 @param[in] size Expected size in pages of node after truncation. If the
58 size provided is more than or equal to the current size
59 of the node storage, return success.
60 @return SUCCESS if truncated successfully, error code otherwise. */
61 [[nodiscard]] virtual Status truncate(Page_number size) = 0;
62
63 /** Makes the @p number_of_pages pages, starting with page number @p
64 first_page contain all zeros. This can be use to efficiently extend the node
65 size. It may be implemented more efficiently than actually writing buffers
66 with zeros, but only if @p optimize_writes is set to true.
67 @param[in] first_page Number of page in node from to be overwritten with
68 zeros.
69 @param[in] number_of_pages Number of pages to overwrite with zeros.
70 @param[in] optimize_writes If true the implementation can use faster and
71 possibly less robust way to zero the range.
72 @return SUCCESS if zeroed successfully, error code otherwise. */
73 [[nodiscard]] virtual Status fill_range_with_zeros(
74 Page_number first_page, Page_number number_of_pages,
75 bool optimize_writes) = 0;
76
77 using Callback = std::function<void(dberr_t io_result)>;
78
79 enum class Status_IO {
80 SUCCESS = 0,
89 };
90
91 /** Reads a requested page synchronously.
92
93 Before the page is returned, the page will be decrypted and decompressed,
94 depending on information present in the page header.
95
96 The size of the buffer in bytes should be at least the tablespace physical
97 page size which was passed to tablespaces_nodes::open() or calculated from
98 flags passed to tablespaces_nodes::create().
99
100 @param[in] req IO request type, compression and encryption
101 information.
102 @param[out] buffer A buffer where to read the data in. It must be aligned
103 in memory to physical page size. It must be able to
104 store physical page size bytes. The memory pointed is
105 managed by the caller and must remain valid until the
106 call finishes.
107 TODO : buffer to be replaced with std::span.
108 @param[in] page_no Offset from the first page in the node to read
109 from.
110 @return Status_IO::SUCCESS on successful read, otherwise error code */
111 [[nodiscard]] virtual Status_IO read_page(IORequest req, byte *buffer,
112 Page_number page_no) = 0;
113
114#ifndef UNIV_HOTBACKUP
115 /** Reads a requested page asynchronously.
116
117 After the operation is completed, successfully or not, the @p callback
118 is called with the result error code, probably in a different thread. If the
119 request is successful, it will always be called from a different thread in
120 context that has no latches taken.
121
122 Before the page is returned, the page will be decrypted and decompressed,
123 depending on information present in the page header.
124
125 The size of the buffer in bytes should be at least the tablespace physical
126 page size which was passed to tablespaces_nodes::open() or calculated from
127 flags passed to tablespaces_nodes::create().
128
129 @param[in] req IO request type, compression and encryption
130 information.
131 @param[out] buffer A buffer where to read the data in. It must be aligned
132 in memory to physical page size. It must be able to
133 store physical page size bytes. The memory pointed is
134 managed by the caller and must remain valid until the
135 @p callback is being called.
136 TODO : buffer to be replaced with std::span.
137 @param[in] page_no Offset from the first page in the node to read
138 from.
139 @param[in] callback A callback to be called exactly once when the result
140 of this IO operation is known. It may be a success if
141 the read or write succeeded or a subset of `dberr_t`
142 errors if the read could not be executed or if it
143 failed. It can be called synchronously in this thread
144 before returning from this method, or can be executed
145 asynchronously from another thread, when @p sync is
146 false, before or after this call returns.
147 @return Status_IO::SUCCESS if IO was successfully posted, error code otherwise
148 */
149 [[nodiscard]] virtual Status_IO read_page_async(IORequest req, byte *buffer,
150 Page_number page_no,
151 Callback callback) = 0;
152#endif /* !UNIV_HOTBACKUP */
153
154 /** Writes a requested page synchronously.
155
156 The page will be encrypted and compressed, below this implementation
157 depending on information present in the page header.
158
159 If punch hole is supported and requested, this API implementation punches the
160 hole depending on input buffer compression metadata (check Punch Hole
161 Optimization), the capability of Implementation and settings in IORequest.
162
163 If compression/encryption is to be done, the input buffer may be modified
164 accordingly with post encryption/compression metadata (eg : Page type,
165 compression info).
166
167 The size of the buffer in bytes should be at most the tablespaces physical
168 page size which was passed to tablespaces_nodes::open() or calculated from
169 flags passed to tablespaces_nodes::create(). In other words,
170 @p buffer_len must not be greater than the tablespace physical page size.
171 In case of `punch hole`, the @p buffer_len can be less than physical page
172 size but it must be divisible by 512. And the @p buffer will be written out
173 and rest of the page will be hole-punched.
174
175 @param[in] req IO request type, compression and encryption
176 information.
177 @param[out] buffer A buffer containing the data to be written. Data from
178 this buffer might be copied and the copy transformed
179 before writing it. It must be aligned in memory to
180 the OS block size (UNIV_SECTOR_SIZE). The memory
181 pointed is managed by the caller and must remain
182 valid until the call returns.
183 @param[in] buffer_len Size of the buffer to be written. It always has to be
184 a multiply of OS block size (UNIV_SECTOR_SIZE). In
185 case of write of an already compressed data, it is a
186 length of the compressed data buffer. Otherwise it
187 should be physical page size. Actual number of bytes
188 written can be smaller if the tablespace has
189 compression enabled and data was not compressed
190 already.
191 TODO : buffer and buffer_len to be replaced with
192 std::span.
193 @param[in] page_no Offset from the first page in the node to write
194 to.
195 @return Status_IO::SUCCESS on successful write, otherwise error code */
196 [[nodiscard]] virtual Status_IO write_page(IORequest req, byte *buffer,
197 size_t buffer_len,
198 Page_number page_no) = 0;
199
200#ifdef UNIV_LINUX
201 /** Writes group of pages synchronously concatenated together at offset
202 aligned to physical_page_size.
203
204 @param[in] buffers Buffers where pages to be written to storage
205 are present. Each buffer should be of physical
206 page size of tablespace. Each buffer must be
207 aligned in memory to OS block size
208 (UNIV_SECTOR_SIZE). These buffers are meant to
209 be written unencrypted and uncompressed. The
210 memory pointed is managed by the caller and
211 must remain valid until the call returns.
212 @param[in] first_page_numebr offset from the first page in the node at
213 which the writing should start
214 @return Status_IO::SUCCESS on successful write, otherwise error code */
215 [[nodiscard]] virtual Status_IO write_pages(
216 std::span<const byte *> buffers, Page_number first_page_numebr) = 0;
217#endif /* UNIV_LINUX */
218
219#ifndef UNIV_HOTBACKUP
220 /** Writes a requested page asynchronously.
221
222 After the operation is completed, successfully or not, the @p callback
223 is called with the result error code, probably in a different thread. If the
224 request is successful, it will always be called from a different thread in
225 context that has no latches taken.
226
227 The page will be encrypted and compressed, below this implementation
228 depending on information present in the page header.
229
230 If punch hole is supported and requested, this API implementation punches the
231 hole depending on input buffer compression metadata (check Punch Hole
232 Optimization), the capability of Implementation and settings in IORequest.
233
234 If compression/encryption is to be done, the input buffer may be modified
235 accordingly with post encryption/compression metadata (eg : Page type,
236 compression info).
237
238 The size of the buffer in bytes should be at most the tablespaces physical
239 page size which was passed to tablespaces_nodes::open() or calculated from
240 flags passed to tablespaces_nodes::create(). In other words,
241 @p buffer_len must not be greater than the tablespace physical page size.
242 In case of `punch hole`, the @p buffer_len can be less than physical page
243 size but it must be divisible by 512. And the @p buffer will be written out
244 and rest of the page will be hole-punched.
245
246 @param[in] req IO request type, compression and encryption
247 information.
248 @param[out] buffer A buffer containing the data to be written. Data from
249 this buffer might be copied and the copy transformed
250 before writing it. It must be aligned in memory to
251 the OS block size (UNIV_SECTOR_SIZE). The memory
252 pointed is managed by the caller and must remain
253 valid until the @p callback is being called.
254 @param[out] buffer_len Size of the buffer to be written. It must be aligned
255 to OS block size (UNIV_SECTOR_SIZE). In case of write
256 of an already compressed data, it is a length of the
257 compressed data buffer. Otherwise it should be
258 physical page size. Actual number of bytes written
259 can be smaller if the tablespace has compression
260 enabled and data was not compressed already.
261 TODO : buffer and buffer_len to be replaced with
262 std::span.
263 @param[in] page_no Offset from the first page in the node to write
264 to.
265 @param[in] callback A callback to be called exactly once when the result
266 of this IO operation is known. It may be a success if
267 the read or write succeeded or a subset of `dberr_t`
268 errors if the write could not be executed or if it
269 failed. It can be called synchronously in this thread
270 before returning from this method, or can be executed
271 asynchronously from another thread, when @p sync is
272 false, before or after this call returns.
273 @return Status_IO::SUCCESS if IO was successfully posted, error code otherwise
274 */
275 [[nodiscard]] virtual Status_IO write_page_async(IORequest req, byte *buffer,
276 size_t buffer_len,
277 Page_number page_no,
278 Callback callback) = 0;
279#endif /* !UNIV_HOTBACKUP */
280};
281
282} /* namespace ib::fil */
Class that stores callback function reference as well as the result of the callback function call (in...
Definition: keyring_service.cc:44
Types for AIO operations.
Definition: os0file.h:262
Definition: fil0tablespace_node_handle_interface.h:35
virtual bool needs_flushes_for_durability() const =0
Returns true if the node must be flushed in general to ensure data durability.
Status_IO
Definition: fil0tablespace_node_handle_interface.h:79
virtual Status fill_range_with_zeros(Page_number first_page, Page_number number_of_pages, bool optimize_writes)=0
Makes the number_of_pages pages, starting with page number first_page contain all zeros.
virtual Status flush()=0
Ensures any data written so far to this tablespace node before this call will be made durable and wil...
virtual Status truncate(Page_number size)=0
Truncate the node storage to the given size.
uint32_t Page_number
Type used for numbering the pages in the node.
Definition: fil0tablespace_node_handle_interface.h:42
Status
Definition: fil0tablespace_node_handle_interface.h:39
virtual Status_IO write_page(IORequest req, byte *buffer, size_t buffer_len, Page_number page_no)=0
Writes a requested page synchronously.
virtual Status_IO write_page_async(IORequest req, byte *buffer, size_t buffer_len, Page_number page_no, Callback callback)=0
Writes a requested page asynchronously.
virtual ~Tablespace_node_handle_interface()=default
Closes the opened node handle.
virtual Status_IO read_page(IORequest req, byte *buffer, Page_number page_no)=0
Reads a requested page synchronously.
virtual Status_IO read_page_async(IORequest req, byte *buffer, Page_number page_no, Callback callback)=0
Reads a requested page asynchronously.
dberr_t
Definition: db0err.h:39
Definition: fil0fil.cc:1392
size_t size(const char *const c)
Definition: base64.h:46
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
The interface to the operating system file io.