MySQL 8.3.0
Source Code Documentation
trx0roll.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 2023, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/trx0roll.h
28 Transaction rollback
29
30 Created 3/26/1996 Heikki Tuuri
31 *******************************************************/
32
33#ifndef trx0roll_h
34#define trx0roll_h
35
36#include "mtr0mtr.h"
37#include "trx0sys.h"
38#include "trx0trx.h"
39#include "trx0types.h"
40#include "univ.i"
41
42#ifdef UNIV_HOTBACKUP
43#include "que0que.h"
44#endif /* UNIV_HOTBACKUP */
45
47
48/** Determines if this transaction is rolling back an incomplete transaction
49 in crash recovery.
50 @return true if trx is an incomplete transaction that is being rolled
51 back in crash recovery */
52bool trx_is_recv(const trx_t *trx); /*!< in: transaction */
53/** Returns a transaction savepoint taken at this point in time.
54 @return savepoint */
55trx_savept_t trx_savept_take(trx_t *trx); /*!< in: transaction */
56
57/** Get next undo log record from redo and noredo rollback segments.
58 @return undo log record copied to heap, NULL if none left, or if the
59 undo number of the top record would be less than the limit */
61 trx_t *trx, /*!< in: transaction */
62 undo_no_t limit, /*!< in: least undo number we need */
63 roll_ptr_t *roll_ptr, /*!< out: roll pointer to undo record */
64 mem_heap_t *heap); /*!< in: memory heap where copied */
65
66/** Rollback or clean up any incomplete transactions which were
67 encountered in crash recovery. If the transaction already was
68 committed, then we clean up a possible insert undo log. If the
69 transaction was not yet committed, then we roll it back. */
71 bool all); /*!< in: false=roll back dictionary transactions;
72 true=roll back all non-PREPARED transactions */
73
74/** Rollback or clean up any incomplete transactions which were
75encountered in crash recovery. If the transaction already was
76committed, then we clean up a possible insert undo log. If the
77transaction was not yet committed, then we roll it back.
78Note: this is done in a background thread. */
80
81/** Creates a rollback command node struct.
82 @return own: rollback node struct */
84 mem_heap_t *heap); /*!< in: mem heap where created */
85/** Performs an execution step for a rollback command node in a query graph.
86 @return query thread to run next, or NULL */
87que_thr_t *trx_rollback_step(que_thr_t *thr); /*!< in: query thread */
88/** Rollback a transaction used in MySQL.
89 @return error code or DB_SUCCESS */
90dberr_t trx_rollback_for_mysql(trx_t *trx); /*!< in/out: transaction */
91/** Rollback the latest SQL statement for MySQL.
92 @return error code or DB_SUCCESS */
94 trx_t *trx); /*!< in/out: transaction */
95/** Rollback a transaction to a given savepoint or do a complete rollback.
96 @return error code or DB_SUCCESS */
98 trx_t *trx, /*!< in: transaction handle */
99 trx_savept_t *savept); /*!< in: pointer to savepoint undo number, if
100 partial rollback requested, or NULL for
101 complete rollback */
102/** Rolls back a transaction back to a named savepoint. Modifications after the
103 savepoint are undone but InnoDB does NOT release the corresponding locks
104 which are stored in memory. If a lock is 'implicit', that is, a new inserted
105 row holds a lock where the lock information is carried by the trx id stored in
106 the row, these locks are naturally released in the rollback. Savepoints which
107 were set after this savepoint are deleted.
108 @return if no savepoint of the name found then DB_NO_SAVEPOINT,
109 otherwise DB_SUCCESS */
111 trx_t *trx, /*!< in: transaction handle */
112 const char *savepoint_name, /*!< in: savepoint name */
113 int64_t *mysql_binlog_cache_pos); /*!< out: the MySQL binlog cache
114 position corresponding to this
115 savepoint; MySQL needs this
116 information to remove the
117 binlog entries of the queries
118 executed after the savepoint */
119/** Creates a named savepoint. If the transaction is not yet started, starts it.
120 If there is already a savepoint of the same name, this call erases that old
121 savepoint and replaces it with a new. Savepoints are deleted in a transaction
122 commit or rollback.
123 @return always DB_SUCCESS */
125 trx_t *trx, /*!< in: transaction handle */
126 const char *savepoint_name, /*!< in: savepoint name */
127 int64_t binlog_cache_pos); /*!< in: MySQL binlog cache
128 position corresponding to this
129 connection at the time of the
130 savepoint */
131/** Releases a named savepoint. Savepoints which
132 were set after this savepoint are deleted.
133 @return if no savepoint of the name found then DB_NO_SAVEPOINT,
134 otherwise DB_SUCCESS */
136 trx_t *trx, /*!< in: transaction handle */
137 const char *savepoint_name); /*!< in: savepoint name */
138
139/** Frees savepoint structs starting from savep.
140@param[in] trx Transaction handle
141@param[in] savep Free all savepoints starting with this savepoint i, if savep is
142nullptr free all save points */
144
145/** Rollback node states */
147 ROLL_NODE_NONE = 0, /*!< Unknown state */
148 ROLL_NODE_SEND, /*!< about to send a rollback signal to
149 the transaction */
150 ROLL_NODE_WAIT /*!< rollback signal sent to the
151 transaction, waiting for completion */
153
154/** Rollback command node in a query graph */
156 que_common_t common; /*!< node type: QUE_NODE_ROLLBACK */
157 enum roll_node_state state; /*!< node execution state */
158 bool partial; /*!< true if we want a partial
159 rollback */
160 trx_savept_t savept; /*!< savepoint to which to
161 roll back, in the case of a
162 partial rollback */
163 que_thr_t *undo_thr; /*!< undo query graph */
164};
165
166/** A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
168 char *name; /*!< savepoint name */
169 trx_savept_t savept; /*!< the undo number corresponding to
170 the savepoint */
172 /*!< the MySQL binlog cache position
173 corresponding to this savepoint, not
174 defined if the MySQL binlogging is not
175 enabled */
177 trx_savepoints; /*!< the list of savepoints of a
178 transaction */
179};
180
182
183#include "trx0roll.ic"
184
185#endif
dberr_t
Definition: db0err.h:38
Mini-transaction buffer.
Query graph.
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:301
InnoDB condition variable.
Definition: os0event.cc:62
Definition: que0types.h:50
Definition: que0que.h:241
Rollback command node in a query graph.
Definition: trx0roll.h:155
trx_savept_t savept
savepoint to which to roll back, in the case of a partial rollback
Definition: trx0roll.h:160
que_common_t common
node type: QUE_NODE_ROLLBACK
Definition: trx0roll.h:156
enum roll_node_state state
node execution state
Definition: trx0roll.h:157
que_thr_t * undo_thr
undo query graph
Definition: trx0roll.h:163
bool partial
true if we want a partial rollback
Definition: trx0roll.h:158
A savepoint set with SQL's "SAVEPOINT savepoint_id" command.
Definition: trx0roll.h:167
trx_savepoints
the list of savepoints of a transaction
Definition: trx0roll.h:177
char * name
savepoint name
Definition: trx0roll.h:168
int64_t mysql_binlog_cache_pos
the MySQL binlog cache position corresponding to this savepoint, not defined if the MySQL binlogging ...
Definition: trx0roll.h:171
trx_savept_t savept
the undo number corresponding to the savepoint
Definition: trx0roll.h:169
Transaction savepoint.
Definition: trx0types.h:147
Definition: trx0trx.h:683
trx_savept_t trx_savept_take(trx_t *trx)
Returns a transaction savepoint taken at this point in time.
Definition: trx0roll.cc:564
dberr_t trx_release_savepoint_for_mysql(trx_t *trx, const char *savepoint_name)
Releases a named savepoint.
Definition: trx0roll.cc:535
que_thr_t * trx_rollback_step(que_thr_t *thr)
Performs an execution step for a rollback command node in a query graph.
Definition: trx0roll.cc:1127
roll_node_state
Rollback node states.
Definition: trx0roll.h:146
@ ROLL_NODE_WAIT
rollback signal sent to the transaction, waiting for completion
Definition: trx0roll.h:150
@ ROLL_NODE_NONE
Unknown state.
Definition: trx0roll.h:147
@ ROLL_NODE_SEND
about to send a rollback signal to the transaction
Definition: trx0roll.h:148
dberr_t trx_rollback_to_savepoint(trx_t *trx, trx_savept_t *savept)
Rollback a transaction to a given savepoint or do a complete rollback.
Definition: trx0roll.cc:141
os_event_t recovery_lock_taken
Definition: ha_innodb.cc:297
void trx_roll_savepoints_free(trx_t *trx, trx_named_savept_t *savep)
Frees savepoint structs starting from savep.
Definition: trx0roll.cc:366
dberr_t trx_savepoint_for_mysql(trx_t *trx, const char *savepoint_name, int64_t binlog_cache_pos)
Creates a named savepoint.
Definition: trx0roll.cc:492
dberr_t trx_rollback_to_savepoint_for_mysql(trx_t *trx, const char *savepoint_name, int64_t *mysql_binlog_cache_pos)
Rolls back a transaction back to a named savepoint.
Definition: trx0roll.cc:431
void trx_rollback_or_clean_recovered(bool all)
Rollback or clean up any incomplete transactions which were encountered in crash recovery.
Definition: trx0roll.cc:711
dberr_t trx_rollback_last_sql_stat_for_mysql(trx_t *trx)
Rollback the latest SQL statement for MySQL.
Definition: trx0roll.cc:283
trx_undo_rec_t * trx_roll_pop_top_rec_of_trx(trx_t *trx, undo_no_t limit, roll_ptr_t *roll_ptr, mem_heap_t *heap)
Get next undo log record from redo and noredo rollback segments.
Definition: trx0roll.cc:1018
dberr_t trx_rollback_for_mysql(trx_t *trx)
Rollback a transaction used in MySQL.
Definition: trx0roll.cc:268
void trx_recovery_rollback_thread()
Rollback or clean up any incomplete transactions which were encountered in crash recovery.
Definition: trx0roll.cc:850
roll_node_t * roll_node_create(mem_heap_t *heap)
Creates a rollback command node struct.
Definition: trx0roll.cc:1111
bool trx_is_recv(const trx_t *trx)
Determines if this transaction is rolling back an incomplete transaction in crash recovery.
Definition: trx0roll.cc:557
Transaction system.
The transaction.
Transaction system global type definitions.
byte trx_undo_rec_t
Undo log record.
Definition: trx0types.h:166
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:141
ib_id_t roll_ptr_t
Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR)
Definition: trx0types.h:139
Version control for database, common definitions, and include files.
#define UT_LIST_NODE_GETTER_DEFINITION(t, m)
A helper for the UT_LIST_BASE_NODE_T_EXTERN which declares a node getter struct which extracts member...
Definition: ut0lst.h:269
#define UT_LIST_NODE_T(t)
Macro used for legacy reasons.
Definition: ut0lst.h:63
static int all(site_def const *s, node_no node)
Definition: xcom_transport.cc:881