~jaypipes/drizzle/new-test-runner

« back to all changes in this revision

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

  • Committer: Jay Pipes
  • Date: 2008-12-11 17:52:34 UTC
  • mfrom: (482.16.152 testable)
  • Revision ID: jpipes@serialcoder-20081211175234-uqsfvmgxejvmellq
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Transaction rollback
 
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
 
6
Created 3/26/1996 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#ifndef trx0roll_h
 
10
#define trx0roll_h
 
11
 
 
12
#include "univ.i"
 
13
#include "trx0trx.h"
 
14
#include "trx0types.h"
 
15
#include "mtr0mtr.h"
 
16
#include "trx0sys.h"
 
17
 
 
18
/***********************************************************************
 
19
Determines if this transaction is rolling back an incomplete transaction
 
20
in crash recovery. */
 
21
UNIV_INTERN
 
22
ibool
 
23
trx_is_recv(
 
24
/*========*/
 
25
                                /* out: TRUE if trx is an incomplete
 
26
                                transaction that is being rolled back
 
27
                                in crash recovery */
 
28
        const trx_t*    trx);   /* in: transaction */
 
29
/***********************************************************************
 
30
Returns a transaction savepoint taken at this point in time. */
 
31
UNIV_INTERN
 
32
trx_savept_t
 
33
trx_savept_take(
 
34
/*============*/
 
35
                        /* out: savepoint */
 
36
        trx_t*  trx);   /* in: transaction */
 
37
/***********************************************************************
 
38
Creates an undo number array. */
 
39
UNIV_INTERN
 
40
trx_undo_arr_t*
 
41
trx_undo_arr_create(void);
 
42
/*=====================*/
 
43
/***********************************************************************
 
44
Frees an undo number array. */
 
45
UNIV_INTERN
 
46
void
 
47
trx_undo_arr_free(
 
48
/*==============*/
 
49
        trx_undo_arr_t* arr);   /* in: undo number array */
 
50
/***********************************************************************
 
51
Returns pointer to nth element in an undo number array. */
 
52
UNIV_INLINE
 
53
trx_undo_inf_t*
 
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. */
 
61
UNIV_INTERN
 
62
void
 
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. */
 
72
UNIV_INTERN
 
73
trx_undo_rec_t*
 
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
 
86
function above. */
 
87
UNIV_INTERN
 
88
ibool
 
89
trx_undo_rec_reserve(
 
90
/*=================*/
 
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. */
 
96
UNIV_INTERN
 
97
void
 
98
trx_undo_rec_release(
 
99
/*=================*/
 
100
        trx_t*  trx,    /* in: transaction */
 
101
        dulint  undo_no);/* in: undo number */
 
102
/*************************************************************************
 
103
Starts a rollback operation. */
 
104
UNIV_INTERN
 
105
void
 
106
trx_rollback(
 
107
/*=========*/
 
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. */
 
121
UNIV_INTERN
 
122
os_thread_ret_t
 
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
 
128
                        os_thread_create */
 
129
/********************************************************************
 
130
Finishes a transaction rollback. */
 
131
UNIV_INTERN
 
132
void
 
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
 
147
graph. */
 
148
UNIV_INTERN
 
149
que_t*
 
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. */
 
156
UNIV_INTERN
 
157
roll_node_t*
 
158
roll_node_create(
 
159
/*=============*/
 
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. */
 
164
UNIV_INTERN
 
165
que_thr_t*
 
166
trx_rollback_step(
 
167
/*==============*/
 
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. */
 
172
UNIV_INTERN
 
173
int
 
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. */
 
180
UNIV_INTERN
 
181
int
 
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. */
 
188
UNIV_INTERN
 
189
int
 
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. */
 
204
UNIV_INTERN
 
205
ulint
 
206
trx_rollback_to_savepoint_for_mysql(
 
207
/*================================*/
 
208
                                                /* out: if no savepoint
 
209
                                                of the name found then
 
210
                                                DB_NO_SAVEPOINT,
 
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. */
 
225
UNIV_INTERN
 
226
ulint
 
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
 
235
                                                savepoint */
 
236
 
 
237
/***********************************************************************
 
238
Releases a named savepoint. Savepoints which
 
239
were set after this savepoint are deleted. */
 
240
UNIV_INTERN
 
241
ulint
 
242
trx_release_savepoint_for_mysql(
 
243
/*============================*/
 
244
                                                /* out: if no savepoint
 
245
                                                of the name found then
 
246
                                                DB_NO_SAVEPOINT,
 
247
                                                otherwise DB_SUCCESS */
 
248
        trx_t*          trx,                    /* in: transaction handle */
 
249
        const char*     savepoint_name);        /* in: savepoint name */
 
250
 
 
251
/***********************************************************************
 
252
Frees savepoint structs. */
 
253
UNIV_INTERN
 
254
void
 
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
 
260
                                        of trx */
 
261
 
 
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
 
265
                                a rollback */
 
266
        dulint  undo_no;        /* undo number of an undo record */
 
267
        ibool   in_use;         /* TRUE if the cell is in use */
 
268
};
 
269
 
 
270
/* During a rollback and a purge, undo numbers of undo records currently being
 
271
processed are stored in this array */
 
272
 
 
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 */
 
278
};
 
279
 
 
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 */
 
287
};
 
288
 
 
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
 
293
                                        the savepoint */
 
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
 
298
                                        enabled */
 
299
        UT_LIST_NODE_T(trx_named_savept_t)
 
300
                        trx_savepoints; /* the list of savepoints of a
 
301
                                        transaction */
 
302
};
 
303
 
 
304
/* Rollback node states */
 
305
#define ROLL_NODE_SEND  1
 
306
#define ROLL_NODE_WAIT  2
 
307
 
 
308
#ifndef UNIV_NONINL
 
309
#include "trx0roll.ic"
 
310
#endif
 
311
 
 
312
#endif