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