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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/trx0undo.ic
23
Created 3/26/1996 Heikki Tuuri
24
*******************************************************/
26
#include "data0type.h"
27
#include "page0page.h"
29
#ifndef UNIV_HOTBACKUP
30
/***********************************************************************//**
31
Builds a roll pointer.
32
@return roll pointer */
35
trx_undo_build_roll_ptr(
36
/*====================*/
37
ibool is_insert, /*!< in: TRUE if insert undo log */
38
ulint rseg_id, /*!< in: rollback segment id */
39
ulint page_no, /*!< in: page number */
40
ulint offset) /*!< in: offset of the undo entry within page */
42
#if DATA_ROLL_PTR_LEN != 7
43
# error "DATA_ROLL_PTR_LEN != 7"
47
return(ut_dulint_create(is_insert * 128 * 256 * 256
49
+ (page_no / 256) / 256,
50
(page_no % (256 * 256)) * 256 * 256
54
/***********************************************************************//**
55
Decodes a roll pointer. */
58
trx_undo_decode_roll_ptr(
59
/*=====================*/
60
roll_ptr_t roll_ptr, /*!< in: roll pointer */
61
ibool* is_insert, /*!< out: TRUE if insert undo log */
62
ulint* rseg_id, /*!< out: rollback segment id */
63
ulint* page_no, /*!< out: page number */
64
ulint* offset) /*!< out: offset of the undo
69
#if DATA_ROLL_PTR_LEN != 7
70
# error "DATA_ROLL_PTR_LEN != 7"
75
high = ut_dulint_get_high(roll_ptr);
76
low = ut_dulint_get_low(roll_ptr);
78
*offset = low % (256 * 256);
80
*is_insert = high / (256 * 256 * 128); /* TRUE == 1 */
81
*rseg_id = (high / (256 * 256)) % 128;
83
*page_no = (high % (256 * 256)) * 256 * 256
87
/***********************************************************************//**
88
Returns TRUE if the roll pointer is of the insert type.
89
@return TRUE if insert undo log */
92
trx_undo_roll_ptr_is_insert(
93
/*========================*/
94
roll_ptr_t roll_ptr) /*!< in: roll pointer */
97
#if DATA_ROLL_PTR_LEN != 7
98
# error "DATA_ROLL_PTR_LEN != 7"
103
high = ut_dulint_get_high(roll_ptr);
105
return(high / (256 * 256 * 128));
107
#endif /* !UNIV_HOTBACKUP */
109
/*****************************************************************//**
110
Writes a roll ptr to an index page. In case that the size changes in
111
some future version, this function should be used instead of
117
byte* ptr, /*!< in: pointer to memory where
119
roll_ptr_t roll_ptr) /*!< in: roll ptr */
121
#if DATA_ROLL_PTR_LEN != 7
122
# error "DATA_ROLL_PTR_LEN != 7"
124
mach_write_to_7(ptr, roll_ptr);
127
/*****************************************************************//**
128
Reads a roll ptr from an index page. In case that the roll ptr size
129
changes in some future version, this function should be used instead of
136
const byte* ptr) /*!< in: pointer to memory from where to read */
138
#if DATA_ROLL_PTR_LEN != 7
139
# error "DATA_ROLL_PTR_LEN != 7"
141
return(mach_read_from_7(ptr));
144
#ifndef UNIV_HOTBACKUP
145
/******************************************************************//**
146
Gets an undo log page and x-latches it.
147
@return pointer to page x-latched */
152
ulint space, /*!< in: space where placed */
153
ulint zip_size, /*!< in: compressed page size in bytes
154
or 0 for uncompressed pages */
155
ulint page_no, /*!< in: page number */
156
mtr_t* mtr) /*!< in: mtr */
158
buf_block_t* block = buf_page_get(space, zip_size, page_no,
160
buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
162
return(buf_block_get_frame(block));
165
/******************************************************************//**
166
Gets an undo log page and s-latches it.
167
@return pointer to page s-latched */
170
trx_undo_page_get_s_latched(
171
/*========================*/
172
ulint space, /*!< in: space where placed */
173
ulint zip_size, /*!< in: compressed page size in bytes
174
or 0 for uncompressed pages */
175
ulint page_no, /*!< in: page number */
176
mtr_t* mtr) /*!< in: mtr */
178
buf_block_t* block = buf_page_get(space, zip_size, page_no,
180
buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
182
return(buf_block_get_frame(block));
185
/******************************************************************//**
186
Returns the start offset of the undo log records of the specified undo
188
@return start offset */
191
trx_undo_page_get_start(
192
/*====================*/
193
page_t* undo_page,/*!< in: undo log page */
194
ulint page_no,/*!< in: undo log header page number */
195
ulint offset) /*!< in: undo log header offset on page */
199
if (page_no == page_get_page_no(undo_page)) {
201
start = mach_read_from_2(offset + undo_page
202
+ TRX_UNDO_LOG_START);
204
start = TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE;
210
/******************************************************************//**
211
Returns the end offset of the undo log records of the specified undo
213
@return end offset */
216
trx_undo_page_get_end(
217
/*==================*/
218
page_t* undo_page,/*!< in: undo log page */
219
ulint page_no,/*!< in: undo log header page number */
220
ulint offset) /*!< in: undo log header offset on page */
222
trx_ulogf_t* log_hdr;
225
if (page_no == page_get_page_no(undo_page)) {
227
log_hdr = undo_page + offset;
229
end = mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG);
232
end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
233
+ TRX_UNDO_PAGE_FREE);
236
end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
237
+ TRX_UNDO_PAGE_FREE);
243
/******************************************************************//**
244
Returns the previous undo record on the page in the specified log, or
246
@return pointer to record, NULL if none */
249
trx_undo_page_get_prev_rec(
250
/*=======================*/
251
trx_undo_rec_t* rec, /*!< in: undo log record */
252
ulint page_no,/*!< in: undo log header page number */
253
ulint offset) /*!< in: undo log header offset on page */
258
undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
260
start = trx_undo_page_get_start(undo_page, page_no, offset);
262
if (start + undo_page == rec) {
267
return(undo_page + mach_read_from_2(rec - 2));
270
/******************************************************************//**
271
Returns the next undo log record on the page in the specified log, or
273
@return pointer to record, NULL if none */
276
trx_undo_page_get_next_rec(
277
/*=======================*/
278
trx_undo_rec_t* rec, /*!< in: undo log record */
279
ulint page_no,/*!< in: undo log header page number */
280
ulint offset) /*!< in: undo log header offset on page */
286
undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
288
end = trx_undo_page_get_end(undo_page, page_no, offset);
290
next = mach_read_from_2(rec);
297
return(undo_page + next);
300
/******************************************************************//**
301
Returns the last undo record on the page in the specified undo log, or
303
@return pointer to record, NULL if none */
306
trx_undo_page_get_last_rec(
307
/*=======================*/
308
page_t* undo_page,/*!< in: undo log page */
309
ulint page_no,/*!< in: undo log header page number */
310
ulint offset) /*!< in: undo log header offset on page */
315
start = trx_undo_page_get_start(undo_page, page_no, offset);
316
end = trx_undo_page_get_end(undo_page, page_no, offset);
323
return(undo_page + mach_read_from_2(undo_page + end - 2));
326
/******************************************************************//**
327
Returns the first undo record on the page in the specified undo log, or
329
@return pointer to record, NULL if none */
332
trx_undo_page_get_first_rec(
333
/*========================*/
334
page_t* undo_page,/*!< in: undo log page */
335
ulint page_no,/*!< in: undo log header page number */
336
ulint offset) /*!< in: undo log header offset on page */
341
start = trx_undo_page_get_start(undo_page, page_no, offset);
342
end = trx_undo_page_get_end(undo_page, page_no, offset);
349
return(undo_page + start);
351
#endif /* !UNIV_HOTBACKUP */