MySQL 8.0.31
Source Code Documentation
dict0sdi.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27#ifndef DICT_SDI_H
28#define DICT_SDI_H
29
30#include <zconf.h>
31#include <zlib.h>
32
33/** Size of sdi_key_t::type */
34constexpr const uint32_t SDI_TYPE_LEN = 4;
35
36/** Size of sdi_key_t::id */
37constexpr const uint32_t SDI_KEY_LEN = 8;
38
39/** Compress SDI using zlib */
41 public:
42 Sdi_Compressor(uint32_t src_len, const void *sdi)
43 : m_src_len(src_len), m_comp_len(), m_sdi(sdi), m_comp_sdi() {}
44
46
47 /** Compress the SDI */
48 inline void compress() {
49 uLongf zlen = compressBound(static_cast<uLong>(m_src_len));
50 auto src = reinterpret_cast<const Bytef *>(m_sdi);
51
53 static_cast<byte *>(ut::malloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, zlen));
54 ut_ad(m_comp_sdi != nullptr);
55
56 switch (
57 compress2(m_comp_sdi, &zlen, src, static_cast<uLong>(m_src_len), 6)) {
58 case Z_BUF_ERROR:
59 ib::fatal(UT_LOCATION_HERE, ER_IB_MSG_FAILED_SDI_Z_BUF_ERROR);
60 break;
61
62 case Z_MEM_ERROR:
63 ib::fatal(UT_LOCATION_HERE, ER_IB_MSG_FAILED_SDI_Z_MEM_ERROR);
64 break;
65
66 case Z_STREAM_ERROR:
67 ib::fatal(UT_LOCATION_HERE, ER_IB_MSG_SDI_Z_STREAM_ERROR);
68 break;
69
70 case Z_OK:
71 m_comp_len = zlen;
72 break;
73
74 default:
75 ib::fatal(UT_LOCATION_HERE, ER_IB_MSG_SDI_Z_UNKNOWN_ERROR);
76 break;
77 }
78 }
79
80 /** @return compressed SDI record */
81 const byte *get_data() const { return (m_comp_sdi); }
82
83 /** @return length of uncompressed SDI */
84 uint32_t get_src_len() const { return (m_src_len); }
85
86 /** @return length of compressed SDI */
87 uint32_t get_comp_len() const { return (m_comp_len); }
88
89 private:
90 /** Length of uncompressed SDI */
91 uint32_t m_src_len;
92 /** Length of compressed SDI */
93 uint32_t m_comp_len;
94 /** Uncompressed SDI */
95 const void *m_sdi;
96 /** Compressed SDI */
98};
99
100/** Create SDI in a tablespace. This API should be used when
101upgrading a tablespace with no SDI.
102@param[in,out] tablespace tablespace object
103@retval false success
104@retval true failure */
105bool dict_sdi_create(dd::Tablespace *tablespace);
106
107/** Drop SDI in a tablespace. This API should be used only
108when SDI is corrupted.
109@param[in,out] tablespace tablespace object
110@retval false success
111@retval true failure */
112bool dict_sdi_drop(dd::Tablespace *tablespace);
113
114/** Get the SDI keys in a tablespace into the vector provided.
115@param[in] tablespace tablespace object
116@param[in,out] vector vector to hold SDI keys
117@retval false success
118@retval true failure */
119bool dict_sdi_get_keys(const dd::Tablespace &tablespace, sdi_vector_t &vector);
120
121/** Retrieve SDI from tablespace.
122@param[in] tablespace tablespace object
123@param[in] sdi_key SDI key
124@param[in,out] sdi SDI retrieved from tablespace
125@param[in,out] sdi_len in: size of memory allocated
126 out: actual length of SDI
127@retval false success
128@retval true in case of failures like record not found,
129 sdi_len is UINT64MAX_T, else sdi_len is
130 actual length of SDI */
131bool dict_sdi_get(const dd::Tablespace &tablespace, const sdi_key_t *sdi_key,
132 void *sdi, uint64_t *sdi_len);
133
134/** Insert/Update SDI in tablespace.
135@param[in] hton handlerton object
136@param[in] tablespace tablespace object
137@param[in] table table object
138@param[in] sdi_key SDI key to uniquely identify the tablespace
139object
140@param[in] sdi SDI to be stored in tablespace
141@param[in] sdi_len SDI length
142@retval false success
143@retval true failure */
144bool dict_sdi_set(handlerton *hton, const dd::Tablespace &tablespace,
145 const dd::Table *table, const sdi_key_t *sdi_key,
146 const void *sdi, uint64_t sdi_len);
147
148/** Delete SDI from tablespace.
149@param[in] tablespace tablespace object
150@param[in] table table object
151@param[in] sdi_key SDI key to uniquely identify the tablespace
152 object
153@retval false success
154@retval true failure */
155bool dict_sdi_delete(const dd::Tablespace &tablespace, const dd::Table *table,
156 const sdi_key_t *sdi_key);
157#endif
#define Z_BUF_ERROR
Definition: azlib.h:170
#define Z_OK
Definition: azlib.h:163
#define Z_STREAM_ERROR
Definition: azlib.h:167
#define Z_MEM_ERROR
Definition: azlib.h:169
Compress SDI using zlib.
Definition: dict0sdi.h:40
const byte * get_data() const
Definition: dict0sdi.h:81
~Sdi_Compressor()
Definition: dict0sdi.h:45
void compress()
Compress the SDI.
Definition: dict0sdi.h:48
uint32_t m_src_len
Length of uncompressed SDI.
Definition: dict0sdi.h:91
byte * m_comp_sdi
Compressed SDI.
Definition: dict0sdi.h:97
Sdi_Compressor(uint32_t src_len, const void *sdi)
Definition: dict0sdi.h:42
uint32_t get_comp_len() const
Definition: dict0sdi.h:87
uint32_t get_src_len() const
Definition: dict0sdi.h:84
uint32_t m_comp_len
Length of compressed SDI.
Definition: dict0sdi.h:93
const void * m_sdi
Uncompressed SDI.
Definition: dict0sdi.h:95
Definition: table.h:46
Definition: tablespace.h:54
The class fatal is used to emit an error message and stop the server by crashing it.
Definition: ut0log.h:251
bool dict_sdi_delete(const dd::Tablespace &tablespace, const dd::Table *table, const sdi_key_t *sdi_key)
Delete SDI from tablespace.
Definition: dict0sdi.cc:414
bool dict_sdi_get_keys(const dd::Tablespace &tablespace, sdi_vector_t &vector)
Get the SDI keys in a tablespace into the vector provided.
Definition: dict0sdi.cc:187
bool dict_sdi_get(const dd::Tablespace &tablespace, const sdi_key_t *sdi_key, void *sdi, uint64_t *sdi_len)
Retrieve SDI from tablespace.
Definition: dict0sdi.cc:225
bool dict_sdi_create(dd::Tablespace *tablespace)
Create SDI in a tablespace.
Definition: dict0sdi.cc:124
bool dict_sdi_drop(dd::Tablespace *tablespace)
Drop SDI in a tablespace.
Definition: dict0sdi.cc:167
bool dict_sdi_set(handlerton *hton, const dd::Tablespace &tablespace, const dd::Table *table, const sdi_key_t *sdi_key, const void *sdi, uint64_t sdi_len)
Insert/Update SDI in tablespace.
Definition: dict0sdi.cc:306
constexpr const uint32_t SDI_TYPE_LEN
Size of sdi_key_t::type.
Definition: dict0sdi.h:34
constexpr const uint32_t SDI_KEY_LEN
Size of sdi_key_t::id.
Definition: dict0sdi.h:37
void * malloc_withkey(PSI_memory_key_t key, std::size_t size) noexcept
Dynamically allocates storage of given size.
Definition: ut0new.h:594
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2855
void free(void *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::malloc*(),...
Definition: ut0new.h:715
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2594
Key to identify a dictionary object.
Definition: handler.h:125
Definition: handler.h:134
#define UT_LOCATION_HERE
Definition: ut0core.h:46
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:68
#define UT_NEW_THIS_FILE_PSI_KEY
Definition: ut0new.h:562