~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
19
/******************************************************
20
Transaction undo log record
21
22
Created 3/26/1996 Heikki Tuuri
23
*******************************************************/
24
25
#ifndef trx0rec_h
26
#define trx0rec_h
27
28
#include "univ.i"
29
#include "trx0types.h"
30
#include "row0types.h"
31
#include "mtr0mtr.h"
32
#include "dict0types.h"
33
#include "que0types.h"
34
#include "data0data.h"
35
#include "rem0types.h"
36
37
/***************************************************************************
38
Copies the undo record to the heap. */
39
UNIV_INLINE
40
trx_undo_rec_t*
41
trx_undo_rec_copy(
42
/*==============*/
43
					/* out, own: copy of undo log record */
44
	trx_undo_rec_t*	undo_rec,	/* in: undo log record */
45
	mem_heap_t*	heap);		/* in: heap where copied */
46
/**************************************************************************
47
Reads the undo log record type. */
48
UNIV_INLINE
49
ulint
50
trx_undo_rec_get_type(
51
/*==================*/
52
					/* out: record type */
53
	trx_undo_rec_t*	undo_rec);	/* in: undo log record */
54
/**************************************************************************
55
Reads from an undo log record the record compiler info. */
56
UNIV_INLINE
57
ulint
58
trx_undo_rec_get_cmpl_info(
59
/*=======================*/
60
					/* out: compiler info */
61
	trx_undo_rec_t*	undo_rec);	/* in: undo log record */
62
/**************************************************************************
63
Returns TRUE if an undo log record contains an extern storage field. */
64
UNIV_INLINE
65
ibool
66
trx_undo_rec_get_extern_storage(
67
/*============================*/
68
					/* out: TRUE if extern */
69
	trx_undo_rec_t*	undo_rec);	/* in: undo log record */
70
/**************************************************************************
71
Reads the undo log record number. */
72
UNIV_INLINE
73
dulint
74
trx_undo_rec_get_undo_no(
75
/*=====================*/
76
					/* out: undo no */
77
	trx_undo_rec_t*	undo_rec);	/* in: undo log record */
78
/**************************************************************************
79
 * Returns the start of the undo record data area. */
80
81
UNIV_INLINE
82
byte*
83
trx_undo_rec_get_ptr(
84
/*==================*/
85
					/* out: compiler info */
86
	trx_undo_rec_t* undo_rec,       /* in: undo log record */
87
	dulint          undo_no);        /* in: undo no read from node */
88
89
/**************************************************************************
90
Reads from an undo log record the general parameters. */
91
UNIV_INTERN
92
byte*
93
trx_undo_rec_get_pars(
94
/*==================*/
95
					/* out: remaining part of undo log
96
					record after reading these values */
97
	trx_undo_rec_t*	undo_rec,	/* in: undo log record */
98
	ulint*		type,		/* out: undo record type:
99
					TRX_UNDO_INSERT_REC, ... */
100
	ulint*		cmpl_info,	/* out: compiler info, relevant only
101
					for update type records */
102
	ibool*		updated_extern,	/* out: TRUE if we updated an
103
					externally stored fild */
104
	dulint*		undo_no,	/* out: undo log record number */
105
	dulint*		table_id);	/* out: table id */
106
/***********************************************************************
107
Builds a row reference from an undo log record. */
108
UNIV_INTERN
109
byte*
110
trx_undo_rec_get_row_ref(
111
/*=====================*/
112
				/* out: pointer to remaining part of undo
113
				record */
114
	byte*		ptr,	/* in: remaining part of a copy of an undo log
115
				record, at the start of the row reference;
116
				NOTE that this copy of the undo log record must
117
				be preserved as long as the row reference is
118
				used, as we do NOT copy the data in the
119
				record! */
120
	dict_index_t*	index,	/* in: clustered index */
121
	dtuple_t**	ref,	/* out, own: row reference */
122
	mem_heap_t*	heap);	/* in: memory heap from which the memory
123
				needed is allocated */
124
/***********************************************************************
125
Skips a row reference from an undo log record. */
126
UNIV_INTERN
127
byte*
128
trx_undo_rec_skip_row_ref(
129
/*======================*/
130
				/* out: pointer to remaining part of undo
131
				record */
132
	byte*		ptr,	/* in: remaining part in update undo log
133
				record, at the start of the row reference */
134
	dict_index_t*	index);	/* in: clustered index */
