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