Debian Codegraph @

storage/innobase/lob/lob0index.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 2016, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 #include "lob0index.h"
29 #include "lob0first.h"
30 #include "lob0pages.h"
31 #include "trx0purge.h"
32 #include "trx0trx.h"
33
34 namespace lob {
35
36 /** Move the version base node from current entry to the given entry.
37 @param[in] to_entry The index entry to which the version base
38 node is moved to. */
39 void index_entry_t::move_version_base_node(index_entry_t &to_entry) {
40 flst_base_node_t *from_node = get_versions_list();
41 flst_base_node_t *to_node = to_entry.get_versions_list();
42 mlog_write_string(to_node, from_node, FLST_BASE_NODE_SIZE, m_mtr);
43 ut_ad(flst_get_len(from_node) == flst_get_len(to_node));
44 flst_init(from_node, m_mtr);
45 }
46
47 fil_addr_t index_entry_t::make_old_version_current(dict_index_t *index,
48 first_page_t &first_page) {
49 flst_base_node_t *base = first_page.index_list();
50 flst_base_node_t *free_list = first_page.free_list();
51 flst_base_node_t *version_list = get_versions_ptr();
52
53 if (flst_get_len(version_list) > 0) {
54 space_id_t space = dict_index_get_space(index);
55 const page_size_t page_size = dict_table_page_size(index->table);
56
57 /* Remove the old version from versions list. */
58 fil_addr_t old_node_addr = flst_get_first(version_list, m_mtr);
59
60 flst_node_t *old_node =
61 fut_get_ptr(space, page_size, old_node_addr, RW_X_LATCH, m_mtr);
62
63 flst_remove(version_list, old_node, m_mtr);
64
65 /* Copy the version base node from current to old entry. */
66 index_entry_t old_entry(old_node, m_mtr, index);
67 move_version_base_node(old_entry);
68
69 /* Insert the old version after the current node. */
70 flst_insert_after(base, m_node, old_node, m_mtr);
71 }
72
73 fil_addr_t loc = purge_version(index, base, free_list);
74
75 ut_d(flst_validate(base, m_mtr));
76
77 return (loc);
78 }
79
80 /** Purge the current index entry. An index entry points to either a FIRST
81 page or DATA page. That LOB page will be freed if it is DATA page. A FIRST
82 page should not be freed. */
83 void index_entry_t::purge(dict_index_t *index) {
84 DBUG_TRACE;
85
86 page_no_t page_no = get_page_no();
87
88 buf_block_t *block = nullptr;
89
90 block = buf_page_get(page_id_t(dict_index_get_space(index), page_no),
91 dict_table_page_size(index->table), RW_X_LATCH,
92 UT_LOCATION_HERE, m_mtr);
93
94 page_type_t type = fil_page_get_type(block->frame);
95
96 if (type != FIL_PAGE_TYPE_LOB_FIRST) {
97 data_page_t data_page(block, m_mtr, index);
98 data_page.dealloc();
99 }
100
101 set_prev_null();
102 set_next_null();
103 set_versions_null();
104 set_page_no(FIL_NULL);
105 set_trx_id(0);
106 set_trx_id_modifier(0);
107 set_trx_undo_no(0);
108 set_data_len(0);
109 }
110
111 fil_addr_t index_entry_t::purge_version(dict_index_t *index,
112 flst_base_node_t *lst,
113 flst_base_node_t *free_list) {
114 /* Save the location of next node. */
115 fil_addr_t next_loc = flst_get_next_addr(m_node, m_mtr);
116
117 /* Remove the current node from the list it belongs. */
118 flst_remove(lst, m_node, m_mtr);
119
120 /* Purge the current node. */
121 purge(index);
122
123 /* Add the current node to the free list. */
124 flst_add_first(free_list, m_node, m_mtr);
125
126 /* Return the next node location. */
127 return (next_loc);
128 }
129
130 std::ostream &index_entry_t::print(std::ostream &out) const {
131 if (!is_null()) {
132 out << "[index_entry_t: node=" << (void *)m_node << ", self=" << get_self()
133 << ", creator trxid=" << get_trx_id()
134 << ", modifier_trxid=" << get_trx_id_modifier()
135 << ", trx_undo_no=" << get_trx_undo_no()
136 << ", page_no=" << get_page_no() << ", data_len=" << get_data_len()
137 << ", lob version=" << get_lob_version() << ", index_id=" << m_index->id
138 << ", next=" << get_next() << ", prev=" << get_prev()
139 << ", versions=" << get_versions_mem() << "]";
140 }
141 return (out);
142 }
143
144 fil_addr_t index_entry_t::get_self() const {
145 if (m_node == nullptr) {
146 return (fil_addr_null);
147 }
148 page_t *frame = page_align(m_node);
149 page_no_t page_no = mach_read_from_4(frame + FIL_PAGE_OFFSET);
150 uint32_t offset = static_cast<uint32_t>(m_node - frame);
151 ut_ad(offset < UNIV_PAGE_SIZE);
152
153 return (fil_addr_t(page_no, offset));
154 }
155
156 void index_entry_t::read(index_entry_mem_t &entry_mem) const {
157 if (is_null()) {
158 entry_mem.reset();
159 return;
160 }
161
162 entry_mem.m_self = get_self();
163 entry_mem.m_prev = get_prev();
164 entry_mem.m_next = get_next();
165 entry_mem.m_versions = get_versions_mem();
166 entry_mem.m_trx_id = get_trx_id();
167 entry_mem.m_trx_id_modifier = get_trx_id_modifier();
168 entry_mem.m_undo_no = get_trx_undo_no();
169 entry_mem.m_undo_no_modifier = get_trx_undo_no_modifier();
170 entry_mem.m_page_no = get_page_no();
171 entry_mem.m_data_len = get_data_len();
172 }
173
174 /** Load the index entry available in the given file address.
175 Take x-latch on the index page.
176 @param[in] addr the file address of the index entry.
177 @return the buffer block containing the index entry. */
178 buf_block_t *index_entry_t::load_x(const fil_addr_t &addr) {
179 ut_ad(m_mtr != nullptr);
180 ut_ad(m_index != nullptr);
181
182 m_block = nullptr;
183 const space_id_t space_id = dict_index_get_space(m_index);
184 const page_size_t page_size = dict_table_page_size(m_index->table);
185
186 m_node = fut_get_ptr(space_id, page_size, addr, RW_X_LATCH, m_mtr, &m_block);
187
188 return (m_block);
189 }
190
191 /** Load the index entry available in the given file address.
192 Take s-latch on the index page.
193 @param[in] addr the file location of index entry.
194 @return the buffer block. */
195 buf_block_t *index_entry_t::load_s(const fil_addr_t &addr) {
196 ut_ad(m_mtr != nullptr);
197 ut_ad(m_index != nullptr);
198
199 m_block = nullptr;
200 const space_id_t space_id = dict_index_get_space(m_index);
201 const page_size_t page_size = dict_table_page_size(m_index->table);
202
203 m_node = fut_get_ptr(space_id, page_size, addr, RW_S_LATCH, m_mtr, &m_block);
204
205 return (m_block);
206 }
207
208 void index_entry_mem_t::reset() {
209 m_self = fil_addr_null;
210 m_prev = fil_addr_null;
211 m_next = fil_addr_null;
212 m_versions.reset();
213 m_trx_id = 0;
214 m_trx_id_modifier = 0;
215 m_undo_no = 0;
216 m_undo_no_modifier = 0;
217 m_page_no = FIL_NULL;
218 m_data_len = 0;
219 }
220
221 /** Print this object into the given output stream.
222 @param[in] out the output stream.
223 @return the output stream. */
224 std::ostream &index_entry_mem_t::print(std::ostream &out) const {
225 out << "[index_entry_mem_t: m_self=" << m_self << ", m_prev=" << m_prev
226 << ", m_next=" << m_next << ", m_versions=" << m_versions
227 << ", m_trx_id=" << m_trx_id
228 << ", m_trx_id_modifier=" << m_trx_id_modifier
229 << ", m_undo_no=" << m_undo_no
230 << ", m_undo_no_modifier=" << m_undo_no_modifier
231 << ", m_page_no=" << m_page_no << ", m_data_len=" << m_data_len << "]";
232 return (out);
233 }
234
235 void index_entry_t::free_data_page(const page_no_t first_page_no) {
236 ut_ad(m_mtr != nullptr);
237 ut_ad(m_index != nullptr);
238 ut_ad(first_page_no != FIL_NULL);
239 ut_ad(first_page_no != 0);
240
241 const page_no_t page_no = get_page_no();
242 if (page_no != first_page_no && page_no != FIL_NULL) {
243 data_page_t data_page(m_mtr, const_cast<dict_index_t *>(m_index));
244 data_page.load_x(page_no);
245 data_page.dealloc();
246 set_page_no(FIL_NULL);
247 }
248 }
249
250 } /* namespace lob */