MySQL  8.0.19
Source Code Documentation
trx0roll.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2019, Oracle and/or its affiliates. All Rights Reserved.
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 also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 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 
46 /** Determines if this transaction is rolling back an incomplete transaction
47  in crash recovery.
48  @return true if trx is an incomplete transaction that is being rolled
49  back in crash recovery */
50 ibool trx_is_recv(const trx_t *trx); /*!< in: transaction */
51 /** Returns a transaction savepoint taken at this point in time.
52  @return savepoint */
53 trx_savept_t trx_savept_take(trx_t *trx); /*!< in: transaction */
54 
55 /** Get next undo log record from redo and noredo rollback segments.
56  @return undo log record copied to heap, NULL if none left, or if the
57  undo number of the top record would be less than the limit */
59  trx_t *trx, /*!< in: transaction */
60  undo_no_t limit, /*!< in: least undo number we need */
61  roll_ptr_t *roll_ptr, /*!< out: roll pointer to undo record */
62  mem_heap_t *heap); /*!< in: memory heap where copied */
63 
64 /** Rollback or clean up any incomplete transactions which were
65  encountered in crash recovery. If the transaction already was
66  committed, then we clean up a possible insert undo log. If the
67  transaction was not yet committed, then we roll it back. */
69  ibool all); /*!< in: FALSE=roll back dictionary transactions;
70  TRUE=roll back all non-PREPARED transactions */
71 
72 /** Rollback or clean up any incomplete transactions which were
73 encountered in crash recovery. If the transaction already was
74 committed, then we clean up a possible insert undo log. If the
75 transaction was not yet committed, then we roll it back.
76 Note: this is done in a background thread. */
78 
79 /** Creates a rollback command node struct.
80  @return own: rollback node struct */
82  mem_heap_t *heap); /*!< in: mem heap where created */
83 /** Performs an execution step for a rollback command node in a query graph.
84  @return query thread to run next, or NULL */
85 que_thr_t *trx_rollback_step(que_thr_t *thr); /*!< in: query thread */
86 /** Rollback a transaction used in MySQL.
87  @return error code or DB_SUCCESS */
88 dberr_t trx_rollback_for_mysql(trx_t *trx); /*!< in/out: transaction */
89 /** Rollback the latest SQL statement for MySQL.
90  @return error code or DB_SUCCESS */
92  trx_t *trx); /*!< in/out: transaction */
93 /** Rollback a transaction to a given savepoint or do a complete rollback.
94  @return error code or DB_SUCCESS */
96  trx_t *trx, /*!< in: transaction handle */
97  trx_savept_t *savept); /*!< in: pointer to savepoint undo number, if
98  partial rollback requested, or NULL for
99  complete rollback */
100 /** Rolls back a transaction back to a named savepoint. Modifications after the
101  savepoint are undone but InnoDB does NOT release the corresponding locks
102  which are stored in memory. If a lock is 'implicit', that is, a new inserted
103  row holds a lock where the lock information is carried by the trx id stored in
104  the row, these locks are naturally released in the rollback. Savepoints which
105  were set after this savepoint are deleted.
106  @return if no savepoint of the name found then DB_NO_SAVEPOINT,
107  otherwise DB_SUCCESS */
109  trx_t *trx, /*!< in: transaction handle */
110  const char *savepoint_name, /*!< in: savepoint name */
111  int64_t *mysql_binlog_cache_pos) /*!< out: the MySQL binlog cache
112  position corresponding to this
113  savepoint; MySQL needs this
114  information to remove the
115  binlog entries of the queries
116  executed after the savepoint */
117  MY_ATTRIBUTE((warn_unused_result));
118 /** Creates a named savepoint. If the transaction is not yet started, starts it.
119  If there is already a savepoint of the same name, this call erases that old
120  savepoint and replaces it with a new. Savepoints are deleted in a transaction
121  commit or rollback.
122  @return always DB_SUCCESS */
124  trx_t *trx, /*!< in: transaction handle */
125  const char *savepoint_name, /*!< in: savepoint name */
126  int64_t binlog_cache_pos); /*!< in: MySQL binlog cache
127  position corresponding to this
128  connection at the time of the
129  savepoint */
130 /** Releases a named savepoint. Savepoints which
131  were set after this savepoint are deleted.
132  @return if no savepoint of the name found then DB_NO_SAVEPOINT,
133  otherwise DB_SUCCESS */
135  trx_t *trx, /*!< in: transaction handle */
136  const char *savepoint_name) /*!< in: savepoint name */
137  MY_ATTRIBUTE((warn_unused_result));
138 /** Frees savepoint structs starting from savep. */
140  trx_t *trx, /*!< in: transaction handle */
141  trx_named_savept_t *savep); /*!< in: free all savepoints > this one;
142  if this is NULL, free all savepoints
143  of trx */
144 /** Rollback node states */
146  ROLL_NODE_NONE = 0, /*!< Unknown state */
147  ROLL_NODE_SEND, /*!< about to send a rollback signal to
148  the transaction */
149  ROLL_NODE_WAIT /*!< rollback signal sent to the
150  transaction, waiting for completion */
151 };
152 
153 /** Rollback command node in a query graph */
154 struct roll_node_t {
155  que_common_t common; /*!< node type: QUE_NODE_ROLLBACK */
156  enum roll_node_state state; /*!< node execution state */
157  bool partial; /*!< TRUE if we want a partial
158  rollback */
159  trx_savept_t savept; /*!< savepoint to which to
160  roll back, in the case of a
161  partial rollback */
162  que_thr_t *undo_thr; /*!< undo query graph */
163 };
164 
165 /** A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
167  char *name; /*!< savepoint name */
168  trx_savept_t savept; /*!< the undo number corresponding to
169  the savepoint */
171  /*!< the MySQL binlog cache position
172  corresponding to this savepoint, not
173  defined if the MySQL binlogging is not
174  enabled */
176  trx_savepoints; /*!< the list of savepoints of a
177  transaction */
178 };
179 
180 #include "trx0roll.ic"
181 
182 #endif
roll_ptr_t
ib_id_t roll_ptr_t
Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR)
Definition: trx0types.h:150
trx0sys.h
undo_no_t
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:152
roll_node_t::partial
bool partial
TRUE if we want a partial rollback.
Definition: trx0roll.h:157
trx_named_savept_t::mysql_binlog_cache_pos
int64_t mysql_binlog_cache_pos
the MySQL binlog cache position corresponding to this savepoint, not defined if the MySQL binlogging ...
Definition: trx0roll.h:170
trx_rollback_to_savepoint_for_mysql
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:424
que0que.h
UT_LIST_NODE_T
#define UT_LIST_NODE_T(TYPE)
Definition: innodb_utility.h:40
dberr_t
dberr_t
Definition: db0err.h:38
trx_rollback_last_sql_stat_for_mysql
dberr_t trx_rollback_last_sql_stat_for_mysql(trx_t *trx)
Rollback the latest SQL statement for MySQL.
Definition: trx0roll.cc:279
roll_node_t
Rollback command node in a query graph.
Definition: trx0roll.h:154
mem_block_info_t
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:337
trx_savept_take
trx_savept_t trx_savept_take(trx_t *trx)
Returns a transaction savepoint taken at this point in time.
Definition: trx0roll.cc:549
roll_node_t::common
que_common_t common
node type: QUE_NODE_ROLLBACK
Definition: trx0roll.h:155
trx_savept_t
Transaction savepoint.
Definition: trx0types.h:158
ROLL_NODE_NONE
@ ROLL_NODE_NONE
Unknown state.
Definition: trx0roll.h:146
trx_recovery_rollback_thread
void trx_recovery_rollback_thread()
Rollback or clean up any incomplete transactions which were encountered in crash recovery.
Definition: trx0roll.cc:739
roll_node_t::savept
trx_savept_t savept
savepoint to which to roll back, in the case of a partial rollback
Definition: trx0roll.h:159
trx_named_savept_t::trx_savepoints
trx_savepoints
the list of savepoints of a transaction
Definition: trx0roll.h:176
trx0types.h
trx_rollback_step
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:1020
que_common_t
Definition: que0types.h:50
roll_node_t::state
enum roll_node_state state
node execution state
Definition: trx0roll.h:156
trx_rollback_or_clean_recovered
void trx_rollback_or_clean_recovered(ibool all)
Rollback or clean up any incomplete transactions which were encountered in crash recovery.
Definition: trx0roll.cc:684
ROLL_NODE_SEND
@ ROLL_NODE_SEND
about to send a rollback signal to the transaction
Definition: trx0roll.h:147
roll_node_t::undo_thr
que_thr_t * undo_thr
undo query graph
Definition: trx0roll.h:162
trx_roll_pop_top_rec_of_trx
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:911
trx_release_savepoint_for_mysql
dberr_t trx_release_savepoint_for_mysql(trx_t *trx, const char *savepoint_name)
Releases a named savepoint.
Definition: trx0roll.cc:520
mtr0mtr.h
trx_undo_rec_t
byte trx_undo_rec_t
Undo log record.
Definition: trx0types.h:177
trx0trx.h
roll_node_state
roll_node_state
Rollback node states.
Definition: trx0roll.h:145
ROLL_NODE_WAIT
@ ROLL_NODE_WAIT
rollback signal sent to the transaction, waiting for completion
Definition: trx0roll.h:149
trx_is_recv
ibool trx_is_recv(const trx_t *trx)
Determines if this transaction is rolling back an incomplete transaction in crash recovery.
Definition: trx0roll.cc:542
roll_node_create
roll_node_t * roll_node_create(mem_heap_t *heap)
Creates a rollback command node struct.
Definition: trx0roll.cc:1004
trx_named_savept_t
A savepoint set with SQL's "SAVEPOINT savepoint_id" command.
Definition: trx0roll.h:166
que_thr_t
Definition: que0que.h:246
trx_savepoint_for_mysql
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:478
trx_roll_savepoints_free
void trx_roll_savepoints_free(trx_t *trx, trx_named_savept_t *savep)
Frees savepoint structs starting from savep.
Definition: trx0roll.cc:354
trx_rollback_for_mysql
dberr_t trx_rollback_for_mysql(trx_t *trx)
Rollback a transaction used in MySQL.
Definition: trx0roll.cc:264
trx_t
Definition: trx0trx.h:780
trx_rollback_to_savepoint
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:140
trx_named_savept_t::savept
trx_savept_t savept
the undo number corresponding to the savepoint
Definition: trx0roll.h:168
trx_named_savept_t::name
char * name
savepoint name
Definition: trx0roll.h:167