~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/trx0roll.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
19
 
/**************************************************//**
20
 
@file include/trx0roll.h
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
 
 
35
 
#define trx_roll_free_all_savepoints(s) trx_roll_savepoints_free((s), NULL)
36
 
 
37
 
/*******************************************************************//**
38
 
Determines if this transaction is rolling back an incomplete transaction
39
 
in crash recovery.
40
 
@return TRUE if trx is an incomplete transaction that is being rolled
41
 
back in crash recovery */
42
 
UNIV_INTERN
43
 
ibool
44
 
trx_is_recv(
45
 
/*========*/
46
 
        const trx_t*    trx);   /*!< in: transaction */
47
 
/*******************************************************************//**
48
 
Returns a transaction savepoint taken at this point in time.
49
 
@return savepoint */
50
 
UNIV_INTERN
51
 
trx_savept_t
52
 
trx_savept_take(
53
 
/*============*/
54
 
        trx_t*  trx);   /*!< in: transaction */
55
 
/*******************************************************************//**
56
 
Creates an undo number array. */
57
 
UNIV_INTERN
58
 
trx_undo_arr_t*
59
 
trx_undo_arr_create(void);
60
 
/*=====================*/
61
 
/*******************************************************************//**
62
 
Frees an undo number array. */
63
 
UNIV_INTERN
64
 
void
65
 
trx_undo_arr_free(
66
 
/*==============*/
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 */
71
 
UNIV_INLINE
72
 
trx_undo_inf_t*
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. */
79
 
UNIV_INTERN
80
 
void
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 */
92
 
UNIV_INTERN
93
 
trx_undo_rec_t*
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
103
 
function above.
104
 
@return TRUE if succeeded */
105
 
UNIV_INTERN
106
 
ibool
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. */
113
 
UNIV_INTERN
114
 
void
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. */
121
 
UNIV_INTERN
122
 
void
123
 
trx_rollback(
124
 
/*=========*/
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 */
139
 
UNIV_INTERN
140
 
os_thread_ret_t
141
 
trx_rollback_or_clean_all_recovered(
142
 
/*================================*/
143
 
        void*   arg);
144
 
                        /*!< in: a dummy parameter required by
145
 
                        os_thread_create */
146
 
/****************************************************************//**
147
 
Finishes a transaction rollback. */
148
 
UNIV_INTERN
149
 
void
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
164
 
graph.
165
 
@return own: the query graph */
166
 
UNIV_INTERN
167
 
que_t*
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 */
174
 
UNIV_INTERN
175
 
roll_node_t*
176
 
roll_node_create(
177
 
/*=============*/
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 */
182
 
UNIV_INTERN
183
 
que_thr_t*
184
 
trx_rollback_step(
185
 
/*==============*/
186
 
        que_thr_t*      thr);   /*!< in: query thread */
187
 
/*******************************************************************//**
188
 
Rollback a transaction used in MySQL.
189
 
@return error code or DB_SUCCESS */
190
 
UNIV_INTERN
191
 
int
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 */
198
 
UNIV_INTERN
199
 
int
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 */
206
 
UNIV_INTERN
207
 
int
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 */
223
 
UNIV_INTERN
224
 
ulint
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
239
 
commit or rollback.
240
 
@return always DB_SUCCESS */
241
 
UNIV_INTERN
242
 
ulint
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
250
 
                                                savepoint */
251
 
 
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 */
257
 
UNIV_INTERN
258
 
ulint
259
 
trx_release_savepoint_for_mysql(
260
 
/*============================*/
261
 
        trx_t*          trx,                    /*!< in: transaction handle */
262
 
        const char*     savepoint_name);        /*!< in: savepoint name */
263
 
 
264
 
/*******************************************************************//**
265
 
Frees a single savepoint struct. */
266
 
UNIV_INTERN
267
 
void
268
 
trx_roll_savepoint_free(
269
 
/*=====================*/
270
 
        trx_t*                  trx,    /*!< in: transaction handle */
271
 
        trx_named_savept_t*     savep); /*!< in: savepoint to free */
272
 
 
273
 
/*******************************************************************//**
274
 
Frees savepoint structs starting from savep, if savep == NULL then
275
 
free all savepoints. */
276
 
UNIV_INTERN
277
 
void
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
283
 
                                        of trx */
284
 
 
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
288
 
                                a rollback */
289
 
        undo_no_t       undo_no;/*!< undo number of an undo record */
290
 
        ibool           in_use; /*!< TRUE if the cell is in use */
291
 
};
292
 
 
293
 
/** During a rollback and a purge, undo numbers of undo records currently being
294
 
processed are stored in this array */
295
 
 
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 */
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 */
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
316
 
                                        rollback */
317
 
        trx_savept_t            savept; /*!< savepoint to which to
318
 
                                        roll back, in the case of a
319
 
                                        partial rollback */
320
 
};
321
 
 
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
326
 
                                        the savepoint */
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
331
 
                                        enabled */
332
 
        UT_LIST_NODE_T(trx_named_savept_t)
333
 
                        trx_savepoints; /*!< the list of savepoints of a
334
 
                                        transaction */
335
 
};
336
 
 
337
 
#ifndef UNIV_NONINL
338
 
#include "trx0roll.ic"
339
 
#endif
340
 
 
341
 
#endif