MySQL 8.4.2
Source Code Documentation
buf0types.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2024, 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/** Algorithm to remove the pages for a tablespace from the buffer pool.
83See buf_LRU_flush_or_remove_pages(). */
85 /** Don't remove any pages. */
87
88 /** Remove all pages from the buffer pool, don't write or sync to disk */
90
91 /** Remove only from the flush list, don't write or sync to disk */
93
94 /** Flush dirty pages to disk only don't remove from the buffer pool */
96};
97
98/** Flags for io_fix types */
99enum buf_io_fix : uint8_t {
100 /** no pending I/O */
102
103 /** read pending */
105
106 /** write pending */
108
109 /** disallow relocation of block and its removal from the flush_list */
112
113/** Alternatives for srv_checksum_algorithm, which can be changed by
114setting innodb_checksum_algorithm */
116 SRV_CHECKSUM_ALGORITHM_CRC32, /*!< Write crc32, allow crc32,
117 innodb or none when reading */
118 SRV_CHECKSUM_ALGORITHM_STRICT_CRC32, /*!< Write crc32, allow crc32
119 when reading */
120 SRV_CHECKSUM_ALGORITHM_INNODB, /*!< Write innodb, allow crc32,
121 innodb or none when reading */
122 SRV_CHECKSUM_ALGORITHM_STRICT_INNODB, /*!< Write innodb, allow
123 innodb when reading */
124 SRV_CHECKSUM_ALGORITHM_NONE, /*!< Write none, allow crc32,
125 innodb or none when reading */
126 SRV_CHECKSUM_ALGORITHM_STRICT_NONE /*!< Write none, allow none
127 when reading */
129
130/** Buffer pool resize status code and progress are tracked using these
131atomic variables to ensure thread synchronization between
132innodb_buffer_pool_size_update (raising srv_buf_resize_event) and
133buf_resize_thread (handling srv_buf_resize_event) */
134extern std::atomic_uint32_t buf_pool_resize_status_code;
135extern std::atomic_uint32_t buf_pool_resize_status_progress;
136
137/** Enumerate possible status codes during buffer pool resize. This is used
138to identify the resize status using the corresponding code. */
140 /** Resize completed or Resize not in progress*/
142
143 /** Resize started */
145
146 /** Disabling Adaptive Hash Index */
148
149 /** Withdrawing blocks */
151
152 /** Acquiring global lock */
154
155 /** Resizing pool */
157
158 /** Resizing hash */
160
161 /** Resizing failed */
164
166 return (algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 ||
169}
170
171inline bool is_checksum_strict(ulint algo) {
172 return (algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 ||
175}
176
177/** Parameters of binary buddy system for compressed pages (buf0buddy.h) */
178/** @{ */
179/** Zip shift value for the smallest page size */
181
182/** Smallest buddy page size */
183constexpr uint32_t BUF_BUDDY_LOW = (1U << BUF_BUDDY_LOW_SHIFT);
184
185/** Actual number of buddy sizes based on current page size */
186#define BUF_BUDDY_SIZES (UNIV_PAGE_SIZE_SHIFT - BUF_BUDDY_LOW_SHIFT)
187
188/** Maximum number of buddy sizes based on the max page size */
189constexpr uint32_t BUF_BUDDY_SIZES_MAX =
191
192/** twice the maximum block size of the buddy system;
193the underlying memory is aligned by this amount:
194this must be equal to UNIV_PAGE_SIZE */
195#define BUF_BUDDY_HIGH (BUF_BUDDY_LOW << BUF_BUDDY_SIZES)
196/** @} */
197
198typedef ib_bpmutex_t BPageMutex;
199typedef ib_mutex_t BufListMutex;
200typedef ib_mutex_t FlushListMutex;
202#ifndef UNIV_HOTBACKUP
204#endif /* !UNIV_HOTBACKUP */
205
206/** Page identifier. */
208 public:
209 /**
210 This class does not have a default constructor, because there is no natural
211 choice for default values of m_space and m_page_no.
212
213 If 0,0 were used, then it's not good as it doesn't match UINT32_UNDEFINED
214 used to denote impossible page_no_t in several places, and 0 is a legal
215 value for both space_id_t and page_id_t of a real page!
216
217 If UINT32_UNDEFINED,UINT32_UNDEFINED were used, then it doesn't match the
218 most common usage where use use memset(parent,0,sizeof(parent_t)); on a
219 parent struct where one of the members has page_id_t type - which is ok
220 given that page_id_t is TriviallyCopyable, and that the field is not
221 used until it is assigned some real value. Such constructor would be
222 misleading to people reading the code, as they might expect UINT32_UNDEFINED
223 value, if they didn't notice the memset code buried somewhere in parent's
224 initialization routine.
225
226 Therefore, please either be explicit by using (space,page_no) overload,
227 or continue to use memset at your own risk.
228 */
229 page_id_t() = delete;
230
231 /** Constructor from (space, page_no).
232 @param[in] space tablespace id
233 @param[in] page_no page number */
236
237 /** Retrieve the tablespace id.
238 @return tablespace id */
239 inline space_id_t space() const { return (m_space); }
240
241 /** Retrieve the page number.
242 @return page number */
243 inline page_no_t page_no() const { return (m_page_no); }
244
245 /** Retrieve the hash value.
246 @return hashed value */
247 inline uint64_t hash() const {
248 constexpr uint64_t HASH_MASK = 1653893711;
249 return (((uint64_t)m_space << 20) + m_space + m_page_no) ^ HASH_MASK;
250 }
251
252 /** Reset the values from a (space, page_no).
253 @param[in] space tablespace id
254 @param[in] page_no page number */
256 m_space = space;
258 }
259
260 /** Reset the page number only.
261 @param[in] page_no page number */
263
264 /** Check if a given page_id_t object is equal to the current one.
265 @param[in] a page_id_t object to compare
266 @return true if equal */
267 inline bool operator==(const page_id_t &a) const {
268 return (a.space() == m_space && a.page_no() == m_page_no);
269 }
270
271 /** Check if a given page_id_t object is not equal to the current one.
272 @param[in] a page_id_t object to compare
273 @return true if not equal */
274 inline bool operator!=(const page_id_t &a) const { return !(*this == a); }
275
276 /** Provides a lexicographic ordering on <space_id,page_no> pairs
277 @param[in] other page_id_t object to compare
278 @return true if this is strictly smaller than other */
279 inline bool operator<(const page_id_t &other) const {
280 return m_space < other.space() ||
281 (m_space == other.space() && m_page_no < other.page_no());
282 }
283
284 private:
285 /** Tablespace id. */
287
288 /** Page number. */
290
291 friend std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
292};
293
294/** Print the given page_id_t object.
295@param[in,out] out the output stream
296@param[in] page_id the page_id_t object to be printed
297@return the output stream */
298std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
299
300#endif /* buf0types.h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:47
uint32_t page_no_t
Page number.
Definition: api0api.h:45
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:180
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:310
BPageMutex BufPoolZipMutex
Definition: buf0types.h:201
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:139
@ BUF_POOL_RESIZE_HASH
Resizing hash.
Definition: buf0types.h:159
@ BUF_POOL_RESIZE_START
Resize started.
Definition: buf0types.h:144
@ BUF_POOL_RESIZE_FAILED
Resizing failed.
Definition: buf0types.h:162
@ BUF_POOL_RESIZE_DISABLE_AHI
Disabling Adaptive Hash Index.
Definition: buf0types.h:147
@ BUF_POOL_RESIZE_COMPLETE
Resize completed or Resize not in progress.
Definition: buf0types.h:141
@ BUF_POOL_RESIZE_GLOBAL_LOCK
Acquiring global lock.
Definition: buf0types.h:153
@ BUF_POOL_RESIZE_WITHDRAW_BLOCKS
Withdrawing blocks.
Definition: buf0types.h:150
@ BUF_POOL_RESIZE_IN_PROGRESS
Resizing pool.
Definition: buf0types.h:156
std::atomic_uint32_t buf_pool_resize_status_progress
Definition: buf0buf.cc:311
constexpr uint32_t BUF_BUDDY_LOW
Smallest buddy page size.
Definition: buf0types.h:183
constexpr uint32_t BUF_BUDDY_SIZES_MAX
Maximum number of buddy sizes based on the max page size.
Definition: buf0types.h:189
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
buf_remove_t
Algorithm to remove the pages for a tablespace from the buffer pool.
Definition: buf0types.h:84
@ BUF_REMOVE_FLUSH_WRITE
Flush dirty pages to disk only don't remove from the buffer pool.
Definition: buf0types.h:95
@ BUF_REMOVE_NONE
Don't remove any pages.
Definition: buf0types.h:86
@ BUF_REMOVE_ALL_NO_WRITE
Remove all pages from the buffer pool, don't write or sync to disk.
Definition: buf0types.h:89
@ BUF_REMOVE_FLUSH_NO_WRITE
Remove only from the flush list, don't write or sync to disk.
Definition: buf0types.h:92
ib_mutex_t BufListMutex
Definition: buf0types.h:199
ib_bpmutex_t BPageMutex
Definition: buf0types.h:198
ib_mutex_t FlushListMutex
Definition: buf0types.h:200
buf_io_fix
Flags for io_fix types.
Definition: buf0types.h:99
@ BUF_IO_NONE
no pending I/O
Definition: buf0types.h:101
@ BUF_IO_WRITE
write pending
Definition: buf0types.h:107
@ BUF_IO_READ
read pending
Definition: buf0types.h:104
@ BUF_IO_PIN
disallow relocation of block and its removal from the flush_list
Definition: buf0types.h:110
rw_lock_t BPageLock
Definition: buf0types.h:203
std::ostream & operator<<(std::ostream &out, const page_id_t &page_id)
Print the given page_id_t object.
Definition: checksum.cc:703
srv_checksum_algorithm_t
Alternatives for srv_checksum_algorithm, which can be changed by setting innodb_checksum_algorithm.
Definition: buf0types.h:115
@ SRV_CHECKSUM_ALGORITHM_STRICT_INNODB
Write innodb, allow innodb when reading.
Definition: buf0types.h:122
@ SRV_CHECKSUM_ALGORITHM_CRC32
Write crc32, allow crc32, innodb or none when reading.
Definition: buf0types.h:116
@ SRV_CHECKSUM_ALGORITHM_STRICT_NONE
Write none, allow none when reading.
Definition: buf0types.h:126
@ SRV_CHECKSUM_ALGORITHM_INNODB
Write innodb, allow crc32, innodb or none when reading.
Definition: buf0types.h:120
@ SRV_CHECKSUM_ALGORITHM_NONE
Write none, allow crc32, innodb or none when reading.
Definition: buf0types.h:124
@ SRV_CHECKSUM_ALGORITHM_STRICT_CRC32
Write crc32, allow crc32 when reading.
Definition: buf0types.h:118
bool is_checksum_strict(srv_checksum_algorithm_t algo)
Definition: buf0types.h:165
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:270
Definition: buf0buf.h:1153
Page identifier.
Definition: buf0types.h:207
uint64_t hash() const
Retrieve the hash value.
Definition: buf0types.h:247
space_id_t m_space
Tablespace id.
Definition: buf0types.h:286
page_id_t(space_id_t space, page_no_t page_no)
Constructor from (space, page_no).
Definition: buf0types.h:234
space_id_t space() const
Retrieve the tablespace id.
Definition: buf0types.h:239
bool operator<(const page_id_t &other) const
Provides a lexicographic ordering on <space_id,page_no> pairs.
Definition: buf0types.h:279
page_no_t m_page_no
Page number.
Definition: buf0types.h:289
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:255
void set_page_no(page_no_t page_no)
Reset the page number only.
Definition: buf0types.h:262
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:267
friend std::ostream & operator<<(std::ostream &out, const page_id_t &page_id)
Print the given page_id_t object.
Definition: checksum.cc:703
page_no_t page_no() const
Retrieve the page number.
Definition: buf0types.h:243
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:274
The interface to the operating system condition variables.
The buffer control block structure.
Definition: buf0buf.h:1747
Statistics of buddy blocks of a given size.
Definition: buf0buf.h:2249
A chunk of buffers.
Definition: buf0buf.ic:53
The buffer pool statistics structure.
Definition: buf0buf.h:2167
The buffer pool structure.
Definition: buf0buf.h:2275
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:363
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:312
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:298
unsigned long int ulint
Definition: univ.i:406
Utilities for byte operations.
Policy based mutexes.
Random numbers and hashing.
Various utilities.