1
/******************************************************
6
Created 3/26/1996 Heikki Tuuri
7
*******************************************************/
14
#include "trx0types.h"
18
/***********************************************************************
19
Determines if this transaction is rolling back an incomplete transaction
25
/* out: TRUE if trx is an incomplete
26
transaction that is being rolled back
28
const trx_t* trx); /* in: transaction */
29
/***********************************************************************
30
Returns a transaction savepoint taken at this point in time. */
36
trx_t* trx); /* in: transaction */
37
/***********************************************************************
38
Creates an undo number array. */
41
trx_undo_arr_create(void);
42
/*=====================*/
43
/***********************************************************************
44
Frees an undo number array. */
49
trx_undo_arr_t* arr); /* in: undo number array */
50
/***********************************************************************
51
Returns pointer to nth element in an undo number array. */
54
trx_undo_arr_get_nth_info(
55
/*======================*/
56
/* out: pointer to the nth element */
57
trx_undo_arr_t* arr, /* in: undo number array */
58
ulint n); /* in: position */
59
/***************************************************************************
60
Tries truncate the undo logs. */
63
trx_roll_try_truncate(
64
/*==================*/
65
trx_t* trx); /* in: transaction */
66
/************************************************************************
67
Pops the topmost record when the two undo logs of a transaction are seen
68
as a single stack of records ordered by their undo numbers. Inserts the
69
undo number of the popped undo record to the array of currently processed
70
undo numbers in the transaction. When the query thread finishes processing
71
of this undo record, it must be released with trx_undo_rec_release. */
74
trx_roll_pop_top_rec_of_trx(
75
/*========================*/
76
/* out: undo log record copied to heap, NULL
77
if none left, or if the undo number of the
78
top record would be less than the limit */
79
trx_t* trx, /* in: transaction */
80
dulint limit, /* in: least undo number we need */
81
dulint* roll_ptr,/* out: roll pointer to undo record */
82
mem_heap_t* heap); /* in: memory heap where copied */
83
/************************************************************************
84
Reserves an undo log record for a query thread to undo. This should be
85
called if the query thread gets the undo log record not using the pop
91
/* out: TRUE if succeeded */
92
trx_t* trx, /* in: transaction */
93
dulint undo_no);/* in: undo number of the record */
94
/***********************************************************************
95
Releases a reserved undo record. */
100
trx_t* trx, /* in: transaction */
101
dulint undo_no);/* in: undo number */
102
/*************************************************************************
103
Starts a rollback operation. */
108
trx_t* trx, /* in: transaction */
109
trx_sig_t* sig, /* in: signal starting the rollback */
110
que_thr_t** next_thr);/* in/out: next query thread to run;
111
if the value which is passed in is
112
a pointer to a NULL pointer, then the
113
calling function can start running
114
a new query thread */
115
/***********************************************************************
116
Rollback or clean up any incomplete transactions which were
117
encountered in crash recovery. If the transaction already was
118
committed, then we clean up a possible insert undo log. If the
119
transaction was not yet committed, then we roll it back.
120
Note: this is done in a background thread. */
123
trx_rollback_or_clean_all_recovered(
124
/*================================*/
125
/* out: a dummy parameter */
126
void* arg __attribute__((unused)));
127
/* in: a dummy parameter required by
129
/********************************************************************
130
Finishes a transaction rollback. */
133
trx_finish_rollback_off_kernel(
134
/*===========================*/
135
que_t* graph, /* in: undo graph which can now be freed */
136
trx_t* trx, /* in: transaction */
137
que_thr_t** next_thr);/* in/out: next query thread to run;
138
if the value which is passed in is
139
a pointer to a NULL pointer, then the
140
calling function can start running
141
a new query thread; if this parameter is
142
NULL, it is ignored */
143
/********************************************************************
144
Builds an undo 'query' graph for a transaction. The actual rollback is
145
performed by executing this query graph like a query subprocedure call.
146
The reply about the completion of the rollback will be sent by this
150
trx_roll_graph_build(
151
/*=================*/
152
/* out, own: the query graph */
153
trx_t* trx); /* in: trx handle */
154
/*************************************************************************
155
Creates a rollback command node struct. */
160
/* out, own: rollback node struct */
161
mem_heap_t* heap); /* in: mem heap where created */
162
/***************************************************************
163
Performs an execution step for a rollback command node in a query graph. */
168
/* out: query thread to run next, or NULL */
169
que_thr_t* thr); /* in: query thread */
170
/***********************************************************************
171
Rollback a transaction used in MySQL. */
174
trx_rollback_for_mysql(
175
/*===================*/
176
/* out: error code or DB_SUCCESS */
177
trx_t* trx); /* in: transaction handle */
178
/***********************************************************************
179
Rollback the latest SQL statement for MySQL. */
182
trx_rollback_last_sql_stat_for_mysql(
183
/*=================================*/
184
/* out: error code or DB_SUCCESS */
185
trx_t* trx); /* in: transaction handle */
186
/***********************************************************************
187
Rollback a transaction used in MySQL. */
190
trx_general_rollback_for_mysql(
191
/*===========================*/
192
/* out: error code or DB_SUCCESS */
193
trx_t* trx, /* in: transaction handle */
194
ibool partial,/* in: TRUE if partial rollback requested */
195
trx_savept_t* savept);/* in: pointer to savepoint undo number, if
196
partial rollback requested */
197
/***********************************************************************
198
Rolls back a transaction back to a named savepoint. Modifications after the
199
savepoint are undone but InnoDB does NOT release the corresponding locks
200
which are stored in memory. If a lock is 'implicit', that is, a new inserted
201
row holds a lock where the lock information is carried by the trx id stored in
202
the row, these locks are naturally released in the rollback. Savepoints which
203
were set after this savepoint are deleted. */
206
trx_rollback_to_savepoint_for_mysql(
207
/*================================*/
208
/* out: if no savepoint
209
of the name found then
211
otherwise DB_SUCCESS */
212
trx_t* trx, /* in: transaction handle */
213
const char* savepoint_name, /* in: savepoint name */
214
ib_int64_t* mysql_binlog_cache_pos);/* out: the MySQL binlog cache
215
position corresponding to this
216
savepoint; MySQL needs this
217
information to remove the
218
binlog entries of the queries
219
executed after the savepoint */
220
/***********************************************************************
221
Creates a named savepoint. If the transaction is not yet started, starts it.
222
If there is already a savepoint of the same name, this call erases that old
223
savepoint and replaces it with a new. Savepoints are deleted in a transaction
224
commit or rollback. */
227
trx_savepoint_for_mysql(
228
/*====================*/
229
/* out: always DB_SUCCESS */
230
trx_t* trx, /* in: transaction handle */
231
const char* savepoint_name, /* in: savepoint name */
232
ib_int64_t binlog_cache_pos); /* in: MySQL binlog cache
233
position corresponding to this
234
connection at the time of the
237
/***********************************************************************
238
Releases a named savepoint. Savepoints which
239
were set after this savepoint are deleted. */
242
trx_release_savepoint_for_mysql(
243
/*============================*/
244
/* out: if no savepoint
245
of the name found then
247
otherwise DB_SUCCESS */
248
trx_t* trx, /* in: transaction handle */
249
const char* savepoint_name); /* in: savepoint name */
251
/***********************************************************************
252
Frees savepoint structs. */
255
trx_roll_savepoints_free(
256
/*=====================*/
257
trx_t* trx, /* in: transaction handle */
258
trx_named_savept_t* savep); /* in: free all savepoints > this one;
259
if this is NULL, free all savepoints
262
/* A cell in the array used during a rollback and a purge */
263
struct trx_undo_inf_struct{
264
dulint trx_no; /* transaction number: not defined during
266
dulint undo_no; /* undo number of an undo record */
267
ibool in_use; /* TRUE if the cell is in use */
270
/* During a rollback and a purge, undo numbers of undo records currently being
271
processed are stored in this array */
273
struct trx_undo_arr_struct{
274
ulint n_cells; /* number of cells in the array */
275
ulint n_used; /* number of cells currently in use */
276
trx_undo_inf_t* infos; /* the array of undo infos */
277
mem_heap_t* heap; /* memory heap from which allocated */
280
/* Rollback command node in a query graph */
281
struct roll_node_struct{
282
que_common_t common; /* node type: QUE_NODE_ROLLBACK */
283
ulint state; /* node execution state */
284
ibool partial;/* TRUE if we want a partial rollback */
285
trx_savept_t savept; /* savepoint to which to roll back, in the
286
case of a partial rollback */
289
/* A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
290
struct trx_named_savept_struct{
291
char* name; /* savepoint name */
292
trx_savept_t savept; /* the undo number corresponding to
294
ib_int64_t mysql_binlog_cache_pos;
295
/* the MySQL binlog cache position
296
corresponding to this savepoint, not
297
defined if the MySQL binlogging is not
299
UT_LIST_NODE_T(trx_named_savept_t)
300
trx_savepoints; /* the list of savepoints of a
304
/* Rollback node states */
305
#define ROLL_NODE_SEND 1
306
#define ROLL_NODE_WAIT 2
309
#include "trx0roll.ic"