MySQL 8.0.31
Source Code Documentation
lob0undo.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
6it under the terms of the GNU General Public License, version 2.0,
7as published by the Free Software Foundation.
8
9This program is also distributed 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 included with MySQL.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License, version 2.0, for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/lob0undo.h
28 Undo logging small changes to BLOBs. */
29
30#ifndef lob0undo_h
31#define lob0undo_h
32
33#include <list>
34#include "dict0mem.h"
35#include "mem0mem.h"
36#include "univ.i"
37
38namespace lob {
39
40/** Undo information about LOB data alone without including LOB index. */
42 /** Apply the undo information to the given LOB.
43 @param[in] index clustered index containing the LOB.
44 @param[in] lob_mem LOB on which the given undo will be
45 applied.
46 @param[in] len length of LOB.
47 @param[in] lob_version lob version number
48 @param[in] first_page_no the first page number of lob */
49 void apply(dict_index_t *index, byte *lob_mem, size_t len, size_t lob_version,
50 page_no_t first_page_no);
51
52 /** The LOB first page number. */
54
55 /** The LOB version number on which this undo should be applied. */
57
58 /** The offset within LOB where partial update happened. */
60
61 /** The length of the modification. */
63
64 /** Changes to the LOB data. */
65 byte *m_old_data = nullptr;
66
67 /** Copy the old data from the undo page into this object.
68 @param[in] undo_ptr the pointer into the undo log record.
69 @param[in] len length of the old data.
70 @return pointer past the old data. */
71 const byte *copy_old_data(const byte *undo_ptr, ulint len);
72
73 /** Free allocated memory for old data. */
74 void destroy();
75
76 std::ostream &print(std::ostream &out) const;
77};
78
79inline std::ostream &operator<<(std::ostream &out, const undo_data_t &obj) {
80 return (obj.print(out));
81}
82
83/** Container to hold a sequence of undo log records containing modification
84of BLOBs. */
85struct undo_seq_t {
86 /** Constructor.
87 @param[in] field_no the field number of LOB.*/
88 undo_seq_t(ulint field_no) : m_field_no(field_no), m_undo_list(nullptr) {}
89
90 /** Apply the undo log records on the given LOB in memory.
91 @param[in] index the clustered index to which LOB belongs.
92 @param[in] lob the BLOB in memory.
93 @param[in] len the length of BLOB in memory.
94 @param[in] lob_version the LOB version number.
95 @param[in] first_page_no the first page number of BLOB.*/
96 void apply(dict_index_t *index, byte *lob, size_t len, size_t lob_version,
97 page_no_t first_page_no) {
98 if (m_undo_list != nullptr) {
99 for (auto iter = m_undo_list->begin(); iter != m_undo_list->end();
100 ++iter) {
101 iter->apply(index, lob, len, lob_version, first_page_no);
102 }
103 }
104 }
105
106 /** Get the field number of BLOB.
107 @return the field number of BLOB. */
108 ulint get_field_no() const { return (m_field_no); }
109
110 /** Append the given undo log record to the end of container.
111 @param[in] u1 the undo log record information. */
113 if (m_undo_list == nullptr) {
115 ut::new_withkey<std::list<undo_data_t>>(UT_NEW_THIS_FILE_PSI_KEY);
116 }
117 m_undo_list->push_back(u1);
118 }
119
120 /** Destroy the contents of this undo sequence list. */
121 void destroy() {
122 if (m_undo_list != nullptr) {
123 std::for_each(m_undo_list->begin(), m_undo_list->end(),
124 [](undo_data_t &obj) { obj.destroy(); });
125 m_undo_list->clear();
127 m_undo_list = nullptr;
128 }
129 }
130
131 /** Check if any undo log exists to apply. */
132 bool exists() const {
133 return (m_undo_list == nullptr ? false : !m_undo_list->empty());
134 }
135
137
138 private:
139 std::list<undo_data_t> *m_undo_list = nullptr;
140};
141
142/** The list of modifications to be applied on LOBs to get older versions.
143Given a field number, it should be able to obtain the list of undo
144information. */
146 public:
147 /** Get the undo log sequence object for the given field number, which
148 represents one blob.
149 @param[in] field_no the field number of the blob.
150 @return the undo sequence object or nullptr. */
152 if (m_versions == nullptr) {
153 return (nullptr);
154 } else {
155 for (auto iter = m_versions->begin(); iter != m_versions->end(); ++iter) {
156 if ((*iter)->get_field_no() == field_no) {
157 return (*iter);
158 }
159 }
160 }
161 return (nullptr);
162 }
163
164 /** Get the undo log sequence object for the given field number, which
165 represents one blob. The undo sequence object is allocated if it does
166 not exist.
167 @param[in] field_no the field number of the blob.
168 @return the undo sequence object. */
170 if (m_versions == nullptr) {
171 m_versions =
172 ut::new_withkey<std::list<undo_seq_t *>>(UT_NEW_THIS_FILE_PSI_KEY);
173 } else {
174 for (auto iter = m_versions->begin(); iter != m_versions->end(); ++iter) {
175 if ((*iter)->get_field_no() == field_no) {
176 return (*iter);
177 }
178 }
179 }
180
181 undo_seq_t *seq =
182 ut::new_withkey<undo_seq_t>(UT_NEW_THIS_FILE_PSI_KEY, field_no);
183 m_versions->push_back(seq);
184
185 return (seq);
186 }
187
188 /** Empty the collected LOB undo information from cache. */
189 void reset() {
190 if (m_versions != nullptr) {
191 for (auto iter = m_versions->begin(); iter != m_versions->end(); ++iter) {
192 (*iter)->destroy();
193 ut::delete_(*iter);
194 }
195 m_versions->clear();
196 }
197 }
198
199 /** Apply the undo log record on the given LOB in memory.
200 @param[in] clust_index the clust index to which LOB belongs.
201 @param[in] field_no the field number of the LOB.
202 @param[in] lob the LOB data.
203 @param[in] len the length of LOB.
204 @param[in] lob_version LOB version number.
205 @param[in] first_page the first page number of LOB.*/
206 void apply(dict_index_t *clust_index, ulint field_no, byte *lob, size_t len,
207 size_t lob_version, page_no_t first_page) {
209
210 if (seq != nullptr) {
211 seq->apply(clust_index, lob, len, lob_version, first_page);
212 }
213 }
214
215 /** Destroy the accumulated undo_seq_t objects. */
216 void destroy() {
217 if (m_versions != nullptr) {
218 reset();
220 m_versions = nullptr;
221 }
222 }
223
224 /** Check if the undo contained older versions.
225 @return true if there are no older versions, false otherwise. */
226 bool is_empty() const { return (m_versions->empty()); }
227
228 /** Destructor to free the resources. */
230
231 private:
232 /** Maintain a list of undo_seq_t objects. */
233 std::list<undo_seq_t *> *m_versions = nullptr;
234};
235
236} /* namespace lob */
237
238#endif /* lob0undo_h */
uint32_t page_no_t
Page number.
Definition: api0api.h:48
Data dictionary memory object creation.
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1122
The memory management.
void for_each(const Shards< COUNT > &shards, Function &&f) noexcept
Iterate over the shards.
Definition: ut0counter.h:322
Provides the large objects (LOB) module.
Definition: lob0del.h:31
std::ostream & operator<<(std::ostream &out, const plist_node_t &obj)
Definition: lob0impl.h:238
void delete_(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new*() variants.
Definition: ut0new.h:807
Data structure for an index.
Definition: dict0mem.h:1021
Undo information about LOB data alone without including LOB index.
Definition: lob0undo.h:41
page_no_t m_page_no
The LOB first page number.
Definition: lob0undo.h:53
void apply(dict_index_t *index, byte *lob_mem, size_t len, size_t lob_version, page_no_t first_page_no)
Apply the undo information to the given LOB.
Definition: lob0undo.cc:40
const byte * copy_old_data(const byte *undo_ptr, ulint len)
Copy the old data from the undo page into this object.
Definition: lob0undo.cc:74
ulint m_version
The LOB version number on which this undo should be applied.
Definition: lob0undo.h:56
byte * m_old_data
Changes to the LOB data.
Definition: lob0undo.h:65
void destroy()
Free allocated memory for old data.
Definition: lob0undo.cc:86
std::ostream & print(std::ostream &out) const
Definition: lob0undo.cc:63
ulint m_length
The length of the modification.
Definition: lob0undo.h:62
ulint m_offset
The offset within LOB where partial update happened.
Definition: lob0undo.h:59
Container to hold a sequence of undo log records containing modification of BLOBs.
Definition: lob0undo.h:85
void apply(dict_index_t *index, byte *lob, size_t len, size_t lob_version, page_no_t first_page_no)
Apply the undo log records on the given LOB in memory.
Definition: lob0undo.h:96
bool exists() const
Check if any undo log exists to apply.
Definition: lob0undo.h:132
undo_seq_t(ulint field_no)
Constructor.
Definition: lob0undo.h:88
std::list< undo_data_t > * m_undo_list
Definition: lob0undo.h:139
void destroy()
Destroy the contents of this undo sequence list.
Definition: lob0undo.h:121
ulint get_field_no() const
Get the field number of BLOB.
Definition: lob0undo.h:108
ulint m_field_no
Definition: lob0undo.h:136
void push_back(undo_data_t &u1)
Append the given undo log record to the end of container.
Definition: lob0undo.h:112
The list of modifications to be applied on LOBs to get older versions.
Definition: lob0undo.h:145
undo_seq_t * get_undo_sequence(ulint field_no)
Get the undo log sequence object for the given field number, which represents one blob.
Definition: lob0undo.h:169
~undo_vers_t()
Destructor to free the resources.
Definition: lob0undo.h:229
void apply(dict_index_t *clust_index, ulint field_no, byte *lob, size_t len, size_t lob_version, page_no_t first_page)
Apply the undo log record on the given LOB in memory.
Definition: lob0undo.h:206
void destroy()
Destroy the accumulated undo_seq_t objects.
Definition: lob0undo.h:216
std::list< undo_seq_t * > * m_versions
Maintain a list of undo_seq_t objects.
Definition: lob0undo.h:233
void reset()
Empty the collected LOB undo information from cache.
Definition: lob0undo.h:189
undo_seq_t * get_undo_sequence_if_exists(ulint field_no)
Get the undo log sequence object for the given field number, which represents one blob.
Definition: lob0undo.h:151
bool is_empty() const
Check if the undo contained older versions.
Definition: lob0undo.h:226
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:407
#define UT_NEW_THIS_FILE_PSI_KEY
Definition: ut0new.h:562