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