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/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 */
43
#if DATA_ROLL_PTR_LEN != 7
44
# error "DATA_ROLL_PTR_LEN != 7"
46
ut_ad(is_insert == 0 || is_insert == 1);
47
ut_ad(rseg_id < TRX_SYS_N_RSEGS);
48
ut_ad(offset < 65536);
50
roll_ptr = (roll_ptr_t) is_insert << 55
51
| (roll_ptr_t) rseg_id << 48
52
| (roll_ptr_t) page_no << 16
57
/***********************************************************************//**
58
Decodes a roll pointer. */
61
trx_undo_decode_roll_ptr(
62
/*=====================*/
63
roll_ptr_t roll_ptr, /*!< in: roll pointer */
64
ibool* is_insert, /*!< out: TRUE if insert undo log */
65
ulint* rseg_id, /*!< out: rollback segment id */
66
ulint* page_no, /*!< out: page number */
67
ulint* offset) /*!< out: offset of the undo
70
#if DATA_ROLL_PTR_LEN != 7
71
# error "DATA_ROLL_PTR_LEN != 7"
76
ut_ad(roll_ptr < (1ULL << 56));
77
*offset = (ulint) roll_ptr & 0xFFFF;
79
*page_no = (ulint) roll_ptr & 0xFFFFFFFF;
81
*rseg_id = (ulint) roll_ptr & 0x7F;
83
*is_insert = (ibool) roll_ptr; /* TRUE==1 */
86
/***********************************************************************//**
87
Returns TRUE if the roll pointer is of the insert type.
88
@return TRUE if insert undo log */
91
trx_undo_roll_ptr_is_insert(
92
/*========================*/
93
roll_ptr_t roll_ptr) /*!< in: roll pointer */
95
#if DATA_ROLL_PTR_LEN != 7
96
# error "DATA_ROLL_PTR_LEN != 7"
101
ut_ad(roll_ptr < (1ULL << 56));
102
return((ibool) (roll_ptr >> 55));
104
#endif /* !UNIV_HOTBACKUP */
106
/*****************************************************************//**
107
Writes a roll ptr to an index page. In case that the size changes in
108
some future version, this function should be used instead of
114
byte* ptr, /*!< in: pointer to memory where
116
roll_ptr_t roll_ptr) /*!< in: roll ptr */
118
#if DATA_ROLL_PTR_LEN != 7
119
# error "DATA_ROLL_PTR_LEN != 7"
121
mach_write_to_7(ptr, roll_ptr);
124
/*****************************************************************//**
125
Reads a roll ptr from an index page. In case that the roll ptr size
126
changes in some future version, this function should be used instead of
133
const byte* ptr) /*!< in: pointer to memory from where to read */
135
#if DATA_ROLL_PTR_LEN != 7
136
# error "DATA_ROLL_PTR_LEN != 7"
138
return(mach_read_from_7(ptr));
141
#ifndef UNIV_HOTBACKUP
142
/******************************************************************//**
143
Gets an undo log page and x-latches it.
144
@return pointer to page x-latched */
149
ulint space, /*!< in: space where placed */
150
ulint zip_size, /*!< in: compressed page size in bytes
151
or 0 for uncompressed pages */
152
ulint page_no, /*!< in: page number */
153
mtr_t* mtr) /*!< in: mtr */
155
buf_block_t* block = buf_page_get(space, zip_size, page_no,
157
buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
159
return(buf_block_get_frame(block));
162
/******************************************************************//**
163
Gets an undo log page and s-latches it.
164
@return pointer to page s-latched */
167
trx_undo_page_get_s_latched(
168
/*========================*/
169
ulint space, /*!< in: space where placed */
170
ulint zip_size, /*!< in: compressed page size in bytes
171
or 0 for uncompressed pages */
172
ulint page_no, /*!< in: page number */
173
mtr_t* mtr) /*!< in: mtr */
175
buf_block_t* block = buf_page_get(space, zip_size, page_no,
177
buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
179
return(buf_block_get_frame(block));
182
/******************************************************************//**
183
Returns the start offset of the undo log records of the specified undo
185
@return start offset */
188
trx_undo_page_get_start(
189
/*====================*/
190
page_t* undo_page,/*!< in: undo log page */
191
ulint page_no,/*!< in: undo log header page number */
192
ulint offset) /*!< in: undo log header offset on page */
196
if (page_no == page_get_page_no(undo_page)) {
198
start = mach_read_from_2(offset + undo_page
199
+ TRX_UNDO_LOG_START);
201
start = TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE;
207
/******************************************************************//**
208
Returns the end offset of the undo log records of the specified undo
210
@return end offset */
213
trx_undo_page_get_end(
214
/*==================*/
215
page_t* undo_page,/*!< in: undo log page */
216
ulint page_no,/*!< in: undo log header page number */
217
ulint offset) /*!< in: undo log header offset on page */
219
trx_ulogf_t* log_hdr;
222
if (page_no == page_get_page_no(undo_page)) {
224
log_hdr = undo_page + offset;
226
end = mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG);
229
end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
230
+ TRX_UNDO_PAGE_FREE);
233
end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
234
+ TRX_UNDO_PAGE_FREE);
240
/******************************************************************//**
241
Returns the previous undo record on the page in the specified log, or
243
@return pointer to record, NULL if none */
246
trx_undo_page_get_prev_rec(
247
/*=======================*/
248
trx_undo_rec_t* rec, /*!< in: undo log record */
249
ulint page_no,/*!< in: undo log header page number */
250
ulint offset) /*!< in: undo log header offset on page */
255
undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
257
start = trx_undo_page_get_start(undo_page, page_no, offset);
259
if (start + undo_page == rec) {
264
return(undo_page + mach_read_from_2(rec - 2));
267
/******************************************************************//**
268
Returns the next undo log record on the page in the specified log, or
270
@return pointer to record, NULL if none */
273
trx_undo_page_get_next_rec(
274
/*=======================*/
275
trx_undo_rec_t* rec, /*!< in: undo log record */
276
ulint page_no,/*!< in: undo log header page number */
277
ulint offset) /*!< in: undo log header offset on page */
283
undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
285
end = trx_undo_page_get_end(undo_page, page_no, offset);
287
next = mach_read_from_2(rec);
294
return(undo_page + next);
297
/******************************************************************//**
298
Returns the last undo record on the page in the specified undo log, or
300
@return pointer to record, NULL if none */
303
trx_undo_page_get_last_rec(
304
/*=======================*/
305
page_t* undo_page,/*!< in: undo log page */
306
ulint page_no,/*!< in: undo log header page number */
307
ulint offset) /*!< in: undo log header offset on page */
312
start = trx_undo_page_get_start(undo_page, page_no, offset);
313
end = trx_undo_page_get_end(undo_page, page_no, offset);
320
return(undo_page + mach_read_from_2(undo_page + end - 2));
323
/******************************************************************//**
324
Returns the first undo record on the page in the specified undo log, or
326
@return pointer to record, NULL if none */
329
trx_undo_page_get_first_rec(
330
/*========================*/
331
page_t* undo_page,/*!< in: undo log page */
332
ulint page_no,/*!< in: undo log header page number */
333
ulint offset) /*!< in: undo log header offset on page */
338
start = trx_undo_page_get_start(undo_page, page_no, offset);
339
end = trx_undo_page_get_end(undo_page, page_no, offset);
346
return(undo_page + start);
348
#endif /* !UNIV_HOTBACKUP */