~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

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
#define trx_roll_free_all_savepoints(s) trx_roll_savepoints_free((s), NULL)
 
19
 
 
20
/***********************************************************************
 
21
Returns a transaction savepoint taken at this point in time. */
 
22
 
 
23
trx_savept_t
 
24
trx_savept_take(
 
25
/*============*/
 
26
                        /* out: savepoint */
 
27
        trx_t*  trx);   /* in: transaction */
 
28
/***********************************************************************
 
29
Creates an undo number array. */
 
30
 
 
31
trx_undo_arr_t*
 
32
trx_undo_arr_create(void);
 
33
/*=====================*/
 
34
/***********************************************************************
 
35
Frees an undo number array. */
 
36
 
 
37
void
 
38
trx_undo_arr_free(
 
39
/*==============*/
 
40
        trx_undo_arr_t* arr);   /* in: undo number array */
 
41
/***********************************************************************
 
42
Returns pointer to nth element in an undo number array. */
 
43
UNIV_INLINE
 
44
trx_undo_inf_t*
 
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. */
 
52
 
 
53
void
 
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. */
 
63
 
 
64
trx_undo_rec_t*
 
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
 
77
function above. */
 
78
 
 
79
ibool
 
80
trx_undo_rec_reserve(
 
81
/*=================*/
 
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. */
 
87
 
 
88
void
 
89
trx_undo_rec_release(
 
90
/*=================*/
 
91
        trx_t*  trx,    /* in: transaction */
 
92
        dulint  undo_no);/* in: undo number */
 
93
/*************************************************************************
 
94
Starts a rollback operation. */
 
95
 
 
96
void
 
97
trx_rollback(
 
98
/*=========*/
 
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. */
 
111
 
 
112
os_thread_ret_t
 
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
 
118
                        os_thread_create */
 
119
/********************************************************************
 
120
Finishes a transaction rollback. */
 
121
 
 
122
void
 
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
 
137
graph. */
 
138
 
 
139
que_t*
 
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. */
 
146
 
 
147
roll_node_t*
 
148
roll_node_create(
 
149
/*=============*/
 
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. */
 
154
 
 
155
que_thr_t*
 
156
trx_rollback_step(
 
157
/*==============*/
 
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. */
 
162
 
 
163
int
 
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. */
 
170
 
 
171
int
 
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. */
 
178
 
 
179
int
 
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. */
 
194
 
 
195
ulint
 
196
trx_rollback_to_savepoint_for_mysql(
 
197
/*================================*/
 
198
                                                /* out: if no savepoint
 
199
                                                of the name found then
 
200
                                                DB_NO_SAVEPOINT,
 
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. */
 
215
 
 
216
ulint
 
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
 
225
                                                savepoint */
 
226
 
 
227
/***********************************************************************
 
228
Releases a named savepoint. Savepoints which
 
229
were set after this savepoint are deleted. */
 
230
 
 
231
ulint
 
232
trx_release_savepoint_for_mysql(
 
233
/*============================*/
 
234
                                                /* out: if no savepoint
 
235
                                                of the name found then
 
236
                                                DB_NO_SAVEPOINT,
 
237
                                                otherwise DB_SUCCESS */
 
238
        trx_t*          trx,                    /* in: transaction handle */
 
239
        const char*     savepoint_name);        /* in: savepoint name */
 
240
 
 
241
/***********************************************************************
 
242
Frees a single savepoint struct. */
 
243
 
 
244
void
 
245
trx_roll_savepoint_free(
 
246
/*=====================*/
 
247
        trx_t*                  trx,    /* in: transaction handle */
 
248
        trx_named_savept_t*     savep); /* in: savepoint to free */
 
249
 
 
250
/***********************************************************************
 
251
Frees savepoint structs starting from savep, if savep == NULL then
 
252
free all savepoints. */
 
253
 
 
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
extern sess_t*          trx_dummy_sess;
 
263
 
 
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
 
267
                                a rollback */
 
268
        dulint  undo_no;        /* undo number of an undo record */
 
269
        ibool   in_use;         /* TRUE if the cell is in use */
 
270
};
 
271
 
 
272
/* During a rollback and a purge, undo numbers of undo records currently being
 
273
processed are stored in this array */
 
274
 
 
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 */
 
280
};
 
281
 
 
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 */
 
289
};
 
290
 
 
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
 
295
                                        the savepoint */
 
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
 
300
                                        enabled */
 
301
        UT_LIST_NODE_T(trx_named_savept_t)
 
302
                        trx_savepoints; /* the list of savepoints of a
 
303
                                        transaction */
 
304
};
 
305
 
 
306
/* Rollback node states */
 
307
#define ROLL_NODE_SEND  1
 
308
#define ROLL_NODE_WAIT  2
 
309
 
 
310
#ifndef UNIV_NONINL
 
311
#include "trx0roll.ic"
 
312
#endif
 
313
 
 
314
#endif