1
/*****************************************************************************
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/trx0roll.h
23
Created 3/26/1996 Heikki Tuuri
24
*******************************************************/
31
#include "trx0types.h"
35
#define trx_roll_free_all_savepoints(s) trx_roll_savepoints_free((s), NULL)
37
/*******************************************************************//**
38
Determines if this transaction is rolling back an incomplete transaction
40
@return TRUE if trx is an incomplete transaction that is being rolled
41
back in crash recovery */
46
const trx_t* trx); /*!< in: transaction */
47
/*******************************************************************//**
48
Returns a transaction savepoint taken at this point in time.
54
trx_t* trx); /*!< in: transaction */
55
/*******************************************************************//**
56
Creates an undo number array. */
59
trx_undo_arr_create(void);
60
/*=====================*/
61
/*******************************************************************//**
62
Frees an undo number array. */
67
trx_undo_arr_t* arr); /*!< in: undo number array */
68
/*******************************************************************//**
69
Returns pointer to nth element in an undo number array.
70
@return pointer to the nth element */
73
trx_undo_arr_get_nth_info(
74
/*======================*/
75
trx_undo_arr_t* arr, /*!< in: undo number array */
76
ulint n); /*!< in: position */
77
/***********************************************************************//**
78
Tries truncate the undo logs. */
81
trx_roll_try_truncate(
82
/*==================*/
83
trx_t* trx); /*!< in/out: transaction */
84
/********************************************************************//**
85
Pops the topmost record when the two undo logs of a transaction are seen
86
as a single stack of records ordered by their undo numbers. Inserts the
87
undo number of the popped undo record to the array of currently processed
88
undo numbers in the transaction. When the query thread finishes processing
89
of this undo record, it must be released with trx_undo_rec_release.
90
@return undo log record copied to heap, NULL if none left, or if the
91
undo number of the top record would be less than the limit */
94
trx_roll_pop_top_rec_of_trx(
95
/*========================*/
96
trx_t* trx, /*!< in: transaction */
97
undo_no_t limit, /*!< in: least undo number we need */
98
roll_ptr_t* roll_ptr,/*!< out: roll pointer to undo record */
99
mem_heap_t* heap); /*!< in: memory heap where copied */
100
/********************************************************************//**
101
Reserves an undo log record for a query thread to undo. This should be
102
called if the query thread gets the undo log record not using the pop
104
@return TRUE if succeeded */
107
trx_undo_rec_reserve(
108
/*=================*/
109
trx_t* trx, /*!< in/out: transaction */
110
undo_no_t undo_no);/*!< in: undo number of the record */
111
/*******************************************************************//**
112
Releases a reserved undo record. */
115
trx_undo_rec_release(
116
/*=================*/
117
trx_t* trx, /*!< in/out: transaction */
118
undo_no_t undo_no);/*!< in: undo number */
119
/*********************************************************************//**
120
Starts a rollback operation. */
125
trx_t* trx, /*!< in: transaction */
126
trx_sig_t* sig, /*!< in: signal starting the rollback */
127
que_thr_t** next_thr);/*!< in/out: next query thread to run;
128
if the value which is passed in is
129
a pointer to a NULL pointer, then the
130
calling function can start running
131
a new query thread */
132
/*******************************************************************//**
133
Rollback or clean up any incomplete transactions which were
134
encountered in crash recovery. If the transaction already was
135
committed, then we clean up a possible insert undo log. If the
136
transaction was not yet committed, then we roll it back.
137
Note: this is done in a background thread.
138
@return a dummy parameter */
141
trx_rollback_or_clean_all_recovered(
142
/*================================*/
144
/*!< in: a dummy parameter required by
146
/****************************************************************//**
147
Finishes a transaction rollback. */
150
trx_finish_rollback_off_kernel(
151
/*===========================*/
152
que_t* graph, /*!< in: undo graph which can now be freed */
153
trx_t* trx, /*!< in: transaction */
154
que_thr_t** next_thr);/*!< in/out: next query thread to run;
155
if the value which is passed in is
156
a pointer to a NULL pointer, then the
157
calling function can start running
158
a new query thread; if this parameter is
159
NULL, it is ignored */
160
/****************************************************************//**
161
Builds an undo 'query' graph for a transaction. The actual rollback is
162
performed by executing this query graph like a query subprocedure call.
163
The reply about the completion of the rollback will be sent by this
165
@return own: the query graph */
168
trx_roll_graph_build(
169
/*=================*/
170
trx_t* trx); /*!< in: trx handle */
171
/*********************************************************************//**
172
Creates a rollback command node struct.
173
@return own: rollback node struct */
178
mem_heap_t* heap); /*!< in: mem heap where created */
179
/***********************************************************//**
180
Performs an execution step for a rollback command node in a query graph.
181
@return query thread to run next, or NULL */
186
que_thr_t* thr); /*!< in: query thread */
187
/*******************************************************************//**
188
Rollback a transaction used in MySQL.
189
@return error code or DB_SUCCESS */
192
trx_rollback_for_mysql(
193
/*===================*/
194
trx_t* trx); /*!< in: transaction handle */
195
/*******************************************************************//**
196
Rollback the latest SQL statement for MySQL.
197
@return error code or DB_SUCCESS */
200
trx_rollback_last_sql_stat_for_mysql(
201
/*=================================*/
202
trx_t* trx); /*!< in: transaction handle */
203
/*******************************************************************//**
204
Rollback a transaction used in MySQL.
205
@return error code or DB_SUCCESS */
208
trx_general_rollback_for_mysql(
209
/*===========================*/
210
trx_t* trx, /*!< in: transaction handle */
211
ibool partial,/*!< in: TRUE if partial rollback requested */
212
trx_savept_t* savept);/*!< in: pointer to savepoint undo number, if
213
partial rollback requested */
214
/*******************************************************************//**
215
Rolls back a transaction back to a named savepoint. Modifications after the
216
savepoint are undone but InnoDB does NOT release the corresponding locks
217
which are stored in memory. If a lock is 'implicit', that is, a new inserted
218
row holds a lock where the lock information is carried by the trx id stored in
219
the row, these locks are naturally released in the rollback. Savepoints which
220
were set after this savepoint are deleted.
221
@return if no savepoint of the name found then DB_NO_SAVEPOINT,
222
otherwise DB_SUCCESS */
225
trx_rollback_to_savepoint_for_mysql(
226
/*================================*/
227
trx_t* trx, /*!< in: transaction handle */
228
const char* savepoint_name, /*!< in: savepoint name */
229
ib_int64_t* mysql_binlog_cache_pos);/*!< out: the MySQL binlog cache
230
position corresponding to this
231
savepoint; MySQL needs this
232
information to remove the
233
binlog entries of the queries
234
executed after the savepoint */
235
/*******************************************************************//**
236
Creates a named savepoint. If the transaction is not yet started, starts it.
237
If there is already a savepoint of the same name, this call erases that old
238
savepoint and replaces it with a new. Savepoints are deleted in a transaction
240
@return always DB_SUCCESS */
243
trx_savepoint_for_mysql(
244
/*====================*/
245
trx_t* trx, /*!< in: transaction handle */
246
const char* savepoint_name, /*!< in: savepoint name */
247
ib_int64_t binlog_cache_pos); /*!< in: MySQL binlog cache
248
position corresponding to this
249
connection at the time of the
252
/*******************************************************************//**
253
Releases a named savepoint. Savepoints which
254
were set after this savepoint are deleted.
255
@return if no savepoint of the name found then DB_NO_SAVEPOINT,
256
otherwise DB_SUCCESS */
259
trx_release_savepoint_for_mysql(
260
/*============================*/
261
trx_t* trx, /*!< in: transaction handle */
262
const char* savepoint_name); /*!< in: savepoint name */
264
/*******************************************************************//**
265
Frees a single savepoint struct. */
268
trx_roll_savepoint_free(
269
/*=====================*/
270
trx_t* trx, /*!< in: transaction handle */
271
trx_named_savept_t* savep); /*!< in: savepoint to free */
273
/*******************************************************************//**
274
Frees savepoint structs starting from savep, if savep == NULL then
275
free all savepoints. */
278
trx_roll_savepoints_free(
279
/*=====================*/
280
trx_t* trx, /*!< in: transaction handle */
281
trx_named_savept_t* savep); /*!< in: free all savepoints > this one;
282
if this is NULL, free all savepoints
285
/** A cell of trx_undo_arr_struct; used during a rollback and a purge */
286
struct trx_undo_inf_struct{
287
trx_id_t trx_no; /*!< transaction number: not defined during
289
undo_no_t undo_no;/*!< undo number of an undo record */
290
ibool in_use; /*!< TRUE if the cell is in use */
293
/** During a rollback and a purge, undo numbers of undo records currently being
294
processed are stored in this array */
296
struct trx_undo_arr_struct{
297
ulint n_cells; /*!< number of cells in the array */
298
ulint n_used; /*!< number of cells currently in use */
299
trx_undo_inf_t* infos; /*!< the array of undo infos */
300
mem_heap_t* heap; /*!< memory heap from which allocated */
303
/** Rollback node states */
304
enum roll_node_state {
305
ROLL_NODE_SEND = 1, /*!< about to send a rollback signal to
307
ROLL_NODE_WAIT /*!< rollback signal sent to the transaction,
308
waiting for completion */
311
/** Rollback command node in a query graph */
312
struct roll_node_struct{
313
que_common_t common; /*!< node type: QUE_NODE_ROLLBACK */
314
enum roll_node_state state; /*!< node execution state */
315
ibool partial;/*!< TRUE if we want a partial
317
trx_savept_t savept; /*!< savepoint to which to
318
roll back, in the case of a
322
/** A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
323
struct trx_named_savept_struct{
324
char* name; /*!< savepoint name */
325
trx_savept_t savept; /*!< the undo number corresponding to
327
ib_int64_t mysql_binlog_cache_pos;
328
/*!< the MySQL binlog cache position
329
corresponding to this savepoint, not
330
defined if the MySQL binlogging is not
332
UT_LIST_NODE_T(trx_named_savept_t)
333
trx_savepoints; /*!< the list of savepoints of a
338
#include "trx0roll.ic"