~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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
Returns a transaction savepoint taken at this point in time. */
 
20
 
 
21
trx_savept_t
 
22
trx_savept_take(
 
23
/*============*/
 
24
                        /* out: savepoint */
 
25
        trx_t*  trx);   /* in: transaction */
 
26
/***********************************************************************
 
27
Creates an undo number array. */
 
28
 
 
29
trx_undo_arr_t*
 
30
trx_undo_arr_create(void);
 
31
/*=====================*/
 
32
/***********************************************************************
 
33
Frees an undo number array. */
 
34
 
 
35
void
 
36
trx_undo_arr_free(
 
37
/*==============*/
 
38
        trx_undo_arr_t* arr);   /* in: undo number array */
 
39
/***********************************************************************
 
40
Returns pointer to nth element in an undo number array. */
 
41
UNIV_INLINE
 
42
trx_undo_inf_t*
 
43
trx_undo_arr_get_nth_info(
 
44
/*======================*/
 
45
                                /* out: pointer to the nth element */
 
46
        trx_undo_arr_t* arr,    /* in: undo number array */
 
47
        ulint           n);     /* in: position */
 
48
/***************************************************************************
 
49
Tries truncate the undo logs. */
 
50
 
 
51
void
 
52
trx_roll_try_truncate(
 
53
/*==================*/
 
54
        trx_t*  trx);   /* in: transaction */
 
55
/************************************************************************
 
56
Pops the topmost record when the two undo logs of a transaction are seen
 
57
as a single stack of records ordered by their undo numbers. Inserts the
 
58
undo number of the popped undo record to the array of currently processed
 
59
undo numbers in the transaction. When the query thread finishes processing
 
60
of this undo record, it must be released with trx_undo_rec_release. */
 
61
 
 
62
trx_undo_rec_t*
 
63
trx_roll_pop_top_rec_of_trx(
 
64
/*========================*/
 
65
                                /* out: undo log record copied to heap, NULL
 
66
                                if none left, or if the undo number of the
 
67
                                top record would be less than the limit */
 
68
        trx_t*          trx,    /* in: transaction */
 
69
        dulint          limit,  /* in: least undo number we need */
 
70
        dulint*         roll_ptr,/* out: roll pointer to undo record */
 
71
        mem_heap_t*     heap);  /* in: memory heap where copied */
 
72
/************************************************************************
 
73
Reserves an undo log record for a query thread to undo. This should be
 
74
called if the query thread gets the undo log record not using the pop
 
75
function above. */
 
76
 
 
77
ibool
 
78
trx_undo_rec_reserve(
 
79
/*=================*/
 
80
                        /* out: TRUE if succeeded */
 
81
        trx_t*  trx,    /* in: transaction */
 
82
        dulint  undo_no);/* in: undo number of the record */
 
83
/***********************************************************************
 
84
Releases a reserved undo record. */
 
85
 
 
86
void
 
87
trx_undo_rec_release(
 
88
/*=================*/
 
89
        trx_t*  trx,    /* in: transaction */
 
90
        dulint  undo_no);/* in: undo number */
 
91
/*************************************************************************
 
92
Starts a rollback operation. */
 
93
 
 
94
void
 
95
trx_rollback(
 
96
/*=========*/
 
97
        trx_t*          trx,    /* in: transaction */
 
98
        trx_sig_t*      sig,    /* in: signal starting the rollback */
 
99
        que_thr_t**     next_thr);/* in/out: next query thread to run;
 
100
                                if the value which is passed in is
 
101
                                a pointer to a NULL pointer, then the
 
102
                                calling function can start running
 
103
                                a new query thread */
 
104
/***********************************************************************
 
105
Rollback or clean up transactions which have no user session. If the
 
106
transaction already was committed, then we clean up a possible insert
 
107
undo log. If the transaction was not yet committed, then we roll it back.
 
108
Note: this is done in a background thread. */
 
109
 
 
110
os_thread_ret_t
 
111
trx_rollback_or_clean_all_without_sess(
 
112
/*===================================*/
 
113
                        /* out: a dummy parameter */
 
114
        void*   arg __attribute__((unused)));
 
115
                        /* in: a dummy parameter required by
 
116
                        os_thread_create */
 
