~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to plugin/innobase/include/trx0undo.ic

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
/**************************************************//**
 
20
@file include/trx0undo.ic
 
21
Transaction undo log
 
22
 
 
23
Created 3/26/1996 Heikki Tuuri
 
24
*******************************************************/
 
25
 
 
26
#include "data0type.h"
 
27
#include "page0page.h"
 
28
 
 
29
#ifndef UNIV_HOTBACKUP
 
30
/***********************************************************************//**
 
31
Builds a roll pointer.
 
32
@return roll pointer */
 
33
UNIV_INLINE
 
34
roll_ptr_t
 
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 */
 
41
{
 
42
#if DATA_ROLL_PTR_LEN != 7
 
43
# error "DATA_ROLL_PTR_LEN != 7"
 
44
#endif
 
45
        ut_ad(rseg_id < 128);
 
46
 
 
47
        return(ut_dulint_create(is_insert * 128 * 256 * 256
 
48
                                + rseg_id * 256 * 256
 
49
                                + (page_no / 256) / 256,
 
50
                                (page_no % (256 * 256)) * 256 * 256
 
51
                                + offset));
 
52
}
 
53
 
 
54
/***********************************************************************//**
 
55
Decodes a roll pointer. */
 
56
UNIV_INLINE
 
57
void
 
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
 
65
                                        entry within page */
 
66
{
 
67
        ulint   low;
 
68
        ulint   high;
 
69
#if DATA_ROLL_PTR_LEN != 7
 
70
# error "DATA_ROLL_PTR_LEN != 7"
 
71
#endif
 
72
#if TRUE != 1
 
73
# error "TRUE != 1"
 
74
#endif
 
75
        high = ut_dulint_get_high(roll_ptr);
 
76
        low = ut_dulint_get_low(roll_ptr);
 
77
 
 
78
        *offset = low % (256 * 256);
 
79
 
 
80
        *is_insert = high / (256 * 256 * 128);  /* TRUE == 1 */
 
81
        *rseg_id = (high / (256 * 256)) % 128;
 
82
 
 
83
        *page_no = (high % (256 * 256)) * 256 * 256
 
84
                + (low / 256) / 256;
 
85
}
 
86
 
 
87
/***********************************************************************//**
 
88
Returns TRUE if the roll pointer is of the insert type.
 
89
@return TRUE if insert undo log */
 
90
UNIV_INLINE
 
91
ibool
 
92
trx_undo_roll_ptr_is_insert(
 
93
/*========================*/
 
94
        roll_ptr_t      roll_ptr)       /*!< in: roll pointer */
 
95
{
 
96
        ulint   high;
 
97
#if DATA_ROLL_PTR_LEN != 7
 
98
# error "DATA_ROLL_PTR_LEN != 7"
 
99
#endif
 
100
#if TRUE != 1
 
101
# error "TRUE != 1"
 
102
#endif
 
103
        high = ut_dulint_get_high(roll_ptr);
 
104
 
 
105
        return(high / (256 * 256 * 128));
 
106
}
 
107
#endif /* !UNIV_HOTBACKUP */
 
108
 
 
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
 
112
mach_write_... */
 
113
UNIV_INLINE
 
114
void
 
115
trx_write_roll_ptr(
 
116
/*===============*/
 
117
        byte*           ptr,            /*!< in: pointer to memory where
 
118
                                        written */
 
119
        roll_ptr_t      roll_ptr)       /*!< in: roll ptr */
 
120
{
 
121
#if DATA_ROLL_PTR_LEN != 7
 
122
# error "DATA_ROLL_PTR_LEN != 7"
 
123
#endif
 
124
        mach_write_to_7(ptr, roll_ptr);
 
125
}
 
126
 
 
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
 
130
mach_read_...
 
131
@return roll ptr */
 
132
UNIV_INLINE
 
133
roll_ptr_t
 
134
trx_read_roll_ptr(
 
135
/*==============*/
 
136
        const byte*     ptr)    /*!< in: pointer to memory from where to read */
 
137
{
 
138
#if DATA_ROLL_PTR_LEN != 7
 
139
# error "DATA_ROLL_PTR_LEN != 7"
 
140
#endif
 
141
        return(mach_read_from_7(ptr));
 
142
}
 
143
 
 
144
#ifndef UNIV_HOTBACKUP
 
145
/******************************************************************//**
 
146
Gets an undo log page and x-latches it.
 
147
@return pointer to page x-latched */
 
148
UNIV_INLINE
 
149
page_t*
 
