1
/*****************************************************************************
3
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/trx0rec.h
21
Transaction undo log record
23
Created 3/26/1996 Heikki Tuuri
24
*******************************************************/
30
#include "trx0types.h"
31
#include "row0types.h"
33
#include "dict0types.h"
34
#include "data0data.h"
35
#include "rem0types.h"
37
#ifndef UNIV_HOTBACKUP
38
# include "que0types.h"
40
/***********************************************************************//**
41
Copies the undo record to the heap.
42
@return own: copy of undo log record */
47
const trx_undo_rec_t* undo_rec, /*!< in: undo log record */
48
mem_heap_t* heap); /*!< in: heap where copied */
49
/**********************************************************************//**
50
Reads the undo log record type.
51
@return record type */
54
trx_undo_rec_get_type(
55
/*==================*/
56
const trx_undo_rec_t* undo_rec); /*!< in: undo log record */
57
/**********************************************************************//**
58
Reads from an undo log record the record compiler info.
59
@return compiler info */
62
trx_undo_rec_get_cmpl_info(
63
/*=======================*/
64
const trx_undo_rec_t* undo_rec); /*!< in: undo log record */
65
/**********************************************************************//**
66
Returns TRUE if an undo log record contains an extern storage field.
67
@return TRUE if extern */
70
trx_undo_rec_get_extern_storage(
71
/*============================*/
72
const trx_undo_rec_t* undo_rec); /*!< in: undo log record */
73
/**********************************************************************//**
74
Reads the undo log record number.
78
trx_undo_rec_get_undo_no(
79
/*=====================*/
80
const trx_undo_rec_t* undo_rec); /*!< in: undo log record */
81
/**********************************************************************//**
82
Returns the start of the undo record data area.
83
@return offset to the data area */
86
trx_undo_rec_get_offset(
87
/*====================*/
88
undo_no_t undo_no) /*!< in: undo no read from node */
89
__attribute__((const));
91
/**********************************************************************//**
92
Returns the start of the undo record data area. */
93
#define trx_undo_rec_get_ptr(undo_rec, undo_no) \
94
((undo_rec) + trx_undo_rec_get_offset(undo_no))
96
/**********************************************************************//**
97
Reads from an undo log record the general parameters.
98
@return remaining part of undo log record after reading these values */
101
trx_undo_rec_get_pars(
102
/*==================*/
103
trx_undo_rec_t* undo_rec, /*!< in: undo log record */
104
ulint* type, /*!< out: undo record type:
105
TRX_UNDO_INSERT_REC, ... */
106
ulint* cmpl_info, /*!< out: compiler info, relevant only
107
for update type records */
108
ibool* updated_extern, /*!< out: TRUE if we updated an
109
externally stored fild */
110
undo_no_t* undo_no, /*!< out: undo log record number */
111
table_id_t* table_id); /*!< out: table id */
112
/*******************************************************************//**
113
Builds a row reference from an undo log record.
114
@return pointer to remaining part of undo record */
117
trx_undo_rec_get_row_ref(
118
/*=====================*/
119
byte* ptr, /*!< in: remaining part of a copy of an undo log
120
record, at the start of the row reference;
121
NOTE that this copy of the undo log record must
122
be preserved as long as the row reference is
123
used, as we do NOT copy the data in the
125
dict_index_t* index, /*!< in: clustered index */
126
dtuple_t** ref, /*!< out, own: row reference */
127
mem_heap_t* heap); /*!< in: memory heap from which the memory
128
needed is allocated */
129
/*******************************************************************//**
130
Skips a row reference from an undo log record.
131
@return pointer to remaining part of undo record */
134
trx_undo_rec_skip_row_ref(
135
/*======================*/
136
byte* ptr, /*!< in: remaining part in update undo log
137
record, at the start of the row reference */
138
dict_index_t* index); /*!< in: clustered index */
139
/**********************************************************************//**
140
Reads from an undo log update record the system field values of the old
142
@return remaining part of undo log record after reading these values */
145
trx_undo_update_rec_get_sys_cols(
146
/*=============================*/
147
byte* ptr, /*!< in: remaining part of undo
148
log record after reading
149
general parameters */
150
trx_id_t* trx_id, /*!< out: trx id */
151
roll_ptr_t* roll_ptr, /*!< out: roll ptr */
152
ulint* info_bits); /*!< out: info bits state */
153
/*******************************************************************//**
154
Builds an update vector based on a remaining part of an undo log record.
155
@return remaining part of the record, NULL if an error detected, which
156
means that the record is corrupted */
159
trx_undo_update_rec_get_update(
160
/*===========================*/
161
byte* ptr, /*!< in: remaining part in update undo log
162
record, after reading the row reference
163
NOTE that this copy of the undo log record must
164
be preserved as long as the update vector is
165
used, as we do NOT copy the data in the
167
dict_index_t* index, /*!< in: clustered index */
168
ulint type, /*!< in: TRX_UNDO_UPD_EXIST_REC,
169
TRX_UNDO_UPD_DEL_REC, or
170
TRX_UNDO_DEL_MARK_REC; in the last case,
171
only trx id and roll ptr fields are added to
173
trx_id_t trx_id, /*!< in: transaction id from this undorecord */
174
roll_ptr_t roll_ptr,/*!< in: roll pointer from this undo record */
175
ulint info_bits,/*!< in: info bits from this undo record */
176
trx_t* trx, /*!< in: transaction */
177
mem_heap_t* heap, /*!< in: memory heap from which the memory
178
needed is allocated */
179
upd_t** upd); /*!< out, own: update vector */
180
/*******************************************************************//**
181
Builds a partial row from an update undo log record. It contains the
182
columns which occur as ordering in any index of the table.
183
@return pointer to remaining part of undo record */
186
trx_undo_rec_get_partial_row(
187
/*=========================*/
188
byte* ptr, /*!< in: remaining part in update undo log
189
record of a suitable type, at the start of
190
the stored index columns;
191
NOTE that this copy of the undo log record must
192
be preserved as long as the partial row is
193
used, as we do NOT copy the data in the
195
dict_index_t* index, /*!< in: clustered index */
196
dtuple_t** row, /*!< out, own: partial row */
197
ibool ignore_prefix, /*!< in: flag to indicate if we
198
expect blob prefixes in undo. Used
199
only in the assertion. */
200
mem_heap_t* heap); /*!< in: memory heap from which the memory
201
needed is allocated */
202
/***********************************************************************//**
203
Writes information to an undo log about an insert, update, or a delete marking
204
of a clustered index record. This information is used in a rollback of the
205
transaction and in consistent reads that must look to the history of this
207
@return DB_SUCCESS or error code */
210
trx_undo_report_row_operation(
211
/*==========================*/
212
ulint flags, /*!< in: if BTR_NO_UNDO_LOG_FLAG bit is
214
ulint op_type, /*!< in: TRX_UNDO_INSERT_OP or
215
TRX_UNDO_MODIFY_OP */
216
que_thr_t* thr, /*!< in: query thread */
217
dict_index_t* index, /*!< in: clustered index */
218
const dtuple_t* clust_entry, /*!< in: in the case of an insert,
219
index entry to insert into the
220
clustered index, otherwise NULL */
221
const upd_t* update, /*!< in: in the case of an update,
222
the update vector, otherwise NULL */
223
ulint cmpl_info, /*!< in: compiler info on secondary
225
const rec_t* rec, /*!< in: case of an update or delete
226
marking, the record in the clustered
227
index, otherwise NULL */
228
roll_ptr_t* roll_ptr); /*!< out: rollback pointer to the
229
inserted undo log record,
231
flag was specified */
232
/******************************************************************//**
233
Copies an undo record to heap. This function can be called if we know that
234
the undo log record exists.
235
@return own: copy of the record */
238
trx_undo_get_undo_rec_low(
239
/*======================*/
240
roll_ptr_t roll_ptr, /*!< in: roll pointer to record */
241
mem_heap_t* heap); /*!< in: memory heap where copied */
242
/******************************************************************//**
243
Copies an undo record to heap.
245
NOTE: the caller must have latches on the clustered index page and
248
@return DB_SUCCESS, or DB_MISSING_HISTORY if the undo log has been
249
truncated and we cannot fetch the old version */
252
trx_undo_get_undo_rec(
253
/*==================*/
254
roll_ptr_t roll_ptr, /*!< in: roll pointer to record */
255
trx_id_t trx_id, /*!< in: id of the trx that generated
256
the roll pointer: it points to an
257
undo log of this transaction */
258
trx_undo_rec_t** undo_rec, /*!< out, own: copy of the record */
259
mem_heap_t* heap); /*!< in: memory heap where copied */
260
/*******************************************************************//**
261
Build a previous version of a clustered index record. This function checks
262
that the caller has a latch on the index page of the clustered index record
263
and an s-latch on the purge_view. This guarantees that the stack of versions
265
@return DB_SUCCESS, or DB_MISSING_HISTORY if the previous version is
266
earlier than purge_view, which means that it may have been removed,
267
DB_ERROR if corrupted record */
270
trx_undo_prev_version_build(
271
/*========================*/
272
const rec_t* index_rec,/*!< in: clustered index record in the
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
#endif /* !UNIV_HOTBACKUP */
285
/***********************************************************//**
286
Parses a redo log record of adding an undo log record.
287
@return end of log record or NULL */
290
trx_undo_parse_add_undo_rec(
291
/*========================*/
292
byte* ptr, /*!< in: buffer */
293
byte* end_ptr,/*!< in: buffer end */
294
page_t* page); /*!< in: page or NULL */
295
/***********************************************************//**
296
Parses a redo log record of erasing of an undo page end.
297
@return end of log record or NULL */
300
trx_undo_parse_erase_page_end(
301
/*==========================*/
302
byte* ptr, /*!< in: buffer */
303
byte* end_ptr,/*!< in: buffer end */
304
page_t* page, /*!< in: page or NULL */
305
mtr_t* mtr); /*!< in: mtr or NULL */
307
#ifndef UNIV_HOTBACKUP
309
/* Types of an undo log record: these have to be smaller than 16, as the
310
compilation info multiplied by 16 is ORed to this value in an undo log
313
#define TRX_UNDO_INSERT_REC 11 /* fresh insert into clustered index */
314
#define TRX_UNDO_UPD_EXIST_REC 12 /* update of a non-delete-marked
316
#define TRX_UNDO_UPD_DEL_REC 13 /* update of a delete marked record to
317
a not delete marked record; also the
318
fields of the record can change */
319
#define TRX_UNDO_DEL_MARK_REC 14 /* delete marking of a record; fields
321
#define TRX_UNDO_CMPL_INFO_MULT 16 /* compilation info is multiplied by
322
this and ORed to the type above */
323
#define TRX_UNDO_UPD_EXTERN 128 /* This bit can be ORed to type_cmpl
324
to denote that we updated external
325
storage fields: used by purge to
326
free the external storage */
328
/* Operation type flags used in trx_undo_report_row_operation */
329
#define TRX_UNDO_INSERT_OP 1
330
#define TRX_UNDO_MODIFY_OP 2
333
#include "trx0rec.ic"
336
#endif /* !UNIV_HOTBACKUP */
338
#endif /* trx0rec_h */