135
/**************************************************************************
136
Reads from an undo log update record the system field values of the old
137
version. */
138
UNIV_INTERN
139
byte*
140
trx_undo_update_rec_get_sys_cols(
141
/*=============================*/
142
				/* out: remaining part of undo log
143
				record after reading these values */
144
	byte*	ptr,		/* in: remaining part of undo log
145
				record after reading general
146
				parameters */
147
	dulint*	trx_id,		/* out: trx id */
148
	dulint*	roll_ptr,	/* out: roll ptr */
149
	ulint*	info_bits);	/* out: info bits state */
150
/***********************************************************************
151
Builds an update vector based on a remaining part of an undo log record. */
152
UNIV_INTERN
153
byte*
154
trx_undo_update_rec_get_update(
155
/*===========================*/
156
				/* out: remaining part of the record,
157
				NULL if an error detected, which means that
158
				the record is corrupted */
159
	byte*		ptr,	/* in: remaining part in update undo log
160
				record, after reading the row reference
161
				NOTE that this copy of the undo log record must
162
				be preserved as long as the update vector is
163
				used, as we do NOT copy the data in the
164
				record! */
165
	dict_index_t*	index,	/* in: clustered index */
166
	ulint		type,	/* in: TRX_UNDO_UPD_EXIST_REC,
167
				TRX_UNDO_UPD_DEL_REC, or
168
				TRX_UNDO_DEL_MARK_REC; in the last case,
169
				only trx id and roll ptr fields are added to
170
				the update vector */
171
	dulint		trx_id,	/* in: transaction id from this undorecord */
172
	dulint		roll_ptr,/* in: roll pointer from this undo record */
173
	ulint		info_bits,/* in: info bits from this undo record */
174
	trx_t*		trx,	/* in: transaction */
175
	mem_heap_t*	heap,	/* in: memory heap from which the memory
176
				needed is allocated */
177
	upd_t**		upd);	/* out, own: update vector */
178
/***********************************************************************
179
Builds a partial row from an update undo log record. It contains the
180
columns which occur as ordering in any index of the table. */
181
UNIV_INTERN
182
byte*
183
trx_undo_rec_get_partial_row(
184
/*=========================*/
185
				/* out: pointer to remaining part of undo
186
				record */
187
	byte*		ptr,	/* in: remaining part in update undo log
188
				record of a suitable type, at the start of
189
				the stored index columns;
190
				NOTE that this copy of the undo log record must
191
				be preserved as long as the partial row is
192
				used, as we do NOT copy the data in the
193
				record! */
194
	dict_index_t*	index,	/* in: clustered index */
195
	dtuple_t**	row,	/* out, own: partial row */
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
196
	ibool		ignore_prefix, /* in: flag to indicate if we
197
				expect blob prefixes in undo. Used
198
				only in the assertion. */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
199
	mem_heap_t*	heap);	/* in: memory heap from which the memory
200
				needed is allocated */
201
/***************************************************************************
202
Writes information to an undo log about an insert, update, or a delete marking
203
of a clustered index record. This information is used in a rollback of the
204
transaction and in consistent reads that must look to the history of this
205
transaction. */
206
UNIV_INTERN
207
ulint
208
trx_undo_report_row_operation(
209
/*==========================*/
210
					/* out: DB_SUCCESS or error code */
211
	ulint		flags,		/* in: if BTR_NO_UNDO_LOG_FLAG bit is
212
					set, does nothing */
213
	ulint		op_type,	/* in: TRX_UNDO_INSERT_OP or
214
					TRX_UNDO_MODIFY_OP */
215
	que_thr_t*	thr,		/* in: query thread */
216
	dict_index_t*	index,		/* in: clustered index */
217
	const dtuple_t*	clust_entry,	/* in: in the case of an insert,
218
					index entry to insert into the
219
					clustered index, otherwise NULL */
220
	const upd_t*	update,		/* in: in the case of an update,
221
					the update vector, otherwise NULL */
222
	ulint		cmpl_info,	/* in: compiler info on secondary
223
					index updates */
224
	const rec_t*	rec,		/* in: case of an update or delete
225
					marking, the record in the clustered
226
					index, otherwise NULL */
227
	dulint*		roll_ptr);	/* out: rollback pointer to the
228
					inserted undo log record,
229
					ut_dulint_zero if BTR_NO_UNDO_LOG
230
					flag was specified */
