MySQL  8.0.19
Source Code Documentation
page0size.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2013, 2019, 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/page0size.h
28  A class describing a page size.
29 
30  Created Nov 14, 2013 Vasil Dimov
31  *******************************************************/
32 
33 #ifndef page0size_t
34 #define page0size_t
35 
36 #include "fsp0types.h"
37 #include "univ.i"
38 
39 #define FIELD_REF_SIZE 20
40 
41 /** A BLOB field reference full of zero, for use in assertions and
42 tests.Initially, BLOB field references are set to zero, in
43 dtuple_convert_big_rec(). */
44 extern const byte field_ref_zero[FIELD_REF_SIZE];
45 
46 #define PAGE_SIZE_T_SIZE_BITS 17
47 
48 /** Page size descriptor. Contains the physical and logical page size, as well
49 as whether the page is compressed or not. */
50 class page_size_t {
51  public:
52  /** Constructor from (physical, logical, is_compressed).
53  @param[in] physical physical (on-disk/zipped) page size
54  @param[in] logical logical (in-memory/unzipped) page size
55  @param[in] is_compressed whether the page is compressed */
56  page_size_t(ulint physical, ulint logical, bool is_compressed) {
57  if (physical == 0) {
58  physical = UNIV_PAGE_SIZE_ORIG;
59  }
60  if (logical == 0) {
61  logical = UNIV_PAGE_SIZE_ORIG;
62  }
63 
64  m_physical = static_cast<unsigned>(physical);
65  m_logical = static_cast<unsigned>(logical);
66  m_is_compressed = static_cast<unsigned>(is_compressed);
67 
70 
73 
74  ut_ad(logical <= UNIV_PAGE_SIZE_MAX);
76  ut_ad(!is_compressed || physical <= UNIV_ZIP_SIZE_MAX);
77  }
78 
79  /** Constructor from (fsp_flags).
80  @param[in] fsp_flags filespace flags */
81  explicit page_size_t(uint32_t fsp_flags) {
82  uint32_t ssize = FSP_FLAGS_GET_PAGE_SSIZE(fsp_flags);
83 
84  /* If the logical page size is zero in fsp_flags, then use the
85  legacy 16k page size. */
86  ssize = (0 == ssize) ? UNIV_PAGE_SSIZE_ORIG : ssize;
87 
88  /* Convert from a 'log2 minus 9' to a page size in bytes. */
89  const ulint size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
90 
91  ut_ad(size <= UNIV_PAGE_SIZE_MAX);
92  ut_ad(size <= (1 << PAGE_SIZE_T_SIZE_BITS));
93 
94  m_logical = size;
95 
96  ssize = FSP_FLAGS_GET_ZIP_SSIZE(fsp_flags);
97 
98  /* If the fsp_flags have zero in the zip_ssize field, then
99  it means that the tablespace does not have compressed pages
100  and the physical page size is the same as the logical page
101  size. */
102  if (ssize == 0) {
103  m_is_compressed = false;
105  } else {
106  m_is_compressed = true;
107 
108  /* Convert from a 'log2 minus 9' to a page size
109  in bytes. */
110  const ulint phy = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
111 
112  ut_ad(phy <= UNIV_ZIP_SIZE_MAX);
113  ut_ad(phy <= (1 << PAGE_SIZE_T_SIZE_BITS));
114 
115  m_physical = phy;
116  }
117  }
118 
119  /** Retrieve the physical page size (on-disk).
120  @return physical page size in bytes */
121  inline uint physical() const {
122  ut_ad(m_physical > 0);
123 
124  return (m_physical);
125  }
126 
127  /** Retrieve the logical page size (in-memory).
128  @return logical page size in bytes */
129  inline uint logical() const {
130  ut_ad(m_logical > 0);
131  return (m_logical);
132  }
133 
135  page_no_t size = 0;
136  switch (m_physical) {
137  case 4096:
138  size = 256;
139  break;
140  case 8192:
141  size = 128;
142  break;
143  case 16384:
144  case 32768:
145  case 65536:
146  size = 64;
147  break;
148  default:
149  ut_ad(0);
150  }
151  return (size);
152  }
153 
154  ulint extents_per_xdes() const { return (m_physical / extent_size()); }
155 
156  /** Check whether the page is compressed on disk.
157  @return true if compressed */
158  inline bool is_compressed() const { return (m_is_compressed); }
159 
160  /** Copy the values from a given page_size_t object.
161  @param[in] src page size object whose values to fetch */
162  inline void copy_from(const page_size_t &src) {
163  m_physical = src.physical();
164  m_logical = src.logical();
166  }
167 
168  /** Check if a given page_size_t object is equal to the current one.
169  @param[in] a page_size_t object to compare
170  @return true if equal */
171  inline bool equals_to(const page_size_t &a) const {
172  return (a.physical() == m_physical && a.logical() == m_logical &&
174  }
175 
176  inline void set_flag(uint32_t fsp_flags) {
177  uint32_t ssize = FSP_FLAGS_GET_PAGE_SSIZE(fsp_flags);
178 
179  /* If the logical page size is zero in fsp_flags, then
180  use the legacy 16k page size. */
181  ssize = (0 == ssize) ? UNIV_PAGE_SSIZE_ORIG : ssize;
182 
183  /* Convert from a 'log2 minus 9' to a page size in bytes. */
184  const uint32_t size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
185 
186  ut_ad(size <= UNIV_PAGE_SIZE_MAX);
187  ut_ad(size <= (1 << PAGE_SIZE_T_SIZE_BITS));
188 
189  m_logical = size;
190 
191  ssize = FSP_FLAGS_GET_ZIP_SSIZE(fsp_flags);
192 
193  /* If the fsp_flags have zero in the zip_ssize field,
194  then it means that the tablespace does not have
195  compressed pages and the physical page size is the same
196  as the logical page size. */
197  if (ssize == 0) {
198  m_is_compressed = false;
200  } else {
201  m_is_compressed = true;
202 
203  /* Convert from a 'log2 minus 9' to a page size
204  in bytes. */
205  const ulint phy = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
206 
207  ut_ad(phy <= UNIV_ZIP_SIZE_MAX);
208  ut_ad(phy <= (1 << PAGE_SIZE_T_SIZE_BITS));
209 
210  m_physical = phy;
211  }
212  }
213 
214  /* Disable implicit copying. */
215  void operator=(const page_size_t &) = delete;
216 
217  page_size_t(const page_size_t &) = default;
218 
219  private:
220  /* For non compressed tablespaces, physical page size is equal to
221  the logical page size and the data is stored in buf_page_t::frame
222  (and is also always equal to univ_page_size (--innodb-page-size=)).
223 
224  For compressed tablespaces, physical page size is the compressed
225  page size as stored on disk and in buf_page_t::zip::data. The logical
226  page size is the uncompressed page size in memory - the size of
227  buf_page_t::frame (currently also always equal to univ_page_size
228  (--innodb-page-size=)). */
229 
230  /** Physical page size. */
232 
233  /** Logical page size. */
235 
236  /** Flag designating whether the physical page is compressed, which is
237  true IFF the whole tablespace where the page belongs is compressed. */
238  unsigned m_is_compressed : 1;
239 };
240 
241 /* Overloading the global output operator to conveniently print an object
242 of type the page_size_t.
243 @param[in,out] out the output stream
244 @param[in] obj an object of type page_size_t to be printed
245 @retval the output stream */
246 inline std::ostream &operator<<(std::ostream &out, const page_size_t &obj) {
247  out << "[page size: physical=" << obj.physical()
248  << ", logical=" << obj.logical() << ", compressed=" << obj.is_compressed()
249  << "]";
250  return (out);
251 }
252 
254 
255 #endif /* page0size_t */
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
page_size_t::m_physical
unsigned m_physical
Physical page size.
Definition: page0size.h:231
page_size_t::copy_from
void copy_from(const page_size_t &src)
Copy the values from a given page_size_t object.
Definition: page0size.h:162
ut_ad
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:65
fsp0types.h
page_size_t::m_logical
unsigned m_logical
Logical page size.
Definition: page0size.h:234
page_size_t::page_size_t
page_size_t(uint32_t fsp_flags)
Constructor from (fsp_flags).
Definition: page0size.h:81
page_size_t::physical
uint physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:121
page_size_t::page_size_t
page_size_t(ulint physical, ulint logical, bool is_compressed)
Constructor from (physical, logical, is_compressed).
Definition: page0size.h:56
PAGE_SIZE_T_SIZE_BITS
#define PAGE_SIZE_T_SIZE_BITS
Definition: page0size.h:46
page_size_t::is_compressed
bool is_compressed() const
Check whether the page is compressed on disk.
Definition: page0size.h:158
page_size_t::extent_size
page_no_t extent_size() const
Definition: page0size.h:134
operator<<
std::ostream & operator<<(std::ostream &out, const page_size_t &obj)
Definition: page0size.h:246
page_size_t
Page size descriptor.
Definition: page0size.h:50
uint
unsigned int uint
Definition: uca-dump.cc:29
page_size_t::equals_to
bool equals_to(const page_size_t &a) const
Check if a given page_size_t object is equal to the current one.
Definition: page0size.h:171
page_size_t::set_flag
void set_flag(uint32_t fsp_flags)
Definition: page0size.h:176
page_size_t::extents_per_xdes
ulint extents_per_xdes() const
Definition: page0size.h:154
FIELD_REF_SIZE
#define FIELD_REF_SIZE
Definition: page0size.h:39
FSP_FLAGS_GET_PAGE_SSIZE
#define FSP_FLAGS_GET_PAGE_SSIZE(flags)
Return the value of the PAGE_SSIZE field.
Definition: fsp0types.h:335
FSP_FLAGS_GET_ZIP_SSIZE
#define FSP_FLAGS_GET_ZIP_SSIZE(flags)
Return the value of the ZIP_SSIZE field.
Definition: fsp0types.h:329
page_size_t::logical
uint logical() const
Retrieve the logical page size (in-memory).
Definition: page0size.h:129
page_size_t::operator=
void operator=(const page_size_t &)=delete
ut_is_2pow
#define ut_is_2pow(n)
Determines if a number is zero or a power of two.
Definition: ut0ut.h:254
field_ref_zero
const byte field_ref_zero[FIELD_REF_SIZE]
A BLOB field reference full of zero, for use in assertions and tests.Initially, BLOB field references...
Definition: page0zip.cc:41
page_size_t::m_is_compressed
unsigned m_is_compressed
Flag designating whether the physical page is compressed, which is true IFF the whole tablespace wher...
Definition: page0size.h:238
univ_page_size
page_size_t univ_page_size