~stewart/haildb/trunk

« back to all changes in this revision

Viewing changes to include/trx0roll.h

  • Committer: Stewart Smith
  • Date: 2010-04-09 07:57:43 UTC
  • Revision ID: stewart@flamingspork.com-20100409075743-jfh1oml3el1uouvh
Embedded InnoDB 1.0.0 released

2009-04-21      The InnoDB Team

        Embedded InnoDB 1.0.0 released

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
Transaction rollback
 
21
 
 
22
Created 3/26/1996 Heikki Tuuri
 
23
*******************************************************/
 
24
 
 
25
#ifndef trx0roll_h
 
26
#define trx0roll_h
 
27
 
 
28
#include "univ.i"
 
29
#include "trx0trx.h"
 
30
#include "trx0types.h"
 
31
#include "mtr0mtr.h"
 
32
#include "trx0sys.h"
 
33
 
 
34
#define trx_roll_free_all_savepoints(s) trx_roll_savepoints_free((s), NULL)
 
35
 
 
36
/***********************************************************************
 
37
Determines if this transaction is rolling back an incomplete transaction
 
38
in crash recovery. */
 
39
UNIV_INTERN
 
40
ibool
 
41
trx_is_recv(
 
42
/*========*/
 
43
                                /* out: TRUE if trx is an incomplete
 
44
                                transaction that is being rolled back
 
45
                                in crash recovery */
 
46
        const trx_t*    trx);   /* in: transaction */
 
47
/***********************************************************************
 
48
Returns a transaction savepoint taken at this point in time. */
 
49
UNIV_INTERN
 
50
trx_savept_t
 
