1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 2013, 2015, Oracle and/or its affiliates. All Rights Reserved. |
4 | Copyright (c) 2017, MariaDB Corporation. |
5 | |
6 | This program is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU General Public License as published by the Free Software |
8 | Foundation; version 2 of the License. |
9 | |
10 | This program is distributed in the hope that it will be useful, but WITHOUT |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License along with |
15 | this program; if not, write to the Free Software Foundation, Inc., |
16 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
17 | |
18 | *****************************************************************************/ |
19 | |
20 | /**************************************************//** |
21 | @file include/page0size.h |
22 | A class describing a page size. |
23 | |
24 | Created Nov 14, 2013 Vasil Dimov |
25 | *******************************************************/ |
26 | |
27 | #ifndef page0size_t |
28 | #define page0size_t |
29 | |
30 | #include "univ.i" |
31 | #include "fsp0types.h" |
32 | |
33 | #define FIELD_REF_SIZE 20U |
34 | |
35 | /** A BLOB field reference full of zero, for use in assertions and |
36 | tests.Initially, BLOB field references are set to zero, in |
37 | dtuple_convert_big_rec(). */ |
38 | extern const byte field_ref_zero[FIELD_REF_SIZE]; |
39 | |
40 | #define PAGE_SIZE_T_SIZE_BITS 17 |
41 | |
42 | /** Page size descriptor. Contains the physical and logical page size, as well |
43 | as whether the page is compressed or not. */ |
44 | class page_size_t { |
45 | public: |
46 | /** Constructor from (physical, logical, is_compressed). |
47 | @param[in] physical physical (on-disk/zipped) page size |
48 | @param[in] logical logical (in-memory/unzipped) page size |
49 | @param[in] is_compressed whether the page is compressed */ |
50 | page_size_t(ulint physical, ulint logical, bool is_compressed) |
51 | { |
52 | if (physical == 0) { |
53 | physical = UNIV_PAGE_SIZE_ORIG; |
54 | } |
55 | if (logical == 0) { |
56 | logical = UNIV_PAGE_SIZE_ORIG; |
57 | } |
58 | |
59 | m_physical = static_cast<unsigned>(physical); |
60 | m_logical = static_cast<unsigned>(logical); |
61 | m_is_compressed = static_cast<unsigned>(is_compressed); |
62 | |
63 | ut_ad(physical <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
64 | ut_ad(logical <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
65 | |
66 | ut_ad(ut_is_2pow(physical)); |
67 | ut_ad(ut_is_2pow(logical)); |
68 | |
69 | ut_ad(logical <= UNIV_PAGE_SIZE_MAX); |
70 | ut_ad(logical >= physical); |
71 | ut_ad(!is_compressed || physical <= UNIV_ZIP_SIZE_MAX); |
72 | } |
73 | |
74 | /** Constructor from (fsp_flags). |
75 | @param[in] fsp_flags filespace flags */ |
76 | explicit page_size_t(ulint fsp_flags) |
77 | { |
78 | ulint ssize = FSP_FLAGS_GET_PAGE_SSIZE(fsp_flags); |
79 | |
80 | /* If the logical page size is zero in fsp_flags, then use the |
81 | legacy 16k page size. */ |
82 | ssize = (0 == ssize) ? UNIV_PAGE_SSIZE_ORIG : ssize; |
83 | |
84 | /* Convert from a 'log2 minus 9' to a page size in bytes. */ |
85 | const unsigned size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize); |
86 | |
87 | ut_ad(size <= UNIV_PAGE_SIZE_MAX); |
88 | ut_ad(size <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
89 | |
90 | m_logical = size; |
91 | |
92 | ssize = FSP_FLAGS_GET_ZIP_SSIZE(fsp_flags); |
93 | |
94 | /* If the fsp_flags have zero in the zip_ssize field, then it means |
95 | that the tablespace does not have compressed pages and the physical |
96 | page size is the same as the logical page size. */ |
97 | if (ssize == 0) { |
98 | m_is_compressed = false; |
99 | m_physical = m_logical; |
100 | } else { |
101 | m_is_compressed = true; |
102 | |
103 | /* Convert from a 'log2 minus 9' to a page size |
104 | in bytes. */ |
105 | const unsigned phy |
106 | = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize); |
107 | |
108 | ut_ad(phy <= UNIV_ZIP_SIZE_MAX); |
109 | ut_ad(phy <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
110 | |
111 | m_physical = phy; |
112 | } |
113 | } |
114 | |
115 | /** Retrieve the physical page size (on-disk). |
116 | @return physical page size in bytes */ |
117 | inline ulint physical() const |
118 | { |
119 | ut_ad(m_physical > 0); |
120 | |
121 | return(m_physical); |
122 | } |
123 | |
124 | /** Retrieve the logical page size (in-memory). |
125 | @return logical page size in bytes */ |
126 | inline ulint logical() const |
127 | { |
128 | ut_ad(m_logical > 0); |
129 | return(m_logical); |
130 | } |
131 | |
132 | /** Check whether the page is compressed on disk. |
133 | @return true if compressed */ |
134 | inline bool is_compressed() const |
135 | { |
136 | return(m_is_compressed); |
137 | } |
138 | |
139 | /** Copy the values from a given page_size_t object. |
140 | @param[in] src page size object whose values to fetch */ |
141 | inline void copy_from(const page_size_t& src) |
142 | { |
143 | *this = src; |
144 | } |
145 | |
146 | /** Check if a given page_size_t object is equal to the current one. |
147 | @param[in] a page_size_t object to compare |
148 | @return true if equal */ |
149 | inline bool equals_to(const page_size_t& a) const |
150 | { |
151 | return(a.physical() == m_physical |
152 | && a.logical() == m_logical |
153 | && a.is_compressed() == m_is_compressed); |
154 | } |
155 | |
156 | private: |
157 | |
158 | /* For non compressed tablespaces, physical page size is equal to |
159 | the logical page size and the data is stored in buf_page_t::frame |
160 | (and is also always equal to univ_page_size (--innodb-page-size=)). |
161 | |
162 | For compressed tablespaces, physical page size is the compressed |
163 | page size as stored on disk and in buf_page_t::zip::data. The logical |
164 | page size is the uncompressed page size in memory - the size of |
165 | buf_page_t::frame (currently also always equal to univ_page_size |
166 | (--innodb-page-size=)). */ |
167 | |
168 | /** Physical page size. */ |
169 | unsigned m_physical:PAGE_SIZE_T_SIZE_BITS; |
170 | |
171 | /** Logical page size. */ |
172 | unsigned m_logical:PAGE_SIZE_T_SIZE_BITS; |
173 | |
174 | /** Flag designating whether the physical page is compressed, which is |
175 | true IFF the whole tablespace where the page belongs is compressed. */ |
176 | unsigned m_is_compressed:1; |
177 | }; |
178 | |
179 | /* Overloading the global output operator to conveniently print an object |
180 | of type the page_size_t. |
181 | @param[in,out] out the output stream |
182 | @param[in] obj an object of type page_size_t to be printed |
183 | @retval the output stream */ |
184 | inline |
185 | std::ostream& |
186 | operator<<( |
187 | std::ostream& out, |
188 | const page_size_t& obj) |
189 | { |
190 | out << "[page size: physical=" << obj.physical() |
191 | << ", logical=" << obj.logical() |
192 | << ", compressed=" << obj.is_compressed() << "]" ; |
193 | return(out); |
194 | } |
195 | |
196 | extern page_size_t univ_page_size; |
197 | |
198 | #endif /* page0size_t */ |
199 | |