MySQL 8.0.32
Source Code Documentation
file.h
Go to the documentation of this file.
1/***********************************************************************
2
3Copyright (c) 1995, 2022, Oracle and/or its affiliates.
4Copyright (c) 2009, Percona Inc.
5
6Portions of this file contain modifications contributed and copyrighted
7by Percona Inc.. Those modifications are
8gratefully acknowledged and are described briefly in the InnoDB
9documentation. The contributions by Percona Inc. are incorporated with
10their permission, and subject to the conditions contained in the file
11COPYING.Percona.
12
13This program is free software; you can redistribute it and/or modify
14it under the terms of the GNU General Public License, version 2.0,
15as published by the Free Software Foundation.
16
17This program is also distributed with certain software (including
18but not limited to OpenSSL) that is licensed under separate terms,
19as designated in a particular file or component or in included license
20documentation. The authors of MySQL hereby grant you an additional
21permission to link the program and your derivative works with the
22separately licensed software that they have included with MySQL.
23
24This program is distributed in the hope that it will be useful,
25but WITHOUT ANY WARRANTY; without even the implied warranty of
26MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27GNU General Public License, version 2.0, for more details.
28
29You should have received a copy of the GNU General Public License
30along with this program; if not, write to the Free Software
31Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32
33***********************************************************************/
34
35/** NOTE: The functions in this file should only use functions from
36other files in library. The code in this file is used to make a library for
37external tools. */
38
39/** @file os/file.h
40 The interface to the operating system file io
41
42 Created 10/21/1995 Heikki Tuuri
43 *******************************************************/
44#ifndef os_file_h
45#define os_file_h
46
47#include "univ.i"
48
49/** Compression algorithm. */
51 /** Algorithm types supported */
52 enum Type : uint8_t {
53 /* Note: During recovery we don't have the compression type
54 because the .frm file has not been read yet. Therefore
55 we write the recovered pages out without compression. */
56
57 /** No compression */
58 NONE = 0,
59
60 /** Use ZLib */
61 ZLIB = 1,
62
63 /** Use LZ4 faster variant, usually lower compression. */
64 LZ4 = 2
65 };
66
67 /** Compressed page meta-data */
68 struct meta_t {
69 /** Version number */
70 uint8_t m_version;
71
72 /** Algorithm type */
74
75 /** Original page type */
77
78 /** Original page size, before compression */
80
81 /** Size after compression */
83 };
84
85 /** Default constructor */
87
88 /** Specific constructor
89 @param[in] type Algorithm type */
91#ifdef UNIV_DEBUG
92 switch (m_type) {
93 case NONE:
94 case ZLIB:
95 case LZ4:
96 break;
97 default:
99 }
100#endif /* UNIV_DEBUG */
101 }
102
103 /** @return string representation. */
104 std::string to_string() const {
106
107 os << "type: ";
108 switch (m_type) {
109 case NONE:
110 os << "NONE";
111 break;
112 case ZLIB:
113 os << "ZLIB";
114 break;
115 case LZ4:
116 os << "LZ4";
117 break;
118 default:
119 os << "<UNKNOWN>";
120 break;
121 }
122
123 return (os.str());
124 }
125
126 /** Version of compressed page */
127 static constexpr uint8_t FIL_PAGE_VERSION_1 = 1;
128 static constexpr uint8_t FIL_PAGE_VERSION_2 = 2;
129
130 /** Check the page header type field.
131 @param[in] page Page contents
132 @return true if it is a compressed page */
133 [[nodiscard]] static bool is_compressed_page(const byte *page);
134
135 /** Check the page header type field.
136 @param[in] page Page contents
137 @return true if it is a compressed and encrypted page */
138 [[nodiscard]] static bool is_compressed_encrypted_page(const byte *page);
139
140 /** Check if the version on page is valid.
141 @param[in] version version
142 @return true if version is valid */
143 static bool is_valid_page_version(uint8_t version);
144
145 /** Check whether the compression algorithm is supported.
146 @param[in] algorithm Compression algorithm to check
147 @param[out] compression The type that algorithm maps to
148 @return DB_SUCCESS or error code */
149 [[nodiscard]] static dberr_t check(const char *algorithm,
150 Compression *compression);
151
152 /** Validate the algorithm string.
153 @param[in] algorithm Compression algorithm to check
154 @return DB_SUCCESS or error code */
155 [[nodiscard]] static dberr_t validate(const char *algorithm);
156
157 /** Validate the algorithm string.
158 @param[in] type compression type
159 @return true if type is valid, else false */
160 [[nodiscard]] static bool validate(const Type type);
161
162 /** Convert to a "string".
163 @param[in] type The compression type
164 @return the string representation */
165 [[nodiscard]] static const char *to_string(Type type);
166
167 /** Convert the meta data to a std::string.
168 @param[in] meta Page Meta data
169 @return the string representation */
170 [[nodiscard]] static std::string to_string(const meta_t &meta);
171
172 /** Deserizlise the page header compression meta-data
173 @param[in] page Pointer to the page header
174 @param[out] control Deserialised data */
175 static void deserialize_header(const byte *page, meta_t *control);
176
177 /** Check if the string is "empty" or "none".
178 @param[in] algorithm Compression algorithm to check
179 @return true if no algorithm requested */
180 [[nodiscard]] static bool is_none(const char *algorithm);
181
182 /** Decompress the page data contents. Page type must be FIL_PAGE_COMPRESSED,
183 if not then the source contents are left unchanged and DB_SUCCESS is returned.
184 @param[in] dblwr_read true if double write recovery in progress
185 @param[in,out] src Data read from disk, decompressed data
186 will be copied to this page
187 @param[in,out] dst Scratch area to use for decompression or
188 nullptr.
189 @param[in] dst_len If dst is valid, size of the scratch area in
190 bytes.
191 @return DB_SUCCESS or error code */
192 [[nodiscard]] static dberr_t deserialize(bool dblwr_read, byte *src,
193 byte *dst, ulint dst_len);
194
195 /** Compression type */
197};
198#endif
int page
Definition: ctype-mb.cc:1235
dberr_t
Definition: db0err.h:38
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2868
required uint64 version
Definition: replication_group_member_actions.proto:40
required string type
Definition: replication_group_member_actions.proto:33
Compressed page meta-data.
Definition: file.h:68
uint16_t m_compressed_size
Size after compression.
Definition: file.h:82
uint16_t m_original_type
Original page type.
Definition: file.h:76
uint16_t m_original_size
Original page size, before compression.
Definition: file.h:79
Type m_algorithm
Algorithm type.
Definition: file.h:73
uint8_t m_version
Version number.
Definition: file.h:70
Compression algorithm.
Definition: file.h:50
static bool is_valid_page_version(uint8_t version)
Check if the version on page is valid.
Definition: file.cc:98
Type
Algorithm types supported.
Definition: file.h:52
@ NONE
No compression.
Definition: file.h:58
@ ZLIB
Use ZLib.
Definition: file.h:61
@ LZ4
Use LZ4 faster variant, usually lower compression.
Definition: file.h:64
Type m_type
Compression type.
Definition: file.h:196
static constexpr uint8_t FIL_PAGE_VERSION_1
Version of compressed page.
Definition: file.h:127
Compression()
Default constructor.
Definition: file.h:86
static dberr_t check(const char *algorithm, Compression *compression)
Check whether the compression algorithm is supported.
Definition: ha_innodb.cc:2604
static bool is_compressed_page(const byte *page)
Check the page header type field.
Definition: file.cc:89
static void deserialize_header(const byte *page, meta_t *control)
Deserizlise the page header compression meta-data.
Definition: file.cc:105
static constexpr uint8_t FIL_PAGE_VERSION_2
Definition: file.h:128
static dberr_t deserialize(bool dblwr_read, byte *src, byte *dst, ulint dst_len)
Decompress the page data contents.
Definition: file.cc:135
static dberr_t validate(const char *algorithm)
Validate the algorithm string.
Definition: ha_innodb.cc:2624
static bool is_none(const char *algorithm)
Check if the string is "empty" or "none".
Definition: ha_innodb.cc:2590
static bool is_compressed_encrypted_page(const byte *page)
Check the page header type field.
Definition: file.cc:93
std::string to_string() const
Definition: file.h:104
Compression(Type type)
Specific constructor.
Definition: file.h:90
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:407
#define ut_error
Abort execution.
Definition: ut0dbg.h:64