51
trx_savept_take(
 
52
/*============*/
 
53
                        /* out: savepoint */
 
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
UNIV_INLINE
 
71
trx_undo_inf_t*
 
72
trx_undo_arr_get_nth_info(
 
73
/*======================*/
 
74
                                /* out: pointer to the nth element */
 
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: 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
UNIV_INTERN
 
91
trx_undo_rec_t*
 
92
trx_roll_pop_top_rec_of_trx(
 
93
/*========================*/
 
94
                                /* out: undo log record copied to heap, NULL
 
95
                                if none left, or if the undo number of the
 
96
                                top record would be less than the limit */
 
97
        trx_t*          trx,    /* in: transaction */
 
98
        dulint          limit,  /* in: least undo number we need */
 
99
        dulint*         roll_ptr,/* out: roll pointer to undo record */
 
100
        mem_heap_t*     heap);  /* in: memory heap where copied */
 
101
/************************************************************************
 
102
Reserves an undo log record for a query thread to undo. This should be
 
103
called if the query thread gets the undo log record not using the pop
 
104
function above. */
 
105
UNIV_INTERN
 
106
ibool
 
107
trx_undo_rec_reserve(
 
108
/*=================*/
 
109
                        /* out: TRUE if succeeded */
 
110
        trx_t*  trx,    /* in: transaction */
 
111
        dulint  undo_no);/* in: undo number of the record */
 
112
/***********************************************************************
 
113
Releases a reserved undo record. */
 
114
UNIV_INTERN
 
115
void
 
116
trx_undo_rec_release(
 
117
/*=================*/
 
118
        trx_t*  trx,    /* in: transaction */
 
119
        dulint  undo_no);/* in: undo number */
 
120
/*************************************************************************
 
121
Starts a rollback operation. */
 
122
UNIV_INTERN
 
123
void
 
124
trx_rollback(
 
125
/*=========*/
 
126
        trx_t*          trx,    /* in: transaction */
 
127
        trx_sig_t*      sig,    /* in: signal starting the rollback */
 
128
        que_thr_t**     next_thr);/* in/out: next query thread to run;
 
129
                                if the value which is passed in is
 
130
                                a pointer to a NULL pointer, then the
 
131
                                calling function can start running
 
132
                                a new query thread */
 
133
/***********************************************************************
 
134
Rollback or clean up any incomplete transactions which were
 
135
encountered in crash recovery.  If the transaction already was
 
136
committed, then we clean up a possible insert undo log. If the
 
137
transaction was not yet committed, then we roll it back.
 
138
Note: this is done in a background thread. */
 
139
UNIV_INTERN
 
140
os_thread_ret_t
 
141
trx_rollback_or_clean_all_recovered(
 
142
/*================================*/
 
143
                        /* out: a dummy parameter */
 
144
        void*   arg __attribute__((unused)));
 
145
                        /* in: a dummy parameter required by
 
146
                        os_thread_create */
 
147
/********************************************************************
 
148
Finishes a transaction rollback. */
 
149
UNIV_INTERN
 
150
void
 
151
trx_finish_rollback_off_kernel(
 
152
/*===========================*/
 
153
        que_t*          graph,  /* in: undo graph which can now be freed */
 
154
        trx_t*          trx,    /* in: transaction */
 
155
        que_thr_t**     next_thr);/* in/out: next query thread to run;
 
156
                                if the value which is passed in is
 
157
                                a pointer to a NULL pointer, then the
 
158
                                calling function can start running
 
159
                                a new query thread; if this parameter is
 
160
                                NULL, it is ignored */
 
161
/********************************************************************
 
162
Builds an undo 'query' graph for a transaction. The actual rollback is
 
163
performed by executing this query graph like a query subprocedure call.
 
164
The reply about the completion of the rollback will be sent by this
 
165
graph. */
 
166
UNIV_INTERN
 
167
que_t*
 
168
trx_roll_graph_build(
 
169
/*=================*/
 
170
                        /* out, own: the query graph */
 
171
        trx_t*  trx);   /* in: trx handle */
 
172
/*************************************************************************
 
173
Creates a rollback command node struct. */
 
174
UNIV_INTERN
 
175
roll_node_t*
 
176
roll_node_create(
 
177
/*=============*/
 
178
                                /* out, own: rollback node struct */
 
179
        mem_heap_t*     heap);  /* in: mem heap where created */
 
180
/***************************************************************
 
181
Performs an execution step for a rollback command node in a query graph. */
 
182
UNIV_INTERN
 
183
que_thr_t*
 
184
trx_rollback_step(
 
185
/*==============*/
 
186
                                /* out: query thread to run next, or NULL */
 
187
        que_thr_t*      thr);   /* in: query thread */
 
188
/***********************************************************************
 
189
Rollback a user transaction. */
 
190
UNIV_INTERN
 
191
int
 
192
trx_general_rollback(
 
193
/*=================*/
 
194
                                /* out: error code or DB_SUCCESS */
 
195
        trx_t*          trx,    /* in: transaction handle */
 
196
        ibool           partial,/* in: TRUE if partial rollback requested */
 
197
        trx_savept_t*   savept);/* in: pointer to savepoint undo number, if
 
198
                                partial rollback requested */
 
199
 
 
200
/***********************************************************************
 
201
Frees savepoint structs starting from savep, if savep == NULL then
 
202
free all savepoints. */
 
203
UNIV_INTERN
 
204
void
 
205
trx_roll_savepoints_free(
 
206
/*=====================*/
 
207
        trx_t*                  trx,    /* in: transaction handle */
 
208
        trx_named_savept_t*     savep); /* in: free all savepoints > this one;
 
209
                                        if this is NULL, free all savepoints
 
210
                                        of trx */
 
211
 
 
212
/* A cell in the array used during a rollback and a purge */
 
213
struct  trx_undo_inf_struct{
 
214
        dulint  trx_no;         /* transaction number: not defined during
 
215
                                a rollback */
 
216
        dulint  undo_no;        /* undo number of an undo record */
 
217
        ibool   in_use;         /* TRUE if the cell is in use */
 
218
};
 
219
 
 
220
/* During a rollback and a purge, undo numbers of undo records currently being
 
221
processed are stored in this array */
 
222
 
 
223
struct trx_undo_arr_struct{
 
224
        ulint           n_cells;        /* number of cells in the array */
 
225
        ulint           n_used;         /* number of cells currently in use */
 
226
        trx_undo_inf_t* infos;          /* the array of undo infos */
 
227
        mem_heap_t*     heap;           /* memory heap from which allocated */
 
228
};
 
229
 
 
230
/* Rollback command node in a query graph */
 
231
struct roll_node_struct{
 
232
        que_common_t    common; /* node type: QUE_NODE_ROLLBACK */
 
233
        ulint           state;  /* node execution state */
 
234
        ibool           partial;/* TRUE if we want a partial rollback */
 
235
        trx_savept_t    savept; /* savepoint to which to roll back, in the
 
236
                                case of a partial rollback */
 
237
};
 
238
 
 
239
/* A savepoint set with SQL's "SAVEPOINT savepoint_id" command */
 
240
struct trx_named_savept_struct{
 
241
        void*           name;           /* savepoint name, it can be any
 
242
                                        arbitrary set of characters. Note:
 
243
                                        When allocating memory for trx_named
 
244
                                        structure allocate an additional
 
245
                                        name_len bytes and set the value of
 
246
                                        name to point to the first byte past
 
247
                                        an instance of this structure */
 
248
        ulint           name_len;       /* length of name in bytes */
 
249
        trx_savept_t    savept;         /* the undo number corresponding to
 
250
                                        the savepoint */
 
251
        UT_LIST_NODE_T(trx_named_savept_t)
 
252
                        trx_savepoints; /* the list of savepoints of a
 
253
                                        transaction */
 
254
};
 
255
 
 
256
/* Rollback node states */
 
257
#define ROLL_NODE_SEND  1
 
258
#define ROLL_NODE_WAIT  2
 
259
 
 
260
#ifndef UNIV_NONINL
 
261
#include "trx0roll.ic"
 
262
#endif
 
263
 
 
264
#endif