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