MySQL  8.0.12
Source Code Documentation
buf0types.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24  The lines above are intentionally left blank
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  /** Retrieve the tablespace id.
165  @return tablespace id */
166  inline space_id_t space() const { return (m_space); }
167 
168  /** Retrieve the page number.
169  @return page number */
170  inline page_no_t page_no() const { return (m_page_no); }
171 
172  /** Retrieve the fold value.
173  @return fold value */
174  inline ulint fold() const {
175  /* Initialize m_fold if it has not been initialized yet. */
176  if (m_fold == ULINT_UNDEFINED) {
177  m_fold = (m_space << 20) + m_space + m_page_no;
178  ut_ad(m_fold != ULINT_UNDEFINED);
179  }
180 
181  return (m_fold);
182  }
183 
184  /** Copy the values from a given page_id_t object.
185  @param[in] src page id object whose values to fetch */
186  inline void copy_from(const page_id_t &src) {
187  m_space = src.space();
188  m_page_no = src.page_no();
189  m_fold = src.fold();
190  }
191 
192  /** Reset the values from a (space, page_no).
193  @param[in] space tablespace id
194  @param[in] page_no page number */
196  m_space = space;
197  m_page_no = page_no;
198  m_fold = ULINT_UNDEFINED;
199  }
200 
201  /** Reset the page number only.
202  @param[in] page_no page number */
204  m_page_no = page_no;
205  m_fold = ULINT_UNDEFINED;
206  }
207 
208  /** Check if a given page_id_t object is equal to the current one.
209  @param[in] a page_id_t object to compare
210  @return true if equal */
211  inline bool equals_to(const page_id_t &a) const {
212  return (a.space() == m_space && a.page_no() == m_page_no);
213  }
214 
215  private:
216  /** Tablespace id. */
218 
219  /** Page number. */
221 
222  /** A fold value derived from m_space and m_page_no,
223  used in hashing. */
224  mutable ulint m_fold;
225 
226  /* Disable implicit copying. */
227  void operator=(const page_id_t &);
228 
229  /** Declare the overloaded global operator<< as a friend of this
230  class. Refer to the global declaration for further details. Print
231  the given page_id_t object.
232  @param[in,out] out the output stream
233  @param[in] page_id the page_id_t object to be printed
234  @return the output stream */
235  friend std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
236 };
237 
238 /** Print the given page_id_t object.
239 @param[in,out] out the output stream
240 @param[in] page_id the page_id_t object to be printed
241 @return the output stream */
242 std::ostream &operator<<(std::ostream &out, const page_id_t &page_id);
243 
244 #endif /* buf0types.h */
Flush dirty pages to disk only don&#39;t remove from the buffer pool.
Definition: buf0types.h:81
void set_page_no(page_no_t page_no)
Reset the page number only.
Definition: buf0types.h:203
unsigned char byte
Blob class.
Definition: common.h:159
buf_remove_t
Algorithm to remove the pages for a tablespace from the buffer pool.
Definition: buf0types.h:76
uint32 page_no_t
Page number.
Definition: api0api.h:57
Remove only, from the flush list, don&#39;t write or sync to disk.
Definition: buf0types.h:79
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:554
void operator=(const page_id_t &)
index of last element + 1
Definition: buf0types.h:71
Various utilities.
The buffer control block structure.
Definition: buf0buf.h:1301
Page identifier.
Definition: buf0types.h:153
Write crc32, allow crc32 when reading.
Definition: buf0types.h:100
ib_mutex_t BufListMutex
Definition: buf0types.h:145
disallow relocation of block and its removal of from the flush_list
Definition: buf0types.h:90
Remove all pages from the buffer pool, don&#39;t write or sync to disk.
Definition: buf0types.h:77
space_id_t space() const
Retrieve the tablespace id.
Definition: buf0types.h:166
The buffer pool structure.
Definition: buf0buf.h:1694
ib_bpmutex_t BPageMutex
Definition: buf0types.h:144
page_id_t(space_id_t space, page_no_t page_no)
Constructor from (space, page_no).
Definition: buf0types.h:161
write pending
Definition: buf0types.h:89
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:740
Write none, allow crc32, innodb or none when reading.
Definition: buf0types.h:106
no pending I/O
Definition: buf0types.h:87
srv_checksum_algorithm_t
Alternatives for srv_checksum_algorithm, which can be changed by setting innodb_checksum_algorithm.
Definition: buf0types.h:97
rw_lock_t BPageLock
Definition: buf0types.h:149
page_no_t m_page_no
Page number.
Definition: buf0types.h:220
buf_io_fix
Flags for io_fix types.
Definition: buf0types.h:86
page_id_t()
Default constructor.
Definition: buf0types.h:156
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:59
The read-write lock (for threads, not for database transactions)
ib_mutex_t FlushListMutex
Definition: buf0types.h:146
We use FlushObserver to track flushing of non-redo logged pages in bulk create index(BtrBulk.cc).Since we disable redo logging during a index build, we need to make sure that all dirty pages modifed by the index build are flushed to disk before any redo logged operations go to the index.
Definition: buf0flu.h:262
Write innodb, allow crc32, innodb or none when reading.
Definition: buf0types.h:102
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:211
Write crc32, allow crc32, innodb or none when reading.
Definition: buf0types.h:98
Policy based mutexes.
Definition: buf0buf.h:1145
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
void copy_from(const page_id_t &src)
Copy the values from a given page_id_t object.
Definition: buf0types.h:186
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:60
flush via the LRU list but only a single page
Definition: buf0types.h:69
Doublewrite control struct.
Definition: buf0dblwr.h:109
ulint fold() const
Retrieve the fold value.
Definition: buf0types.h:174
flush via the LRU list
Definition: buf0types.h:66
bool is_checksum_strict(srv_checksum_algorithm_t algo)
Definition: buf0types.h:112
void reset(space_id_t space, page_no_t page_no)
Reset the values from a (space, page_no).
Definition: buf0types.h:195
The buffer pool statistics structure.
Definition: buf0buf.h:1645
buf_flush_t
Flags for flush types.
Definition: buf0types.h:65
The interface to the operating system condition variables.
page_no_t page_no() const
Retrieve the page number.
Definition: buf0types.h:170
Write none, allow none when reading.
Definition: buf0types.h:108
Write innodb, allow innodb when reading.
Definition: buf0types.h:104
BPageMutex BufPoolZipMutex
Definition: buf0types.h:147
ulint m_fold
A fold value derived from m_space and m_page_no, used in hashing.
Definition: buf0types.h:224
space_id_t m_space
Tablespace id.
Definition: buf0types.h:217
flush via the flush list of dirty blocks
Definition: buf0types.h:67
read pending
Definition: buf0types.h:88
Statistics of buddy blocks of a given size.
Definition: buf0buf.h:1680