~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: patrick crews
  • Date: 2010-09-29 15:15:19 UTC
  • mfrom: (1099.4.188 drizzle)
  • Revision ID: gleebix@gmail.com-20100929151519-6mrmzd1ciw2p9nws
Tags: 2010.09.1802
Update translations

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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 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
 
        roll_ptr_t      roll_ptr;
43
 
#if DATA_ROLL_PTR_LEN != 7
44
 
# error "DATA_ROLL_PTR_LEN != 7"
45
 
#endif
46
 
        ut_ad(is_insert == 0 || is_insert == 1);
47
 
        ut_ad(rseg_id < TRX_SYS_N_RSEGS);
48
 
        ut_ad(offset < 65536);
49
 
 
50
 
        roll_ptr = (roll_ptr_t) is_insert << 55
51
 
                | (roll_ptr_t) rseg_id << 48
52
 
                | (roll_ptr_t) page_no << 16
53
 
                | offset;
54
 
        return(roll_ptr);
55
 
}
56
 
 
57
 
/***********************************************************************//**
58
 
Decodes a roll pointer. */
59
 
UNIV_INLINE
60
 
void
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
68
 
                                        entry within page */
69
 
{
70
 
#if DATA_ROLL_PTR_LEN != 7
71
 
# error "DATA_ROLL_PTR_LEN != 7"
72
 
#endif
73
 
#if TRUE != 1
74
 
# error "TRUE != 1"
75
 
#endif
76
 
        ut_ad(roll_ptr < (1ULL << 56));
77
 
        *offset = (ulint) roll_ptr & 0xFFFF;
78
 
        roll_ptr >>= 16;
79
 
        *page_no = (ulint) roll_ptr & 0xFFFFFFFF;
80
 
        roll_ptr >>= 32;
81
 
        *rseg_id = (ulint) roll_ptr & 0x7F;
82
 
        roll_ptr >>= 7;
83
 
        *is_insert = (ibool) roll_ptr; /* TRUE==1 */
84
 
}
85
 
 
86
 
/***********************************************************************//**
87
 
Returns TRUE if the roll pointer is of the insert type.
88
 
@return TRUE if insert undo log */
89
 
UNIV_INLINE
90
 
ibool
91
 
trx_undo_roll_ptr_is_insert(
92
 
/*========================*/
93
 
        roll_ptr_t      roll_ptr)       /*!< in: roll pointer */
94
 
{
95
 
#if DATA_ROLL_PTR_LEN != 7
96
 
# error "DATA_ROLL_PTR_LEN != 7"
97
 
#endif
98
 
#if TRUE != 1
99
 
# error "TRUE != 1"
100
 
#endif
101
 
        ut_ad(roll_ptr < (1ULL << 56));
102
 
        return((ibool) (roll_ptr >> 55));
103
 
}
104
 
#endif /* !UNIV_HOTBACKUP */
105
 
 
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
109
 
mach_write_... */
110
 
UNIV_INLINE
111
 
void
112
 
trx_write_roll_ptr(
113
 
/*===============*/
114
 
        byte*           ptr,            /*!< in: pointer to memory where
115
 
                                        written */
116
 
        roll_ptr_t      roll_ptr)       /*!< in: roll ptr */
117
 
{
118
 
#if DATA_ROLL_PTR_LEN != 7
119
 
# error "DATA_ROLL_PTR_LEN != 7"
120
 
#endif
121
 
        mach_write_to_7(ptr, roll_ptr);
122
 
}
123
 
 
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
127
 
mach_read_...
128
 
@return roll ptr */
129
 
UNIV_INLINE
130
 
roll_ptr_t
131
 
trx_read_roll_ptr(
132
 
/*==============*/
133
 
        const byte*     ptr)    /*!< in: pointer to memory from where to read */
134
 
{
135
 
#if DATA_ROLL_PTR_LEN != 7
136
 
# error "DATA_ROLL_PTR_LEN != 7"
137
 
#endif
138
 
        return(mach_read_from_7(ptr));
139
 
}
140
 
 
141
 
#ifndef UNIV_HOTBACKUP
142
 
/******************************************************************//**
143
 
Gets an undo log page and x-latches it.
144
 
@return pointer to page x-latched */
145
 
UNIV_INLINE
146
 
page_t*
147
 