117
/********************************************************************
 
118
Finishes a transaction rollback. */
 
119
 
 
120
void
 
121
trx_finish_rollback_off_kernel(
 
122
/*===========================*/
 
123
        que_t*          graph,  /* in: undo graph which can now be freed */
 
124
        trx_t*          trx,    /* in: transaction */
 
125
        que_thr_t**     next_thr);/* in/out: next query thread to run;
 
126
                                if the value which is passed in is
 
127
                                a pointer to a NULL pointer, then the
 
128
                                calling function can start running
 
129
                                a new query thread; if this parameter is
 
130
                                NULL, it is ignored */
 
131
/********************************************************************
 
132
Builds an undo 'query' graph for a transaction. The actual rollback is
 
133
performed by executing this query graph like a query subprocedure call.
 
134
The reply about the completion of the rollback will be sent by this
 
135
graph. */
 
136
 
 
137
que_t*
 
138
trx_roll_graph_build(
 
139
/*=================*/
 
140
                        /* out, own: the query graph */
 
141
        trx_t*  trx);   /* in: trx handle */
 
142
/*************************************************************************
 
143
Creates a rollback command node struct. */
 
144
 
 
145
roll_node_t*
 
146
roll_node_create(
 
147
/*=============*/
 
148
                                /* out, own: rollback node struct */
 
149
        mem_heap_t*     heap);  /* in: mem heap where created */
 
150
/***************************************************************
 
151
Performs an execution step for a rollback command node in a query graph. */
 
152
 
 
153
que_thr_t*
 
154
trx_rollback_step(
 
155
/*==============*/
 
156
                                /* out: query thread to run next, or NULL */
 
157
        que_thr_t*      thr);   /* in: query thread */
 
158
/***********************************************************************
 
159
Rollback a transaction used in MySQL. */
 
160
 
 
161
int
 
162
trx_rollback_for_mysql(
 
163
/*===================*/
 
164
                        /* out: error code or DB_SUCCESS */
 
165
        trx_t*  trx);   /* in: transaction handle */
 
166
/***********************************************************************
 
167
Rollback the latest SQL statement for MySQL. */
 
168
 
 
169
int
 
170
trx_rollback_last_sql_stat_for_mysql(
 
171
/*=================================*/
 
172
                        /* out: error code or DB_SUCCESS */
 
173
        trx_t*  trx);   /* in: transaction handle */
 
174
/***********************************************************************
 
175
Rollback a transaction used in MySQL. */
 
176
 
 
177
int
 
178
trx_general_rollback_for_mysql(
 
179
/*===========================*/
 
180
                                /* out: error code or DB_SUCCESS */
 
181
        trx_t*          trx,    /* in: transaction handle */
 
182
        ibool           partial,/* in: TRUE if partial rollback requested */
 
183
        trx_savept_t*   savept);/* in: pointer to savepoint undo number, if
 
184
                                partial rollback requested */
 
185
/***********************************************************************
 
186
Rolls back a transaction back to a named savepoint. Modifications after the
 
187
savepoint are undone but InnoDB does NOT release the corresponding locks
 
188
which are stored in memory. If a lock is 'implicit', that is, a new inserted
 
189
row holds a lock where the lock information is carried by the trx id stored in
 
190
the row, these locks are naturally released in the rollback. Savepoints which
 
191
were set after this savepoint are deleted. */
 
192
 
 
193
ulint
 
194
trx_rollback_to_savepoint_for_mysql(
 
195
/*================================*/
 
196
                                                /* out: if no savepoint
 
197
                                                of the name found then
 
198
                                                DB_NO_SAVEPOINT,
 
199
                                                otherwise DB_SUCCESS */
 
200
        trx_t*          trx,                    /* in: transaction handle */
 
201
        const char*     savepoint_name,         /* in: savepoint name */
 
202
        ib_longlong*    mysql_binlog_cache_pos);/* out: the MySQL binlog cache
 
203
                                                position corresponding to this
 
204
                                                savepoint; MySQL needs this
 
205
                                                information to remove the
 
206
                                                binlog entries of the queries
 
207
                                                executed after the savepoint */
 
