~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

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
 
UNIV_INTERN
 
22
 
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
 
UNIV_INTERN
 
46
 
47
47
void
48
48
mlog_write_initial_log_record(
49
49
/*==========================*/
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 */
 
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 */
55
54
{
56
55
        byte*   log_ptr;
57
56
 
58
57
        ut_ad(type <= MLOG_BIGGEST_TYPE);
59
58
        ut_ad(type > MLOG_8BYTES);
60
59
 
 
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
 
61
67
        log_ptr = mlog_open(mtr, 11);
62
68
 
63
69
        /* If no logging is requested, we may return now */
73
79
 
74
80
/************************************************************
75
81
Parses an initial log record written by mlog_write_initial_log_record. */
76
 
UNIV_INTERN
 
82
 
77
83
byte*
78
84
mlog_parse_initial_log_record(
79
85
/*==========================*/
114
120
 
115
121
/************************************************************
116
122
Parses a log record written by mlog_write_ulint or mlog_write_dulint. */
117
 
UNIV_INTERN
 
123
 
118
124
byte*
119
125
mlog_parse_nbytes(
120
126
/*==============*/
123
129
        ulint   type,   /* in: log record type: MLOG_1BYTE, ... */
124
130
        byte*   ptr,    /* in: buffer */
125
131
        byte*   end_ptr,/* in: buffer end */
126
 
        byte*   page,   /* in: page where to apply the log record, or NULL */
127
 
        void*   page_zip)/* in/out: compressed page, or NULL */
 
132
        byte*   page)   /* in: page where to apply the log record, or NULL */
128
133
{
129
134
        ulint   offset;
130
135
        ulint   val;
131
136
        dulint  dval;
132
137
 
133
138
        ut_a(type <= MLOG_8BYTES);
134
 
        ut_a(!page || !page_zip || fil_page_get_type(page) != FIL_PAGE_INDEX);
135
139
 
136
140
        if (end_ptr < ptr + 2) {
137
141
 
156
160
                }
157
161
 
158
162
                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
 
                        }
164
163
                        mach_write_to_8(page + offset, dval);
165
164
                }
166
165
 
174
173
                return(NULL);
175
174
        }
176
175
 
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
 
                        }
 
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) {
188
198
                        mach_write_to_1(page + offset, val);
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
 
                        }
 
199
                } else if (type == MLOG_2BYTES) {
201
200
                        mach_write_to_2(page + offset, val);
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
 
                        }
 
201
                } else {
 
202
                        ut_a(type == MLOG_4BYTES);
211
203
                        mach_write_to_4(page + offset, val);
212
204
                }
213
 
                break;
214
 
        default:
215
 
        corrupt:
216
 
                recv_sys->found_corrupt_log = TRUE;
217
 
                ptr = NULL;
218
205
        }
219
206
 
220
207
        return(ptr);
223
210
/************************************************************
224
211
Writes 1 - 4 bytes to a file page buffered in the buffer pool.
225
212
Writes the corresponding log record to the mini-transaction log. */
226
 
UNIV_INTERN
 
213
 