231
/**********************************************************************
232
Copies an undo record to heap. This function can be called if we know that
233
the undo log record exists. */
234
UNIV_INTERN
235
trx_undo_rec_t*
236
trx_undo_get_undo_rec_low(
237
/*======================*/
238
					/* out, own: copy of the record */
239
	dulint		roll_ptr,	/* in: roll pointer to record */
240
	mem_heap_t*	heap);		/* in: memory heap where copied */
241
/**********************************************************************
242
Copies an undo record to heap. */
243
UNIV_INTERN
244
ulint
245
trx_undo_get_undo_rec(
246
/*==================*/
247
					/* out: DB_SUCCESS, or
248
					DB_MISSING_HISTORY if the undo log
249
					has been truncated and we cannot
250
					fetch the old version; NOTE: the
251
					caller must have latches on the
252
					clustered index page and purge_view */
253
	dulint		roll_ptr,	/* in: roll pointer to record */
254
	dulint		trx_id,		/* in: id of the trx that generated
255
					the roll pointer: it points to an
256
					undo log of this transaction */
257
	trx_undo_rec_t** undo_rec,	/* out, own: copy of the record */
258
	mem_heap_t*	heap);		/* in: memory heap where copied */
259
/***********************************************************************
260
Build a previous version of a clustered index record. This function checks
261
that the caller has a latch on the index page of the clustered index record
262
and an s-latch on the purge_view. This guarantees that the stack of versions
263
is locked. */
264
UNIV_INTERN
265
ulint
266
trx_undo_prev_version_build(
267
/*========================*/
268
				/* out: DB_SUCCESS, or DB_MISSING_HISTORY if
269
				the previous version is not >= purge_view,
270
				which means that it may have been removed,
271
				DB_ERROR if corrupted record */
272
	const rec_t*	index_rec,/* in: clustered index record in the
273
				index tree */
274
	mtr_t*		index_mtr,/* in: mtr which contains the latch to
275
				index_rec page and purge_view */
276
	const rec_t*	rec,	/* in: version of a clustered index record */
277
	dict_index_t*	index,	/* in: clustered index */
278
	ulint*		offsets,/* in: rec_get_offsets(rec, index) */
279
	mem_heap_t*	heap,	/* in: memory heap from which the memory
280
				needed is allocated */
281
	rec_t**		old_vers);/* out, own: previous version, or NULL if
282
				rec is the first inserted version, or if
283
				history data has been deleted */
284
/***************************************************************
285
Parses a redo log record of adding an undo log record. */
286
UNIV_INTERN
287
byte*
288
trx_undo_parse_add_undo_rec(
289
/*========================*/
290
			/* out: end of log record or NULL */
291
	byte*	ptr,	/* in: buffer */
292
	byte*	end_ptr,/* in: buffer end */
293
	page_t*	page);	/* in: page or NULL */
294
/***************************************************************
295
Parses a redo log record of erasing of an undo page end. */
296
UNIV_INTERN
297
byte*
298
trx_undo_parse_erase_page_end(
299
/*==========================*/
300
			/* out: end of log record or NULL */
301
	byte*	ptr,	/* in: buffer */
302
	byte*	end_ptr,/* in: buffer end */
303
	page_t*	page,	/* in: page or NULL */
304
	mtr_t*	mtr);	/* in: mtr or NULL */
305
306
/* Types of an undo log record: these have to be smaller than 16, as the
307
compilation info multiplied by 16 is ORed to this value in an undo log
308
record */
309
310
#define	TRX_UNDO_INSERT_REC	11	/* fresh insert into clustered index */
311
#define	TRX_UNDO_UPD_EXIST_REC	12	/* update of a non-delete-marked
312
					record */
313
#define	TRX_UNDO_UPD_DEL_REC	13	/* update of a delete marked record to
314
					a not delete marked record; also the
315
					fields of the record can change */
316
#define	TRX_UNDO_DEL_MARK_REC	14	/* delete marking of a record; fields
317
					do not change */
318
#define	TRX_UNDO_CMPL_INFO_MULT	16	/* compilation info is multiplied by
319
					this and ORed to the type above */
320
#define	TRX_UNDO_UPD_EXTERN	128	/* This bit can be ORed to type_cmpl
321
					to denote that we updated external
322
					storage fields: used by purge to
323
					free the external storage */
324
325
/* Operation type flags used in trx_undo_report_row_operation */
326
#define	TRX_UNDO_INSERT_OP		1
327
#define	TRX_UNDO_MODIFY_OP		2
328
329
#ifndef UNIV_NONINL
330
#include "trx0rec.ic"
331
#endif
332
333
#endif