Debian Codegraph @

storage/innobase/include/mtr0mtr.ic

raw
1 /*****************************************************************************
2
3 Copyright (c) 1995, 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 /** @file include/mtr0mtr.ic
29 Mini-transaction buffer
30
31 Created 11/26/1995 Heikki Tuuri
32 *******************************************************/
33
34 #include "buf0buf.h"
35
36 /**
37 Pushes an object to an mtr memo stack. */
38 void mtr_t::memo_push(void *object, mtr_memo_type_t type) {
39 ut_ad(is_active());
40 ut_ad(object != nullptr);
41 ut_ad(type >= MTR_MEMO_PAGE_S_FIX);
42 ut_ad(type <= MTR_MEMO_SX_LOCK);
43 ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
44 ut_ad(ut_is_2pow(type));
45
46 mtr_memo_slot_t *slot;
47
48 slot = m_impl.m_memo.push<mtr_memo_slot_t *>(sizeof(*slot));
49
50 slot->type = type;
51 slot->object = object;
52 }
53
54 /**
55 Releases the (index tree) s-latch stored in an mtr memo after a
56 savepoint. */
57 void mtr_t::release_s_latch_at_savepoint(ulint savepoint, rw_lock_t *lock) {
58 #ifndef UNIV_HOTBACKUP
59 ut_ad(is_active());
60 ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
61
62 ut_ad(m_impl.m_memo.size() > savepoint);
63
64 mtr_memo_slot_t *slot = m_impl.m_memo.at<mtr_memo_slot_t *>(savepoint);
65
66 ut_ad(slot->object == lock);
67 ut_ad(slot->type == MTR_MEMO_S_LOCK);
68
69 rw_lock_s_unlock(lock);
70
71 slot->object = nullptr;
72 #else /* !UNIV_HOTBACKUP */
73 UT_NOT_USED(savepoint);
74 UT_NOT_USED(lock);
75 #endif /* !UNIV_HOTBACKUP */
76 }
77
78 #ifndef UNIV_HOTBACKUP
79 /**
80 SX-latches the not yet latched block after a savepoint. */
81
82 void mtr_t::sx_latch_at_savepoint(ulint savepoint, buf_block_t *block) {
83 ut_ad(is_active());
84 ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
85 ut_ad(m_impl.m_memo.size() > savepoint);
86
87 ut_ad(!memo_contains_flagged(
88 block, MTR_MEMO_PAGE_S_FIX | MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX));
89
90 mtr_memo_slot_t *slot;
91
92 slot = m_impl.m_memo.at<mtr_memo_slot_t *>(savepoint);
93
94 ut_ad(slot->object == block);
95
96 /* == RW_NO_LATCH */
97 ut_a(slot->type == MTR_MEMO_BUF_FIX);
98
99 rw_lock_sx_lock(&block->lock, UT_LOCATION_HERE);
100
101 slot->type = MTR_MEMO_PAGE_SX_FIX;
102 }
103
104 /**
105 X-latches the not yet latched block after a savepoint. */
106
107 void mtr_t::x_latch_at_savepoint(ulint savepoint, buf_block_t *block) {
108 ut_ad(is_active());
109 ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
110 ut_ad(m_impl.m_memo.size() > savepoint);
111
112 ut_ad(!memo_contains_flagged(
113 block, MTR_MEMO_PAGE_S_FIX | MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX));
114
115 mtr_memo_slot_t *slot;
116
117 slot = m_impl.m_memo.at<mtr_memo_slot_t *>(savepoint);
118
119 ut_ad(slot->object == block);
120
121 /* == RW_NO_LATCH */
122 ut_a(slot->type == MTR_MEMO_BUF_FIX);
123
124 rw_lock_x_lock(&block->lock, UT_LOCATION_HERE);
125
126 slot->type = MTR_MEMO_PAGE_X_FIX;
127 }
128
129 /**
130 Releases the block in an mtr memo after a savepoint. */
131
132 void mtr_t::release_block_at_savepoint(ulint savepoint, buf_block_t *block) {
133 ut_ad(is_active());
134 ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
135
136 mtr_memo_slot_t *slot;
137
138 slot = m_impl.m_memo.at<mtr_memo_slot_t *>(savepoint);
139
140 ut_a(slot->object == block);
141
142 buf_page_release_latch(block, slot->type);
143 buf_block_unfix(block);
144
145 slot->object = nullptr;
146 }
147 #endif /* !UNIV_HOTBACKUP */
148
149 /**
150 Gets the logging mode of a mini-transaction.
151 @return logging mode: MTR_LOG_NONE, ... */
152
153 mtr_log_t mtr_t::get_log_mode() const {
154 ut_ad(m_impl.m_log_mode >= MTR_LOG_ALL);
155 ut_ad(m_impl.m_log_mode <= MTR_LOG_SHORT_INSERTS);
156
157 return (m_impl.m_log_mode);
158 }
159
160 #ifndef UNIV_HOTBACKUP
161 /**
162 Locks a lock in s-mode. */
163
164 void mtr_t::s_lock(rw_lock_t *lock, ut::Location location) {
165 rw_lock_s_lock_gen(lock, 0, location);
166
167 memo_push(lock, MTR_MEMO_S_LOCK);
168 }
169
170 /**
171 Locks a lock in x-mode. */
172
173 void mtr_t::x_lock(rw_lock_t *lock, ut::Location location) {
174 rw_lock_x_lock_gen(lock, 0, location);
175
176 memo_push(lock, MTR_MEMO_X_LOCK);
177 }
178
179 /**
180 Locks a lock in sx-mode. */
181
182 void mtr_t::sx_lock(rw_lock_t *lock, ut::Location location) {
183 rw_lock_sx_lock_gen(lock, 0, location);
184
185 memo_push(lock, MTR_MEMO_SX_LOCK);
186 }
187 #endif /* !UNIV_HOTBACKUP */
188
189 /**
190 Reads 1 - 4 bytes from a file page buffered in the buffer pool.
191 @return value read */
192
193 uint32_t mtr_t::read_ulint(const byte *ptr, mlog_id_t type) const {
194 ut_ad(is_active());
195
196 ut_ad(memo_contains_page_flagged(
197 ptr, MTR_MEMO_PAGE_S_FIX | MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX));
198
199 return (mach_read_ulint(ptr, type));
200 }