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
/******************************************************
22
Created 3/26/1996 Heikki Tuuri
23
*******************************************************/
30
#include "trx0types.h"
34
#define trx_roll_free_all_savepoints(s) trx_roll_savepoints_free((s), NULL)
36
/***********************************************************************
37
Determines if this transaction is rolling back an incomplete transaction
43
/* out: TRUE if trx is an incomplete
44
transaction that is being rolled back
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. */
72
trx_undo_arr_get_nth_info(
73
/*======================*/
74
/* out: pointer to the nth element */
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: 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. */
92
trx_roll_pop_top_rec_of_trx(
93
/*========================*/
94
/* out: undo log record copied to heap, NULL
95
if none left, or if the undo number of the
96
top record would be less than the limit */
97
trx_t* trx, /* in: transaction */
98
dulint limit, /* in: least undo number we need */
99
dulint* roll_ptr,/* out: roll pointer to undo record */
100
mem_heap_t* heap); /* in: memory heap where copied */
101
/************************************************************************
102
Reserves an undo log record for a query thread to undo. This should be
103
called if the query thread gets the undo log record not using the pop
107
trx_undo_rec_reserve(
108
/*=================*/
109
/* out: TRUE if succeeded */
110
trx_t* trx, /* in: transaction */
111
dulint undo_no);/* in: undo number of the record */
112
/***********************************************************************
113
Releases a reserved undo record. */
116
trx_undo_rec_release(
117
/*=================*/
118
trx_t* trx, /* in: transaction */
119
dulint undo_no);/* in: undo number */
120
/*************************************************************************
121
Starts a rollback operation. */
126
trx_t* trx, /* in: transaction */
127
trx_sig_t* sig, /* in: signal starting the rollback */
128
que_thr_t** next_thr);/* in/out: next query thread to run;
129
if the value which is passed in is
130
a pointer to a NULL pointer, then the
131
calling function can start running
132
a new query thread */
133
/***********************************************************************
134
Rollback or clean up any incomplete transactions which were
135
encountered in crash recovery. If the transaction already was
136
committed, then we clean up a possible insert undo log. If the
137
transaction was not yet committed, then we roll it back.
138
Note: this is done in a background thread. */
141
trx_rollback_or_clean_all_recovered(
142
/*================================*/
143
/* out: a dummy parameter */
144
void* arg __attribute__((unused)));
145
/* in: a dummy parameter required by
147
/********************************************************************
148
Finishes a transaction rollback. */
151
trx_finish_rollback_off_kernel(
152
/*===========================*/
153
que_t* graph, /* in: undo graph which can now be freed */
154
trx_t* trx, /* in: transaction */
155
que_thr_t** next_thr);/* in/out: next query thread to run;
156
if the value which is passed in is
157
a pointer to a NULL pointer, then the
158
calling function can start running
159
a new query thread; if this parameter is
160
NULL, it is ignored */
161
/********************************************************************
162
Builds an undo 'query' graph for a transaction. The actual rollback is
163
performed by executing this query graph like a query subprocedure call.
164
The reply about the completion of the rollback will be sent by this
168
trx_roll_graph_build(
169
/*=================*/
170
/* out, own: the query graph */
171
trx_t* trx); /* in: trx handle */
172
/*************************************************************************
173
Creates a rollback command node struct. */
178
/* out, own: rollback node struct */
179
mem_heap_t* heap); /* in: mem heap where created */
180
/***************************************************************
181
Performs an execution step for a rollback command node in a query graph. */
186
/* out: query thread to run next, or NULL */
187
que_thr_t* thr); /* in: query thread */
188
/***********************************************************************
189
Rollback a user transaction. */
192
trx_general_rollback(
193
/*=================*/
194
/* out: error code or DB_SUCCESS */
195
trx_t* trx, /* in: transaction handle */
196
ibool partial,/* in: TRUE if partial rollback requested */
197
trx_savept_t* savept);/* in: pointer to savepoint undo number, if
198
partial rollback requested */
200
/***********************************************************************
201
Frees savepoint structs starting from savep, if savep == NULL then
202
free all savepoints. */
205
trx_roll_savepoints_free(
206
/*=====================*/
207
trx_t* trx, /* in: transaction handle */
208
trx_named_savept_t* savep); /* in: free all savepoints > this one;
209
if this is NULL, free all savepoints
212
/* A cell in the array used during a rollback and a purge */
213
struct trx_undo_inf_struct{
214
dulint trx_no; /* transaction number: not defined during
216
dulint undo_no; /* undo number of an undo record */
217
ibool in_use; /* TRUE if the cell is in use */
220
/* During a rollback and a purge, undo numbers of undo records currently being
221
processed are stored in this array */
223
struct trx_undo_arr_struct{
224
ulint n_cells; /* number of cells in the array */
225
ulint n_used; /* number of cells currently in use */
226
trx_undo_inf_t* infos; /* the array of undo infos */
227
mem_heap_t* heap; /* memory heap from which allocated */
230
/* Rollback command node in a query graph */
231
struct roll_node_struct{
232
que_common_t common; /* node type: QUE_NODE_ROLLBACK */
233
ulint state; /* node execution state */
234
ibool partial;/* TRUE if we want a partial rollback */
235
trx_savept_t savept; /* savepoint to which to roll back, in the
236
case of a partial rollback */
239
/* A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
240
struct trx_named_savept_struct{
241
void* name; /* savepoint name, it can be any
242
arbitrary set of characters. Note:
243
When allocating memory for trx_named
244
structure allocate an additional
245
name_len bytes and set the value of
246
name to point to the first byte past
247
an instance of this structure */
248
ulint name_len; /* length of name in bytes */
249
trx_savept_t savept; /* the undo number corresponding to
251
UT_LIST_NODE_T(trx_named_savept_t)
252
trx_savepoints; /* the list of savepoints of a
256
/* Rollback node states */
257
#define ROLL_NODE_SEND 1
258
#define ROLL_NODE_WAIT 2
261
#include "trx0roll.ic"