Debian Codegraph @

storage/innobase/trx/trx0roll.cc

raw symbols SCIP
1 /*****************************************************************************
2
3 Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2016, 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 trx/trx0roll.cc
22 Transaction rollback
23
24 Created 3/26/1996 Heikki Tuuri
25 *******************************************************/
26
27 #include "trx0roll.h"cxx . . $ `<file>/storage/innobase/include/trx0roll.h`/
28
29 #include <my_service_manager.h>cxx . . $ `<file>/include/my_service_manager.h`/
30 #include <mysql/service_wsrep.h>cxx . . $ `<file>/include/mysql/service_wsrep.h`/
31
32 #include "fsp0fsp.h"cxx . . $ `<file>/storage/innobase/include/fsp0fsp.h`/
33 #include "lock0lock.h"cxx . . $ `<file>/storage/innobase/include/lock0lock.h`/
34 #include "mach0data.h"cxx . . $ `<file>/storage/innobase/include/mach0data.h`/
35 #include "pars0pars.h"cxx . . $ `<file>/storage/innobase/include/pars0pars.h`/
36 #include "que0que.h"cxx . . $ `<file>/storage/innobase/include/que0que.h`/
37 #include "row0mysql.h"cxx . . $ `<file>/storage/innobase/include/row0mysql.h`/
38 #include "row0undo.h"cxx . . $ `<file>/storage/innobase/include/row0undo.h`/
39 #include "srv0mon.h"cxx . . $ `<file>/storage/innobase/include/srv0mon.h`/
40 #include "srv0start.h"cxx . . $ `<file>/storage/innobase/include/srv0start.h`/
41 #include "trx0rec.h"cxx . . $ `<file>/storage/innobase/include/trx0rec.h`/
42 #include "trx0rseg.h"cxx . . $ `<file>/storage/innobase/include/trx0rseg.h`/
43 #include "trx0sys.h"cxx . . $ `<file>/storage/innobase/include/trx0sys.h`/
44 #include "trx0trx.h"cxx . . $ `<file>/storage/innobase/include/trx0trx.h`/
45 #include "trx0undo.h"cxx . . $ `<file>/storage/innobase/include/trx0undo.h`/
46 #include "log.h"cxx . . $ `<file>/sql/log.h`/
47
48 #ifdef UNIV_PFS_THREADcxx . . $ `storage/innobase/include/univ.i:71:10`!
49 mysql_pfs_key_tcxx . . $ mysql_pfs_key_t# trx_rollback_clean_thread_keycxx . . $ trx_rollback_clean_thread_key.;
50 #endif
51
52 tpoolcxx . . $ tpool/::task_groupcxx . . $ tpool/task_group# rollback_all_recovered_groupcxx . . $ rollback_all_recovered_group.(1);
53 tpoolcxx . . $ tpool/::waitable_taskcxx . . $ tpool/waitable_task# rollback_all_recovered_taskcxx . . $ rollback_all_recovered_task.(trx_rollback_all_recoveredcxx . . $ trx_rollback_all_recovered(5d22bdacc48458e8).,
54 nullptr,
55 &rollback_all_recovered_groupcxx . . $ rollback_all_recovered_group.);
56
57 /** true if trx_rollback_all_recovered() thread is active */
58 bool trx_rollback_is_activecxx . . $ trx_rollback_is_active.;
59
60 /** In crash recovery, the current trx to be rolled back; NULL otherwise */
61 const trx_tcxx . . $ trx_t#* trx_roll_crash_recv_trxcxx . . $ trx_roll_crash_recv_trx.;
62
63 bool trx_tcxx . . $ trx_t#::rollback_finishcxx . . $ trx_t#rollback_finish(77ce49a7840d23c7).() noexcept
64 {
65 apply_online_logcxx . . $ trx_t#apply_online_log.= false;
66 if (UNIV_LIKELYcxx . . $ `storage/innobase/include/univ.i:437:9`!(error_state == DB_SUCCESS))
67 {
68 commitcxx . . $ trx_t#commit(77ce49a7840d23c7).();
69 commit_lsncxx . . $ trx_t#commit_lsn.= 0;
70 return true;
71 }
72
73 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(error_state == DB_INTERRUPTED);
74 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(srv_shutdown_state != SRV_SHUTDOWN_NONE);
75 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(!srv_undo_sources);
76 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(srv_fast_shutdown);
77 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(in_rollback= false);
78 if (trx_undo_tcxx . . $ trx_undo_t# *&undo= rsegscxx . . $ trx_t#rsegs..m_redocxx . . $ trx_rsegs_t#m_redo..undocxx . . $ trx_undo_ptr_t#undo.)
79 {
80 UT_LIST_REMOVEcxx . . $ `storage/innobase/include/ut0lst.h:394:9`!(rsegs.m_redo.rseg->undo_list, undo);
81 ut_freecxx . . $ `storage/innobase/include/ut0new.h:1044:9`!(undo);
82 undo= nullptr;
83 }
84 if (trx_undo_tcxx . . $ trx_undo_t# *&undo= rsegscxx . . $ trx_t#rsegs..m_noredocxx . . $ trx_rsegs_t#m_noredo..undocxx . . $ trx_temp_undo_t#undo.)
85 {
86 UT_LIST_REMOVEcxx . . $ `storage/innobase/include/ut0lst.h:394:9`!(rsegs.m_noredo.rseg->undo_list, undo);
87 ut_freecxx . . $ `storage/innobase/include/ut0new.h:1044:9`!(undo);
88 undo= nullptr;
89 }
90 commitcxx . . $ trx_t#commit(77ce49a7840d23c7).();
91 commit_lsncxx . . $ trx_t#commit_lsn.= 0;
92 return false;
93 }
94
95 dberr_tcxx . . $ dberr_t# trx_tcxx . . $ trx_t#::rollback_lowcxx . . $ trx_t#rollback_low(67cbeeee34b51046).(const undo_no_tcxx . . $ undo_no_t# *savept) noexcept
96 {
97 op_infocxx . . $ trx_t#op_info.= "rollback";
98 mem_heap_tcxx . . $ mem_heap_t# *heap= mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(512);
99 roll_node_tcxx . . $ roll_node_t# *roll_node= roll_node_createcxx . . $ roll_node_create(918e88ed85629af4).(heap);
100
101 roll_node->saveptcxx . . $ roll_node_t#savept.= savept ? *savept : 0;
102
103 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!in_rollback);
104 #ifdef UNIV_DEBUG
105 if (savept)
106 {
107 ut_ad(state == TRX_STATE_ACTIVE);
108 ut_ad(mysql_thd);
109 ut_ad(!is_recovered);
110 }
111 #endif
112
113 error_statecxx . . $ trx_t#error_state.= DB_SUCCESScxx . . $ DB_SUCCESS.;
114
115 if (has_loggedcxx . . $ trx_t#has_logged(50ce9a9e25b4a850).())
116 {
117 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(rsegs.m_redo.rseg || rsegs.m_noredo.rseg);
118 que_thr_tcxx . . $ que_thr_t# *thr= pars_complete_graph_for_execcxx . . $ pars_complete_graph_for_exec(f72f1e5ba9fa5b9a).(roll_node, this, heap,
119 nullptr);
120 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(thr == que_fork_start_command(static_cast<que_fork_t*>
121 (que_node_get_parent(thr))));
122 que_run_threadscxx . . $ que_run_threads(373e0c8040d5ad47).(thr);
123 que_run_threadscxx . . $ que_run_threads(373e0c8040d5ad47).(roll_node->undo_thrcxx . . $ roll_node_t#undo_thr.);
124
125 /* Free the memory reserved by the undo graph. */
126 que_graph_freecxx . . $ que_graph_free(f8c7f37b8426cc28).(static_cast<que_tcxx . . $ que_t#*>(roll_node->undo_thrcxx . . $ roll_node_t#undo_thr.->commoncxx . . $ que_thr_t#common..parentcxx . . $ que_common_t#parent.));
127 }
128
129 if (!savept)
130 {
131 rollback_finishcxx . . $ trx_t#rollback_finish(77ce49a7840d23c7).();
132 MONITOR_INCcxx . . $ `storage/innobase/include/srv0mon.h:512:9`!(MONITOR_TRX_ROLLBACK);
133 }
134 else
135 {
136 /* There must not be partial rollback if transaction was chosen as deadlock
137 victim. Galera transaction abort can be invoked during partial rollback. */
138 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!(lock.was_chosen_as_deadlock_victim & 1));
139 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(error_state == DB_SUCCESS);
140 const undo_no_tcxx . . $ undo_no_t# limit{*savept};
141 apply_online_logcxx . . $ trx_t#apply_online_log.= false;
142 for (trx_mod_tables_tcxx . . $ trx_mod_tables_t#::iteratorcxx . . $ std/map#iterator# i= mod_tablescxx . . $ trx_t#mod_tables..begincxx . . $ std/map#begin(7e4de33083b6e738).();
143 i !=cxx . . $ std/`operator!=`(be6a71a859368080). mod_tablescxx . . $ trx_t#mod_tables..endcxx . . $ std/map#end(7e4de33083b6e738).(); )
144 {
145 trx_mod_tables_tcxx . . $ trx_mod_tables_t#::iteratorcxx . . $ std/map#iterator# j= i++cxx . . $ std/_Rb_tree_iterator#operator++(2987e7ff93f61dc1).;
146 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(j->second.valid());
147 if (j->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).second.rollbackcxx . . $ trx_mod_table_time_t#rollback(31596a199e1d8a50).(limit))
148 {
149 j->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).second.clear_bulk_buffercxx . . $ trx_mod_table_time_t#clear_bulk_buffer(49f6e7a06ebc5aa8).();
150 mod_tablescxx . . $ trx_t#mod_tables..erasecxx . . $ std/map#erase(9238c2f1608b9ba6).(j);
151 }
152 else if (!apply_online_logcxx . . $ trx_t#apply_online_log.)
153 apply_online_logcxx . . $ trx_t#apply_online_log.= j->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).first->is_native_online_ddlcxx . . $ dict_table_t#is_native_online_ddl(50ce9a9e25b4a850).();
154 }
155 MONITOR_INCcxx . . $ `storage/innobase/include/srv0mon.h:512:9`!(MONITOR_TRX_ROLLBACK_SAVEPOINT);
156 }
157
158 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
159 op_infocxx . . $ trx_t#op_info.= "";
160 return error_statecxx . . $ trx_t#error_state.;
161 }
162
163 dberr_tcxx . . $ dberr_t# trx_tcxx . . $ trx_t#::rollbackcxx . . $ trx_t#rollback(67cbeeee34b51046).(const undo_no_tcxx . . $ undo_no_t# *savept) noexcept
164 {
165 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!mutex_is_owner());
166 switch (statecxx . . $ trx_t#state.) {
167 case TRX_STATE_ABORTEDcxx . . $ TRX_STATE_ABORTED.:
168 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!savept);
169 statecxx . . $ trx_t#state.=cxx . . $ Atomic_relaxed#`operator=`(ada6a8422704cf8a). TRX_STATE_NOT_STARTEDcxx . . $ TRX_STATE_NOT_STARTED.;
170 /* fall through */
171 case TRX_STATE_NOT_STARTEDcxx . . $ TRX_STATE_NOT_STARTED.:
172 error_statecxx . . $ trx_t#error_state.= DB_SUCCESScxx . . $ DB_SUCCESS.;
173 return DB_SUCCESScxx . . $ DB_SUCCESS.;
174 case TRX_STATE_PREPAREDcxx . . $ TRX_STATE_PREPARED.:
175 case TRX_STATE_PREPARED_RECOVEREDcxx . . $ TRX_STATE_PREPARED_RECOVERED.:
176 case TRX_STATE_COMMITTED_IN_MEMORYcxx . . $ TRX_STATE_COMMITTED_IN_MEMORY.:
177 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!("invalid state" == 0);
178 /* fall through */
179 case TRX_STATE_ACTIVEcxx . . $ TRX_STATE_ACTIVE.:
180 break;
181 }
182 #ifdef WITH_WSREPcxx . . $ `/build/tmp.NxIY9EeyJN/package/build/include/my_config.h:539:9`!
183 if (!savept && is_wsrepcxx . . $ trx_t#is_wsrep(50ce9a9e25b4a850).() && wsrep_thd_is_SR(mysql_thdcxx . . $ trx_t#mysql_thd.))
184 wsrep_handle_SR_rollback(nullptr, mysql_thdcxx . . $ trx_t#mysql_thd.);
185 #endif /* WITH_WSREP */
186 return rollback_lowcxx . . $ trx_t#rollback_low(67cbeeee34b51046).(savept);
187 }
188
189 /** Rollback a transaction used in MySQL
190 @param[in, out] trx transaction
191 @return error code or DB_SUCCESS */
192 dberr_tcxx . . $ dberr_t# trx_rollback_for_mysqlcxx . . $ trx_rollback_for_mysql(fa66d1d27bf62ad6).(trx_tcxx . . $ trx_t#* trx)
193 {
194 /* We are reading trx->state without holding trx->mutex
195 here, because the rollback should be invoked for a running
196 active MySQL transaction (or recovered prepared transaction)
197 that is associated with the current thread. */
198
199 switch (trx->statecxx . . $ trx_t#state.) {
200 case TRX_STATE_ABORTEDcxx . . $ TRX_STATE_ABORTED.:
201 trx->statecxx . . $ trx_t#state. =cxx . . $ Atomic_relaxed#`operator=`(ada6a8422704cf8a). TRX_STATE_NOT_STARTEDcxx . . $ TRX_STATE_NOT_STARTED.;
202 /* fall through */
203 case TRX_STATE_NOT_STARTEDcxx . . $ TRX_STATE_NOT_STARTED.:
204 trx->will_lockcxx . . $ trx_t#will_lock. = false;
205 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx->mysql_thd);
206 /* Galera transaction abort can be invoked from MDL acquision
207 code, so trx->lock.was_chosen_as_deadlock_victim can be set
208 even if trx->state is TRX_STATE_NOT_STARTED. */
209 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!(trx->lock.was_chosen_as_deadlock_victim & 1));
210 #ifdef WITH_WSREPcxx . . $ `/build/tmp.NxIY9EeyJN/package/build/include/my_config.h:539:9`!
211 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!trx->is_wsrep());
212 trx->lockcxx . . $ trx_t#lock..was_chosen_as_deadlock_victimcxx . . $ trx_lock_t#was_chosen_as_deadlock_victim.=cxx . . $ Atomic_relaxed#`operator=`(ada6a8422704cf8a). false;
213 #endif
214 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(UT_LIST_GET_LENcxx . . $ `storage/innobase/include/ut0lst.h:415:9`!(trx->lock.trx_locks) == 0);
215 return(DB_SUCCESScxx . . $ DB_SUCCESS.);
216 case TRX_STATE_ACTIVEcxx . . $ TRX_STATE_ACTIVE.:
217 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx->mysql_thd);
218 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!trx->is_recovered);
219 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!trx->is_autocommit_non_locking() || trx->read_only);
220 return trx->rollback_lowcxx . . $ trx_t#rollback_low(67cbeeee34b51046).();
221
222 case TRX_STATE_PREPAREDcxx . . $ TRX_STATE_PREPARED.:
223 case TRX_STATE_PREPARED_RECOVEREDcxx . . $ TRX_STATE_PREPARED_RECOVERED.:
224 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!trx->is_autocommit_non_locking());
225 if (trx->rsegscxx . . $ trx_t#rsegs..m_redocxx . . $ trx_rsegs_t#m_redo..undocxx . . $ trx_undo_ptr_t#undo.) {
226 /* The XA ROLLBACK of a XA PREPARE transaction
227 will consist of multiple mini-transactions.
228
229 As the very first step of XA ROLLBACK, we must
230 change the undo log state back from
231 TRX_UNDO_PREPARED to TRX_UNDO_ACTIVE, in order
232 to ensure that recovery will complete the
233 rollback.
234
235 Failure to perform this step could cause a
236 situation where we would roll back part of
237 a XA PREPARE transaction, the server would be
238 killed, and finally, the transaction would be
239 recovered in XA PREPARE state, with some of
240 the actions already having been rolled back. */
241 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx->rsegs.m_redo.undo->rseg
242 == trx->rsegs.m_redo.rseg);
243 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{trx};
244 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
245 if (trx_undo_tcxx . . $ trx_undo_t#* undo = trx->rsegscxx . . $ trx_t#rsegs..m_redocxx . . $ trx_rsegs_t#m_redo..undocxx . . $ trx_undo_ptr_t#undo.) {
246 trx_undo_set_state_at_preparecxx . . $ trx_undo_set_state_at_prepare(5d11429a9a877c11).(undo, true,
247 &mtr);
248 }
249 /* Write the redo log for the XA ROLLBACK
250 state change to the global buffer. It is
251 not necessary to flush the redo log. If
252 a durable log write of a later mini-transaction
253 takes place for whatever reason, then this state
254 change will be durable as well. */
255 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
256 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr.commit_lsn() > 0);
257 }
258 return trx->rollback_lowcxx . . $ trx_t#rollback_low(67cbeeee34b51046).();
259
260 case TRX_STATE_COMMITTED_IN_MEMORYcxx . . $ TRX_STATE_COMMITTED_IN_MEMORY.:
261 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!trx->is_autocommit_non_locking());
262 break;
263 }
264
265 ut_errorcxx . . $ `storage/innobase/include/ut0dbg.h:58:9`!;
266 return(DB_CORRUPTIONcxx . . $ DB_CORRUPTION.);
267 }
268
269 /*******************************************************************//**
270 Roll back an active transaction. */
271 static
272 void
273 trx_rollback_activecxx . . $ trx_rollback_active(a6968fd0d8f26912).(
274 /*================*/
275 trx_tcxx . . $ trx_t#* trx) /*!< in/out: transaction */
276 {
277 mem_heap_tcxx . . $ mem_heap_t#* heap;
278 que_fork_tcxx . . $ que_fork_t#* fork;
279 que_thr_tcxx . . $ que_thr_t#* thr;
280 roll_node_tcxx . . $ roll_node_t#* roll_node;
281 const trx_id_tcxx . . $ trx_id_t# trx_id = trx->idcxx . . $ trx_t#id.;
282
283 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx_id);
284
285 heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(512);
286
287 fork = que_fork_createcxx . . $ que_fork_create(37d82b36cccf16b8).(heap);
288 fork->trxcxx . . $ que_fork_t#trx. = trx;
289
290 thr = que_thr_createcxx . . $ que_thr_create(9bbc1169be87f5c4).(fork, heap, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
291
292 roll_node = roll_node_createcxx . . $ roll_node_create(918e88ed85629af4).(heap);
293
294 thr->childcxx . . $ que_thr_t#child. = roll_node;
295 roll_node->commoncxx . . $ roll_node_t#common..parentcxx . . $ que_common_t#parent. = thr;
296
297 trx->graphcxx . . $ trx_t#graph. = fork;
298
299 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(thr == que_fork_start_command(fork));
300
301 trx_roll_crash_recv_trxcxx . . $ trx_roll_crash_recv_trx. = trx;
302
303 const bool dictionary_locked = trx->dict_operationcxx . . $ trx_t#dict_operation.;
304
305 if (dictionary_locked) {
306 row_mysql_lock_data_dictionarycxx . . $ `storage/innobase/include/row0mysql.h:306:9`!(trx);
307 }
308
309 que_run_threadscxx . . $ que_run_threads(373e0c8040d5ad47).(thr);
310 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(roll_node->undo_thr != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
311
312 que_run_threadscxx . . $ que_run_threads(373e0c8040d5ad47).(roll_node->undo_thrcxx . . $ roll_node_t#undo_thr.);
313
314 que_graph_freecxx . . $ que_graph_free(f8c7f37b8426cc28).(
315 static_cast<que_tcxx . . $ que_t#*>(roll_node->undo_thrcxx . . $ roll_node_t#undo_thr.->commoncxx . . $ que_thr_t#common..parentcxx . . $ que_common_t#parent.));
316
317 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(!trx->rollback_finish())) {
318 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dictionary_locked);
319 } else {
320 sql_print_informationcxx . . $ sql_print_information(326aeb464d16410c).(
321 "InnoDB: Rolled back recovered transaction "
322 TRX_ID_FMTcxx . . $ `storage/innobase/include/trx0types.h:34:9`!, trx_id);
323 }
324
325 if (dictionary_locked) {
326 row_mysql_unlock_data_dictionarycxx . . $ `storage/innobase/include/row0mysql.h:314:9`!(trx);
327 }
328
329 mem_heap_freecxx . . $ mem_heap_free(5231cf397463bfab).(heap);
330
331 trx_roll_crash_recv_trxcxx . . $ trx_roll_crash_recv_trx. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
332 }
333
334
335 struct trx_roll_count_callback_argcxx . . $ trx_roll_count_callback_arg#
336 {
337 uint32_tcxx . . $ uint32_t# n_trxcxx . . $ trx_roll_count_callback_arg#n_trx.;
338 uint64_tcxx . . $ uint64_t# n_rowscxx . . $ trx_roll_count_callback_arg#n_rows.;
339 trx_roll_count_callback_argcxx . . $ trx_roll_count_callback_arg#trx_roll_count_callback_arg(49f6e7a06ebc5aa8).(): n_trxcxx . . $ trx_roll_count_callback_arg#n_trx.(0), n_rowscxx . . $ trx_roll_count_callback_arg#n_rows.(0) {}
340 };
341
342
343 static my_boolcxx . . $ my_bool# trx_roll_count_callbackcxx . . $ trx_roll_count_callback(804c471a51efcf41).(rw_trx_hash_element_tcxx . . $ rw_trx_hash_element_t# *element,
344 trx_roll_count_callback_argcxx . . $ trx_roll_count_callback_arg# *arg)
345 {
346 element->mutexcxx . . $ rw_trx_hash_element_t#mutex..wr_lockcxx . . $ srw_mutex_impl#wr_lock(ced63f7c635d850d).();
347 if (trx_tcxx . . $ trx_t# *trx= element->trxcxx . . $ rw_trx_hash_element_t#trx.)
348 {
349 if (trx->is_recoveredcxx . . $ trx_t#is_recovered. && trx_state_eqcxx . . $ trx_state_eq(27159ea98b1cf0b4).(trx, TRX_STATE_ACTIVEcxx . . $ TRX_STATE_ACTIVE.))
350 {
351 arg->n_trxcxx . . $ trx_roll_count_callback_arg#n_trx.++;
352 arg->n_rowscxx . . $ trx_roll_count_callback_arg#n_rows.+= trx->undo_nocxx . . $ trx_t#undo_no.;
353 }
354 }
355 element->mutexcxx . . $ rw_trx_hash_element_t#mutex..wr_unlockcxx . . $ srw_mutex_impl#wr_unlock(ced63f7c635d850d).();
356 return 0;
357 }
358
359 /** Report progress when rolling back a row of a recovered transaction. */
360 void trx_roll_report_progresscxx . . $ trx_roll_report_progress(49f6e7a06ebc5aa8).()
361 {
362 time_tcxx . . $ time_t# now = time(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
363 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&recv_sys.mutex);
364 bool report = recv_syscxx . . $ recv_sys..reportcxx . . $ recv_sys_t#report(2ff18951ca35fa3e).(now);
365 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&recv_sys.mutex);
366
367 if (report) {
368 trx_roll_count_callback_argcxx . . $ trx_roll_count_callback_arg# argcxx . . $ trx_roll_count_callback_arg#trx_roll_count_callback_arg(49f6e7a06ebc5aa8).;
369
370 /* Get number of recovered active transactions and number of
371 rows they modified. Numbers must be accurate, because only this
372 thread is allowed to touch recovered transactions. */
373 trx_syscxx . . $ trx_sys..rw_trx_hashcxx . . $ trx_sys_t#rw_trx_hash..iterate_no_dupscxx . . $ rw_trx_hash_t#iterate_no_dups(b52874388e5be12f).(
374 trx_roll_count_callbackcxx . . $ trx_roll_count_callback(804c471a51efcf41)., &arg);
375
376 if (arg.n_rowscxx . . $ trx_roll_count_callback_arg#n_rows. > 0) {
377 service_manager_extend_timeoutcxx . . $ `include/my_service_manager.h:32:9`!(
378 INNODB_EXTEND_TIMEOUT_INTERVALcxx . . $ `storage/innobase/include/univ.i:31:9`!,
379 "To roll back: " UINT32PFcxx . . $ `storage/innobase/include/univ.i:312:10`! " transactions, "
380 UINT64PFcxx . . $ `storage/innobase/include/univ.i:322:9`! " rows", arg.n_trx, arg.n_rows);
381 }
382
383 ibcxx . . $ ib/::infocxx . . $ ib/info#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "To roll back: " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). arg.n_trxcxx . . $ trx_roll_count_callback_arg#n_trx.
384 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " transactions, " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). arg.n_rowscxx . . $ trx_roll_count_callback_arg#n_rows. <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " rows";
385
386 }
387 }
388
389
390 static my_boolcxx . . $ my_bool# trx_rollback_recovered_callbackcxx . . $ trx_rollback_recovered_callback(5550265b054ebc4b).(rw_trx_hash_element_tcxx . . $ rw_trx_hash_element_t# *element,
391 stdcxx . . $ std/::vectorcxx . . $ std/vector#<trx_tcxx . . $ trx_t#*> *trx_list)
392 {
393 element->mutexcxx . . $ rw_trx_hash_element_t#mutex..wr_lockcxx . . $ srw_mutex_impl#wr_lock(ced63f7c635d850d).();
394 if (trx_tcxx . . $ trx_t# *trx= element->trxcxx . . $ rw_trx_hash_element_t#trx.)
395 {
396 trx->mutex_lockcxx . . $ trx_t#mutex_lock(49f6e7a06ebc5aa8).();
397 if (trx_state_eqcxx . . $ trx_state_eq(27159ea98b1cf0b4).(trx, TRX_STATE_ACTIVEcxx . . $ TRX_STATE_ACTIVE.) && trx->is_recoveredcxx . . $ trx_t#is_recovered.)
398 trx_list->push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(trx);
399 trx->mutex_unlockcxx . . $ trx_t#mutex_unlock(49f6e7a06ebc5aa8).();
400 }
401 element->mutexcxx . . $ rw_trx_hash_element_t#mutex..wr_unlockcxx . . $ srw_mutex_impl#wr_unlock(ced63f7c635d850d).();
402 return 0;
403 }
404
405 /**
406 Rollback any incomplete transactions which were encountered in crash recovery.
407
408 If the transaction already was committed, then we clean up a possible insert
409 undo log. If the transaction was not yet committed, then we roll it back.
410
411 Note: For XA recovered transactions, we rely on MySQL to
412 do rollback. They will be in TRX_STATE_PREPARED state. If the server
413 is shutdown and they are still lingering in trx_sys_t::trx_list
414 then the shutdown will hang.
415
416 @param[in] all true=roll back all recovered active transactions;
417 false=roll back any incomplete dictionary transaction
418 */
419
420 void trx_rollback_recoveredcxx . . $ trx_rollback_recovered(b45ddcbc8423892c).(bool all)
421 {
422 stdcxx . . $ std/::vectorcxx . . $ std/vector#<trx_tcxx . . $ trx_t#*> trx_listcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
423
424 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(srv_force_recovery <
425 ulong(all ? SRV_FORCE_NO_TRX_UNDO : SRV_FORCE_NO_DDL_UNDO));
426
427 /*
428 Collect list of recovered ACTIVE transaction ids first. Once collected, no
429 other thread is allowed to modify or remove these transactions from
430 rw_trx_hash.
431 */
432 trx_syscxx . . $ trx_sys..rw_trx_hashcxx . . $ trx_sys_t#rw_trx_hash..iterate_no_dupscxx . . $ rw_trx_hash_t#iterate_no_dups(b52874388e5be12f).(trx_rollback_recovered_callbackcxx . . $ trx_rollback_recovered_callback(5550265b054ebc4b).,
433 &trx_list);
434
435 while (!trx_list.emptycxx . . $ std/vector#empty(3482b152b9333168).())
436 {
437 trx_tcxx . . $ trx_t# *trx= trx_list.backcxx . . $ std/vector#back(6baabfa6fc7b3a8e).();
438 trx_list.pop_backcxx . . $ std/vector#pop_back(ced63f7c635d850d).();
439
440 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx);
441 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(trx->mutex_lock());
442 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx->is_recovered);
443 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx_state_eq(trx, TRX_STATE_ACTIVE));
444 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(trx->mutex_unlock());
445
446 if (srv_shutdown_statecxx . . $ srv_shutdown_state. != SRV_SHUTDOWN_NONEcxx . . $ SRV_SHUTDOWN_NONE. && !srv_undo_sourcescxx . . $ srv_undo_sources. &&
447 srv_fast_shutdowncxx . . $ srv_fast_shutdown.)
448 goto discard;
449
450 if (all || trx->dict_operationcxx . . $ trx_t#dict_operation. || trx->has_stats_table_lockcxx . . $ trx_t#has_stats_table_lock(50ce9a9e25b4a850).())
451 {
452 trx_rollback_activecxx . . $ trx_rollback_active(a6968fd0d8f26912).(trx);
453 if (trx->error_statecxx . . $ trx_t#error_state. != DB_SUCCESScxx . . $ DB_SUCCESS.)
454 {
455 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx->error_state == DB_INTERRUPTED);
456 trx->error_statecxx . . $ trx_t#error_state.= DB_SUCCESScxx . . $ DB_SUCCESS.;
457 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!srv_undo_sources);
458 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(srv_fast_shutdown);
459 discard:
460 /* Note: before kill_server() invoked innobase_end() via
461 unireg_end(), it invoked close_connections(), which should initiate
462 the rollback of any user transactions via THD::cleanup() in the
463 connection threads, and wait for all THD::cleanup() to complete.
464 So, no active user transactions should exist at this point.
465
466 srv_undo_sources=false was cleared early in innobase_end().
467
468 Generally, the server guarantees that all connections using
469 InnoDB must be disconnected by the time we are reaching this code,
470 be it during shutdown or UNINSTALL PLUGIN.
471
472 Because there is no possible race condition with any
473 concurrent user transaction, we do not have to invoke
474 trx->commit_state() or wait for !trx->is_referenced()
475 before trx_sys.deregister_rw(trx). */
476 trx_syscxx . . $ trx_sys..deregister_rwcxx . . $ trx_sys_t#deregister_rw(a6968fd0d8f26912).(trx);
477 trx_free_at_shutdowncxx . . $ trx_free_at_shutdown(a6968fd0d8f26912).(trx);
478 }
479 else
480 trx->freecxx . . $ trx_t#free(ced63f7c635d850d).();
481 }
482 }
483 }
484
485 /*******************************************************************//**
486 Rollback or clean up any incomplete transactions which were
487 encountered in crash recovery. If the transaction already was
488 committed, then we clean up a possible insert undo log. If the
489 transaction was not yet committed, then we roll it back.
490 Note: this is done in a background thread. */
491 void trx_rollback_all_recoveredcxx . . $ trx_rollback_all_recovered(5d22bdacc48458e8).(void*)
492 {
493 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!srv_read_only_mode);
494
495 if (trx_syscxx . . $ trx_sys..rw_trx_hashcxx . . $ trx_sys_t#rw_trx_hash..sizecxx . . $ rw_trx_hash_t#size(db52760e79bf9054).()) {
496 ibcxx . . $ ib/::infocxx . . $ ib/info#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Starting in background the rollback of"
497 " recovered transactions";
498 trx_rollback_recoveredcxx . . $ trx_rollback_recovered(b45ddcbc8423892c).(true);
499 ibcxx . . $ ib/::infocxx . . $ ib/info#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Rollback of non-prepared transactions"
500 " completed";
501 }
502
503 trx_rollback_is_activecxx . . $ trx_rollback_is_active. = false;
504 }
505
506 /****************************************************************//**
507 Builds an undo 'query' graph for a transaction. The actual rollback is
508 performed by executing this query graph like a query subprocedure call.
509 The reply about the completion of the rollback will be sent by this
510 graph.
511 @return own: the query graph */
512 static
513 que_tcxx . . $ que_t#*
514 trx_roll_graph_buildcxx . . $ trx_roll_graph_build(ce45ddf854e43f2a).(
515 /*=================*/
516 trx_tcxx . . $ trx_t#* trx) /*!< in/out: transaction */
517 {
518 mem_heap_tcxx . . $ mem_heap_t#* heap;
519 que_fork_tcxx . . $ que_fork_t#* fork;
520 que_thr_tcxx . . $ que_thr_t#* thr;
521
522 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx->mutex_is_owner());
523 heap = mem_heap_createcxx . . $ `storage/innobase/include/mem0mem.h:85:10`!(512);
524 fork = que_fork_createcxx . . $ que_fork_create(37d82b36cccf16b8).(heap);
525 fork->trxcxx . . $ que_fork_t#trx. = trx;
526
527 thr = que_thr_createcxx . . $ que_thr_create(9bbc1169be87f5c4).(fork, heap, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
528
529 thr->childcxx . . $ que_thr_t#child. = row_undo_node_createcxx . . $ row_undo_node_create(34bc3cab307d1340).(trx, thr, heap);
530
531 return(fork);
532 }
533
534 /*********************************************************************//**
535 Starts a rollback operation, creates the UNDO graph that will do the
536 actual undo operation.
537 @return query graph thread that will perform the UNDO operations. */
538 static
539 que_thr_tcxx . . $ que_thr_t#*
540 trx_rollback_startcxx . . $ trx_rollback_start(f3555fff30e4a7e0).(
541 /*===============*/
542 trx_tcxx . . $ trx_t#* trx, /*!< in: transaction */
543 undo_no_tcxx . . $ undo_no_t# roll_limit) /*!< in: rollback to undo no (for
544 partial undo), 0 if we are rolling back
545 the entire transaction */
546 {
547 /* Initialize the rollback field in the transaction */
548
549 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(trx->mutex_is_owner());
550 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!trx->roll_limit);
551 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!trx->in_rollback);
552
553 trx->roll_limitcxx . . $ trx_t#roll_limit. = roll_limit;
554 trx->in_rollbackcxx . . $ trx_t#in_rollback. = true;
555
556 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(trx->roll_limit <= trx->undo_no);
557
558 trx->pages_undonecxx . . $ trx_t#pages_undone. = 0;
559
560 /* Build a 'query' graph which will perform the undo operations */
561
562 que_tcxx . . $ que_t#* roll_graph = trx_roll_graph_buildcxx . . $ trx_roll_graph_build(ce45ddf854e43f2a).(trx);
563
564 trx->graphcxx . . $ trx_t#graph. = roll_graph;
565
566 return(que_fork_start_commandcxx . . $ que_fork_start_command(c600e4000009b3ee).(roll_graph));
567 }
568
569 /*********************************************************************//**
570 Creates a rollback command node struct.
571 @return own: rollback node struct */
572 roll_node_tcxx . . $ roll_node_t#*
573 roll_node_createcxx . . $ roll_node_create(918e88ed85629af4).(
574 /*=============*/
575 mem_heap_tcxx . . $ mem_heap_t#* heap) /*!< in: mem heap where created */
576 {
577 roll_node_tcxx . . $ roll_node_t#* node;
578
579 node = static_cast<roll_node_tcxx . . $ roll_node_t#*>(mem_heap_zalloccxx . . $ mem_heap_zalloc(3f50e4c8b9ca77c0).(heap, sizeof(*node)));
580
581 node->statecxx . . $ roll_node_t#state. = ROLL_NODE_SENDcxx . . $ ROLL_NODE_SEND.;
582
583 node->commoncxx . . $ roll_node_t#common..typecxx . . $ que_common_t#type. = QUE_NODE_ROLLBACKcxx . . $ `storage/innobase/include/que0types.h:52:9`!;
584
585 return(node);
586 }
587
588 /***********************************************************//**
589 Performs an execution step for a rollback command node in a query graph.
590 @return query thread to run next, or NULL */
591 que_thr_tcxx . . $ que_thr_t#*
592 trx_rollback_stepcxx . . $ trx_rollback_step(e73e5dc3217c6744).(
593 /*==============*/
594 que_thr_tcxx . . $ que_thr_t#* thr) /*!< in: query thread */
595 {
596 roll_node_tcxx . . $ roll_node_t#* node;
597
598 node = static_cast<roll_node_tcxx . . $ roll_node_t#*>(thr->run_nodecxx . . $ que_thr_t#run_node.);
599
600 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(que_node_get_type(node) == QUE_NODE_ROLLBACK);
601
602 if (thr->prev_nodecxx . . $ que_thr_t#prev_node. == que_node_get_parentcxx . . $ que_node_get_parent(9f162e79bfc6c74).(node)) {
603 node->statecxx . . $ roll_node_t#state. = ROLL_NODE_SENDcxx . . $ ROLL_NODE_SEND.;
604 }
605
606 if (node->statecxx . . $ roll_node_t#state. == ROLL_NODE_SENDcxx . . $ ROLL_NODE_SEND.) {
607 trx_tcxx . . $ trx_t#* trx;
608
609 trx = thr_get_trxcxx . . $ thr_get_trx(bce191eb970ff2ca).(thr);
610
611 node->statecxx . . $ roll_node_t#state. = ROLL_NODE_WAITcxx . . $ ROLL_NODE_WAIT.;
612
613 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(node->undo_thr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
614
615 trx->mutex_lockcxx . . $ trx_t#mutex_lock(49f6e7a06ebc5aa8).();
616
617 trx_commit_or_rollback_preparecxx . . $ trx_commit_or_rollback_prepare(a6968fd0d8f26912).(trx);
618
619 node->undo_thrcxx . . $ roll_node_t#undo_thr. = trx_rollback_startcxx . . $ trx_rollback_start(f3555fff30e4a7e0).(trx, node->saveptcxx . . $ roll_node_t#savept.);
620
621 trx->mutex_unlockcxx . . $ trx_t#mutex_unlock(49f6e7a06ebc5aa8).();
622 } else {
623 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(node->state == ROLL_NODE_WAIT);
624
625 thr->run_nodecxx . . $ que_thr_t#run_node. = que_node_get_parentcxx . . $ que_node_get_parent(9f162e79bfc6c74).(node);
626 }
627
628 return(thr);
629 }