Debian Codegraph @

storage/innobase/include/trx0roll.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 1996, 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/trx0roll.h
29 Transaction rollback
30
31 Created 3/26/1996 Heikki Tuuri
32 *******************************************************/
33
34 #ifndef trx0roll_h
35 #define trx0roll_h
36
37 #include "mtr0mtr.h"
38 #include "trx0sys.h"
39 #include "trx0trx.h"
40 #include "trx0types.h"
41 #include "univ.i"
42
43 #ifdef UNIV_HOTBACKUP
44 #include "que0que.h"
45 #endif /* UNIV_HOTBACKUP */
46
47 extern os_event_t recovery_lock_taken;
48
49 /** Determines if this transaction is rolling back an incomplete transaction
50 in crash recovery.
51 @return true if trx is an incomplete transaction that is being rolled
52 back in crash recovery */
53 bool trx_is_recv(const trx_t *trx); /*!< in: transaction */
54 /** Returns a transaction savepoint taken at this point in time.
55 @return savepoint */
56 trx_savept_t trx_savept_take(trx_t *trx); /*!< in: transaction */
57
58 /** Get next undo log record from redo and noredo rollback segments.
59 @return undo log record copied to heap, NULL if none left, or if the
60 undo number of the top record would be less than the limit */
61 trx_undo_rec_t *trx_roll_pop_top_rec_of_trx(
62 trx_t *trx, /*!< in: transaction */
63 undo_no_t limit, /*!< in: least undo number we need */
64 roll_ptr_t *roll_ptr, /*!< out: roll pointer to undo record */
65 mem_heap_t *heap); /*!< in: memory heap where copied */
66
67 /** Rollback or clean up any incomplete transactions which were
68 encountered in crash recovery. If the transaction already was
69 committed, then we clean up a possible insert undo log. If the
70 transaction was not yet committed, then we roll it back. */
71 void trx_rollback_or_clean_recovered(
72 bool all); /*!< in: false=roll back dictionary transactions;
73 true=roll back all non-PREPARED transactions */
74
75 /** Rollback or clean up any incomplete transactions which were
76 encountered in crash recovery. If the transaction already was
77 committed, then we clean up a possible insert undo log. If the
78 transaction was not yet committed, then we roll it back.
79 Note: this is done in a background thread. */
80 void trx_recovery_rollback_thread();
81
82 /** Creates a rollback command node struct.
83 @return own: rollback node struct */
84 roll_node_t *roll_node_create(
85 mem_heap_t *heap); /*!< in: mem heap where created */
86 /** Performs an execution step for a rollback command node in a query graph.
87 @return query thread to run next, or NULL */
88 que_thr_t *trx_rollback_step(que_thr_t *thr); /*!< in: query thread */
89 /** Rollback a transaction used in MySQL.
90 @return error code or DB_SUCCESS */
91 dberr_t trx_rollback_for_mysql(trx_t *trx); /*!< in/out: transaction */
92 /** Rollback the latest SQL statement for MySQL.
93 @return error code or DB_SUCCESS */
94 dberr_t trx_rollback_last_sql_stat_for_mysql(
95 trx_t *trx); /*!< in/out: transaction */
96 /** Rollback a transaction to a given savepoint or do a complete rollback.
97 @return error code or DB_SUCCESS */
98 dberr_t trx_rollback_to_savepoint(
99 trx_t *trx, /*!< in: transaction handle */
100 trx_savept_t *savept); /*!< in: pointer to savepoint undo number, if
101 partial rollback requested, or NULL for
102 complete rollback */
103 /** Rolls back a transaction back to a named savepoint. Modifications after the
104 savepoint are undone but InnoDB does NOT release the corresponding locks
105 which are stored in memory. If a lock is 'implicit', that is, a new inserted
106 row holds a lock where the lock information is carried by the trx id stored in
107 the row, these locks are naturally released in the rollback. Savepoints which
108 were set after this savepoint are deleted.
109 @return if no savepoint of the name found then DB_NO_SAVEPOINT,
110 otherwise DB_SUCCESS */
111 [[nodiscard]] dberr_t trx_rollback_to_savepoint_for_mysql(
112 trx_t *trx, /*!< in: transaction handle */
113 const char *savepoint_name, /*!< in: savepoint name */
114 int64_t *mysql_binlog_cache_pos); /*!< out: the MySQL binlog cache
115 position corresponding to this
116 savepoint; MySQL needs this
117 information to remove the
118 binlog entries of the queries
119 executed after the savepoint */
120 /** Creates a named savepoint. If the transaction is not yet started, starts it.
121 If there is already a savepoint of the same name, this call erases that old
122 savepoint and replaces it with a new. Savepoints are deleted in a transaction
123 commit or rollback.
124 @return always DB_SUCCESS */
125 dberr_t trx_savepoint_for_mysql(
126 trx_t *trx, /*!< in: transaction handle */
127 const char *savepoint_name, /*!< in: savepoint name */
128 int64_t binlog_cache_pos); /*!< in: MySQL binlog cache
129 position corresponding to this
130 connection at the time of the
131 savepoint */
132 /** Releases a named savepoint. Savepoints which
133 were set after this savepoint are deleted.
134 @return if no savepoint of the name found then DB_NO_SAVEPOINT,
135 otherwise DB_SUCCESS */
136 [[nodiscard]] dberr_t trx_release_savepoint_for_mysql(
137 trx_t *trx, /*!< in: transaction handle */
138 const char *savepoint_name); /*!< in: savepoint name */
139
140 /** Frees savepoint structs starting from savep.
141 @param[in] trx Transaction handle
142 @param[in] savep Free all savepoints starting with this savepoint i, if savep is
143 nullptr free all save points */
144 void trx_roll_savepoints_free(trx_t *trx, trx_named_savept_t *savep);
145
146 /** Rollback node states */
147 enum roll_node_state {
148 ROLL_NODE_NONE = 0, /*!< Unknown state */
149 ROLL_NODE_SEND, /*!< about to send a rollback signal to
150 the transaction */
151 ROLL_NODE_WAIT /*!< rollback signal sent to the
152 transaction, waiting for completion */
153 };
154
155 /** Rollback command node in a query graph */
156 struct roll_node_t {
157 que_common_t common; /*!< node type: QUE_NODE_ROLLBACK */
158 enum roll_node_state state; /*!< node execution state */
159 bool partial; /*!< true if we want a partial
160 rollback */
161 trx_savept_t savept; /*!< savepoint to which to
162 roll back, in the case of a
163 partial rollback */
164 que_thr_t *undo_thr; /*!< undo query graph */
165 };
166
167 /** A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
168 struct trx_named_savept_t {
169 char *name; /*!< savepoint name */
170 trx_savept_t savept; /*!< the undo number corresponding to
171 the savepoint */
172 int64_t mysql_binlog_cache_pos;
173 /*!< the MySQL binlog cache position
174 corresponding to this savepoint, not
175 defined if the MySQL binlogging is not
176 enabled */
177 UT_LIST_NODE_T(trx_named_savept_t)
178 trx_savepoints; /*!< the list of savepoints of a
179 transaction */
180 };
181
182 UT_LIST_NODE_GETTER_DEFINITION(trx_named_savept_t, trx_savepoints)
183
184 #include "trx0roll.ic"
185
186 #endif