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