MySQL 26.7.0
Source Code Documentation
buf0types.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2026, 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 designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/buf0types.h
29 The database buffer pool global types for the directory
30
31 Created 11/17/1995 Heikki Tuuri
32 *******************************************************/
33
34#ifndef buf0types_h
35#define buf0types_h
36
37#include "os0event.h"
38#include "sync0rw.h"
39#include "ut0byte.h"
40#include "ut0mutex.h"
41#include "ut0rnd.h"
42#include "ut0ut.h"
43
44/** Magic value to use instead of checksums when they are disabled */
45constexpr uint32_t BUF_NO_CHECKSUM_MAGIC = 0xDEADBEEFUL;
46
47/** Buffer page (uncompressed or compressed) */
48class buf_page_t;
49/** Buffer block for which an uncompressed page exists */
50struct buf_block_t;
51/** Buffer pool chunk comprising buf_block_t */
52struct buf_chunk_t;
53/** Buffer pool comprising buf_chunk_t */
54struct buf_pool_t;
55/** Buffer pool statistics struct */
56struct buf_pool_stat_t;
57/** Buffer pool buddy statistics struct */
58struct buf_buddy_stat_t;
59/** Doublewrite memory struct */
60struct buf_dblwr_t;
61/** Flush observer for bulk create index */
62class Flush_observer;
63
64/** A buffer frame. @see page_t */
65typedef byte buf_frame_t;
66
67/** Flags for flush types */
68enum buf_flush_t : uint8_t {
69 /** Flush via the LRU list */
71
72 /** Flush via the flush list of dirty blocks */
74
75 /** Flush via the LRU list but only a single page */
77
78 /** Index of last element + 1 */
80};
81
82/** Flags for io_fix types */
83enum buf_io_fix : uint8_t {
84 /** no pending I/O */
86
87 /** read pending */
89
90 /** write pending */
92
93 /** disallow relocation of block and its removal from the flush_list */
95};
96
97/** Alternatives for srv_checksum_algorithm, which can be changed by
98setting innodb_checksum_algorithm */
100 SRV_CHECKSUM_ALGORITHM_CRC32, /*!< Write crc32, allow crc32,
101 innodb or none when reading */
102 SRV_CHECKSUM_ALGORITHM_STRICT_CRC32, /*!< Write crc32, allow crc32
103 when reading */
104 SRV_CHECKSUM_ALGORITHM_INNODB, /*!< Write innodb, allow crc32,
105 innodb or none when reading */
106 SRV_CHECKSUM_ALGORITHM_STRICT_INNODB, /*!< Write innodb, allow
107 innodb when reading */
108 SRV_CHECKSUM_ALGORITHM_NONE, /*!< Write none, allow crc32,
109 innodb or none when reading */
110 SRV_CHECKSUM_ALGORITHM_STRICT_NONE /*!< Write none, allow none
111 when reading */
113
114/** Buffer pool resize status code and progress are tracked using these
115atomic variables to ensure thread synchronization between
116innodb_buffer_pool_size_update (raising srv_buf_resize_event) and
117buf_resize_thread (handling srv_buf_resize_event) */
118extern std::atomic_uint32_t buf_pool_resize_status_code;
119extern std::atomic_uint32_t buf_pool_resize_status_progress;
120
121/** Enumerate possible status codes during buffer pool resize. This is used
122to identify the resize status using the corresponding code. */
124 /** Resize completed or Resize not in progress*/
126
127 /** Resize started */
129
130 /** Disabling Adaptive Hash Index */
132
133 /** Withdrawing blocks */
135
136 /** Acquiring global lock */
138
139 /** Resizing pool */
141
142 /** Resizing hash */
144
145 /** Resizing failed */
148
150 return (algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 ||
153}
154
155inline bool is_checksum_strict(ulint algo) {
156 return (algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 ||
159}
160
161/** Parameters of binary buddy system for compressed pages (buf0buddy.h) */
162/** @{ */
163/** Zip shift value for the smallest page size */
165
166/** Smallest buddy page size */
167constexpr uint32_t BUF_BUDDY_LOW = (1U << BUF_BUDDY_LOW_SHIFT);
168
169/** Actual number of buddy sizes based on current page size */
170#define BUF_BUDDY_SIZES (UNIV_PAGE_SIZE_SHIFT - BUF_BUDDY_LOW_SHIFT)
171
172/** Maximum number of buddy sizes based on the max page size */
173constexpr uint32_t BUF_BUDDY_SIZES_MAX =
175
176/** twice the maximum block size of the buddy system;
177the underlying memory is aligned by this amount:
178this must be equal to UNIV_PAGE_SIZE */
179#define BUF_BUDDY_HIGH (BUF_BUDDY_LOW << BUF_BUDDY_SIZES)
180/** @} */
181
182typedef ib_bpmutex_t BPageMutex;
183typedef ib_mutex_t BufListMutex;
184typedef ib_mutex_t FlushListMutex;
186#ifndef UNIV_HOTBACKUP
188#endif /* !UNIV_HOTBACKUP */
189
190/** Page identifier. */
192 public:
193 /**
194 This class does not have a default constructor, because there is no natural
195 choice for default values of m_space and m_page_no.
196
197 If 0,0 were used, then it's not good as it doesn't match UINT32_UNDEFINED
198 used to denote impossible page_no_t in several places, and 0 is a legal
199 value for both space_id_t and page_id_t of a real page!
200
201 If UINT32_UNDEFINED,UINT32_UNDEFINED were used, then it doesn't match the
202 most common usage where use use memset(parent,0,sizeof(parent_t)); on a
203 parent struct where one of the members has page_id_t type - which is ok
204 given that page_id_t is TriviallyCopyable, and that the field is not
205 used until it is assigned some real value. Such constructor would be
206 misleading to people reading the code, as they might expect UINT32_UNDEFINED
207 value, if they didn't notice the memset code buried somewhere in parent's
208 initialization routine.
209
210 Therefore, please either be explicit by using (space,page_no) overload,
211 or continue to use memset at your own risk.
212 */
213 page_id_t() = delete;
214
215 /** Constructor from (space, page_no).
216 @param[in] space tablespace id
217 @param[in] page_no page number */
220
221 /** Retrieve the tablespace id.
222 @return tablespace id */
223 space_id_t space() const { return (m_space); }
224
225 /** Retrieve the page number.
226 @return page number */
227 page_no_t page_no() const { return (m_page_no); }
228
229 /** Retrieve the hash value.
230 @return hashed value */
231 uint64_t hash() const {
232 constexpr uint64_t HASH_MASK = 1653893711;
233 return (((uint64_t)m_space << 20) + m_space + m_page_no) ^ HASH_MASK;
234 }
235
236 /** Reset the values from a (space, page_no).
237 @param[in] space tablespace id
238 @param[in] page_no page number */
240 m_space = space;
242 }
243
244 /** Reset the page number only.
245 @param[in] page_no page number */
247
248 /** Check if a given page_id_t object is equal to the current one.
249 @param[in] a page_id_t object to compare
250 @return true if equal */
251 bool operator==(const page_id_t &a) const {
252 return (a.space() == m_space && a.page_no() == m_page_no);
253 }
254
255 /** Check if a given page_id_t object is not equal to the current one.
256 @param[in] a page_id_t object to compare
257 @return true if not equal */
258 bool operator!=(const page_id_t &a) const { return !(*this == a); }
259
260 /** Provides a lexicographic ordering on <space_id,page_no> pairs
261 @param[in] other page_id_t object to compare
262 @return true if this is strictly smaller than other */
263 bool operator<(const page_id_t &other) const {
264 return m_space < other.space() ||
265 (m_space == other.space() && m_page_no < other.page_no());
266 }
267 std::string to_string() const {
269 oss << *this;
270 return oss.str();
271 }
272
273 private:
274 /** Tablespace id. */
276
277 /** Page number. */
279
280 friend std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
281};
282
283/** Print the given page_id_t object.
284@param[in,out] out the output stream
285@param[in] page_id the page_id_t object to be printed
286@return the output stream */
287std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
288
289#endif /* buf0types.h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
uint32_t page_no_t
Page number.
Definition: api0api.h:47
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:62
constexpr uint32_t BUF_BUDDY_LOW_SHIFT
Parameters of binary buddy system for compressed pages (buf0buddy.h)
Definition: buf0types.h:164
std::atomic_uint32_t buf_pool_resize_status_code
Buffer pool resize status code and progress are tracked using these atomic variables to ensure thread...
Definition: buf0buf.cc:313
BPageMutex BufPoolZipMutex
Definition: buf0types.h:185
constexpr uint32_t BUF_NO_CHECKSUM_MAGIC
Magic value to use instead of checksums when they are disabled.
Definition: buf0types.h:45
buf_pool_resize_status_code_t
Enumerate possible status codes during buffer pool resize.
Definition: buf0types.h:123
@ BUF_POOL_RESIZE_HASH
Resizing hash.
Definition: buf0types.h:143
@ BUF_POOL_RESIZE_START
Resize started.
Definition: buf0types.h:128
@ BUF_POOL_RESIZE_FAILED
Resizing failed.
Definition: buf0types.h:146
@ BUF_POOL_RESIZE_DISABLE_AHI
Disabling Adaptive Hash Index.
Definition: buf0types.h:131
@ BUF_POOL_RESIZE_COMPLETE
Resize completed or Resize not in progress.
Definition: buf0types.h:125
@ BUF_POOL_RESIZE_GLOBAL_LOCK
Acquiring global lock.
Definition: buf0types.h:137
@ BUF_POOL_RESIZE_WITHDRAW_BLOCKS
Withdrawing blocks.
Definition: buf0types.h:134
@ BUF_POOL_RESIZE_IN_PROGRESS
Resizing pool.
Definition: buf0types.h:140
std::atomic_uint32_t buf_pool_resize_status_progress
Definition: buf0buf.cc:314
constexpr uint32_t BUF_BUDDY_LOW
Smallest buddy page size.
Definition: buf0types.h:167
constexpr uint32_t BUF_BUDDY_SIZES_MAX
Maximum number of buddy sizes based on the max page size.
Definition: buf0types.h:173
buf_flush_t
Flags for flush types.
Definition: buf0types.h:68
@ BUF_FLUSH_LRU
Flush via the LRU list.
Definition: buf0types.h:70
@ BUF_FLUSH_LIST
Flush via the flush list of dirty blocks.
Definition: buf0types.h:73
@ BUF_FLUSH_SINGLE_PAGE
Flush via the LRU list but only a single page.
Definition: buf0types.h:76
@ BUF_FLUSH_N_TYPES
Index of last element + 1
Definition: buf0types.h:79
ib_mutex_t BufListMutex
Definition: buf0types.h:183
ib_bpmutex_t BPageMutex
Definition: buf0types.h:182
ib_mutex_t FlushListMutex
Definition: buf0types.h:184
buf_io_fix
Flags for io_fix types.
Definition: buf0types.h:83
@ BUF_IO_NONE
no pending I/O
Definition: buf0types.h:85
@ BUF_IO_WRITE
write pending
Definition: buf0types.h:91
@ BUF_IO_READ
read pending
Definition: buf0types.h:88
@ BUF_IO_PIN
disallow relocation of block and its removal from the flush_list
Definition: buf0types.h:94
rw_lock_t BPageLock
Definition: buf0types.h:187
std::ostream & operator<<(std::ostream &out, const page_id_t &page_id)
Print the given page_id_t object.
Definition: checksum.cc:704
srv_checksum_algorithm_t
Alternatives for srv_checksum_algorithm, which can be changed by setting innodb_checksum_algorithm.
Definition: buf0types.h:99
@ SRV_CHECKSUM_ALGORITHM_STRICT_INNODB
Write innodb, allow innodb when reading.
Definition: buf0types.h:106
@ SRV_CHECKSUM_ALGORITHM_CRC32
Write crc32, allow crc32, innodb or none when reading.
Definition: buf0types.h:100
@ SRV_CHECKSUM_ALGORITHM_STRICT_NONE
Write none, allow none when reading.
Definition: buf0types.h:110
@ SRV_CHECKSUM_ALGORITHM_INNODB
Write innodb, allow crc32, innodb or none when reading.
Definition: buf0types.h:104
@ SRV_CHECKSUM_ALGORITHM_NONE
Write none, allow crc32, innodb or none when reading.
Definition: buf0types.h:108
@ SRV_CHECKSUM_ALGORITHM_STRICT_CRC32
Write crc32, allow crc32 when reading.
Definition: buf0types.h:102
bool is_checksum_strict(srv_checksum_algorithm_t algo)
Definition: buf0types.h:149
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:283
Definition: buf0buf.h:1156
Page identifier.
Definition: buf0types.h:191
std::string to_string() const
Definition: buf0types.h:267
uint64_t hash() const
Retrieve the hash value.
Definition: buf0types.h:231
space_id_t m_space
Tablespace id.
Definition: buf0types.h:275
page_id_t(space_id_t space, page_no_t page_no)
Constructor from (space, page_no).
Definition: buf0types.h:218
space_id_t space() const
Retrieve the tablespace id.
Definition: buf0types.h:223
bool operator<(const page_id_t &other) const
Provides a lexicographic ordering on <space_id,page_no> pairs.
Definition: buf0types.h:263
page_no_t m_page_no
Page number.
Definition: buf0types.h:278
page_id_t()=delete
This class does not have a default constructor, because there is no natural choice for default values...
void reset(space_id_t space, page_no_t page_no)
Reset the values from a (space, page_no).
Definition: buf0types.h:239
void set_page_no(page_no_t page_no)
Reset the page number only.
Definition: buf0types.h:246
bool operator==(const page_id_t &a) const
Check if a given page_id_t object is equal to the current one.
Definition: buf0types.h:251
friend std::ostream & operator<<(std::ostream &out, const page_id_t &page_id)
Print the given page_id_t object.
Definition: checksum.cc:704
page_no_t page_no() const
Retrieve the page number.
Definition: buf0types.h:227
bool operator!=(const page_id_t &a) const
Check if a given page_id_t object is not equal to the current one.
Definition: buf0types.h:258
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2720
The interface to the operating system condition variables.
The buffer control block structure.
Definition: buf0buf.h:1756
Statistics of buddy blocks of a given size.
Definition: buf0buf.h:2259
A chunk of buffers.
Definition: buf0buf.ic:53
The buffer pool statistics structure.
Definition: buf0buf.h:2177
The buffer pool structure.
Definition: buf0buf.h:2285
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:362
The read-write lock (for threads, not for database transactions)
constexpr uint32_t UNIV_PAGE_SIZE_SHIFT_MAX
Maximum Page Size Shift (power of 2)
Definition: univ.i:309
constexpr uint32_t UNIV_ZIP_SIZE_SHIFT_MIN
log2 of smallest compressed page size (1<<10 == 1024 bytes) Note: This must never change!
Definition: univ.i:295
unsigned long int ulint
Definition: univ.i:403
Utilities for byte operations.
Policy based mutexes.
Random numbers and hashing.
Various utilities.