MySQL  8.0.23
Source Code Documentation
buf0types.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2020, Oracle and/or its affiliates.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 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 "ut0mutex.h"
39 #include "ut0ut.h"
40 
41 /** Magic value to use instead of checksums when they are disabled */
42 #define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
43 
44 /** Buffer page (uncompressed or compressed) */
45 class buf_page_t;
46 /** Buffer block for which an uncompressed page exists */
47 struct buf_block_t;
48 /** Buffer pool chunk comprising buf_block_t */
49 struct buf_chunk_t;
50 /** Buffer pool comprising buf_chunk_t */
51 struct buf_pool_t;
52 /** Buffer pool statistics struct */
53 struct buf_pool_stat_t;
54 /** Buffer pool buddy statistics struct */
55 struct buf_buddy_stat_t;
56 /** Doublewrite memory struct */
57 struct buf_dblwr_t;
58 /** Flush observer for bulk create index */
59 class FlushObserver;
60 
61 /** A buffer frame. @see page_t */
62 typedef byte buf_frame_t;
63 
64 /** Flags for flush types */
65 enum buf_flush_t : uint8_t {
66  /** Flush via the LRU list */
68 
69  /** Flush via the flush list of dirty blocks */
71 
72  /** Flush via the LRU list but only a single page */
74 
75  /** Index of last element + 1 */
77 };
78 
79 /** Algorithm to remove the pages for a tablespace from the buffer pool.
80 See buf_LRU_flush_or_remove_pages(). */
82  /** Don't remove any pages. */
84 
85  /** Remove all pages from the buffer pool, don't write or sync to disk */
87 
88  /** Remove only from the flush list, don't write or sync to disk */
90 
91  /** Flush dirty pages to disk only don't remove from the buffer pool */
93 };
94 
95 /** Flags for io_fix types */
96 enum buf_io_fix : uint8_t {
97  /** no pending I/O */
99 
100  /** read pending */
102 
103  /** write pending */
105 
106  /** disallow relocation of block and its removal from the flush_list */
107  BUF_IO_PIN
108 };
109 
110 /** Alternatives for srv_checksum_algorithm, which can be changed by
111 setting innodb_checksum_algorithm */
113  SRV_CHECKSUM_ALGORITHM_CRC32, /*!< Write crc32, allow crc32,
114  innodb or none when reading */
115  SRV_CHECKSUM_ALGORITHM_STRICT_CRC32, /*!< Write crc32, allow crc32
116  when reading */
117  SRV_CHECKSUM_ALGORITHM_INNODB, /*!< Write innodb, allow crc32,
118  innodb or none when reading */
119  SRV_CHECKSUM_ALGORITHM_STRICT_INNODB, /*!< Write innodb, allow
120  innodb when reading */
121  SRV_CHECKSUM_ALGORITHM_NONE, /*!< Write none, allow crc32,
122  innodb or none when reading */
123  SRV_CHECKSUM_ALGORITHM_STRICT_NONE /*!< Write none, allow none
124  when reading */
125 };
126 
128  return (algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 ||
131 }
132 
133 inline bool is_checksum_strict(ulint algo) {
134  return (algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 ||
137 }
138 
139 /** Parameters of binary buddy system for compressed pages (buf0buddy.h) */
140 /** @{ */
141 /** Zip shift value for the smallest page size */
142 #define BUF_BUDDY_LOW_SHIFT UNIV_ZIP_SIZE_SHIFT_MIN
143 
144 /** Smallest buddy page size */
145 #define BUF_BUDDY_LOW (1U << BUF_BUDDY_LOW_SHIFT)
146 
147 /** Actual number of buddy sizes based on current page size */
148 #define BUF_BUDDY_SIZES (UNIV_PAGE_SIZE_SHIFT - BUF_BUDDY_LOW_SHIFT)
149 
150 /** Maximum number of buddy sizes based on the max page size */
151 #define BUF_BUDDY_SIZES_MAX (UNIV_PAGE_SIZE_SHIFT_MAX - BUF_BUDDY_LOW_SHIFT)
152 
153 /** twice the maximum block size of the buddy system;
154 the underlying memory is aligned by this amount:
155 this must be equal to UNIV_PAGE_SIZE */
156 #define BUF_BUDDY_HIGH (BUF_BUDDY_LOW << BUF_BUDDY_SIZES)
157 /** @} */
158 
159 typedef ib_bpmutex_t BPageMutex;
160 typedef ib_mutex_t BufListMutex;
161 typedef ib_mutex_t FlushListMutex;
163 #ifndef UNIV_HOTBACKUP
165 #endif /* !UNIV_HOTBACKUP */
166 
167 /** Page identifier. */
168 class page_id_t {
169  public:
170  /**
171  This class does not have a default constructor, because there is no natural
172  choice for default values of m_space and m_page_no.
173 
174  If 0,0 were used, then it's not good as it doesn't match UINT32_UNDEFINED
175  used to denote impossible page_no_t in several places, and 0 is a legal
176  value for both space_id_t and page_id_t of a real page!
177 
178  If UINT32_UNDEFINED,UINT32_UNDEFINED were used, then it doesn't match the
179  most common usage where use use memset(parent,0,sizeof(parent_t)); on a
180  parent struct where one of the members has page_id_t type - which is ok
181  given that page_id_t is TriviallyCopyable, and that the field is not
182  used until it is assigned some real value. Such constructor would be
183  misleading to people reading the code, as they might expect UINT32_UNDEFINED
184  value, if they didn't notice the memset code burried somewhere in parent's
185  initialization routine.
186 
187  Therefore, please either be explicit by using (space,page_no) overload,
188  or continue to use memset at your own risk.
189  */
190  page_id_t() = delete;
191 
192  /** Constructor from (space, page_no).
193  @param[in] space tablespace id
194  @param[in] page_no page number */
197 
198  /** Retrieve the tablespace id.
199  @return tablespace id */
200  inline space_id_t space() const { return (m_space); }
201 
202  /** Retrieve the page number.
203  @return page number */
204  inline page_no_t page_no() const { return (m_page_no); }
205 
206  /** Retrieve the fold value.
207  @return fold value */
208  inline uint32_t fold() const { return (m_space << 20) + m_space + m_page_no; }
209 
210  /** Reset the values from a (space, page_no).
211  @param[in] space tablespace id
212  @param[in] page_no page number */
214  m_space = space;
215  m_page_no = page_no;
216  }
217 
218  /** Reset the page number only.
219  @param[in] page_no page number */
221 
222  /** Check if a given page_id_t object is equal to the current one.
223  @param[in] a page_id_t object to compare
224  @return true if equal */
225  inline bool operator==(const page_id_t &a) const {
226  return (a.space() == m_space && a.page_no() == m_page_no);
227  }
228 
229  /** Check if a given page_id_t object is not equal to the current one.
230  @param[in] a page_id_t object to compare
231  @return true if not equal */
232  inline bool operator!=(const page_id_t &a) const { return !(*this == a); }
233 
234  /** Provides a lexicographic ordering on <space_id,page_no> pairs
235  @param[in] other page_id_t object to compare
236  @return true if this is strictly smaller than other */
237  inline bool operator<(const page_id_t &other) const {
238  return m_space < other.space() ||
239  (m_space == other.space() && m_page_no < other.page_no());
240  }
241 
242  private:
243  /** Tablespace id. */
245 
246  /** Page number. */
248 
249  friend std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
250 };
251 
252 /** Print the given page_id_t object.
253 @param[in,out] out the output stream
254 @param[in] page_id the page_id_t object to be printed
255 @return the output stream */
256 std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
257 
258 #endif /* buf0types.h */
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
page_id_t::m_space
space_id_t m_space
Tablespace id.
Definition: buf0types.h:244
BUF_FLUSH_SINGLE_PAGE
@ BUF_FLUSH_SINGLE_PAGE
Flush via the LRU list but only a single page.
Definition: buf0types.h:73
BUF_FLUSH_N_TYPES
@ BUF_FLUSH_N_TYPES
Index of last element + 1
Definition: buf0types.h:76
BPageMutex
ib_bpmutex_t BPageMutex
Definition: buf0types.h:159
FlushListMutex
ib_mutex_t FlushListMutex
Definition: buf0types.h:161
page_id_t::operator<<
friend std::ostream & operator<<(std::ostream &out, const page_id_t &page_id)
Print the given page_id_t object.
Definition: checksum.cc:755
page_id_t::space
space_id_t space() const
Retrieve the tablespace id.
Definition: buf0types.h:200
BufListMutex
ib_mutex_t BufListMutex
Definition: buf0types.h:160
BUF_REMOVE_FLUSH_WRITE
@ BUF_REMOVE_FLUSH_WRITE
Flush dirty pages to disk only don't remove from the buffer pool.
Definition: buf0types.h:92
buf_block_t
The buffer control block structure.
Definition: buf0buf.h:1544
page_id_t::fold
uint32_t fold() const
Retrieve the fold value.
Definition: buf0types.h:208
buf_flush_t
buf_flush_t
Flags for flush types.
Definition: buf0types.h:65
SRV_CHECKSUM_ALGORITHM_INNODB
@ SRV_CHECKSUM_ALGORITHM_INNODB
Write innodb, allow crc32, innodb or none when reading.
Definition: buf0types.h:117
BUF_REMOVE_NONE
@ BUF_REMOVE_NONE
Don't remove any pages.
Definition: buf0types.h:83
buf_page_t
Definition: buf0buf.h:1202
page_id_t::page_id_t
page_id_t(space_id_t space, page_no_t page_no)
Constructor from (space, page_no).
Definition: buf0types.h:195
buf_frame_t
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:59
BUF_IO_READ
@ BUF_IO_READ
read pending
Definition: buf0types.h:101
is_checksum_strict
bool is_checksum_strict(srv_checksum_algorithm_t algo)
Definition: buf0types.h:127
BufPoolZipMutex
BPageMutex BufPoolZipMutex
Definition: buf0types.h:162
BPageLock
rw_lock_t BPageLock
Definition: buf0types.h:164
BUF_FLUSH_LIST
@ BUF_FLUSH_LIST
Flush via the flush list of dirty blocks.
Definition: buf0types.h:70
buf_remove_t
buf_remove_t
Algorithm to remove the pages for a tablespace from the buffer pool.
Definition: buf0types.h:81
page_id_t::operator==
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:225
SRV_CHECKSUM_ALGORITHM_STRICT_INNODB
@ SRV_CHECKSUM_ALGORITHM_STRICT_INNODB
Write innodb, allow innodb when reading.
Definition: buf0types.h:119
BUF_REMOVE_FLUSH_NO_WRITE
@ BUF_REMOVE_FLUSH_NO_WRITE
Remove only from the flush list, don't write or sync to disk.
Definition: buf0types.h:89
page_id_t::m_page_no
page_no_t m_page_no
Page number.
Definition: buf0types.h:247
buf_pool_stat_t
The buffer pool statistics structure.
Definition: buf0buf.h:1899
page_id_t::operator!=
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:232
SRV_CHECKSUM_ALGORITHM_STRICT_NONE
@ SRV_CHECKSUM_ALGORITHM_STRICT_NONE
Write none, allow none when reading.
Definition: buf0types.h:123
SRV_CHECKSUM_ALGORITHM_NONE
@ SRV_CHECKSUM_ALGORITHM_NONE
Write none, allow crc32, innodb or none when reading.
Definition: buf0types.h:121
page_id_t
Page identifier.
Definition: buf0types.h:168
BUF_IO_WRITE
@ BUF_IO_WRITE
write pending
Definition: buf0types.h:104
os0event.h
page_id_t::page_id_t
page_id_t()=delete
This class does not have a default constructor, because there is no natural choice for default values...
BUF_IO_PIN
@ BUF_IO_PIN
disallow relocation of block and its removal from the flush_list
Definition: buf0types.h:107
SRV_CHECKSUM_ALGORITHM_STRICT_CRC32
@ SRV_CHECKSUM_ALGORITHM_STRICT_CRC32
Write crc32, allow crc32 when reading.
Definition: buf0types.h:115
SRV_CHECKSUM_ALGORITHM_CRC32
@ SRV_CHECKSUM_ALGORITHM_CRC32
Write crc32, allow crc32, innodb or none when reading.
Definition: buf0types.h:113
ut0mutex.h
BUF_FLUSH_LRU
@ BUF_FLUSH_LRU
Flush via the LRU list.
Definition: buf0types.h:67
space_id_t
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
rw_lock_t
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:568
page_id_t::operator<
bool operator<(const page_id_t &other) const
Provides a lexicographic ordering on <space_id,page_no> pairs.
Definition: buf0types.h:237
BUF_IO_NONE
@ BUF_IO_NONE
no pending I/O
Definition: buf0types.h:98
buf_buddy_stat_t
Statistics of buddy blocks of a given size.
Definition: buf0buf.h:1981
operator<<
std::ostream & operator<<(std::ostream &out, const page_id_t &page_id)
Print the given page_id_t object.
Definition: checksum.cc:755
page_id_t::set_page_no
void set_page_no(page_no_t page_no)
Reset the page number only.
Definition: buf0types.h:220
FlushObserver
We use FlushObserver to track flushing of non-redo logged pages in bulk create index(BtrBulk....
Definition: buf0flu.h:266
buf_pool_t
The buffer pool structure.
Definition: buf0buf.h:2007
sync0rw.h
BUF_REMOVE_ALL_NO_WRITE
@ BUF_REMOVE_ALL_NO_WRITE
Remove all pages from the buffer pool, don't write or sync to disk.
Definition: buf0types.h:86
page_id_t::page_no
page_no_t page_no() const
Retrieve the page number.
Definition: buf0types.h:204
ut0ut.h
page_id_t::reset
void reset(space_id_t space, page_no_t page_no)
Reset the values from a (space, page_no).
Definition: buf0types.h:213
buf_io_fix
buf_io_fix
Flags for io_fix types.
Definition: buf0types.h:96
srv_checksum_algorithm_t
srv_checksum_algorithm_t
Alternatives for srv_checksum_algorithm, which can be changed by setting innodb_checksum_algorithm.
Definition: buf0types.h:112