~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1996, 2009, Innobase Oy. 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 as published by the Free Software
7
Foundation; version 2 of the License.
8
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.
12
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
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/**************************************************//**
20
@file include/trx0roll.h
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
Transaction rollback
22
23
Created 3/26/1996 Heikki Tuuri
24
*******************************************************/
25
26
#ifndef trx0roll_h
27
#define trx0roll_h
28
29
#include "univ.i"
30
#include "trx0trx.h"
31
#include "trx0types.h"
32
#include "mtr0mtr.h"
33
#include "trx0sys.h"
34
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
35
#define trx_roll_free_all_savepoints(s) trx_roll_savepoints_free((s), NULL)
36
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
37
/*******************************************************************//**
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
38
Determines if this transaction is rolling back an incomplete transaction
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
39
in crash recovery.
40
@return TRUE if trx is an incomplete transaction that is being rolled
41
back in crash recovery */
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
42
UNIV_INTERN
43
ibool
44
trx_is_recv(
45
/*========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
46
	const trx_t*	trx);	/*!< in: transaction */
47
/*******************************************************************//**
48
Returns a transaction savepoint taken at this point in time.
49
@return	savepoint */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
50
UNIV_INTERN
51
trx_savept_t
52
trx_savept_take(
53
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
54
	trx_t*	trx);	/*!< in: transaction */
55
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
56
Creates an undo number array. */
57
UNIV_INTERN
58
trx_undo_arr_t*
59
trx_undo_arr_create(void);
60
/*=====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
61
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
62
Frees an undo number array. */
63
UNIV_INTERN
64
void
65
trx_undo_arr_free(
66
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
71
UNIV_INLINE
72
trx_undo_inf_t*
73
trx_undo_arr_get_nth_info(
74
/*======================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
75
	trx_undo_arr_t*	arr,	/*!< in: undo number array */
76
	ulint		n);	/*!< in: position */
77
/***********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
78
Tries truncate the undo logs. */
79
UNIV_INTERN
80
void
81
trx_roll_try_truncate(
82
/*==================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
83
	trx_t*	trx);	/*!< in/out: transaction */
84
/********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
92
UNIV_INTERN
93
trx_undo_rec_t*
94
trx_roll_pop_top_rec_of_trx(
95
/*========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
/********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
103
function above.
104
@return	TRUE if succeeded */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
105
UNIV_INTERN
106
ibool
107
trx_undo_rec_reserve(
108
/*=================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
109
	trx_t*		trx,	/*!< in/out: transaction */
110
	undo_no_t	undo_no);/*!< in: undo number of the record */
111
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
112
Releases a reserved undo record. */
113
UNIV_INTERN
114
void
115
trx_undo_rec_release(
116
/*=================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
117
	trx_t*		trx,	/*!< in/out: transaction */
118
	undo_no_t	undo_no);/*!< in: undo number */
119
/*********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
120
Starts a rollback operation. */
121
UNIV_INTERN
122
void
123
trx_rollback(
124
/*=========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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 */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
132
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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.
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
137
Note: this is done in a background thread.
138
@return	a dummy parameter */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
139
UNIV_INTERN
140
os_thread_ret_t
141
trx_rollback_or_clean_all_recovered(
142
/*================================*/
779.1.28 by Monty Taylor
More __attribute__ removal.
143
	void*	arg);
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
144
			/*!< in: a dummy parameter required by
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
145
			os_thread_create */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
146
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
147
Finishes a transaction rollback. */
148
UNIV_INTERN
149
void
150
trx_finish_rollback_off_kernel(
151
/*===========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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 */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
160
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
164
graph.
165
@return	own: the query graph */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
166
UNIV_INTERN
167
que_t*
168
trx_roll_graph_build(
169
/*=================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
170
	trx_t*	trx);	/*!< in: trx handle */
171
/*********************************************************************//**
172
Creates a rollback command node struct.
173
@return	own: rollback node struct */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
174
UNIV_INTERN
175
roll_node_t*
176
roll_node_create(
177
/*=============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
182
UNIV_INTERN
183
que_thr_t*
184
trx_rollback_step(
185
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
186
	que_thr_t*	thr);	/*!< in: query thread */
187
/*******************************************************************//**
188
Rollback a transaction used in MySQL.
189
@return	error code or DB_SUCCESS */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
190
UNIV_INTERN
191
int
192
trx_rollback_for_mysql(
193
/*===================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
194
	trx_t*	trx);	/*!< in: transaction handle */
195
/*******************************************************************//**
196
Rollback the latest SQL statement for MySQL.
197
@return	error code or DB_SUCCESS */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
198
UNIV_INTERN
199
int
200
trx_rollback_last_sql_stat_for_mysql(
201
/*=================================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
202
	trx_t*	trx);	/*!< in: transaction handle */
203
/*******************************************************************//**
204
Rollback a transaction used in MySQL.
205
@return	error code or DB_SUCCESS */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
206
UNIV_INTERN
207
int
208
trx_general_rollback_for_mysql(
209
/*===========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
213
				partial rollback requested */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
214
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
223
UNIV_INTERN
224
ulint
225
trx_rollback_to_savepoint_for_mysql(
226
/*================================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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 */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
235
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
239
commit or rollback.
240
@return	always DB_SUCCESS */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
241
UNIV_INTERN
242
ulint
243
trx_savepoint_for_mysql(
244
/*====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
248
						position corresponding to this
249
						connection at the time of the
250
						savepoint */
251
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
252
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
253
Releases a named savepoint. Savepoints which
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
257
UNIV_INTERN
258
ulint
259
trx_release_savepoint_for_mysql(
260
/*============================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
261
	trx_t*		trx,			/*!< in: transaction handle */
262
	const char*	savepoint_name);	/*!< in: savepoint name */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
263
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
264
/*******************************************************************//**
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
265
Frees a single savepoint struct. */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
266
UNIV_INTERN
267
void
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
268
trx_roll_savepoint_free(
269
/*=====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
270
	trx_t*			trx,	/*!< in: transaction handle */
271
	trx_named_savept_t*	savep);	/*!< in: savepoint to free */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
272
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
273
/*******************************************************************//**
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
274
Frees savepoint structs starting from savep, if savep == NULL then
275
free all savepoints. */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
276
UNIV_INTERN
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
277
void
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
278
trx_roll_savepoints_free(
279
/*=====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
280
	trx_t*			trx,	/*!< in: transaction handle */
281
	trx_named_savept_t*	savep);	/*!< in: free all savepoints > this one;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
282
					if this is NULL, free all savepoints
283
					of trx */
284
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
285
/** A cell of trx_undo_arr_struct; used during a rollback and a purge */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
286
struct	trx_undo_inf_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
287
	trx_id_t	trx_no;	/*!< transaction number: not defined during
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
288
				a rollback */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
289
	undo_no_t	undo_no;/*!< undo number of an undo record */
290
	ibool		in_use;	/*!< TRUE if the cell is in use */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
291
};
292
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
293
/** During a rollback and a purge, undo numbers of undo records currently being
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
294
processed are stored in this array */
295
296
struct trx_undo_arr_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
301
};
302
303
/** Rollback node states */
304
enum roll_node_state {
305
	ROLL_NODE_SEND = 1,	/*!< about to send a rollback signal to
306
				the transaction */
307
	ROLL_NODE_WAIT		/*!< rollback signal sent to the transaction,
308
				waiting for completion */
309
};
310
311
/** Rollback command node in a query graph */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
312
struct roll_node_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
316
					rollback */
317
	trx_savept_t		savept;	/*!< savepoint to which to
318
					roll back, in the case of a
319
					partial rollback */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
320
};
321
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
322
/** A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
323
struct trx_named_savept_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
324
	char*		name;		/*!< savepoint name */
325
	trx_savept_t	savept;		/*!< the undo number corresponding to
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
326
					the savepoint */
327
	ib_int64_t	mysql_binlog_cache_pos;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
328
					/*!< the MySQL binlog cache position
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
329
					corresponding to this savepoint, not
330
					defined if the MySQL binlogging is not
331
					enabled */
332
	UT_LIST_NODE_T(trx_named_savept_t)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
333
			trx_savepoints;	/*!< the list of savepoints of a
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
334
					transaction */
335
};
336
337
#ifndef UNIV_NONINL
338
#include "trx0roll.ic"
339
#endif
340
341
#endif