~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-11-16 05:36:13 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116053613-bld4rqxhlkb49c02
Split out cache_row and type_holder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Transaction undo log
 
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
 
6
Created 3/26/1996 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#include "data0type.h"
 
10
#include "page0page.h"
 
11
 
 
12
/***************************************************************************
 
13
Builds a roll pointer dulint. */
 
14
UNIV_INLINE
 
15
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 */
 
23
{
 
24
#if DATA_ROLL_PTR_LEN != 7
 
25
# error "DATA_ROLL_PTR_LEN != 7"
 
26
#endif
 
27
        ut_ad(rseg_id < 128);
 
28
 
 
29
        return(ut_dulint_create(is_insert * 128 * 256 * 256
 
30
                                + rseg_id * 256 * 256
 
31
                                + (page_no / 256) / 256,
 
32
                                (page_no % (256 * 256)) * 256 * 256
 
33
                                + offset));
 
34
}
 
35
 
 
36
/***************************************************************************
 
37
Decodes a roll pointer dulint. */
 
38
UNIV_INLINE
 
39
void
 
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 */
 
47
{
 
48
        ulint   low;
 
49
        ulint   high;
 
50
#if DATA_ROLL_PTR_LEN != 7
 
51
# error "DATA_ROLL_PTR_LEN != 7"
 
52
#endif
 
53
#if TRUE != 1
 
54
# error "TRUE != 1"
 
55
#endif
 
56
        high = ut_dulint_get_high(roll_ptr);
 
57
        low = ut_dulint_get_low(roll_ptr);
 
58
 
 
59
        *offset = low % (256 * 256);
 
60
 
 
61
        *is_insert = high / (256 * 256 * 128);  /* TRUE == 1 */
 
62
        *rseg_id = (high / (256 * 256)) % 128;
 
63
 
 
64
        *page_no = (high % (256 * 256)) * 256 * 256
 
65
                + (low / 256) / 256;
 
66
}
 
67
 
 
68
/***************************************************************************
 
69
Returns TRUE if the roll pointer is of the insert type. */
 
70
UNIV_INLINE
 
71
ibool
 
72
trx_undo_roll_ptr_is_insert(
 
73
/*========================*/
 
74
                                /* out: TRUE if insert undo log */
 
75
        dulint  roll_ptr)       /* in: roll pointer */
 
76
{
 
77
        ulint   high;
 
78
#if DATA_ROLL_PTR_LEN != 7
 
79
# error "DATA_ROLL_PTR_LEN != 7"
 
80
#endif
 
81
#if TRUE != 1
 
82
# error "TRUE != 1"
 
83
#endif
 
84
        high = ut_dulint_get_high(roll_ptr);
 
85
 
 
86
        return(high / (256 * 256 * 128));
 
87
}
 
88
 
 
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
 
92
mach_write_... */
 
93
UNIV_INLINE
 
94
void
 
95
trx_write_roll_ptr(
 
96
/*===============*/
 
97
        byte*   ptr,            /* in: pointer to memory where written */
 
98
        dulint  roll_ptr)       /* in: roll ptr */
 
99
{
 
100
#if DATA_ROLL_PTR_LEN != 7
 
101
# error "DATA_ROLL_PTR_LEN != 7"
 
102
#endif
 
103
        mach_write_to_7(ptr, roll_ptr);
 
104
}
 
105
 
 
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
 
109
mach_read_... */
 
110
UNIV_INLINE
 
111
dulint
 
112
trx_read_roll_ptr(
 
113
/*==============*/
 
114
                                /* out: roll ptr */
 
115
        const byte*     ptr)    /* in: pointer to memory from where to read */
 
116
{
 
117
#if DATA_ROLL_PTR_LEN != 7
 
118
# error "DATA_ROLL_PTR_LEN != 7"
 
119
#endif
 
120
        return(mach_read_from_7(ptr));
 
121
}
 
122
 
 
123
/**********************************************************************
 
124
Gets an undo log page and x-latches it. */
 
125
UNIV_INLINE
 
126
page_t*
 