227
214
void
228
215
mlog_write_ulint(
229
216
/*=============*/
234
221
{
235
222
        byte*   log_ptr;
236
223
 
237
 
        switch (type) {
238
 
        case MLOG_1BYTE:
 
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) {
239
232
                mach_write_to_1(ptr, val);
240
 
                break;
241
 
        case MLOG_2BYTES:
 
233
        } else if (type == MLOG_2BYTES) {
242
234
                mach_write_to_2(ptr, val);
243
 
                break;
244
 
        case MLOG_4BYTES:
 
235
        } else {
 
236
                ut_ad(type == MLOG_4BYTES);
245
237
                mach_write_to_4(ptr, val);
246
 
                break;
247
 
        default:
248
 
                ut_error;
249
238
        }
250
239
 
251
240
        log_ptr = mlog_open(mtr, 11 + 2 + 5);
258
247
 
259
248
        log_ptr = mlog_write_initial_log_record_fast(ptr, type, log_ptr, mtr);
260
249
 
261
 
        mach_write_to_2(log_ptr, page_offset(ptr));
 
250
        mach_write_to_2(log_ptr, ptr - buf_frame_align(ptr));
262
251
        log_ptr += 2;
263
252
 
264
253
        log_ptr += mach_write_compressed(log_ptr, val);
269
258
/************************************************************
270
259
Writes 8 bytes to a file page buffered in the buffer pool.
271
260
Writes the corresponding log record to the mini-transaction log. */
272
 
UNIV_INTERN
 
261
 
273
262
void
274
263
mlog_write_dulint(
275
264
/*==============*/
279
268
{
280
269
        byte*   log_ptr;
281
270
 
 
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
 
282
279
        ut_ad(ptr && mtr);
283
280
 
284
281
        mach_write_to_8(ptr, val);
294
291
        log_ptr = mlog_write_initial_log_record_fast(ptr, MLOG_8BYTES,
295
292
                                                     log_ptr, mtr);
296
293
 
297
 
        mach_write_to_2(log_ptr, page_offset(ptr));
 
294
        mach_write_to_2(log_ptr, ptr - buf_frame_align(ptr));
298
295
        log_ptr += 2;
299
296
 
300
297
        log_ptr += mach_dulint_write_compressed(log_ptr, val);
305
302
/************************************************************
306
303
Writes a string to a file page buffered in the buffer pool. Writes the
307
304
corresponding log record to the mini-transaction log. */
308
 
UNIV_INTERN
 
305
 
309
306
void
310
307
mlog_write_string(
311
308
/*==============*/
314
311
        ulint           len,    /* in: string length */
315
312
        mtr_t*          mtr)    /* in: mini-transaction handle */
316
313
{
 
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
        }
317
323
        ut_ad(ptr && mtr);
318
324
        ut_a(len < UNIV_PAGE_SIZE);
319
325
 
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);
 
326
        ut_memcpy(ptr, str, len);
340
327
 
341
328
        log_ptr = mlog_open(mtr, 30);
342
329
 
348
335
 
349
336
        log_ptr = mlog_write_initial_log_record_fast(ptr, MLOG_WRITE_STRING,
350
337
                                                     log_ptr, mtr);
351
 
        mach_write_to_2(log_ptr, page_offset(ptr));
 
338
        mach_write_to_2(log_ptr, ptr - buf_frame_align(ptr));
352
339
        log_ptr += 2;
353
340
 
354
341
        mach_write_to_2(log_ptr, len);
356
343
 
357
344
        mlog_close(mtr, log_ptr);
358
345
 
359
 
        mlog_catenate_string(mtr, ptr, len);
 
346
        mlog_catenate_string(mtr, str, len);
360
347
}
361
348
 
362
349
/************************************************************
363
350
Parses a log record written by mlog_write_string. */
364
 
UNIV_INTERN
 
351
 
365
352
byte*
366
353
mlog_parse_string(
367
354
/*==============*/
369
356
                        record */
370
357
        byte*   ptr,    /* in: buffer */
371
358
        byte*   end_ptr,/* in: buffer end */
372
 
        byte*   page,   /* in: page where to apply the log record, or NULL */
373
 
        void*   page_zip)/* in/out: compressed page, or NULL */
 
359
        byte*   page)   /* in: page where to apply the log record, or NULL */
374
360
{
375
361
        ulint   offset;
376
362
        ulint   len;
377
363
 
378
 
        ut_a(!page || !page_zip || fil_page_get_type(page) != FIL_PAGE_INDEX);
379
 
 
380
364
        if (end_ptr < ptr + 4) {
381
365
 
382
366
                return(NULL);
384
368
 
385
369
        offset = mach_read_from_2(ptr);
386
370
        ptr += 2;
 
371
 
 
372
        if (offset >= UNIV_PAGE_SIZE) {
 
373
                recv_sys->found_corrupt_log = TRUE;
 
374
 
 
375
                return(NULL);
 
376
        }
 
377
 
387
378
        len = mach_read_from_2(ptr);
388
379
        ptr += 2;
389
380
 
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
 
        }
 
381
        ut_a(len + offset < UNIV_PAGE_SIZE);
396
382
 
397
383
        if (end_ptr < ptr + len) {
398
384
 
400
386
        }
401
387
 
402
388
        if (page) {
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);
 
389
                ut_memcpy(page + offset, ptr, len);
408
390
        }
409
391
 
410
392
        return(ptr + len);
413
395
/************************************************************
414
396
Opens a buffer for mlog, writes the initial log record and,
415
397
if needed, the field lengths of an index. */
416
 
UNIV_INTERN
 
398
 
417
399
byte*
418
400
mlog_open_and_write_index(
419
401
/*======================*/
510
492
 
511
493
/************************************************************
512
494
Parses a log record written by mlog_open_and_write_index. */
513
 
UNIV_INTERN
 
495
 
514
496
byte*
515
497
mlog_parse_index(
516
498
/*=============*/
567
549
                                len & 0x8000 ? DATA_NOT_NULL : 0,
568
550
                                len & 0x7fff);
569
551
 
570
 
                        dict_index_add_col(ind, table,
 
552
                        dict_index_add_col(ind, table, (dict_col_t*)
571
553
                                           dict_table_get_nth_col(table, i),
572
554
                                           0);
573
555
                }