~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/mtr/mtr0log.c

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
/************************************************************
21
21
Catenates n bytes to the mtr log. */
22
 
 
 
22
UNIV_INTERN
23
23
void
24
24
mlog_catenate_string(
25
25
/*=================*/
43
43
Writes the initial part of a log record consisting of one-byte item
44
44
type and four-byte space and page numbers. Also pushes info
45
45
to the mtr memo that a buffer page has been modified. */
46
 
 
 
46
UNIV_INTERN
47
47
void
48
48
mlog_write_initial_log_record(
49
49
/*==========================*/
50
 
        byte*   ptr,    /* in: pointer to (inside) a buffer frame holding the
51
 
                        file page where modification is made */
52
 
        byte    type,   /* in: log item type: MLOG_1BYTE, ... */
53
 
        mtr_t*  mtr)    /* in: mini-transaction handle */
 
50
        const byte*     ptr,    /* in: pointer to (inside) a buffer
 
51
                                frame holding the file page where
 
52
                                modification is made */
 
53
        byte            type,   /* in: log item type: MLOG_1BYTE, ... */
 
54
        mtr_t*          mtr)    /* in: mini-transaction handle */
54
55
{
55
56
        byte*   log_ptr;
56
57
 
57
58
        ut_ad(type <= MLOG_BIGGEST_TYPE);
58
59
        ut_ad(type > MLOG_8BYTES);
59
60
 
60
 
        if (ptr < buf_pool->frame_zero || ptr >= buf_pool->high_end) {
61
 
                fprintf(stderr,
62
 
                        "InnoDB: Error: trying to write to"
63
 
                        " a stray memory location %p\n", (void*) ptr);
64
 
                ut_error;
65
 
        }
66
 
 
67
61
        log_ptr = mlog_open(mtr, 11);
68
62
 
69
63
        /* If no logging is requested, we may return now */
79
73
 
80
74
/************************************************************
81
75
Parses an initial log record written by mlog_write_initial_log_record. */
82
 
 
 
76
UNIV_INTERN
83
77
byte*
84
78
mlog_parse_initial_log_record(
85
79
/*==========================*/
120
114
 
121
115
/************************************************************
122
116
Parses a log record written by mlog_write_ulint or mlog_write_dulint. */
123
 
 
 
117
UNIV_INTERN
124
118
byte*
125
119
mlog_parse_nbytes(
126
120
/*==============*/
129
123
        ulint   type,   /* in: log record type: MLOG_1BYTE, ... */
130
124
        byte*   ptr,    /* in: buffer */
131
125
        byte*   end_ptr,/* in: buffer end */
132
 
        byte*   page)   /* in: page where to apply the log record, or NULL */
 
126
        byte*   page,   /* in: page where to apply the log record, or NULL */
 
127
        void*   page_zip)/* in/out: compressed page, or NULL */
133
128
{
134
129
        ulint   offset;
135
130
        ulint   val;
136
131
        dulint  dval;
137
132
 
138
133
        ut_a(type <= MLOG_8BYTES);
 
134
        ut_a(!page || !page_zip || fil_page_get_type(page) != FIL_PAGE_INDEX);
139
135
 
140
136
        if (end_ptr < ptr + 2) {
141
137
 
160
156
                }
161
157
 
162
158
                if (page) {
 
159
                        if (UNIV_LIKELY_NULL(page_zip)) {
 
160
                                mach_write_to_8
 
161
                                        (((page_zip_des_t*) page_zip)->data
 
162
                                         + offset, dval);
 
163
                        }
163
164
                        mach_write_to_8(page + offset, dval);
164
165
                }
165
166
 
173
174
                return(NULL);
174
175
        }
175
176
 
176
 
        if (type == MLOG_1BYTE) {
177
 
                if (val > 0xFFUL) {
178
 
                        recv_sys->found_corrupt_log = TRUE;
179
 
 
180
 
                        return(NULL);
181
 
                }
182
 
        } else if (type == MLOG_2BYTES) {
183
 
                if (val > 0xFFFFUL) {
184
 
                        recv_sys->found_corrupt_log = TRUE;
185
 
 
186
 
                        return(NULL);
187
 
                }
188
 
        } else {
189
 
                if (type != MLOG_4BYTES) {
190
 
                        recv_sys->found_corrupt_log = TRUE;
191
 
 
192
 
                        return(NULL);
193
 
                }
194
 
        }
195
 
 
196
 
        if (page) {
197
 
                if (type == MLOG_1BYTE) {
 
177
        switch (type) {
 
178
        case MLOG_1BYTE:
 
179
                if (UNIV_UNLIKELY(val > 0xFFUL)) {
 
180
                        goto corrupt;
 
181
                }
 
182
                if (page) {
 
183
                        if (UNIV_LIKELY_NULL(page_zip)) {
 
184
                                mach_write_to_1
 
185
                                        (((page_zip_des_t*) page_zip)->data
 
186
                                         + offset, val);
 
187
                        }
198
188
                        mach_write_to_1(page + offset, val);
199
 
                } else if (type == MLOG_2BYTES) {
 
189
                }
 
190
                break;
 
191
        case MLOG_2BYTES:
 
192
                if (UNIV_UNLIKELY(val > 0xFFFFUL)) {
 
193
                        goto corrupt;
 
194
                }
 
195
                if (page) {
 
196
                        if (UNIV_LIKELY_NULL(page_zip)) {
 
197
                                mach_write_to_2
 
198
                                        (((page_zip_des_t*) page_zip)->data
 
199
                                         + offset, val);
 
200
                        }
200
201
                        mach_write_to_2(page + offset, val);
201
 
                } else {
202
 
                        ut_a(type == MLOG_4BYTES);
 
202
                }
 
203
                break;
 
204
        case MLOG_4BYTES:
 
205
                if (page) {
 
206
                        if (UNIV_LIKELY_NULL(page_zip)) {
 
207
                                mach_write_to_4
 
208
                                        (((page_zip_des_t*) page_zip)->data
 
209
                                         + offset, val);
 
210
                        }
203
211
                        mach_write_to_4(page + offset, val);
204
212
                }
 
213
                break;
 
214
        default:
 
215
        corrupt:
 
216
                recv_sys->found_corrupt_log = TRUE;
 
217
                ptr = NULL;
205
218
        }
206
219
 
207
220
        return(ptr);
210
223
/************************************************************
211
224
Writes 1 - 4 bytes to a file page buffered in the buffer pool.
212
225
Writes the corresponding log record to the mini-transaction log. */
213
 
 
 
226
UNIV_INTERN
214
227
void
215
228
mlog_write_ulint(
216
229
/*=============*/
221
234
{
222
235
        byte*   log_ptr;
223
236
 
224
 
        if (ptr < buf_pool->frame_zero || ptr >= buf_pool->high_end) {
225
 
                fprintf(stderr,
226
 
                        "InnoDB: Error: trying to write to"
227
 
                        " a stray memory location %p\n", (void*) ptr);
228
 
                ut_error;
229
 
        }
230
 
 
231
 
        if (type == MLOG_1BYTE) {
 
237
        switch (type) {
 
238
        case MLOG_1BYTE:
232
239
                mach_write_to_1(ptr, val);
233
 
        } else if (type == MLOG_2BYTES) {
 
240
                break;
 
241
        case MLOG_2BYTES:
234
242
                mach_write_to_2(ptr, val);
235
 
        } else {
236
 
                ut_ad(type == MLOG_4BYTES);
 
243
                break;
 
244
        case MLOG_4BYTES:
237
245
                mach_write_to_4(ptr, val);
 
246
                break;
 
247
        default:
 
248
                ut_error;
238
249
        }
239
250
 
240
251
        log_ptr = mlog_open(mtr, 11 + 2 + 5);
247
258
 
248
259
        log_ptr = mlog_write_initial_log_record_fast(ptr, type, log_ptr, mtr);
249
260
 
250
 
        mach_write_to_2(log_ptr, ptr - buf_frame_align(ptr));
 
261
        mach_write_to_2(log_ptr, page_offset(ptr));
251
262
        log_ptr += 2;
252
263
 
253
264
        log_ptr += mach_write_compressed(log_ptr, val);
258
269
/************************************************************
259
270
Writes 8 bytes to a file page buffered in the buffer pool.
260
271
Writes the corresponding log record to the mini-transaction log. */
261
 
 
 
272
UNIV_INTERN
262
273
void
263
274
mlog_write_dulint(
264
275
/*==============*/
268
279
{
269
280
        byte*   log_ptr;
270
281
 
271
 
        if (UNIV_UNLIKELY(ptr < buf_pool->frame_zero)
272
 
            || UNIV_UNLIKELY(ptr >= buf_pool->high_end)) {
273
 
                fprintf(stderr,
274
 
                        "InnoDB: Error: trying to write to"
275
 
                        " a stray memory location %p\n", (void*) ptr);
276
 
                ut_error;
277
 
        }
278
 
 
279
282
        ut_ad(ptr && mtr);
280
283
 
281
284
        mach_write_to_8(ptr, val);
291
294
        log_ptr = mlog_write_initial_log_record_fast(ptr, MLOG_8BYTES,
292
295
                                                     log_ptr, mtr);
293
296
 
294
 
        mach_write_to_2(log_ptr, ptr - buf_frame_align(ptr));
 
297
        mach_write_to_2(log_ptr, page_offset(ptr));
295
298
        log_ptr += 2;
296
299
 
297
300
        log_ptr += mach_dulint_write_compressed(log_ptr, val);
302
305
/************************************************************
303
306
Writes a string to a file page buffered in the buffer pool. Writes the
304
307
corresponding log record to the mini-transaction log. */
305
 
 
 
308
UNIV_INTERN
306
309
void
307
310
mlog_write_string(
308
311
/*==============*/
311
314
        ulint           len,    /* in: string length */
312
315
        mtr_t*          mtr)    /* in: mini-transaction handle */
313
316
{
314
 
        byte*   log_ptr;
315
 
 
316
 
        if (UNIV_UNLIKELY(ptr < buf_pool->frame_zero)
317
 
            || UNIV_UNLIKELY(ptr >= buf_pool->high_end)) {
318
 
                fprintf(stderr,
319
 
                        "InnoDB: Error: trying to write to"
320
 
                        " a stray memory location %p\n", (void*) ptr);
321
 
                ut_error;
322
 
        }
323
317
        ut_ad(ptr && mtr);
324
318
        ut_a(len < UNIV_PAGE_SIZE);
325
319
 
326
 
        ut_memcpy(ptr, str, len);
 
320
        memcpy(ptr, str, len);
 
321
 
 
322
        mlog_log_string(ptr, len, mtr);
 
323
}
 
324
 
 
325
/************************************************************
 
326
Logs a write of a string to a file page buffered in the buffer pool.
 
327
Writes the corresponding log record to the mini-transaction log. */
 
328
UNIV_INTERN
 
329
void
 
330
mlog_log_string(
 
331
/*============*/
 
332
        byte*   ptr,    /* in: pointer written to */
 
333
        ulint   len,    /* in: string length */
 
334
        mtr_t*  mtr)    /* in: mini-transaction handle */
 
335
{
 
336
        byte*   log_ptr;
 
337
 
 
338
        ut_ad(ptr && mtr);
 
339
        ut_ad(len <= UNIV_PAGE_SIZE);
327
340
 
328
341
        log_ptr = mlog_open(mtr, 30);
329
342
 
335
348
 
336
349
        log_ptr = mlog_write_initial_log_record_fast(ptr, MLOG_WRITE_STRING,
337
350
                                                     log_ptr, mtr);
338
 
        mach_write_to_2(log_ptr, ptr - buf_frame_align(ptr));
 
351
        mach_write_to_2(log_ptr, page_offset(ptr));
339
352
        log_ptr += 2;
340
353
 
341
354
        mach_write_to_2(log_ptr, len);
343
356
 
344
357
        mlog_close(mtr, log_ptr);
345
358
 
346
 
        mlog_catenate_string(mtr, str, len);
 
359
        mlog_catenate_string(mtr, ptr, len);
347
360
}
348
361
 
349
362
/************************************************************
350
363
Parses a log record written by mlog_write_string. */
351
 
 
 
364
UNIV_INTERN
352
365
byte*
353
366
mlog_parse_string(
354
367
/*==============*/
356
369
                        record */
357
370
        byte*   ptr,    /* in: buffer */
358
371
        byte*   end_ptr,/* in: buffer end */
359
 
        byte*   page)   /* in: page where to apply the log record, or NULL */
 
372
        byte*   page,   /* in: page where to apply the log record, or NULL */
 
373
        void*   page_zip)/* in/out: compressed page, or NULL */
360
374
{
361
375
        ulint   offset;
362
376
        ulint   len;
363
377
 
 
378
        ut_a(!page || !page_zip || fil_page_get_type(page) != FIL_PAGE_INDEX);
 
379
 
364
380
        if (end_ptr < ptr + 4) {
365
381
 
366
382
                return(NULL);
368
384
 
369
385
        offset = mach_read_from_2(ptr);
370
386
        ptr += 2;
371
 
 
372
 
        if (offset >= UNIV_PAGE_SIZE) {
373
 
                recv_sys->found_corrupt_log = TRUE;
374
 
 
375
 
                return(NULL);
376
 
        }
377
 
 
378
387
        len = mach_read_from_2(ptr);
379
388
        ptr += 2;
380
389
 
381
 
        ut_a(len + offset < UNIV_PAGE_SIZE);
 
390
        if (UNIV_UNLIKELY(offset >= UNIV_PAGE_SIZE)
 
391
                        || UNIV_UNLIKELY(len + offset) > UNIV_PAGE_SIZE) {
 
392
                recv_sys->found_corrupt_log = TRUE;
 
393
 
 
394
                return(NULL);
 
395
        }
382
396
 
383
397
        if (end_ptr < ptr + len) {
384
398
 
386
400
        }
387
401
 
388
402
        if (page) {
389
 
                ut_memcpy(page + offset, ptr, len);
 
403
                if (UNIV_LIKELY_NULL(page_zip)) {
 
404
                        memcpy(((page_zip_des_t*) page_zip)->data
 
405
                                + offset, ptr, len);
 
406
                }
 
407
                memcpy(page + offset, ptr, len);
390
408
        }
391
409
 
392
410
        return(ptr + len);
395
413
/************************************************************
396
414
Opens a buffer for mlog, writes the initial log record and,
397
415
if needed, the field lengths of an index. */
398
 
 
 
416
UNIV_INTERN
399
417
byte*
400
418
mlog_open_and_write_index(
401
419
/*======================*/
492
510
 
493
511
/************************************************************
494
512
Parses a log record written by mlog_open_and_write_index. */
495
 
 
 
513
UNIV_INTERN
496
514
byte*
497
515
mlog_parse_index(
498
516
/*=============*/
549
567
                                len & 0x8000 ? DATA_NOT_NULL : 0,
550
568
                                len & 0x7fff);
551
569
 
552
 
                        dict_index_add_col(ind, table, (dict_col_t*)
 
570
                        dict_index_add_col(ind, table,
553
571
                                           dict_table_get_nth_col(table, i),
554
572
                                           0);
555
573
                }