208
/***********************************************************************
 
209
Creates a named savepoint. If the transaction is not yet started, starts it.
 
210
If there is already a savepoint of the same name, this call erases that old
 
211
savepoint and replaces it with a new. Savepoints are deleted in a transaction
 
212
commit or rollback. */
 
213
 
 
214
ulint
 
215
trx_savepoint_for_mysql(
 
216
/*====================*/
 
217
                                                /* out: always DB_SUCCESS */
 
218
        trx_t*          trx,                    /* in: transaction handle */
 
219
        const char*     savepoint_name,         /* in: savepoint name */
 
220
        ib_longlong     binlog_cache_pos);      /* in: MySQL binlog cache
 
221
                                                position corresponding to this
 
222
                                                connection at the time of the
 
223
                                                savepoint */
 
224
 
 
225
/***********************************************************************
 
226
Releases a named savepoint. Savepoints which
 
227
were set after this savepoint are deleted. */
 
228
 
 
229
ulint
 
230
trx_release_savepoint_for_mysql(
 
231
/*============================*/
 
232
                                                /* out: if no savepoint
 
233
                                                of the name found then
 
234
                                                DB_NO_SAVEPOINT,
 
235
                                                otherwise DB_SUCCESS */
 
236
        trx_t*          trx,                    /* in: transaction handle */
 
237
        const char*     savepoint_name);        /* in: savepoint name */
 
238
 
 
239
/***********************************************************************
 
240
Frees savepoint structs. */
 
241
 
 
242
void
 
243
trx_roll_savepoints_free(
 
244
/*=====================*/
 
245
        trx_t*                  trx,    /* in: transaction handle */
 
246
        trx_named_savept_t*     savep); /* in: free all savepoints > this one;
 
247
                                        if this is NULL, free all savepoints
 
248
                                        of trx */
 
249
 
 
250
extern sess_t*          trx_dummy_sess;
 
251
 
 
252
/* A cell in the array used during a rollback and a purge */
 
253
struct  trx_undo_inf_struct{
 
254
        dulint  trx_no;         /* transaction number: not defined during
 
255
                                a rollback */
 
256
        dulint  undo_no;        /* undo number of an undo record */
 
257
        ibool   in_use;         /* TRUE if the cell is in use */
 
258
};
 
259
 
 
260
/* During a rollback and a purge, undo numbers of undo records currently being
 
261
processed are stored in this array */
 
262
 
 
263
struct trx_undo_arr_struct{
 
264
        ulint           n_cells;        /* number of cells in the array */
 
265
        ulint           n_used;         /* number of cells currently in use */
 
266
        trx_undo_inf_t* infos;          /* the array of undo infos */
 
267
        mem_heap_t*     heap;           /* memory heap from which allocated */
 
268
};
 
269
 
 
270
/* Rollback command node in a query graph */
 
271
struct roll_node_struct{
 
272
        que_common_t    common; /* node type: QUE_NODE_ROLLBACK */
 
273
        ulint           state;  /* node execution state */
 
274
        ibool           partial;/* TRUE if we want a partial rollback */
 
275
        trx_savept_t    savept; /* savepoint to which to roll back, in the
 
276
                                case of a partial rollback */
 
277
};
 
278
 
 
279
/* A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
 
280
struct trx_named_savept_struct{
 
281
        char*           name;           /* savepoint name */
 
282
        trx_savept_t    savept;         /* the undo number corresponding to
 
283
                                        the savepoint */
 
284
        ib_longlong     mysql_binlog_cache_pos;
 
285
                                        /* the MySQL binlog cache position
 
286
                                        corresponding to this savepoint, not
 
287
                                        defined if the MySQL binlogging is not
 
288
                                        enabled */
 
289
        UT_LIST_NODE_T(trx_named_savept_t)
 
290
                        trx_savepoints; /* the list of savepoints of a
 
291
                                        transaction */
 
292
};
 
293
 
 
294
/* Rollback node states */
 
295
#define ROLL_NODE_SEND  1
 
296
#define ROLL_NODE_WAIT  2
 
297
 
 
298
#ifndef UNIV_NONINL
 
299
#include "trx0roll.ic"
 
300
#endif
 
301
 
 
302
#endif