1
/******************************************************
6
Created 3/26/1996 Heikki Tuuri
7
*******************************************************/
10
#include "page0page.h"
12
/***************************************************************************
13
Builds a roll pointer dulint. */
16
trx_undo_build_roll_ptr(
17
/*====================*/
18
/* out: roll pointer */
19
ibool is_insert, /* in: TRUE if insert undo log */
20
ulint rseg_id, /* in: rollback segment id */
21
ulint page_no, /* in: page number */
22
ulint offset) /* in: offset of the undo entry within page */
24
#if DATA_ROLL_PTR_LEN != 7
25
# error "DATA_ROLL_PTR_LEN != 7"
29
return(ut_dulint_create(is_insert * 128 * 256 * 256
31
+ (page_no / 256) / 256,
32
(page_no % (256 * 256)) * 256 * 256
36
/***************************************************************************
37
Decodes a roll pointer dulint. */
40
trx_undo_decode_roll_ptr(
41
/*=====================*/
42
dulint roll_ptr, /* in: roll pointer */
43
ibool* is_insert, /* out: TRUE if insert undo log */
44
ulint* rseg_id, /* out: rollback segment id */
45
ulint* page_no, /* out: page number */
46
ulint* offset) /* out: offset of the undo entry within page */
50
#if DATA_ROLL_PTR_LEN != 7
51
# error "DATA_ROLL_PTR_LEN != 7"
56
high = ut_dulint_get_high(roll_ptr);
57
low = ut_dulint_get_low(roll_ptr);
59
*offset = low % (256 * 256);
61
*is_insert = high / (256 * 256 * 128); /* TRUE == 1 */
62
*rseg_id = (high / (256 * 256)) % 128;
64
*page_no = (high % (256 * 256)) * 256 * 256
68
/***************************************************************************
69
Returns TRUE if the roll pointer is of the insert type. */
72
trx_undo_roll_ptr_is_insert(
73
/*========================*/
74
/* out: TRUE if insert undo log */
75
dulint roll_ptr) /* in: roll pointer */
78
#if DATA_ROLL_PTR_LEN != 7
79
# error "DATA_ROLL_PTR_LEN != 7"
84
high = ut_dulint_get_high(roll_ptr);
86
return(high / (256 * 256 * 128));
89
/*********************************************************************
90
Writes a roll ptr to an index page. In case that the size changes in
91
some future version, this function should be used instead of
97
byte* ptr, /* in: pointer to memory where written */
98
dulint roll_ptr) /* in: roll ptr */
100
#if DATA_ROLL_PTR_LEN != 7
101
# error "DATA_ROLL_PTR_LEN != 7"
103
mach_write_to_7(ptr, roll_ptr);
106
/*********************************************************************
107
Reads a roll ptr from an index page. In case that the roll ptr size
108
changes in some future version, this function should be used instead of
115
const byte* ptr) /* in: pointer to memory from where to read */
117
#if DATA_ROLL_PTR_LEN != 7
118
# error "DATA_ROLL_PTR_LEN != 7"
120
return(mach_read_from_7(ptr));
123
/**********************************************************************
124
Gets an undo log page and x-latches it. */
129
/* out: pointer to page x-latched */
130
ulint space, /* in: space where placed */
131
ulint zip_size, /* in: compressed page size in bytes
132
or 0 for uncompressed pages */
133
ulint page_no, /* in: page number */
134
mtr_t* mtr) /* in: mtr */
136
buf_block_t* block = buf_page_get(space, zip_size, page_no,
138
#ifdef UNIV_SYNC_DEBUG
139
buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
140
#endif /* UNIV_SYNC_DEBUG */
142
return(buf_block_get_frame(block));
145
/**********************************************************************
146
Gets an undo log page and s-latches it. */
149
trx_undo_page_get_s_latched(
150
/*========================*/
151
/* out: pointer to page s-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
#ifdef UNIV_SYNC_DEBUG
161
buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
162
#endif /* UNIV_SYNC_DEBUG */
164
return(buf_block_get_frame(block));
167
/**********************************************************************
168
Returns the start offset of the undo log records of the specified undo
172
trx_undo_page_get_start(
173
/*====================*/
174
/* out: start offset */
175
page_t* undo_page,/* in: undo log page */
176
ulint page_no,/* in: undo log header page number */
177
ulint offset) /* in: undo log header offset on page */
181
if (page_no == page_get_page_no(undo_page)) {
183
start = mach_read_from_2(offset + undo_page
184
+ TRX_UNDO_LOG_START);
186
start = TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE;
192
/**********************************************************************
193
Returns the end offset of the undo log records of the specified undo
197
trx_undo_page_get_end(
198
/*==================*/
199
/* out: end offset */
200
page_t* undo_page,/* in: undo log page */
201
ulint page_no,/* in: undo log header page number */
202
ulint offset) /* in: undo log header offset on page */
204
trx_ulogf_t* log_hdr;
207
if (page_no == page_get_page_no(undo_page)) {
209
log_hdr = undo_page + offset;
211
end = mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG);
214
end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
215
+ TRX_UNDO_PAGE_FREE);
218
end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
219
+ TRX_UNDO_PAGE_FREE);
225
/**********************************************************************
226
Returns the previous undo record on the page in the specified log, or
227
NULL if none exists. */
230
trx_undo_page_get_prev_rec(
231
/*=======================*/
232
/* out: pointer to record, NULL if none */
233
trx_undo_rec_t* rec, /* in: undo log record */
234
ulint page_no,/* in: undo log header page number */
235
ulint offset) /* in: undo log header offset on page */
240
undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
242
start = trx_undo_page_get_start(undo_page, page_no, offset);
244
if (start + undo_page == rec) {
249
return(undo_page + mach_read_from_2(rec - 2));
252
/**********************************************************************
253
Returns the next undo log record on the page in the specified log, or
254
NULL if none exists. */
257
trx_undo_page_get_next_rec(
258
/*=======================*/
259
/* out: pointer to record, NULL if none */
260
trx_undo_rec_t* rec, /* in: undo log record */
261
ulint page_no,/* in: undo log header page number */
262
ulint offset) /* in: undo log header offset on page */
268
undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
270
end = trx_undo_page_get_end(undo_page, page_no, offset);
272
next = mach_read_from_2(rec);
279
return(undo_page + next);
282
/**********************************************************************
283
Returns the last undo record on the page in the specified undo log, or
284
NULL if none exists. */
287
trx_undo_page_get_last_rec(
288
/*=======================*/
289
/* out: pointer to record, NULL if none */
290
page_t* undo_page,/* in: undo log page */
291
ulint page_no,/* in: undo log header page number */
292
ulint offset) /* in: undo log header offset on page */
297
start = trx_undo_page_get_start(undo_page, page_no, offset);
298
end = trx_undo_page_get_end(undo_page, page_no, offset);
305
return(undo_page + mach_read_from_2(undo_page + end - 2));
308
/**********************************************************************
309
Returns the first undo record on the page in the specified undo log, or
310
NULL if none exists. */
313
trx_undo_page_get_first_rec(
314
/*========================*/
315
/* out: pointer to record, NULL if none */
316
page_t* undo_page,/* in: undo log page */
317
ulint page_no,/* in: undo log header page number */
318
ulint offset) /* in: undo log header offset on page */
323
start = trx_undo_page_get_start(undo_page, page_no, offset);
324
end = trx_undo_page_get_end(undo_page, page_no, offset);
331
return(undo_page + start);