127
trx_undo_page_get(
 
128
/*==============*/
 
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 */
 
135
{
 
136
        buf_block_t*    block = buf_page_get(space, zip_size, page_no,
 
137
                                             RW_X_LATCH, mtr);
 
138
#ifdef UNIV_SYNC_DEBUG
 
139
        buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
 
140
#endif /* UNIV_SYNC_DEBUG */
 
141
 
 
142
        return(buf_block_get_frame(block));
 
143
}
 
144
 
 
145
/**********************************************************************
 
146
Gets an undo log page and s-latches it. */
 
147
UNIV_INLINE
 
148
page_t*
 
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 */
 
157
{
 
158
        buf_block_t*    block = buf_page_get(space, zip_size, page_no,
 
159
                                             RW_S_LATCH, mtr);
 
160
#ifdef UNIV_SYNC_DEBUG
 
161
        buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
 
162
#endif /* UNIV_SYNC_DEBUG */
 
163
 
 
164
        return(buf_block_get_frame(block));
 
165
}
 
166
 
 
167
/**********************************************************************
 
168
Returns the start offset of the undo log records of the specified undo
 
169
log on the page. */
 
170
UNIV_INLINE
 
171
ulint
 
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 */
 
178
{
 
179
        ulint   start;
 
180
 
 
181
        if (page_no == page_get_page_no(undo_page)) {
 
182
 
 
183
                start = mach_read_from_2(offset + undo_page
 
184
                                         + TRX_UNDO_LOG_START);
 
185
        } else {
 
186
                start = TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE;
 
187
        }
 
188
 
 
189
        return(start);
 
190
}
 
191
 
 
192
/**********************************************************************
 
193
Returns the end offset of the undo log records of the specified undo
 
194
log on the page. */
 
195
UNIV_INLINE
 
196
ulint
 
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 */
 
203
{
 
204
        trx_ulogf_t*    log_hdr;
 
205
        ulint           end;
 
206
 
 
207
        if (page_no == page_get_page_no(undo_page)) {
 
208
 
 
209
                log_hdr = undo_page + offset;
 
210
 
 
211
                end = mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG);
 
212
 
 
213
                if (end == 0) {
 
214
                        end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
 
215
                                               + TRX_UNDO_PAGE_FREE);
 
216
                }
 
217
        } else {
 
218
                end = mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
 
219
                                       + TRX_UNDO_PAGE_FREE);
 
220
        }
 
221
 
 
222
        return(end);
 
223
}
 
224
 
 
225
/**********************************************************************
 
226
Returns the previous undo record on the page in the specified log, or
 
227
NULL if none exists. */
 
228
UNIV_INLINE
 
229
trx_undo_rec_t*
 
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 */
 
236
{
 
237
        page_t* undo_page;
 
238
        ulint   start;
 
239
 
 
240
        undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
 
241
 
 
242
        start = trx_undo_page_get_start(undo_page, page_no, offset);
 
243
 
 
244
        if (start + undo_page == rec) {
 
245
 
 
246
                return(NULL);
 
247
        }
 
248
 
 
249
        return(undo_page + mach_read_from_2(rec - 2));
 
250
}
 
251
 
 
252
/**********************************************************************
 
253
Returns the next undo log record on the page in the specified log, or
 
254
NULL if none exists. */
 
255
UNIV_INLINE
 
256
trx_undo_rec_t*
 
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 */
 
263
{
 
264
        page_t* undo_page;
 
265
        ulint   end;
 
266
        ulint   next;
 
267
 
 
268
        undo_page = (page_t*) ut_align_down(rec, UNIV_PAGE_SIZE);
 
269
 
 
270
        end = trx_undo_page_get_end(undo_page, page_no, offset);
 
271
 
 
272
        next = mach_read_from_2(rec);
 
273
 
 
274
        if (next == end) {
 
275
 
 
276
                return(NULL);
 
277
        }
 
278
 
 
279
        return(undo_page + next);
 
280
}
 
281
 
 
282
/**********************************************************************
 
283
Returns the last undo record on the page in the specified undo log, or
 
284
NULL if none exists. */
 
285
UNIV_INLINE
 
286
trx_undo_rec_t*
 
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 */
 
293
{
 
294
        ulint   start;
 
295
        ulint   end;
 
296
 
 
297
        start = trx_undo_page_get_start(undo_page, page_no, offset);
 
298
        end = trx_undo_page_get_end(undo_page, page_no, offset);
 
299
 
 
300
        if (start == end) {
 
301
 
 
302
                return(NULL);
 
303
        }
 
304
 
 
305
        return(undo_page + mach_read_from_2(undo_page + end - 2));
 
306
}
 
307
 
 
308
/**********************************************************************
 
309
Returns the first undo record on the page in the specified undo log, or
 
310
NULL if none exists. */
 
311
UNIV_INLINE
 
312
trx_undo_rec_t*
 
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 */
 
319
{
 
320
        ulint   start;
 
321
        ulint   end;
 
322
 
 
323
        start = trx_undo_page_get_start(undo_page, page_no, offset);
 
324
        end = trx_undo_page_get_end(undo_page, page_no, offset);
 
325
 
 
326
        if (start == end) {
 
327
 
 
328
                return(NULL);
 
329
        }
 
330
 
 
331
        return(undo_page + start);
 
332
}