1
/******************************************************
6
Created 3/26/1996 Heikki Tuuri
7
*******************************************************/
14
#include "trx0types.h"
18
#define trx_roll_free_all_savepoints(s) trx_roll_savepoints_free((s), NULL)
20
/***********************************************************************
21
Returns a transaction savepoint taken at this point in time. */
27
trx_t* trx); /* in: transaction */
28
/***********************************************************************
29
Creates an undo number array. */
32
trx_undo_arr_create(void);
33
/*=====================*/
34
/***********************************************************************
35
Frees an undo number array. */
40
trx_undo_arr_t* arr); /* in: undo number array */
41
/***********************************************************************
42
Returns pointer to nth element in an undo number array. */
45
trx_undo_arr_get_nth_info(
46
/*======================*/
47
/* out: pointer to the nth element */
48
trx_undo_arr_t* arr, /* in: undo number array */
49
ulint n); /* in: position */
50
/***************************************************************************
51
Tries truncate the undo logs. */
54
trx_roll_try_truncate(
55
/*==================*/
56
trx_t* trx); /* in: transaction */
57
/************************************************************************
58
Pops the topmost record when the two undo logs of a transaction are seen
59
as a single stack of records ordered by their undo numbers. Inserts the
60
undo number of the popped undo record to the array of currently processed
61
undo numbers in the transaction. When the query thread finishes processing
62
of this undo record, it must be released with trx_undo_rec_release. */
65
trx_roll_pop_top_rec_of_trx(
66
/*========================*/
67
/* out: undo log record copied to heap, NULL
68
if none left, or if the undo number of the
69
top record would be less than the limit */
70
trx_t* trx, /* in: transaction */
71
dulint limit, /* in: least undo number we need */
72
dulint* roll_ptr,/* out: roll pointer to undo record */
73
mem_heap_t* heap); /* in: memory heap where copied */
74
/************************************************************************
75
Reserves an undo log record for a query thread to undo. This should be
76
called if the query thread gets the undo log record not using the pop
82
/* out: TRUE if succeeded */
83
trx_t* trx, /* in: transaction */
84
dulint undo_no);/* in: undo number of the record */
85
/***********************************************************************
86
Releases a reserved undo record. */
91
trx_t* trx, /* in: transaction */
92
dulint undo_no);/* in: undo number */
93
/*************************************************************************
94
Starts a rollback operation. */
99
trx_t* trx, /* in: transaction */
100
trx_sig_t* sig, /* in: signal starting the rollback */
101
que_thr_t** next_thr);/* in/out: next query thread to run;
102
if the value which is passed in is
103
a pointer to a NULL pointer, then the
104
calling function can start running
105
a new query thread */
106
/***********************************************************************
107
Rollback or clean up transactions which have no user session. If the
108
transaction already was committed, then we clean up a possible insert
109
undo log. If the transaction was not yet committed, then we roll it back.
110
Note: this is done in a background thread. */
113
trx_rollback_or_clean_all_without_sess(
114
/*===================================*/
115
/* out: a dummy parameter */
116
void* arg __attribute__((unused)));
117
/* in: a dummy parameter required by
119
/********************************************************************
120
Finishes a transaction rollback. */
123
trx_finish_rollback_off_kernel(
124
/*===========================*/
125
que_t* graph, /* in: undo graph which can now be freed */
126
trx_t* trx, /* in: transaction */
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; if this parameter is
132
NULL, it is ignored */
133
/********************************************************************
134
Builds an undo 'query' graph for a transaction. The actual rollback is
135
performed by executing this query graph like a query subprocedure call.
136
The reply about the completion of the rollback will be sent by this
140
trx_roll_graph_build(
141
/*=================*/
142
/* out, own: the query graph */
143
trx_t* trx); /* in: trx handle */
144
/*************************************************************************
145
Creates a rollback command node struct. */
150
/* out, own: rollback node struct */
151
mem_heap_t* heap); /* in: mem heap where created */
152
/***************************************************************
153
Performs an execution step for a rollback command node in a query graph. */
158
/* out: query thread to run next, or NULL */
159
que_thr_t* thr); /* in: query thread */
160
/***********************************************************************
161
Rollback a transaction used in MySQL. */
164
trx_rollback_for_mysql(
165
/*===================*/
166
/* out: error code or DB_SUCCESS */
167
trx_t* trx); /* in: transaction handle */
168
/***********************************************************************
169
Rollback the latest SQL statement for MySQL. */
172
trx_rollback_last_sql_stat_for_mysql(
173
/*=================================*/
174
/* out: error code or DB_SUCCESS */
175
trx_t* trx); /* in: transaction handle */
176
/***********************************************************************
177
Rollback a transaction used in MySQL. */
180
trx_general_rollback_for_mysql(
181
/*===========================*/
182
/* out: error code or DB_SUCCESS */
183
trx_t* trx, /* in: transaction handle */
184
ibool partial,/* in: TRUE if partial rollback requested */
185
trx_savept_t* savept);/* in: pointer to savepoint undo number, if
186
partial rollback requested */
187
/***********************************************************************
188
Rolls back a transaction back to a named savepoint. Modifications after the
189
savepoint are undone but InnoDB does NOT release the corresponding locks
190
which are stored in memory. If a lock is 'implicit', that is, a new inserted
191
row holds a lock where the lock information is carried by the trx id stored in
192
the row, these locks are naturally released in the rollback. Savepoints which
193
were set after this savepoint are deleted. */
196
trx_rollback_to_savepoint_for_mysql(
197
/*================================*/
198
/* out: if no savepoint
199
of the name found then
201
otherwise DB_SUCCESS */
202
trx_t* trx, /* in: transaction handle */
203
const char* savepoint_name, /* in: savepoint name */
204
ib_longlong* mysql_binlog_cache_pos);/* out: the MySQL binlog cache
205
position corresponding to this
206
savepoint; MySQL needs this
207
information to remove the
208
binlog entries of the queries
209
executed after the savepoint */
210
/***********************************************************************
211
Creates a named savepoint. If the transaction is not yet started, starts it.
212
If there is already a savepoint of the same name, this call erases that old
213
savepoint and replaces it with a new. Savepoints are deleted in a transaction
214
commit or rollback. */
217
trx_savepoint_for_mysql(
218
/*====================*/
219
/* out: always DB_SUCCESS */
220
trx_t* trx, /* in: transaction handle */
221
const char* savepoint_name, /* in: savepoint name */
222
ib_longlong binlog_cache_pos); /* in: MySQL binlog cache
223
position corresponding to this
224
connection at the time of the
227
/***********************************************************************
228
Releases a named savepoint. Savepoints which
229
were set after this savepoint are deleted. */
232
trx_release_savepoint_for_mysql(
233
/*============================*/
234
/* out: if no savepoint
235
of the name found then
237
otherwise DB_SUCCESS */
238
trx_t* trx, /* in: transaction handle */
239
const char* savepoint_name); /* in: savepoint name */
241
/***********************************************************************
242
Frees a single savepoint struct. */
245
trx_roll_savepoint_free(
246
/*=====================*/
247
trx_t* trx, /* in: transaction handle */
248
trx_named_savept_t* savep); /* in: savepoint to free */
250
/***********************************************************************
251
Frees savepoint structs starting from savep, if savep == NULL then
252
free all savepoints. */
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
extern sess_t* trx_dummy_sess;
264
/* A cell in the array used during a rollback and a purge */
265
struct trx_undo_inf_struct{
266
dulint trx_no; /* transaction number: not defined during
268
dulint undo_no; /* undo number of an undo record */
269
ibool in_use; /* TRUE if the cell is in use */
272
/* During a rollback and a purge, undo numbers of undo records currently being
273
processed are stored in this array */
275
struct trx_undo_arr_struct{
276
ulint n_cells; /* number of cells in the array */
277
ulint n_used; /* number of cells currently in use */
278
trx_undo_inf_t* infos; /* the array of undo infos */
279
mem_heap_t* heap; /* memory heap from which allocated */
282
/* Rollback command node in a query graph */
283
struct roll_node_struct{
284
que_common_t common; /* node type: QUE_NODE_ROLLBACK */
285
ulint state; /* node execution state */
286
ibool partial;/* TRUE if we want a partial rollback */
287
trx_savept_t savept; /* savepoint to which to roll back, in the
288
case of a partial rollback */
291
/* A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
292
struct trx_named_savept_struct{
293
char* name; /* savepoint name */
294
trx_savept_t savept; /* the undo number corresponding to
296
ib_longlong mysql_binlog_cache_pos;
297
/* the MySQL binlog cache position
298
corresponding to this savepoint, not
299
defined if the MySQL binlogging is not
301
UT_LIST_NODE_T(trx_named_savept_t)
302
trx_savepoints; /* the list of savepoints of a
306
/* Rollback node states */
307
#define ROLL_NODE_SEND 1
308
#define ROLL_NODE_WAIT 2
311
#include "trx0roll.ic"