MySQL  8.0.19
Source Code Documentation
file.h
Go to the documentation of this file.
1 /***********************************************************************
2 
3 Copyright (c) 1995, 2019, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2009, Percona Inc.
5 
6 Portions of this file contain modifications contributed and copyrighted
7 by Percona Inc.. Those modifications are
8 gratefully acknowledged and are described briefly in the InnoDB
9 documentation. The contributions by Percona Inc. are incorporated with
10 their permission, and subject to the conditions contained in the file
11 COPYING.Percona.
12 
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License, version 2.0,
15 as published by the Free Software Foundation.
16 
17 This program is also distributed with certain software (including
18 but not limited to OpenSSL) that is licensed under separate terms,
19 as designated in a particular file or component or in included license
20 documentation. The authors of MySQL hereby grant you an additional
21 permission to link the program and your derivative works with the
22 separately licensed software that they have included with MySQL.
23 
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License, version 2.0, for more details.
28 
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, 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
36 other files in library. The code in this file is used to make a library for
37 external 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. */
50 struct Compression {
51  /** Algorithm types supported */
52  enum Type {
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 */
76  uint16_t m_original_type;
77 
78  /** Original page size, before compression */
79  uint16_t m_original_size;
80 
81  /** Size after compression */
83  };
84 
85  /** Default constructor */
87 
88  /** Specific constructor
89  @param[in] type Algorithm type */
90  explicit Compression(Type type) : m_type(type) {
91 #ifdef UNIV_DEBUG
92  switch (m_type) {
93  case NONE:
94  case ZLIB:
95  case LZ4:
96 
97  default:
98  ut_error;
99  }
100 #endif /* UNIV_DEBUG */
101  }
102 
103  /** Check the page header type field.
104  @param[in] page Page contents
105  @return true if it is a compressed page */
106  static bool is_compressed_page(const byte *page)
107  MY_ATTRIBUTE((warn_unused_result));
108 
109  /** Check wether the compression algorithm is supported.
110  @param[in] algorithm Compression algorithm to check
111  @param[out] compression The type that algorithm maps to
112  @return DB_SUCCESS or error code */
113  static dberr_t check(const char *algorithm, Compression *compression)
114  MY_ATTRIBUTE((warn_unused_result));
115 
116  /** Validate the algorithm string.
117  @param[in] algorithm Compression algorithm to check
118  @return DB_SUCCESS or error code */
119  static dberr_t validate(const char *algorithm)
120  MY_ATTRIBUTE((warn_unused_result));
121 
122  /** Convert to a "string".
123  @param[in] type The compression type
124  @return the string representation */
125  static const char *to_string(Type type) MY_ATTRIBUTE((warn_unused_result));
126 
127  /** Convert the meta data to a std::string.
128  @param[in] meta Page Meta data
129  @return the string representation */
130  static std::string to_string(const meta_t &meta)
131  MY_ATTRIBUTE((warn_unused_result));
132 
133  /** Deserizlise the page header compression meta-data
134  @param[in] page Pointer to the page header
135  @param[out] control Deserialised data */
136  static void deserialize_header(const byte *page, meta_t *control);
137 
138  /** Check if the string is "empty" or "none".
139  @param[in] algorithm Compression algorithm to check
140  @return true if no algorithm requested */
141  static bool is_none(const char *algorithm) MY_ATTRIBUTE((warn_unused_result));
142 
143  /** Decompress the page data contents. Page type must be
144  FIL_PAGE_COMPRESSED, if not then the source contents are
145  left unchanged and DB_SUCCESS is returned.
146  @param[in] dblwr_recover true of double write recovery
147  in progress
148  @param[in,out] src Data read from disk, decompressed
149  data will be copied to this page
150  @param[in,out] dst Scratch area to use for decompression
151  @param[in] dst_len Size of the scratch area in bytes
152  @return DB_SUCCESS or error code */
153  static dberr_t deserialize(bool dblwr_recover, byte *src, byte *dst,
154  ulint dst_len) MY_ATTRIBUTE((warn_unused_result));
155 
156  /** Compression type */
158 };
159 #endif
Compression::Type
Type
Algorithm types supported.
Definition: file.h:52
Compression::ZLIB
@ ZLIB
Use ZLib.
Definition: file.h:61
Compression::deserialize_header
static void deserialize_header(const byte *page, meta_t *control)
Deserizlise the page header compression meta-data.
Definition: file.cc:96
Compression::Compression
Compression()
Default constructor.
Definition: file.h:86
Compression::meta_t::m_original_type
uint16_t m_original_type
Original page type.
Definition: file.h:76
dberr_t
dberr_t
Definition: db0err.h:38
ut_error
#define ut_error
Abort execution.
Definition: ut0dbg.h:61
Compression::NONE
@ NONE
No compression.
Definition: file.h:58
Compression::meta_t::m_original_size
uint16_t m_original_size
Original page size, before compression.
Definition: file.h:79
Compression::validate
static dberr_t validate(const char *algorithm)
Validate the algorithm string.
Definition: ha_innodb.cc:2350
Compression::meta_t
Compressed page meta-data.
Definition: file.h:68
Compression::is_compressed_page
static bool is_compressed_page(const byte *page)
Check the page header type field.
Definition: file.cc:89
Compression
Compression algorithm.
Definition: file.h:50
Compression::Compression
Compression(Type type)
Specific constructor.
Definition: file.h:90
Compression::LZ4
@ LZ4
Use LZ4 faster variant, usually lower compression.
Definition: file.h:64
page
int page
Definition: ctype-mb.cc:1232
Compression::meta_t::m_version
uint8_t m_version
Version number.
Definition: file.h:70
Compression::m_type
Type m_type
Compression type.
Definition: file.h:157
Compression::meta_t::m_algorithm
Type m_algorithm
Algorithm type.
Definition: file.h:73
Compression::is_none
static bool is_none(const char *algorithm)
Check if the string is "empty" or "none".
Definition: ha_innodb.cc:2316
Compression::to_string
static const char * to_string(Type type)
Convert to a "string".
Definition: file.cc:57
Compression::check
static dberr_t check(const char *algorithm, Compression *compression)
Check wether the compression algorithm is supported.
Definition: ha_innodb.cc:2330
HttpMethod::type
int type
Definition: http_common.h:411
Compression::meta_t::m_compressed_size
uint16_t m_compressed_size
Size after compression.
Definition: file.h:82
Compression::deserialize
static dberr_t deserialize(bool dblwr_recover, byte *src, byte *dst, ulint dst_len)
Decompress the page data contents.
Definition: file.cc:124