Debian Codegraph @

storage/innobase/include/trx0rseg.h

raw symbols SCIP
1 /*****************************************************************************
2
3 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2017, 2022, MariaDB Corporation.
5
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
17
18 *****************************************************************************/
19
20 /**************************************************//**
21 @file include/trx0rseg.h
22 Rollback segment
23
24 Created 3/26/1996 Heikki Tuuri
25 *******************************************************/
26
27 #pragma once
28 #include "trx0types.h"cxx . . $ `<file>/storage/innobase/include/trx0types.h`/
29 #include "fut0lst.h"cxx . . $ `<file>/storage/innobase/include/fut0lst.h`/
30
31 /** Create a rollback segment header.
32 @param[in,out] space system, undo, or temporary tablespace
33 @param[in] rseg_id rollback segment identifier
34 @param[in] max_trx_id new value of TRX_RSEG_MAX_TRX_ID
35 @param[in,out] mtr mini-transaction
36 @param[out] err error code
37 @return the created rollback segment
38 @retval nullptr on failure */
39 buf_block_tcxx . . $ buf_block_t# *trx_rseg_header_createcxx . . $ trx_rseg_header_create(7b723b36864cf194).(fil_space_tcxx . . $ fil_space_t# *space, ulintcxx . . $ ulint# rseg_id,
40 trx_id_tcxx . . $ trx_id_t# max_trx_id, mtr_tcxx . . $ mtr_t# *mtr,
41 dberr_tcxx . . $ dberr_t# *err)
42 MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((nonnull, warn_unused_result));
43
44 /** Initialize or recover the rollback segments at startup. */
45 dberr_tcxx . . $ dberr_t# trx_rseg_array_initcxx . . $ trx_rseg_array_init(629d9d73bf1a44e9).();
46
47 /** Create the temporary rollback segments. */
48 dberr_tcxx . . $ dberr_t# trx_temp_rseg_createcxx . . $ trx_temp_rseg_create(5ccbb810592e2a69).(mtr_tcxx . . $ mtr_t# *mtr);
49
50 /* Number of undo log slots in a rollback segment file copy */
51 #define TRX_RSEG_N_SLOTScxx . . $ `storage/innobase/include/trx0rseg.h:51:9`! (srv_page_size / 16)
52
53 /* Maximum number of transactions supported by a single rollback segment */
54 #define TRX_RSEG_MAX_N_TRXScxx . . $ `storage/innobase/include/trx0rseg.h:54:9`! (TRX_RSEG_N_SLOTS / 2)
55
56 /** The rollback segment memory object */
57 struct alignas(CPU_LEVEL1_DCACHE_LINESIZEcxx . . $ `include/my_global.h:1180:13`!) trx_rseg_tcxx . . $ trx_rseg_t#
58 {
59 /** tablespace containing the rollback segment; constant after init() */
60 fil_space_tcxx . . $ fil_space_t# *spacecxx . . $ trx_rseg_t#space.;
61 /** latch protecting everything except page_no, space */
62 IF_DBUGcxx . . $ `include/my_dbug.h:192:9`!(srw_lock_debug,srw_spin_lock) latchcxx . . $ trx_rseg_t#latch.;
63 /** rollback segment header page number; constant after init() */
64 uint32_tcxx . . $ uint32_t# page_nocxx . . $ trx_rseg_t#page_no.;
65 /** length of the TRX_RSEG_HISTORY list (number of transactions) */
66 uint32_tcxx . . $ uint32_t# history_sizecxx . . $ trx_rseg_t#history_size.;
67
68 /** Last known transaction that has not been purged yet,
69 or 0 if everything has been purged. */
70 trx_id_tcxx . . $ trx_id_t# needs_purgecxx . . $ trx_rseg_t#needs_purge.;
71
72 private:
73 /** Reference counter to track is_persistent() transactions,
74 with SKIP flag. */
75 stdcxx . . $ std/::atomiccxx . . $ std/atomic#<uint32_tcxx . . $ uint32_t#> refcxx . . $ trx_rseg_t#ref.;
76 public:
77 /** Whether undo tablespace truncation is pending */
78 static constexpr uint32_tcxx . . $ uint32_t# SKIPcxx . . $ trx_rseg_t#SKIP.= 1;
79 /** Transaction reference count multiplier */
80 static constexpr uint32_tcxx . . $ uint32_t# REFcxx . . $ trx_rseg_t#REF.= 2;
81
82 /** @return the reference count and flags */
83 uint32_tcxx . . $ uint32_t# ref_loadcxx . . $ trx_rseg_t#ref_load(ddd8539a2fcdd4ce).() const { return refcxx . . $ trx_rseg_t#ref..loadcxx . . $ std/__atomic_base#load(1776886d83107284).(stdcxx . . $ std/::memory_order_relaxedcxx . . $ std/memory_order_relaxed.); }
84 private:
85 /** Set the SKIP bit */
86 void ref_set_skipcxx . . $ trx_rseg_t#ref_set_skip(49f6e7a06ebc5aa8).()
87 {
88 refcxx . . $ trx_rseg_t#ref..fetch_orcxx . . $ std/__atomic_base#fetch_or(8de7200f212ddeb7).(SKIPcxx . . $ trx_rseg_t#SKIP., stdcxx . . $ std/::memory_order_relaxedcxx . . $ std/memory_order_relaxed.);
89 }
90 /** Clear a bit in ref */
91 void ref_reset_skipcxx . . $ trx_rseg_t#ref_reset_skip(49f6e7a06ebc5aa8).()
92 {
93 refcxx . . $ trx_rseg_t#ref..fetch_andcxx . . $ std/__atomic_base#fetch_and(8de7200f212ddeb7).(~SKIPcxx . . $ trx_rseg_t#SKIP., stdcxx . . $ std/::memory_order_relaxedcxx . . $ std/memory_order_relaxed.);
94 }
95
96 public:
97
98 /** Initialize the fields that are not zero-initialized. */
99 void initcxx . . $ trx_rseg_t#init(9b026bbe728f3d55).(fil_space_tcxx . . $ fil_space_t# *space, uint32_tcxx . . $ uint32_t# page);
100 /** Reinitialize the fields on undo tablespace truncation. */
101 void reinitcxx . . $ trx_rseg_t#reinit(cb2f890c2fdad230).(uint32_tcxx . . $ uint32_t# page);
102 /** Clean up. */
103 void destroycxx . . $ trx_rseg_t#destroy(49f6e7a06ebc5aa8).();
104
105 /** Note that undo tablespace truncation was started. */
106 void set_skip_allocationcxx . . $ trx_rseg_t#set_skip_allocation(49f6e7a06ebc5aa8).() { ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(is_persistent()); ref_set_skipcxx . . $ trx_rseg_t#ref_set_skip(49f6e7a06ebc5aa8).(); }
107 /** Note that undo tablespace truncation was completed. */
108 void clear_skip_allocationcxx . . $ trx_rseg_t#clear_skip_allocation(49f6e7a06ebc5aa8).()
109 {
110 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(is_persistent());
111 #if defined DBUG_OFFcxx . . $ `<built-in>:492:9`!
112 ref_reset_skipcxx . . $ trx_rseg_t#ref_reset_skip(49f6e7a06ebc5aa8).();
113 #else
114 ut_d(auto r=) ref.fetch_and(~SKIP, std::memory_order_relaxed);
115 ut_ad(r == SKIP);
116 #endif
117 }
118 /** @return whether the segment is marked for undo truncation */
119 bool skip_allocationcxx . . $ trx_rseg_t#skip_allocation(50ce9a9e25b4a850).() const
120 { return refcxx . . $ trx_rseg_t#ref..loadcxx . . $ std/__atomic_base#load(1776886d83107284).(stdcxx . . $ std/::memory_order_acquirecxx . . $ std/memory_order_acquire.) & SKIPcxx . . $ trx_rseg_t#SKIP.; }
121 /** Increment the reference count */
122 void acquirecxx . . $ trx_rseg_t#acquire(49f6e7a06ebc5aa8).()
123 { ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(auto r=) refcxx . . $ trx_rseg_t#ref..fetch_addcxx . . $ std/__atomic_base#fetch_add(8de7200f212ddeb7).(REFcxx . . $ trx_rseg_t#REF.); ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!(r & SKIP)); }
124 /** Increment the reference count if possible
125 @retval true if the reference count was incremented
126 @retval false if skip_allocation() holds */
127 bool acquire_if_availablecxx . . $ trx_rseg_t#acquire_if_available(c9857a73d68e59ba).()
128 {
129 uint32_tcxx . . $ uint32_t# r= 0;
130 while (!refcxx . . $ trx_rseg_t#ref..compare_exchange_weakcxx . . $ std/__atomic_base#compare_exchange_weak(747dd5cfc7d0fd78).(r, r + REFcxx . . $ trx_rseg_t#REF.,
131 stdcxx . . $ std/::memory_order_relaxedcxx . . $ std/memory_order_relaxed.,
132 stdcxx . . $ std/::memory_order_relaxedcxx . . $ std/memory_order_relaxed.))
133 if (r & SKIPcxx . . $ trx_rseg_t#SKIP.)
134 return false;
135 return true;
136 }
137
138 /** Decrement the reference count */
139 void releasecxx . . $ trx_rseg_t#release(49f6e7a06ebc5aa8).()
140 {
141 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(const auto r=)
142 refcxx . . $ trx_rseg_t#ref..fetch_subcxx . . $ std/__atomic_base#fetch_sub(8de7200f212ddeb7).(REFcxx . . $ trx_rseg_t#REF., stdcxx . . $ std/::memory_order_relaxedcxx . . $ std/memory_order_relaxed.);
143 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(r >= REF);
144 }
145 /** @return whether references exist */
146 bool is_referencedcxx . . $ trx_rseg_t#is_referenced(50ce9a9e25b4a850).() const { return ref_loadcxx . . $ trx_rseg_t#ref_load(ddd8539a2fcdd4ce).() >= REFcxx . . $ trx_rseg_t#REF.; }
147
148 /** current size in pages */
149 uint32_tcxx . . $ uint32_t# curr_sizecxx . . $ trx_rseg_t#curr_size.;
150
151 /** List of undo logs (transactions) */
152 UT_LIST_BASE_NODE_Tcxx . . $ ut_list_base#(trx_undo_t) undo_listcxx . . $ trx_rseg_t#undo_list.;
153 /** List of undo log segments cached for fast reuse */
154 UT_LIST_BASE_NODE_Tcxx . . $ ut_list_base#(trx_undo_t) undo_cachedcxx . . $ trx_rseg_t#undo_cached.;
155
156 /** Last not yet purged undo log header; FIL_NULL if all purged */
157 uint32_tcxx . . $ uint32_t# last_page_nocxx . . $ trx_rseg_t#last_page_no.;
158
159 /** trx_t::no << 16 | last_offset */
160 uint64_tcxx . . $ uint64_t# last_commit_and_offsetcxx . . $ trx_rseg_t#last_commit_and_offset.;
161
162 /** @return the commit ID of the last committed transaction */
163 trx_id_tcxx . . $ trx_id_t# last_trx_nocxx . . $ trx_rseg_t#last_trx_no(fe4d2d262d4164a8).() const
164 { return last_commit_and_offsetcxx . . $ trx_rseg_t#last_commit_and_offset. >> 16; }
165 /** @return header offset of the last committed transaction */
166 uint16_tcxx . . $ uint16_t# last_offsetcxx . . $ trx_rseg_t#last_offset(72085aa11f4b6e09).() const
167 {
168 return static_cast<uint16_tcxx . . $ uint16_t#>(last_commit_and_offsetcxx . . $ trx_rseg_t#last_commit_and_offset.);
169 }
170
171 void set_last_commitcxx . . $ trx_rseg_t#set_last_commit(9b5a7e2bc6d3acc9).(uint16_tcxx . . $ uint16_t# last_offset, trx_id_tcxx . . $ trx_id_t# trx_no)
172 {
173 last_commit_and_offsetcxx . . $ trx_rseg_t#last_commit_and_offset.= trx_no << 16 | static_cast<uint64_tcxx . . $ uint64_t#>(last_offset);
174 }
175
176 /** @return the page identifier */
177 page_id_tcxx . . $ page_id_t# page_idcxx . . $ trx_rseg_t#page_id(bf57bd4462354dd6).() const { return page_id_tcxx . . $ page_id_t#{spacecxx . . $ trx_rseg_t#space.->idcxx . . $ fil_space_t#id., page_nocxx . . $ trx_rseg_t#page_no.}; }
178
179 /** @return the rollback segment header page, exclusively latched */
180 buf_block_tcxx . . $ buf_block_t# *getcxx . . $ trx_rseg_t#get(665680646f084746).(mtr_tcxx . . $ mtr_t# *mtr, dberr_tcxx . . $ dberr_t# *err) const;
181
182 /** @return whether the rollback segment is persistent */
183 bool is_persistentcxx . . $ trx_rseg_t#is_persistent(50ce9a9e25b4a850).() const
184 {
185 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space == fil_system.temp_space || space == fil_system.sys_space ||
186 (srv_undo_space_id_start > 0 &&
187 space->id >= srv_undo_space_id_start &&
188 space->id <= srv_undo_space_id_start + TRX_SYS_MAX_UNDO_SPACES));
189 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space == fil_system.temp_space || space == fil_system.sys_space ||
190 !srv_was_started ||
191 (srv_undo_space_id_start > 0 &&
192 space->id >= srv_undo_space_id_start
193 && space->id <= srv_undo_space_id_start +
194 srv_undo_tablespaces_open));
195 return spacecxx . . $ trx_rseg_t#space.->idcxx . . $ fil_space_t#id. != SRV_TMP_SPACE_IDcxx . . $ SRV_TMP_SPACE_ID.;
196 }
197 };
198
199 /* Undo log segment slot in a rollback segment header */
200 /*-------------------------------------------------------------*/
201 #define TRX_RSEG_SLOT_PAGE_NOcxx . . $ `storage/innobase/include/trx0rseg.h:201:9`! 0 /* Page number of the header page of
202 an undo log segment */
203 /*-------------------------------------------------------------*/
204 /* Slot size */
205 #define TRX_RSEG_SLOT_SIZEcxx . . $ `storage/innobase/include/trx0rseg.h:205:9`! 4
206
207 /* The offset of the rollback segment header on its page */
208 #define TRX_RSEGcxx . . $ `storage/innobase/include/trx0rseg.h:208:9`! FSEG_PAGE_DATAcxx . . $ `storage/innobase/include/fsp0types.h:78:9`!
209
210 /* Transaction rollback segment header */
211 /*-------------------------------------------------------------*/
212 /** 0xfffffffe = pre-MariaDB 10.3.5 format; 0=MariaDB 10.3.5 or later */
213 #define TRX_RSEG_FORMATcxx . . $ `storage/innobase/include/trx0rseg.h:213:9`! 0
214 /** Number of pages in the TRX_RSEG_HISTORY list */
215 #define TRX_RSEG_HISTORY_SIZEcxx . . $ `storage/innobase/include/trx0rseg.h:215:9`! 4
216 /** Committed transaction logs that have not been purged yet */
217 #define TRX_RSEG_HISTORYcxx . . $ `storage/innobase/include/trx0rseg.h:217:9`! 8
218 #define TRX_RSEG_FSEG_HEADERcxx . . $ `storage/innobase/include/trx0rseg.h:218:9`! (8 + FLST_BASE_NODE_SIZEcxx . . $ `storage/innobase/include/fut0lst.h:30:9`!)
219 /* Header for the file segment where
220 this page is placed */
221 #define TRX_RSEG_UNDO_SLOTScxx . . $ `storage/innobase/include/trx0rseg.h:221:9`! (8 + FLST_BASE_NODE_SIZEcxx . . $ `storage/innobase/include/fut0lst.h:30:9`! + FSEG_HEADER_SIZEcxx . . $ `storage/innobase/include/fsp0types.h:90:9`!)
222 /* Undo log segment slots */
223 /** Maximum transaction ID (valid only if TRX_RSEG_FORMAT is 0) */
224 #define TRX_RSEG_MAX_TRX_IDcxx . . $ `storage/innobase/include/trx0rseg.h:224:9`! (TRX_RSEG_UNDO_SLOTScxx . . $ `storage/innobase/include/trx0rseg.h:221:9`! + TRX_RSEG_N_SLOTScxx . . $ `storage/innobase/include/trx0rseg.h:51:9`! \
225 * TRX_RSEG_SLOT_SIZEcxx . . $ `storage/innobase/include/trx0rseg.h:205:9`!)
226
227 /** 8 bytes offset within the binlog file */
228 #define TRX_RSEG_BINLOG_OFFSETcxx . . $ `storage/innobase/include/trx0rseg.h:228:9`! TRX_RSEG_MAX_TRX_IDcxx . . $ `storage/innobase/include/trx0rseg.h:224:9`! + 8
229 /** MySQL log file name, 512 bytes, including terminating NUL
230 (valid only if TRX_RSEG_FORMAT is 0).
231 If no binlog information is present, the first byte is NUL. */
232 #define TRX_RSEG_BINLOG_NAMEcxx . . $ `storage/innobase/include/trx0rseg.h:232:9`! TRX_RSEG_MAX_TRX_IDcxx . . $ `storage/innobase/include/trx0rseg.h:224:9`! + 16
233 /** Maximum length of binlog file name, including terminating NUL, in bytes */
234 #define TRX_RSEG_BINLOG_NAME_LENcxx . . $ `storage/innobase/include/trx0rseg.h:234:9`! 512
235
236 #ifdef WITH_WSREPcxx . . $ `build/include/my_config.h:539:9`!
237 # include "trx0xa.h"cxx . . $ `<file>/storage/innobase/include/trx0xa.h`/
238
239 /** Update the WSREP XID information in rollback segment header.
240 @param[in,out] rseg_header rollback segment header
241 @param[in] xid WSREP XID
242 @param[in,out] mtr mini-transaction */
243 void
244 trx_rseg_update_wsrep_checkpointcxx . . $ trx_rseg_update_wsrep_checkpoint(f0606f2b5f242699).(
245 buf_block_tcxx . . $ buf_block_t#* rseg_header,
246 const XIDcxx . . $ XID#* xid,
247 mtr_tcxx . . $ mtr_t#* mtr);
248
249 /** Update WSREP checkpoint XID in first rollback segment header
250 as part of wsrep_set_SE_checkpoint() when it is guaranteed that there
251 are no wsrep transactions committing.
252 If the UUID part of the WSREP XID does not match to the UUIDs of XIDs already
253 stored into rollback segments, the WSREP XID in all the remaining rollback
254 segments will be reset.
255 @param[in] xid WSREP XID */
256 void trx_rseg_update_wsrep_checkpointcxx . . $ trx_rseg_update_wsrep_checkpoint(b93dbd95271dcf1b).(const XIDcxx . . $ XID#* xid);
257
258 /** Recover the latest WSREP checkpoint XID.
259 @param[out] xid WSREP XID
260 @return whether the WSREP XID was found */
261 bool trx_rseg_read_wsrep_checkpointcxx . . $ trx_rseg_read_wsrep_checkpoint(c83631430a1c0e70).(XIDcxx . . $ XID#& xid);
262 #endif /* WITH_WSREP */
263
264 /** Read the page number of an undo log slot.
265 @param[in] rseg_header rollback segment header
266 @param[in] n slot number */
267 inline uint32_tcxx . . $ uint32_t# trx_rsegf_get_nth_undocxx . . $ trx_rsegf_get_nth_undo(8bf97e93036f040c).(const buf_block_tcxx . . $ buf_block_t# *rseg_header, ulintcxx . . $ ulint# n)
268 {
269 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(n < TRX_RSEG_N_SLOTS);
270 return mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(TRX_RSEGcxx . . $ `storage/innobase/include/trx0rseg.h:208:9`! + TRX_RSEG_UNDO_SLOTScxx . . $ `storage/innobase/include/trx0rseg.h:221:9`! +
271 n * TRX_RSEG_SLOT_SIZEcxx . . $ `storage/innobase/include/trx0rseg.h:205:9`! + rseg_header->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
272 }
273
274 /** Upgrade a rollback segment header page to MariaDB 10.3 format.
275 @param[in,out] rseg_header rollback segment header page
276 @param[in,out] mtr mini-transaction */
277 void trx_rseg_format_upgradecxx . . $ trx_rseg_format_upgrade(c4796673375b2726).(buf_block_tcxx . . $ buf_block_t# *rseg_header, mtr_tcxx . . $ mtr_t# *mtr);
278
279 /** Update the offset information about the end of the binlog entry
280 which corresponds to the transaction just being committed.
281 In a replication slave, this updates the master binlog position
282 up to which replication has proceeded.
283 @param[in,out] rseg_header rollback segment header
284 @param[in] log_file_name binlog file name
285 @param[in] log_offset binlog offset value
286 @param[in,out] mtr mini-transaction */
287 void trx_rseg_update_binlog_offsetcxx . . $ trx_rseg_update_binlog_offset(f30604bdcff3669a).(buf_block_tcxx . . $ buf_block_t# *rseg_header,
288 const char *log_file_name,
289 ulonglongcxx . . $ ulonglong# log_offset,
290 mtr_tcxx . . $ mtr_t# *mtr);