trx_undo_page_get(
148
 
/*==============*/
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 */
154
 
{
155
 
        buf_block_t*    block = buf_page_get(space, zip_size, page_no,
156
 
                                             RW_X_LATCH, mtr);
157
 
        buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
158
 
 
159
 
        return(buf_block_get_frame(block));
160
 
}
161
 
 
162
 
/******************************************************************//**
163
 
Gets an undo log page and s-latches it.
164
 
@return pointer to page s-latched */
165
 
UNIV_INLINE
166
 
page_t*
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 */
174
 
{
175
 
        buf_block_t*    block = buf_page_get(space, zip_size, page_no,
176
 
                                             RW_S_LATCH, mtr);
177
 
        buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
178
 
 
179
 
        return(buf_block_get_frame(block));
180
 
}
181
 
 
182
 
/******************************************************************//**
183
 
Returns the start offset of the undo log records of the specified undo
184
 
log on the page.
185
 
@return start offset */
186
 
UNIV_INLINE
187
 
ulint
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 */
193
 
{
194
 
        ulint   start;
195
 
 
196
 
        if (page_no == page_get_page_no(undo_page)) {
197
 
 
198
 
                start = mach_read_from_2(offset + undo_page
199
 
                                         + TRX_UNDO_LOG_START);
200
 
        } else {
201
 
                start = TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE;
202
 
        }
203
 
 
204
 
        return(start);
205
 
}
206
 
 
207
 
/******************************************************************//**
208
 
Returns the end offset of the undo log records of the specified undo
209
 
log on the page.
210
 
@return end offset */
211
 
UNIV_INLINE
212
 
ulint
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 */
218
 
{
219
 
        trx_ulogf_t*    log_hdr;
220
 
        ulint           end;
221
 
 
222
 
        if (page_no == page_get_page_no(undo_page)) {
223
 
 
224
 
                log_hdr = undo_page + offset;
225
 
 
226
 
                end = mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG);
227
 
 
228
 
                if (end == 0) {
229
 
                        end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
230
 
                                               + TRX_UNDO_PAGE_FREE);
231
 
                }
232
 
        } else {
233
 
                end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
234
 
                                       + TRX_UNDO_PAGE_FREE);
235
 
        }
236
 
 
237
 
        return(end);
238
 
}
239
 
 
240
 
/******************************************************************//**
241
 
Returns the previous undo record on the page in the specified log, or
242
 
NULL if none exists.
243
 
@return pointer to record, NULL if none */
244
 
UNIV_INLINE
245
 
trx_undo_rec_t*
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 */
251
 
{
252
 
        page_t* undo_page;
253
 
        ulint   start;
254
 
 
255
 
        undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
256
 
 
257
 
        start = trx_undo_page_get_start(undo_page, page_no, offset);
258
 
 
259
 
        if (start + undo_page == rec) {
260
 
 
261
 
                return(NULL);
262
 
        }
263
 
 
264
 
        return(undo_page + mach_read_from_2(rec - 2));
265
 
}
266
 
 
267
 
/******************************************************************//**
268
 
Returns the next undo log record on the page in the specified log, or
269
 
NULL if none exists.
270
 
@return pointer to record, NULL if none */
271
 
UNIV_INLINE
272
 
trx_undo_rec_t*
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 */
278
 
{
279
 
        page_t* undo_page;
280
 
        ulint   end;
281
 
        ulint   next;
282
 
 
283
 
        undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
284
 
 
285
 
        end = trx_undo_page_get_end(undo_page, page_no, offset);
286
 
 
287
 
        next = mach_read_from_2(rec);
288
 
 
289
 
        if (next == end) {
290
 
 
291
 
                return(NULL);
292
 
        }
293
 
 
294
 
        return(undo_page + next);
295
 
}
296
 
 
297
 
/******************************************************************//**
298
 
Returns the last undo record on the page in the specified undo log, or
299
 
NULL if none exists.
300
 
@return pointer to record, NULL if none */
301
 
UNIV_INLINE
302
 
trx_undo_rec_t*
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 */
308
 
{
309
 
        ulint   start;
310
 
        ulint   end;
311
 
 
312
 
        start = trx_undo_page_get_start(undo_page, page_no, offset);
313
 
        end = trx_undo_page_get_end(undo_page, page_no, offset);
314
 
 
315
 
        if (start == end) {
316
 
 
317
 
                return(NULL);
318
 
        }
319
 
 
320
 
        return(undo_page + mach_read_from_2(undo_page + end - 2));
321
 
}
322
 
 
323
 
/******************************************************************//**
324
 
Returns the first undo record on the page in the specified undo log, or
325
 
NULL if none exists.
326
 
@return pointer to record, NULL if none */
327
 
UNIV_INLINE
328
 
trx_undo_rec_t*
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 */
334
 
{
335
 
        ulint   start;
336
 
        ulint   end;
337
 
 
338
 
        start = trx_undo_page_get_start(undo_page, page_no, offset);
339
 
        end = trx_undo_page_get_end(undo_page, page_no, offset);
340
 
 
341
 
        if (start == end) {
342
 
 
343
 
                return(NULL);
344
 
        }
345
 
 
346
 
        return(undo_page + start);
347
 
}
348
 
#endif /* !UNIV_HOTBACKUP */