MySQL  8.0.19
Source Code Documentation
buf0types.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
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 */
60 
61 /** A buffer frame. @see page_t */
62 typedef byte buf_frame_t;
63 
64 /** Flags for flush types */
66  BUF_FLUSH_LRU = 0, /*!< flush via the LRU list */
67  BUF_FLUSH_LIST, /*!< flush via the flush list
68  of dirty blocks */
69  BUF_FLUSH_SINGLE_PAGE, /*!< flush via the LRU list
70  but only a single page */
71  BUF_FLUSH_N_TYPES /*!< index of last element + 1 */
72 };
73 
74 /** Algorithm to remove the pages for a tablespace from the buffer pool.
75 See buf_LRU_flush_or_remove_pages(). */
77  BUF_REMOVE_ALL_NO_WRITE, /*!< Remove all pages from the buffer
78  pool, don't write or sync to disk */
79  BUF_REMOVE_FLUSH_NO_WRITE, /*!< Remove only, from the flush list,
80  don't write or sync to disk */
81  BUF_REMOVE_FLUSH_WRITE /*!< Flush dirty pages to disk only
82  don't remove from the buffer pool */
83 };
84 
85 /** Flags for io_fix types */
86 enum buf_io_fix {
87  BUF_IO_NONE = 0, /**< no pending I/O */
88  BUF_IO_READ, /**< read pending */
89  BUF_IO_WRITE, /**< write pending */
90  BUF_IO_PIN /**< disallow relocation of
91  block and its removal of from
92  the flush_list */
93 };
94 
95 /** Alternatives for srv_checksum_algorithm, which can be changed by
96 setting innodb_checksum_algorithm */
98  SRV_CHECKSUM_ALGORITHM_CRC32, /*!< Write crc32, allow crc32,
99  innodb or none when reading */
100  SRV_CHECKSUM_ALGORITHM_STRICT_CRC32, /*!< Write crc32, allow crc32
101  when reading */
102  SRV_CHECKSUM_ALGORITHM_INNODB, /*!< Write innodb, allow crc32,
103  innodb or none when reading */
104  SRV_CHECKSUM_ALGORITHM_STRICT_INNODB, /*!< Write innodb, allow
105  innodb when reading */
106  SRV_CHECKSUM_ALGORITHM_NONE, /*!< Write none, allow crc32,
107  innodb or none when reading */
108  SRV_CHECKSUM_ALGORITHM_STRICT_NONE /*!< Write none, allow none
109  when reading */
110 };
111 
113  return (algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 ||
116 }
117 
118 inline bool is_checksum_strict(ulint algo) {
119  return (algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32 ||
122 }
123 
124 /** Parameters of binary buddy system for compressed pages (buf0buddy.h) */
125 /* @{ */
126 /** Zip shift value for the smallest page size */
127 #define BUF_BUDDY_LOW_SHIFT UNIV_ZIP_SIZE_SHIFT_MIN
128 
129 /** Smallest buddy page size */
130 #define BUF_BUDDY_LOW (1U << BUF_BUDDY_LOW_SHIFT)
131 
132 /** Actual number of buddy sizes based on current page size */
133 #define BUF_BUDDY_SIZES (UNIV_PAGE_SIZE_SHIFT - BUF_BUDDY_LOW_SHIFT)
134 
135 /** Maximum number of buddy sizes based on the max page size */
136 #define BUF_BUDDY_SIZES_MAX (UNIV_PAGE_SIZE_SHIFT_MAX - BUF_BUDDY_LOW_SHIFT)
137 
138 /** twice the maximum block size of the buddy system;
139 the underlying memory is aligned by this amount:
140 this must be equal to UNIV_PAGE_SIZE */
141 #define BUF_BUDDY_HIGH (BUF_BUDDY_LOW << BUF_BUDDY_SIZES)
142 /* @} */
143 
144 typedef ib_bpmutex_t BPageMutex;
145 typedef ib_mutex_t BufListMutex;
146 typedef ib_mutex_t FlushListMutex;
148 #ifndef UNIV_HOTBACKUP
150 #endif /* !UNIV_HOTBACKUP */
151 
152 /** Page identifier. */
153 class page_id_t {
154  public:
155  /** Default constructor */
157 
158  /** Constructor from (space, page_no).
159  @param[in] space tablespace id
160  @param[in] page_no page number */
162  : m_space(space), m_page_no(page_no), m_fold(ULINT_UNDEFINED) {}
163 
164  page_id_t(const page_id_t &) = default;
165 
166  /** Retrieve the tablespace id.
167  @return tablespace id */
168  inline space_id_t space() const { return (m_space); }
169 
170  /** Retrieve the page number.
171  @return page number */
172  inline page_no_t page_no() const { return (m_page_no); }
173 
174  /** Retrieve the fold value.
175  @return fold value */
176  inline ulint fold() const {
177  /* Initialize m_fold if it has not been initialized yet. */
178  if (m_fold == ULINT_UNDEFINED) {
179  m_fold = (m_space << 20) + m_space + m_page_no;
180  ut_ad(m_fold != ULINT_UNDEFINED);
181  }
182 
183  return (m_fold);
184  }
185 
186  /** Copy the values from a given page_id_t object.
187  @param[in] src page id object whose values to fetch */
188  inline void copy_from(const page_id_t &src) {
189  m_space = src.space();
190  m_page_no = src.page_no();
191  m_fold = src.fold();
192  }
193 
194  /** Reset the values from a (space, page_no).
195  @param[in] space tablespace id
196  @param[in] page_no page number */
198  m_space = space;
199  m_page_no = page_no;
200  m_fold = ULINT_UNDEFINED;
201  }
202 
203  /** Reset the page number only.
204  @param[in] page_no page number */
206  m_page_no = page_no;
207  m_fold = ULINT_UNDEFINED;
208  }
209 
210  /** Check if a given page_id_t object is equal to the current one.
211  @param[in] a page_id_t object to compare
212  @return true if equal */
213  inline bool equals_to(const page_id_t &a) const {
214  return (a.space() == m_space && a.page_no() == m_page_no);
215  }
216 
217  private:
218  /** Tablespace id. */
220 
221  /** Page number. */
223 
224  /** A fold value derived from m_space and m_page_no,
225  used in hashing. */
226  mutable ulint m_fold;
227 
228  /* Disable implicit copying. */
229  void operator=(const page_id_t &) = delete;
230 
231  /** Declare the overloaded global operator<< as a friend of this
232  class. Refer to the global declaration for further details. Print
233  the given page_id_t object.
234  @param[in,out] out the output stream
235  @param[in] page_id the page_id_t object to be printed
236  @return the output stream */
237  friend std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
238 };
239 
240 /** Print the given page_id_t object.
241 @param[in,out] out the output stream
242 @param[in] page_id the page_id_t object to be printed
243 @return the output stream */
244 std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
245 
246 #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:219
ut_ad
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:65
BPageMutex
ib_bpmutex_t BPageMutex
Definition: buf0types.h:144
FlushListMutex
ib_mutex_t FlushListMutex
Definition: buf0types.h:146
BUF_FLUSH_LIST
@ BUF_FLUSH_LIST
flush via the flush list of dirty blocks
Definition: buf0types.h:67
page_id_t::operator<<
friend std::ostream & operator<<(std::ostream &out, const page_id_t &page_id)
Declare the overloaded global operator<< as a friend of this class.
Definition: checksum.cc:739
page_id_t::space
space_id_t space() const
Retrieve the tablespace id.
Definition: buf0types.h:168
BufListMutex
ib_mutex_t BufListMutex
Definition: buf0types.h:145
BUF_REMOVE_FLUSH_WRITE
@ BUF_REMOVE_FLUSH_WRITE
Flush dirty pages to disk only don't remove from the buffer pool.
Definition: buf0types.h:81
BUF_FLUSH_LRU
@ BUF_FLUSH_LRU
flush via the LRU list
Definition: buf0types.h:66
buf_block_t
The buffer control block structure.
Definition: buf0buf.h:1318
SRV_CHECKSUM_ALGORITHM_INNODB
@ SRV_CHECKSUM_ALGORITHM_INNODB
Write innodb, allow crc32, innodb or none when reading.
Definition: buf0types.h:102
buf_page_t
Definition: buf0buf.h:1161
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:161
buf_frame_t
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:59
page_id_t::page_id_t
page_id_t()
Default constructor.
Definition: buf0types.h:156
BUF_FLUSH_SINGLE_PAGE
@ BUF_FLUSH_SINGLE_PAGE
flush via the LRU list but only a single page
Definition: buf0types.h:69
is_checksum_strict
bool is_checksum_strict(srv_checksum_algorithm_t algo)
Definition: buf0types.h:112
BufPoolZipMutex
BPageMutex BufPoolZipMutex
Definition: buf0types.h:147
page_id_t::equals_to
bool equals_to(const page_id_t &a) const
Check if a given page_id_t object is equal to the current one.
Definition: buf0types.h:213
BPageLock
rw_lock_t BPageLock
Definition: buf0types.h:149
buf_flush_t
buf_flush_t
Flags for flush types.
Definition: buf0types.h:65
BUF_IO_READ
@ BUF_IO_READ
read pending
Definition: buf0types.h:88
buf_remove_t
buf_remove_t
Algorithm to remove the pages for a tablespace from the buffer pool.
Definition: buf0types.h:76
page_id_t::fold
ulint fold() const
Retrieve the fold value.
Definition: buf0types.h:176
page_id_t::operator=
void operator=(const page_id_t &)=delete
BUF_IO_NONE
@ BUF_IO_NONE
no pending I/O
Definition: buf0types.h:87
SRV_CHECKSUM_ALGORITHM_STRICT_INNODB
@ SRV_CHECKSUM_ALGORITHM_STRICT_INNODB
Write innodb, allow innodb when reading.
Definition: buf0types.h:104
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:79
page_id_t::m_page_no
page_no_t m_page_no
Page number.
Definition: buf0types.h:222
BUF_IO_PIN
@ BUF_IO_PIN
disallow relocation of block and its removal of from the flush_list
Definition: buf0types.h:90
buf_pool_stat_t
The buffer pool statistics structure.
Definition: buf0buf.h:1665
SRV_CHECKSUM_ALGORITHM_STRICT_NONE
@ SRV_CHECKSUM_ALGORITHM_STRICT_NONE
Write none, allow none when reading.
Definition: buf0types.h:108
SRV_CHECKSUM_ALGORITHM_NONE
@ SRV_CHECKSUM_ALGORITHM_NONE
Write none, allow crc32, innodb or none when reading.
Definition: buf0types.h:106
page_id_t
Page identifier.
Definition: buf0types.h:153
os0event.h
SRV_CHECKSUM_ALGORITHM_STRICT_CRC32
@ SRV_CHECKSUM_ALGORITHM_STRICT_CRC32
Write crc32, allow crc32 when reading.
Definition: buf0types.h:100
SRV_CHECKSUM_ALGORITHM_CRC32
@ SRV_CHECKSUM_ALGORITHM_CRC32
Write crc32, allow crc32, innodb or none when reading.
Definition: buf0types.h:98
ut0mutex.h
buf_io_fix
buf_io_fix
Flags for io_fix types.
Definition: buf0types.h:86
BUF_FLUSH_N_TYPES
@ BUF_FLUSH_N_TYPES
index of last element + 1
Definition: buf0types.h:71
buf_dblwr_t
Doublewrite control struct.
Definition: buf0dblwr.h:109
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:555
BUF_IO_WRITE
@ BUF_IO_WRITE
write pending
Definition: buf0types.h:89
buf_buddy_stat_t
Statistics of buddy blocks of a given size.
Definition: buf0buf.h:1700
operator<<
std::ostream & operator<<(std::ostream &out, const page_id_t &page_id)
Print the given page_id_t object.
Definition: checksum.cc:739
page_id_t::copy_from
void copy_from(const page_id_t &src)
Copy the values from a given page_id_t object.
Definition: buf0types.h:188
page_id_t::set_page_no
void set_page_no(page_no_t page_no)
Reset the page number only.
Definition: buf0types.h:205
FlushObserver
We use FlushObserver to track flushing of non-redo logged pages in bulk create index(BtrBulk....
Definition: buf0flu.h:269
buf_pool_t
The buffer pool structure.
Definition: buf0buf.h:1714
sync0rw.h
page_id_t::m_fold
ulint m_fold
A fold value derived from m_space and m_page_no, used in hashing.
Definition: buf0types.h:226
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:77
page_id_t::page_no
page_no_t page_no() const
Retrieve the page number.
Definition: buf0types.h:172
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:197
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:97