150
trx_undo_page_get(
 
151
/*==============*/
 
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 */
 
157
{
 
158
        buf_block_t*    block = buf_page_get(space, zip_size, page_no,
 
159
                                             RW_X_LATCH, mtr);
 
160
        buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
 
161
 
 
162
        return(buf_block_get_frame(block));
 
163
}
 
164
 
 
165
/******************************************************************//**
 
166
Gets an undo log page and s-latches it.
 
167
@return pointer to page s-latched */
 
168
UNIV_INLINE
 
169
page_t*
 
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 */
 
177
{
 
178
        buf_block_t*    block = buf_page_get(space, zip_size, page_no,
 
179
                                             RW_S_LATCH, mtr);
 
180
        buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
 
181
 
 
182
        return(buf_block_get_frame(block));
 
183
}
 
184
 
 
185
/******************************************************************//**
 
186
Returns the start offset of the undo log records of the specified undo
 
187
log on the page.
 
188
@return start offset */
 
189
UNIV_INLINE
 
190
ulint
 
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 */
 
196
{
 
197
        ulint   start;
 
198
 
 
199
        if (page_no == page_get_page_no(undo_page)) {
 
200
 
 
201
                start = mach_read_from_2(offset + undo_page
 
202
                                         + TRX_UNDO_LOG_START);
 
203
        } else {
 
204
                start = TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE;
 
205
        }
 
206
 
 
207
        return(start);
 
208
}
 
209
 
 
210
/******************************************************************//**
 
211
Returns the end offset of the undo log records of the specified undo
 
212
log on the page.
 
213
@return end offset */
 
214
UNIV_INLINE
 
215
ulint
 
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 */
 
221
{
 
222
        trx_ulogf_t*    log_hdr;
 
223
        ulint           end;
 
224
 
 
225
        if (page_no == page_get_page_no(undo_page)) {
 
226
 
 
227
                log_hdr = undo_page + offset;
 
228
 
 
229
                end = mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG);
 
230
 
 
231
                if (end == 0) {
 
232
                        end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
 
233
                                               + TRX_UNDO_PAGE_FREE);
 
234
                }
 
235
        } else {
 
236
                end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
 
237
                                       + TRX_UNDO_PAGE_FREE);
 
238
        }
 
239
 
 
240
        return(end);
 
241
}
 
242
 
 
243
/******************************************************************//**
 
244
Returns the previous undo record on the page in the specified log, or
 
245
NULL if none exists.
 
246
@return pointer to record, NULL if none */
 
247
UNIV_INLINE
 
248
trx_undo_rec_t*
 
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 */
 
254
{
 
255
        page_t* undo_page;
 
256
        ulint   start;
 
257
 
 
258
        undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
 
259
 
 
260
        start = trx_undo_page_get_start(undo_page, page_no, offset);
 
261
 
 
262
        if (start + undo_page == rec) {
 
263
 
 
264
                return(NULL);
 
265
        }
 
266
 
 
267
        return(undo_page + mach_read_from_2(rec - 2));
 
268
}
 
269
 
 
270
/******************************************************************//**
 
271
Returns the next undo log record on the page in the specified log, or
 
272
NULL if none exists.
 
273
@return pointer to record, NULL if none */
 
274
UNIV_INLINE
 
275
trx_undo_rec_t*
 
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 */
 
281
{
 
282
        page_t* undo_page;
 
283
        ulint   end;
 
284
        ulint   next;
 
285
 
 
286
        undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
 
287
 
 
288
        end = trx_undo_page_get_end(undo_page, page_no, offset);
 
289
 
 
290
        next = mach_read_from_2(rec);
 
291
 
 
292
        if (next == end) {
 
293
 
 
294
                return(NULL);
 
295
        }
 
296
 
 
297
        return(undo_page + next);
 
298
}
 
299
 
 
300
/******************************************************************//**
 
301
Returns the last undo record on the page in the specified undo log, or
 
302
NULL if none exists.
 
303
@return pointer to record, NULL if none */
 
304
UNIV_INLINE
 
305
trx_undo_rec_t*
 
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 */
 
311
{
 
312
        ulint   start;
 
313
        ulint   end;
 
314
 
 
315
        start = trx_undo_page_get_start(undo_page, page_no, offset);
 
316
        end = trx_undo_page_get_end(undo_page, page_no, offset);
 
317
 
 
318
        if (start == end) {
 
319
 
 
320
                return(NULL);
 
321
        }
 
322
 
 
323
        return(undo_page + mach_read_from_2(undo_page + end - 2));
 
324
}
 
325
 
 
326
/******************************************************************//**
 
327
Returns the first undo record on the page in the specified undo log, or
 
328
NULL if none exists.
 
329
@return pointer to record, NULL if none */
 
330
UNIV_INLINE
 
331
trx_undo_rec_t*
 
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 */
 
337
{
 
338
        ulint   start;
 
339
        ulint   end;
 
340
 
 
341
        start = trx_undo_page_get_start(undo_page, page_no, offset);
 
342
        end = trx_undo_page_get_end(undo_page, page_no, offset);
 
343
 
 
344
        if (start == end) {
 
345
 
 
346
                return(NULL);
 
347
        }
 
348
 
 
349
        return(undo_page + start);
 
350
}
 
351
#endif /* !UNIV_HOTBACKUP */