~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/trx/trx0undo.c

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

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 trx/trx0undo.c
 
1
/******************************************************
21
2
Transaction undo log
22
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
23
6
Created 3/26/1996 Heikki Tuuri
24
7
*******************************************************/
25
8
 
30
13
#endif
31
14
 
32
15
#include "fsp0fsp.h"
33
 
#ifndef UNIV_HOTBACKUP
34
16
#include "mach0data.h"
35
 
#include "mtr0log.h"
36
17
#include "trx0rseg.h"
37
18
#include "trx0trx.h"
38
19
#include "srv0srv.h"
39
20
#include "trx0rec.h"
40
21
#include "trx0purge.h"
 
22
#include "trx0xa.h"
41
23
 
42
24
/* How should the old versions in the history list be managed?
43
25
   ----------------------------------------------------------
93
75
of the list and release undo log segments. In stepping through the list,
94
76
s-latches on the undo log pages are enough, but in a truncate, x-latches must
95
77
be obtained on the rollback segment and individual pages. */
96
 
#endif /* !UNIV_HOTBACKUP */
97
78
 
98
 
/********************************************************************//**
 
79
/************************************************************************
99
80
Initializes the fields in an undo log segment page. */
100
81
static
101
82
void
102
83
trx_undo_page_init(
103
84
/*===============*/
104
 
        page_t* undo_page,      /*!< in: undo log segment page */
105
 
        ulint   type,           /*!< in: undo log segment type */
106
 
        mtr_t*  mtr);           /*!< in: mtr */
107
 
 
108
 
#ifndef UNIV_HOTBACKUP
109
 
/********************************************************************//**
110
 
Creates and initializes an undo log memory object.
111
 
@return own: the undo log memory object */
 
85
        page_t* undo_page,      /* in: undo log segment page */
 
86
        ulint   type,           /* in: undo log segment type */
 
87
        mtr_t*  mtr);           /* in: mtr */
 
88
/************************************************************************
 
89
Creates and initializes an undo log memory object. */
112
90
static
113
91
trx_undo_t*
114
92
trx_undo_mem_create(
115
93
/*================*/
116
 
        trx_rseg_t*     rseg,   /*!< in: rollback segment memory object */
117
 
        ulint           id,     /*!< in: slot index within rseg */
118
 
        ulint           type,   /*!< in: type of the log: TRX_UNDO_INSERT or
 
94
                                /* out, own: the undo log memory object */
 
95
        trx_rseg_t*     rseg,   /* in: rollback segment memory object */
 
96
        ulint           id,     /* in: slot index within rseg */
 
97
        ulint           type,   /* in: type of the log: TRX_UNDO_INSERT or
119
98
                                TRX_UNDO_UPDATE */
120
 
        trx_id_t        trx_id, /*!< in: id of the trx for which the undo log
 
99
        dulint          trx_id, /* in: id of the trx for which the undo log
121
100
                                is created */
122
 
        const XID*      xid,    /*!< in: X/Open XA transaction identification*/
123
 
        ulint           page_no,/*!< in: undo log header page number */
124
 
        ulint           offset);/*!< in: undo log header byte offset on page */
125
 
#endif /* !UNIV_HOTBACKUP */
126
 
/***************************************************************//**
 
101
        const XID*      xid,    /* in: X/Open XA transaction identification*/
 
102
        ulint           page_no,/* in: undo log header page number */
 
103
        ulint           offset);/* in: undo log header byte offset on page */
 
104
/*******************************************************************
127
105
Initializes a cached insert undo log header page for new use. NOTE that this
128
106
function has its own log record type MLOG_UNDO_HDR_REUSE. You must NOT change
129
 
the operation of this function!
130
 
@return undo log header byte offset on page */
 
107
the operation of this function! */
131
108
static
132
109
ulint
133
110
trx_undo_insert_header_reuse(
134
111
/*=========================*/
135
 
        page_t*         undo_page,      /*!< in/out: insert undo log segment
136
 
                                        header page, x-latched */
137
 
        trx_id_t        trx_id,         /*!< in: transaction id */
138
 
        mtr_t*          mtr);           /*!< in: mtr */
139
 
/**********************************************************************//**
 
112
                                /* out: undo log header byte offset on page */
 
113
        page_t* undo_page,      /* in: insert undo log segment header page,
 
114
                                x-latched */
 
115
        dulint  trx_id,         /* in: transaction id */
 
116
        mtr_t*  mtr);           /* in: mtr */
 
117
/**************************************************************************
140
118
If an update undo log can be discarded immediately, this function frees the
141
119
space, resetting the page to the proper state for caching. */
142
120
static
143
121
void
144
122
trx_undo_discard_latest_update_undo(
145
123
/*================================*/
146
 
        page_t* undo_page,      /*!< in: header page of an undo log of size 1 */
147
 
        mtr_t*  mtr);           /*!< in: mtr */
148
 
 
149
 
#ifndef UNIV_HOTBACKUP
150
 
/***********************************************************************//**
151
 
Gets the previous record in an undo log from the previous page.
152
 
@return undo log record, the page s-latched, NULL if none */
 
124
        page_t* undo_page,      /* in: header page of an undo log of size 1 */
 
125
        mtr_t*  mtr);           /* in: mtr */
 
126
 
 
127
 
 
128
/***************************************************************************
 
129
Gets the previous record in an undo log from the previous page. */
153
130
static
154
131
trx_undo_rec_t*
155
132
trx_undo_get_prev_rec_from_prev_page(
156
133
/*=================================*/
157
 
        trx_undo_rec_t* rec,    /*!< in: undo record */
158
 
        ulint           page_no,/*!< in: undo log header page number */
159
 
        ulint           offset, /*!< in: undo log header offset on page */
160
 
        mtr_t*          mtr)    /*!< in: mtr */
 
134
                                /* out: undo log record, the page s-latched,
 
135
                                NULL if none */
 
136
        trx_undo_rec_t* rec,    /* in: undo record */
 
137
        ulint           page_no,/* in: undo log header page number */
 
138
        ulint           offset, /* in: undo log header offset on page */
 
139
        mtr_t*          mtr)    /* in: mtr */
161
140
{
162
141
        ulint   space;
163
142
        ulint   zip_size;
185
164
        return(trx_undo_page_get_last_rec(prev_page, page_no, offset));
186
165
}
187
166
 
188
 
/***********************************************************************//**
189
 
Gets the previous record in an undo log.
190
 
@return undo log record, the page s-latched, NULL if none */
 
167
/***************************************************************************
 
168
Gets the previous record in an undo log. */
191
169
UNIV_INTERN
192
170
trx_undo_rec_t*
193
171
trx_undo_get_prev_rec(
194
172
/*==================*/
195
 
        trx_undo_rec_t* rec,    /*!< in: undo record */
196
 
        ulint           page_no,/*!< in: undo log header page number */
197
 
        ulint           offset, /*!< in: undo log header offset on page */
198
 
        mtr_t*          mtr)    /*!< in: mtr */
 
173
                                /* out: undo log record, the page s-latched,
 
174
                                NULL if none */
 
175
        trx_undo_rec_t* rec,    /* in: undo record */
 
176
        ulint           page_no,/* in: undo log header page number */
 
177
        ulint           offset, /* in: undo log header offset on page */
 
178
        mtr_t*          mtr)    /* in: mtr */
199
179
{
200
180
        trx_undo_rec_t* prev_rec;
201
181
 
213
193
                                                    mtr));
214
194
}
215
195
 
216
 
/***********************************************************************//**
217
 
Gets the next record in an undo log from the next page.
218
 
@return undo log record, the page latched, NULL if none */
 
196
/***************************************************************************
 
197
Gets the next record in an undo log from the next page. */
219
198
static
220
199
trx_undo_rec_t*
221
200
trx_undo_get_next_rec_from_next_page(
222
201
/*=================================*/
223
 
        ulint   space,  /*!< in: undo log header space */
224
 
        ulint   zip_size,/*!< in: compressed page size in bytes
 
202
                        /* out: undo log record, the page latched, NULL if
 
203
                        none */
 
204
        ulint   space,  /* in: undo log header space */
 
205
        ulint   zip_size,/* in: compressed page size in bytes
225
206
                        or 0 for uncompressed pages */
226
 
        page_t* undo_page, /*!< in: undo log page */
227
 
        ulint   page_no,/*!< in: undo log header page number */
228
 
        ulint   offset, /*!< in: undo log header offset on page */
229
 
        ulint   mode,   /*!< in: latch mode: RW_S_LATCH or RW_X_LATCH */
230
 
        mtr_t*  mtr)    /*!< in: mtr */
 
207
        page_t* undo_page, /* in: undo log page */
 
208
        ulint   page_no,/* in: undo log header page number */
 
209
        ulint   offset, /* in: undo log header offset on page */
 
210
        ulint   mode,   /* in: latch mode: RW_S_LATCH or RW_X_LATCH */
 
211
        mtr_t*  mtr)    /* in: mtr */
231
212
{
232
213
        trx_ulogf_t*    log_hdr;
233
214
        ulint           next_page_no;
265
246
        return(trx_undo_page_get_first_rec(next_page, page_no, offset));
266
247
}
267
248
 
268
 
/***********************************************************************//**
269
 
Gets the next record in an undo log.
270
 
@return undo log record, the page s-latched, NULL if none */
 
249
/***************************************************************************
 
250
Gets the next record in an undo log. */
271
251
UNIV_INTERN
272
252
trx_undo_rec_t*
273
253
trx_undo_get_next_rec(
274
254
/*==================*/
275
 
        trx_undo_rec_t* rec,    /*!< in: undo record */
276
 
        ulint           page_no,/*!< in: undo log header page number */
277
 
        ulint           offset, /*!< in: undo log header offset on page */
278
 
        mtr_t*          mtr)    /*!< in: mtr */
 
255
                                /* out: undo log record, the page s-latched,
 
256
                                NULL if none */
 
257
        trx_undo_rec_t* rec,    /* in: undo record */
 
258
        ulint           page_no,/* in: undo log header page number */
 
259
        ulint           offset, /* in: undo log header offset on page */
 
260
        mtr_t*          mtr)    /* in: mtr */
279
261
{
280
262
        ulint           space;
281
263
        ulint           zip_size;
296
278
                                                    RW_S_LATCH, mtr));
297
279
}
298
280
 
299
 
/***********************************************************************//**
300
 
Gets the first record in an undo log.
301
 
@return undo log record, the page latched, NULL if none */
 
281
/***************************************************************************
 
282
Gets the first record in an undo log. */
302
283
UNIV_INTERN
303
284
trx_undo_rec_t*
304
285
trx_undo_get_first_rec(
305
286
/*===================*/
306
 
        ulint   space,  /*!< in: undo log header space */
307
 
        ulint   zip_size,/*!< in: compressed page size in bytes
 
287
                        /* out: undo log record, the page latched, NULL if
 
288
                        none */
 
289
        ulint   space,  /* in: undo log header space */
 
290
        ulint   zip_size,/* in: compressed page size in bytes
308
291
                        or 0 for uncompressed pages */
309
 
        ulint   page_no,/*!< in: undo log header page number */
310
 
        ulint   offset, /*!< in: undo log header offset on page */
311
 
        ulint   mode,   /*!< in: latching mode: RW_S_LATCH or RW_X_LATCH */
312
 
        mtr_t*  mtr)    /*!< in: mtr */
 
292
        ulint   page_no,/* in: undo log header page number */
 
293
        ulint   offset, /* in: undo log header offset on page */
 
294
        ulint   mode,   /* in: latching mode: RW_S_LATCH or RW_X_LATCH */
 
295
        mtr_t*  mtr)    /* in: mtr */
313
296
{
314
297
        page_t*         undo_page;
315
298
        trx_undo_rec_t* rec;
334
317
 
335
318
/*============== UNDO LOG FILE COPY CREATION AND FREEING ==================*/
336
319
 
337
 
/**********************************************************************//**
 
320
/**************************************************************************
338
321
Writes the mtr log entry of an undo log page initialization. */
339
322
UNIV_INLINE
340
323
void
341
324
trx_undo_page_init_log(
342
325
/*===================*/
343
 
        page_t* undo_page,      /*!< in: undo log page */
344
 
        ulint   type,           /*!< in: undo log type */
345
 
        mtr_t*  mtr)            /*!< in: mtr */
 
326
        page_t* undo_page,      /* in: undo log page */
 
327
        ulint   type,           /* in: undo log type */
 
328
        mtr_t*  mtr)            /* in: mtr */
346
329
{
347
330
        mlog_write_initial_log_record(undo_page, MLOG_UNDO_INIT, mtr);
348
331
 
349
332
        mlog_catenate_ulint_compressed(mtr, type);
350
333
}
351
 
#else /* !UNIV_HOTBACKUP */
352
 
# define trx_undo_page_init_log(undo_page,type,mtr) ((void) 0)
353
 
#endif /* !UNIV_HOTBACKUP */
354
334
 
355
 
/***********************************************************//**
356
 
Parses the redo log entry of an undo log page initialization.
357
 
@return end of log record or NULL */
 
335
/***************************************************************
 
336
Parses the redo log entry of an undo log page initialization. */
358
337
UNIV_INTERN
359
338
byte*
360
339
trx_undo_parse_page_init(
361
340
/*=====================*/
362
 
        byte*   ptr,    /*!< in: buffer */
363
 
        byte*   end_ptr,/*!< in: buffer end */
364
 
        page_t* page,   /*!< in: page or NULL */
365
 
        mtr_t*  mtr)    /*!< in: mtr or NULL */
 
341
                        /* out: end of log record or NULL */
 
342
        byte*   ptr,    /* in: buffer */
 
343
        byte*   end_ptr,/* in: buffer end */
 
344
        page_t* page,   /* in: page or NULL */
 
345
        mtr_t*  mtr)    /* in: mtr or NULL */
366
346
{
367
347
        ulint   type;
368
348
 
380
360
        return(ptr);
381
361
}
382
362
 
383
 
/********************************************************************//**
 
363
/************************************************************************
384
364
Initializes the fields in an undo log segment page. */
385
365
static
386
366
void
387
367
trx_undo_page_init(
388
368
/*===============*/
389
 
        page_t* undo_page,      /*!< in: undo log segment page */
390
 
        ulint   type,           /*!< in: undo log segment type */
391
 
        mtr_t*  mtr)            /*!< in: mtr */
 
369
        page_t* undo_page,      /* in: undo log segment page */
 
370
        ulint   type,           /* in: undo log segment type */
 
371
        mtr_t*  mtr)            /* in: mtr */
392
372
{
393
373
        trx_upagef_t*   page_hdr;
394
374
 
406
386
        trx_undo_page_init_log(undo_page, type, mtr);
407
387
}
408
388
 
409
 
#ifndef UNIV_HOTBACKUP
410
 
/***************************************************************//**
411
 
Creates a new undo log segment in file.
412
 
@return DB_SUCCESS if page creation OK possible error codes are:
413
 
DB_TOO_MANY_CONCURRENT_TRXS DB_OUT_OF_FILE_SPACE */
 
389
/*******************************************************************
 
390
Creates a new undo log segment in file. */
414
391
static
415
392
ulint
416
393
trx_undo_seg_create(
417
394
/*================*/
418
 
        trx_rseg_t*     /*rseg*/,/*!< in: rollback segment */
419
 
        trx_rsegf_t*    rseg_hdr,/*!< in: rollback segment header, page
 
395
                                /* out: DB_SUCCESS if page creation OK
 
396
                                possible error codes are:
 
397
                                DB_TOO_MANY_CONCURRENT_TRXS
 
398
                                DB_OUT_OF_FILE_SPACE */
 
399
        trx_rseg_t*     rseg __attribute__((unused)),/* in: rollback segment */
 
400
        trx_rsegf_t*    rseg_hdr,/* in: rollback segment header, page
420
401
                                x-latched */
421
 
        ulint           type,   /*!< in: type of the segment: TRX_UNDO_INSERT or
 
402
        ulint           type,   /* in: type of the segment: TRX_UNDO_INSERT or
422
403
                                TRX_UNDO_UPDATE */
423
 
        ulint*          id,     /*!< out: slot index within rseg header */
 
404
        ulint*          id,     /* out: slot index within rseg header */
424
405
        page_t**        undo_page,
425
 
                                /*!< out: segment header page x-latched, NULL
 
406
                                /* out: segment header page x-latched, NULL
426
407
                                if there was an error */
427
 
        mtr_t*          mtr)    /*!< in: mtr */
 
408
        mtr_t*          mtr)    /* in: mtr */
428
409
{
429
410
        ulint           slot_no;
430
411
        ulint           space;
446
427
        if (slot_no == ULINT_UNDEFINED) {
447
428
                ut_print_timestamp(stderr);
448
429
                fprintf(stderr,
449
 
                        "  InnoDB: Warning: cannot find a free slot for"
 
430
                        "InnoDB: Warning: cannot find a free slot for"
450
431
                        " an undo log. Do you have too\n"
451
432
                        "InnoDB: many active transactions"
452
433
                        " running concurrently?\n");
503
484
        return(err);
504
485
}
505
486
 
506
 
/**********************************************************************//**
 
487
/**************************************************************************
507
488
Writes the mtr log entry of an undo log header initialization. */
508
489
UNIV_INLINE
509
490
void
510
491
trx_undo_header_create_log(
511
492
/*=======================*/
512
 
        const page_t*   undo_page,      /*!< in: undo log header page */
513
 
        trx_id_t        trx_id,         /*!< in: transaction id */
514
 
        mtr_t*          mtr)            /*!< in: mtr */
 
493
        page_t* undo_page,      /* in: undo log header page */
 
494
        dulint  trx_id,         /* in: transaction id */
 
495
        mtr_t*  mtr)            /* in: mtr */
515
496
{
516
497
        mlog_write_initial_log_record(undo_page, MLOG_UNDO_HDR_CREATE, mtr);
517
498
 
518
 
        mlog_catenate_ull_compressed(mtr, trx_id);
 
499
        mlog_catenate_dulint_compressed(mtr, trx_id);
519
500
}
520
 
#else /* !UNIV_HOTBACKUP */
521
 
# define trx_undo_header_create_log(undo_page,trx_id,mtr) ((void) 0)
522
 
#endif /* !UNIV_HOTBACKUP */
523
501
 
524
 
/***************************************************************//**
 
502
/*******************************************************************
525
503
Creates a new undo log header in file. NOTE that this function has its own
526
504
log record type MLOG_UNDO_HDR_CREATE. You must NOT change the operation of
527
 
this function!
528
 
@return header byte offset on page */
 
505
this function! */
529
506
static
530
507
ulint
531
508
trx_undo_header_create(
532
509
/*===================*/
533
 
        page_t*         undo_page,      /*!< in/out: undo log segment
534
 
                                        header page, x-latched; it is
535
 
                                        assumed that there is
536
 
                                        TRX_UNDO_LOG_XA_HDR_SIZE bytes
537
 
                                        free space on it */
538
 
        trx_id_t        trx_id,         /*!< in: transaction id */
539
 
        mtr_t*          mtr)            /*!< in: mtr */
 
510
                                /* out: header byte offset on page */
 
511
        page_t* undo_page,      /* in: undo log segment header page,
 
512
                                x-latched; it is assumed that there are
 
513
                                TRX_UNDO_LOG_XA_HDR_SIZE bytes free space
 
514
                                on it */
 
515
        dulint  trx_id,         /* in: transaction id */
 
516
        mtr_t*  mtr)            /* in: mtr */
540
517
{
541
518
        trx_upagef_t*   page_hdr;
542
519
        trx_usegf_t*    seg_hdr;
594
571
        return(free);
595
572
}
596
573
 
597
 
#ifndef UNIV_HOTBACKUP
598
 
/********************************************************************//**
 
574
/************************************************************************
599
575
Write X/Open XA Transaction Identification (XID) to undo log header */
600
576
static
601
577
void
602
578
trx_undo_write_xid(
603
579
/*===============*/
604
 
        trx_ulogf_t*    log_hdr,/*!< in: undo log header */
605
 
        const XID*      xid,    /*!< in: X/Open XA Transaction Identification */
606
 
        mtr_t*          mtr)    /*!< in: mtr */
 
580
        trx_ulogf_t*    log_hdr,/* in: undo log header */
 
581
        const XID*      xid,    /* in: X/Open XA Transaction Identification */
 
582
        mtr_t*          mtr)    /* in: mtr */
607
583
{
608
584
        mlog_write_ulint(log_hdr + TRX_UNDO_XA_FORMAT,
609
585
                         (ulint)xid->formatID, MLOG_4BYTES, mtr);
618
594
                          XIDDATASIZE, mtr);
619
595
}
620
596
 
621
 
/********************************************************************//**
 
597
/************************************************************************
622
598
Read X/Open XA Transaction Identification (XID) from undo log header */
623
599
static
624
600
void
625
601
trx_undo_read_xid(
626
602
/*==============*/
627
 
        trx_ulogf_t*    log_hdr,/*!< in: undo log header */
628
 
        XID*            xid)    /*!< out: X/Open XA Transaction Identification */
 
603
        trx_ulogf_t*    log_hdr,/* in: undo log header */
 
604
        XID*            xid)    /* out: X/Open XA Transaction Identification */
629
605
{
630
606
        xid->formatID = (long)mach_read_from_4(log_hdr + TRX_UNDO_XA_FORMAT);
631
607
 
637
613
        memcpy(xid->data, log_hdr + TRX_UNDO_XA_XID, XIDDATASIZE);
638
614
}
639
615
 
640
 
/***************************************************************//**
 
616
/*******************************************************************
641
617
Adds space for the XA XID after an undo log old-style header. */
642
618
static
643
619
void
644
620
trx_undo_header_add_space_for_xid(
645
621
/*==============================*/
646
 
        page_t*         undo_page,/*!< in: undo log segment header page */
647
 
        trx_ulogf_t*    log_hdr,/*!< in: undo log header */
648
 
        mtr_t*          mtr)    /*!< in: mtr */
 
622
        page_t*         undo_page,/* in: undo log segment header page */
 
623
        trx_ulogf_t*    log_hdr,/* in: undo log header */
 
624
        mtr_t*          mtr)    /* in: mtr */
649
625
{
650
626
        trx_upagef_t*   page_hdr;
651
627
        ulint           free;
675
651
                         MLOG_2BYTES, mtr);
676
652
}
677
653
 
678
 
/**********************************************************************//**
 
654
/**************************************************************************
679
655
Writes the mtr log entry of an undo log header reuse. */
680
656
UNIV_INLINE
681
657
void
682
658
trx_undo_insert_header_reuse_log(
683
659
/*=============================*/
684
 
        const page_t*   undo_page,      /*!< in: undo log header page */
685
 
        trx_id_t        trx_id,         /*!< in: transaction id */
686
 
        mtr_t*          mtr)            /*!< in: mtr */
 
660
        page_t* undo_page,      /* in: undo log header page */
 
661
        dulint  trx_id,         /* in: transaction id */
 
662
        mtr_t*  mtr)            /* in: mtr */
687
663
{
688
664
        mlog_write_initial_log_record(undo_page, MLOG_UNDO_HDR_REUSE, mtr);
689
665
 
690
 
        mlog_catenate_ull_compressed(mtr, trx_id);
 
666
        mlog_catenate_dulint_compressed(mtr, trx_id);
691
667
}
692
 
#else /* !UNIV_HOTBACKUP */
693
 
# define trx_undo_insert_header_reuse_log(undo_page,trx_id,mtr) ((void) 0)
694
 
#endif /* !UNIV_HOTBACKUP */
695
668
 
696
 
/***********************************************************//**
697
 
Parses the redo log entry of an undo log page header create or reuse.
698
 
@return end of log record or NULL */
 
669
/***************************************************************
 
670
Parses the redo log entry of an undo log page header create or reuse. */
699
671
UNIV_INTERN
700
672
byte*
701
673
trx_undo_parse_page_header(
702
674
/*=======================*/
703
 
        ulint   type,   /*!< in: MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE */
704
 
        byte*   ptr,    /*!< in: buffer */
705
 
        byte*   end_ptr,/*!< in: buffer end */
706
 
        page_t* page,   /*!< in: page or NULL */
707
 
        mtr_t*  mtr)    /*!< in: mtr or NULL */
 
675
                        /* out: end of log record or NULL */
 
676
        ulint   type,   /* in: MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE */
 
677
        byte*   ptr,    /* in: buffer */
 
678
        byte*   end_ptr,/* in: buffer end */
 
679
        page_t* page,   /* in: page or NULL */
 
680
        mtr_t*  mtr)    /* in: mtr or NULL */
708
681
{
709
 
        trx_id_t        trx_id;
710
 
        /* Silence a GCC warning about possibly uninitialized variable
711
 
        when mach_ull_parse_compressed() is not inlined. */
712
 
        ut_d(trx_id = 0);
713
 
        /* Declare the variable uninitialized in Valgrind, so that the
714
 
        above initialization will not mask any bugs. */
715
 
        UNIV_MEM_INVALID(&trx_id, sizeof trx_id);
 
682
        dulint  trx_id;
716
683
 
717
 
        ptr = mach_ull_parse_compressed(ptr, end_ptr, &trx_id);
 
684
        ptr = mach_dulint_parse_compressed(ptr, end_ptr, &trx_id);
718
685
 
719
686
        if (ptr == NULL) {
720
687
 
733
700
        return(ptr);
734
701
}
735
702
 
736
 
/***************************************************************//**
 
703
/*******************************************************************
737
704
Initializes a cached insert undo log header page for new use. NOTE that this
738
705
function has its own log record type MLOG_UNDO_HDR_REUSE. You must NOT change
739
 
the operation of this function!
740
 
@return undo log header byte offset on page */
 
706
the operation of this function! */
741
707
static
742
708
ulint
743
709
trx_undo_insert_header_reuse(
744
710
/*=========================*/
745
 
        page_t*         undo_page,      /*!< in/out: insert undo log segment
746
 
                                        header page, x-latched */
747
 
        trx_id_t        trx_id,         /*!< in: transaction id */
748
 
        mtr_t*          mtr)            /*!< in: mtr */
 
711
                                /* out: undo log header byte offset on page */
 
712
        page_t* undo_page,      /* in: insert undo log segment header page,
 
713
                                x-latched */
 
714
        dulint  trx_id,         /* in: transaction id */
 
715
        mtr_t*  mtr)            /* in: mtr */
749
716
{
750
717
        trx_upagef_t*   page_hdr;
751
718
        trx_usegf_t*    seg_hdr;
793
760
        return(free);
794
761
}
795
762
 
796
 
#ifndef UNIV_HOTBACKUP
797
 
/**********************************************************************//**
 
763
/**************************************************************************
798
764
Writes the redo log entry of an update undo log header discard. */
799
765
UNIV_INLINE
800
766
void
801
767
trx_undo_discard_latest_log(
802
768
/*========================*/
803
 
        page_t* undo_page,      /*!< in: undo log header page */
804
 
        mtr_t*  mtr)            /*!< in: mtr */
 
769
        page_t* undo_page,      /* in: undo log header page */
 
770
        mtr_t*  mtr)            /* in: mtr */
805
771
{
806
772
        mlog_write_initial_log_record(undo_page, MLOG_UNDO_HDR_DISCARD, mtr);
807
773
}
808
 
#else /* !UNIV_HOTBACKUP */
809
 
# define trx_undo_discard_latest_log(undo_page, mtr) ((void) 0)
810
 
#endif /* !UNIV_HOTBACKUP */
811
774
 
812
 
/***********************************************************//**
813
 
Parses the redo log entry of an undo log page header discard.
814
 
@return end of log record or NULL */
 
775
/***************************************************************
 
776
Parses the redo log entry of an undo log page header discard. */
815
777
UNIV_INTERN
816
778
byte*
817
779
trx_undo_parse_discard_latest(
818
780
/*==========================*/
819
 
        byte*   ptr,    /*!< in: buffer */
820
 
        byte*   /*end_ptr*/, /*!< in: buffer end */
821
 
        page_t* page,   /*!< in: page or NULL */
822
 
        mtr_t*  mtr)    /*!< in: mtr or NULL */
 
781
                        /* out: end of log record or NULL */
 
782
        byte*   ptr,    /* in: buffer */
 
783
        byte*   end_ptr __attribute__((unused)), /* in: buffer end */
 
784
        page_t* page,   /* in: page or NULL */
 
785
        mtr_t*  mtr)    /* in: mtr or NULL */
823
786
{
824
787
        ut_ad(end_ptr);
825
788
 
830
793
        return(ptr);
831
794
}
832
795
 
833
 
/**********************************************************************//**
 
796
/**************************************************************************
834
797
If an update undo log can be discarded immediately, this function frees the
835
798
space, resetting the page to the proper state for caching. */
836
799
static
837
800
void
838
801
trx_undo_discard_latest_update_undo(
839
802
/*================================*/
840
 
        page_t* undo_page,      /*!< in: header page of an undo log of size 1 */
841
 
        mtr_t*  mtr)            /*!< in: mtr */
 
803
        page_t* undo_page,      /* in: header page of an undo log of size 1 */
 
804
        mtr_t*  mtr)            /* in: mtr */
842
805
{
843
806
        trx_usegf_t*    seg_hdr;
844
807
        trx_upagef_t*   page_hdr;
872
835
        trx_undo_discard_latest_log(undo_page, mtr);
873
836
}
874
837
 
875
 
#ifndef UNIV_HOTBACKUP
876
 
/********************************************************************//**
877
 
Tries to add a page to the undo log segment where the undo log is placed.
878
 
@return page number if success, else FIL_NULL */
 
838
/************************************************************************
 
839
Tries to add a page to the undo log segment where the undo log is placed. */
879
840
UNIV_INTERN
880
841
ulint
881
842
trx_undo_add_page(
882
843
/*==============*/
883
 
        trx_t*          trx,    /*!< in: transaction */
884
 
        trx_undo_t*     undo,   /*!< in: undo log memory object */
885
 
        mtr_t*          mtr)    /*!< in: mtr which does not have a latch to any
 
844
                                /* out: page number if success, else
 
845
                                FIL_NULL */
 
846
        trx_t*          trx,    /* in: transaction */
 
847
        trx_undo_t*     undo,   /* in: undo log memory object */
 
848
        mtr_t*          mtr)    /* in: mtr which does not have a latch to any
886
849
                                undo log page; the caller must have reserved
887
850
                                the rollback segment mutex */
888
851
{
943
906
        return(page_no);
944
907
}
945
908
 
946
 
/********************************************************************//**
947
 
Frees an undo log page that is not the header page.
948
 
@return last page number in remaining log */
 
909
/************************************************************************
 
910
Frees an undo log page that is not the header page. */
949
911
static
950
912
ulint
951
913
trx_undo_free_page(
952
914
/*===============*/
953
 
        trx_rseg_t* rseg,       /*!< in: rollback segment */
954
 
        ibool   in_history,     /*!< in: TRUE if the undo log is in the history
 
915
                                /* out: last page number in remaining log */
 
916
        trx_rseg_t* rseg,       /* in: rollback segment */
 
917
        ibool   in_history,     /* in: TRUE if the undo log is in the history
955
918
                                list */
956
 
        ulint   space,          /*!< in: space */
957
 
        ulint   hdr_page_no,    /*!< in: header page number */
958
 
        ulint   page_no,        /*!< in: page number to free: must not be the
 
919
        ulint   space,          /* in: space */
 
920
        ulint   hdr_page_no,    /* in: header page number */
 
921
        ulint   page_no,        /* in: page number to free: must not be the
959
922
                                header page */
960
 
        mtr_t*  mtr)            /*!< in: mtr which does not have a latch to any
 
923
        mtr_t*  mtr)            /* in: mtr which does not have a latch to any
961
924
                                undo log page; the caller must have reserved
962
925
                                the rollback segment mutex */
963
926
{
1002
965
        return(last_addr.page);
1003
966
}
1004
967
 
1005
 
/********************************************************************//**
 
968
/************************************************************************
1006
969
Frees an undo log page when there is also the memory object for the undo
1007
970
log. */
1008
971
static
1009
972
void
1010
973
trx_undo_free_page_in_rollback(
1011
974
/*===========================*/
1012
 
        trx_t*          /*trx*/, /*!< in: transaction */
1013
 
        trx_undo_t*     undo,   /*!< in: undo log memory copy */
1014
 
        ulint           page_no,/*!< in: page number to free: must not be the
 
975
        trx_t*          trx __attribute__((unused)), /* in: transaction */
 
976
        trx_undo_t*     undo,   /* in: undo log memory copy */
 
977
        ulint           page_no,/* in: page number to free: must not be the
1015
978
                                header page */
1016
 
        mtr_t*          mtr)    /*!< in: mtr which does not have a latch to any
 
979
        mtr_t*          mtr)    /* in: mtr which does not have a latch to any
1017
980
                                undo log page; the caller must have reserved
1018
981
                                the rollback segment mutex */
1019
982
{
1029
992
        undo->size--;
1030
993
}
1031
994
 
1032
 
/********************************************************************//**
 
995
/************************************************************************
1033
996
Empties an undo log header page of undo records for that undo log. Other
1034
997
undo logs may still have records on that page, if it is an update undo log. */
1035
998
static
1036
999
void
1037
1000
trx_undo_empty_header_page(
1038
1001
/*=======================*/
1039
 
        ulint   space,          /*!< in: space */
1040
 
        ulint   zip_size,       /*!< in: compressed page size in bytes
 
1002
        ulint   space,          /* in: space */
 
1003
        ulint   zip_size,       /* in: compressed page size in bytes
1041
1004
                                or 0 for uncompressed pages */
1042
 
        ulint   hdr_page_no,    /*!< in: header page number */
1043
 
        ulint   hdr_offset,     /*!< in: header offset */
1044
 
        mtr_t*  mtr)            /*!< in: mtr */
 
1005
        ulint   hdr_page_no,    /* in: header page number */
 
1006
        ulint   hdr_offset,     /* in: header offset */
 
1007
        mtr_t*  mtr)            /* in: mtr */
1045
1008
{
1046
1009
        page_t*         header_page;
1047
1010
        trx_ulogf_t*    log_hdr;
1056
1019
        mlog_write_ulint(log_hdr + TRX_UNDO_LOG_START, end, MLOG_2BYTES, mtr);
1057
1020
}
1058
1021
 
1059
 
/***********************************************************************//**
 
1022
/***************************************************************************
1060
1023
Truncates an undo log from the end. This function is used during a rollback
1061
1024
to free space from an undo log. */
1062
1025
UNIV_INTERN
1063
1026
void
1064
1027
trx_undo_truncate_end(
1065
1028
/*==================*/
1066
 
        trx_t*          trx,    /*!< in: transaction whose undo log it is */
1067
 
        trx_undo_t*     undo,   /*!< in: undo log */
1068
 
        undo_no_t       limit)  /*!< in: all undo records with undo number
 
1029
        trx_t*          trx,    /* in: transaction whose undo log it is */
 
1030
        trx_undo_t*     undo,   /* in: undo log */
 
1031
        dulint          limit)  /* in: all undo records with undo number
1069
1032
                                >= this value should be truncated */
1070
1033
{
1071
1034
        page_t*         undo_page;
1072
1035
        ulint           last_page_no;
1073
1036
        trx_undo_rec_t* rec;
1074
1037
        trx_undo_rec_t* trunc_here;
 
1038
        trx_rseg_t*     rseg;
1075
1039
        mtr_t           mtr;
1076
1040
 
1077
1041
        ut_ad(mutex_own(&(trx->undo_mutex)));
1078
1042
        ut_ad(mutex_own(&(trx->rseg->mutex)));
1079
1043
 
 
1044
        rseg = trx->rseg;
 
1045
 
1080
1046
        for (;;) {
1081
1047
                mtr_start(&mtr);
1082
1048
 
1101
1067
                                break;
1102
1068
                        }
1103
1069
 
1104
 
                        if (trx_undo_rec_get_undo_no(rec) >= limit) {
 
1070
                        if (ut_dulint_cmp(trx_undo_rec_get_undo_no(rec), limit)
 
1071
                            >= 0) {
1105
1072
                                /* Truncate at least this record off, maybe
1106
1073
                                more */
1107
1074
                                trunc_here = rec;
1127
1094
        mtr_commit(&mtr);
1128
1095
}
1129
1096
 
1130
 
/***********************************************************************//**
 
1097
/***************************************************************************
1131
1098
Truncates an undo log from the start. This function is used during a purge
1132
1099
operation. */
1133
1100
UNIV_INTERN
1134
1101
void
1135
1102
trx_undo_truncate_start(
1136
1103
/*====================*/
1137
 
        trx_rseg_t*     rseg,           /*!< in: rollback segment */
1138
 
        ulint           space,          /*!< in: space id of the log */
1139
 
        ulint           hdr_page_no,    /*!< in: header page number */
1140
 
        ulint           hdr_offset,     /*!< in: header offset on the page */
1141
 
        undo_no_t       limit)          /*!< in: all undo pages with
1142
 
                                        undo numbers < this value
1143
 
                                        should be truncated; NOTE that
1144
 
                                        the function only frees whole
1145
 
                                        pages; the header page is not
1146
 
                                        freed, but emptied, if all the
1147
 
                                        records there are < limit */
 
1104
        trx_rseg_t* rseg,       /* in: rollback segment */
 
1105
        ulint   space,          /* in: space id of the log */
 
1106
        ulint   hdr_page_no,    /* in: header page number */
 
1107
        ulint   hdr_offset,     /* in: header offset on the page */
 
1108
        dulint  limit)          /* in: all undo pages with undo numbers <
 
1109
                                this value should be truncated; NOTE that
 
1110
                                the function only frees whole pages; the
 
1111
                                header page is not freed, but emptied, if
 
1112
                                all the records there are < limit */
1148
1113
{
1149
1114
        page_t*         undo_page;
1150
1115
        trx_undo_rec_t* rec;
1154
1119
 
1155
1120
        ut_ad(mutex_own(&(rseg->mutex)));
1156
1121
 
1157
 
        if (!limit) {
 
1122
        if (ut_dulint_is_zero(limit)) {
1158
1123
 
1159
1124
                return;
1160
1125
        }
1176
1141
 
1177
1142
        last_rec = trx_undo_page_get_last_rec(undo_page, hdr_page_no,
1178
1143
                                              hdr_offset);
1179
 
        if (trx_undo_rec_get_undo_no(last_rec) >= limit) {
 
1144
        if (ut_dulint_cmp(trx_undo_rec_get_undo_no(last_rec), limit) >= 0) {
1180
1145
 
1181
1146
                mtr_commit(&mtr);
1182
1147
 
1199
1164
        goto loop;
1200
1165
}
1201
1166
 
1202
 
/**********************************************************************//**
 
1167
/**************************************************************************
1203
1168
Frees an undo log segment which is not in the history list. */
1204
1169
static
1205
1170
void
1206
1171
trx_undo_seg_free(
1207
1172
/*==============*/
1208
 
        trx_undo_t*     undo)   /*!< in: undo log */
 
1173
        trx_undo_t*     undo)   /* in: undo log */
1209
1174
{
1210
1175
        trx_rseg_t*     rseg;
1211
1176
        fseg_header_t*  file_seg;
1248
1213
 
1249
1214
/*========== UNDO LOG MEMORY COPY INITIALIZATION =====================*/
1250
1215
 
1251
 
/********************************************************************//**
 
1216
/************************************************************************
1252
1217
Creates and initializes an undo log memory object according to the values
1253
1218
in the header in file, when the database is started. The memory object is
1254
 
inserted in the appropriate list of rseg.
1255
 
@return own: the undo log memory object */
 
1219
inserted in the appropriate list of rseg. */
1256
1220
static
1257
1221
trx_undo_t*
1258
1222
trx_undo_mem_create_at_db_start(
1259
1223
/*============================*/
1260
 
        trx_rseg_t*     rseg,   /*!< in: rollback segment memory object */
1261
 
        ulint           id,     /*!< in: slot index within rseg */
1262
 
        ulint           page_no,/*!< in: undo log segment page number */
1263
 
        mtr_t*          mtr)    /*!< in: mtr */
 
1224
                                /* out, own: the undo log memory object */
 
1225
        trx_rseg_t*     rseg,   /* in: rollback segment memory object */
 
1226
        ulint           id,     /* in: slot index within rseg */
 
1227
        ulint           page_no,/* in: undo log segment page number */
 
1228
        mtr_t*          mtr)    /* in: mtr */
1264
1229
{
1265
1230
        page_t*         undo_page;
1266
1231
        trx_upagef_t*   page_header;
1269
1234
        trx_undo_t*     undo;
1270
1235
        ulint           type;
1271
1236
        ulint           state;
1272
 
        trx_id_t        trx_id;
 
1237
        dulint          trx_id;
1273
1238
        ulint           offset;
1274
1239
        fil_addr_t      last_addr;
1275
1240
        page_t*         last_page;
1298
1263
 
1299
1264
        undo_header = undo_page + offset;
1300
1265
 
1301
 
        trx_id = mach_read_from_8(undo_header + TRX_UNDO_TRX_ID);
 
1266
        trx_id = mtr_read_dulint(undo_header + TRX_UNDO_TRX_ID, mtr);
1302
1267
 
1303
1268
        xid_exists = mtr_read_ulint(undo_header + TRX_UNDO_XID_EXISTS,
1304
1269
                                    MLOG_1BYTE, mtr);
1322
1287
        undo->dict_operation =  mtr_read_ulint(
1323
1288
                undo_header + TRX_UNDO_DICT_TRANS, MLOG_1BYTE, mtr);
1324
1289
 
1325
 
        undo->table_id = mach_read_from_8(undo_header + TRX_UNDO_TABLE_ID);
 
1290
        undo->table_id = mtr_read_dulint(undo_header + TRX_UNDO_TABLE_ID, mtr);
1326
1291
        undo->state = state;
1327
1292
        undo->size = flst_get_len(seg_header + TRX_UNDO_PAGE_LIST, mtr);
1328
1293
 
1372
1337
        return(undo);
1373
1338
}
1374
1339
 
1375
 
/********************************************************************//**
 
1340
/************************************************************************
1376
1341
Initializes the undo log lists for a rollback segment memory copy. This
1377
1342
function is only called when the database is started or a new rollback
1378
 
segment is created.
1379
 
@return the combined size of undo log segments in pages */
 
1343
segment is created. */
1380
1344
UNIV_INTERN
1381
1345
ulint
1382
1346
trx_undo_lists_init(
1383
1347
/*================*/
1384
 
        trx_rseg_t*     rseg)   /*!< in: rollback segment memory object */
 
1348
                                /* out: the combined size of undo log segments
 
1349
                                in pages */
 
1350
        trx_rseg_t*     rseg)   /* in: rollback segment memory object */
1385
1351
{
1386
1352
        ulint           page_no;
1387
1353
        trx_undo_t*     undo;
1430
1396
        return(size);
1431
1397
}
1432
1398
 
1433
 
/********************************************************************//**
1434
 
Creates and initializes an undo log memory object.
1435
 
@return own: the undo log memory object */
 
1399
/************************************************************************
 
1400
Creates and initializes an undo log memory object. */
1436
1401
static
1437
1402
trx_undo_t*
1438
1403
trx_undo_mem_create(
1439
1404
/*================*/
1440
 
        trx_rseg_t*     rseg,   /*!< in: rollback segment memory object */
1441
 
        ulint           id,     /*!< in: slot index within rseg */
1442
 
        ulint           type,   /*!< in: type of the log: TRX_UNDO_INSERT or
 
1405
                                /* out, own: the undo log memory object */
 
1406
        trx_rseg_t*     rseg,   /* in: rollback segment memory object */
 
1407
        ulint           id,     /* in: slot index within rseg */
 
1408
        ulint           type,   /* in: type of the log: TRX_UNDO_INSERT or
1443
1409
                                TRX_UNDO_UPDATE */
1444
 
        trx_id_t        trx_id, /*!< in: id of the trx for which the undo log
 
1410
        dulint          trx_id, /* in: id of the trx for which the undo log
1445
1411
                                is created */
1446
 
        const XID*      xid,    /*!< in: X/Open transaction identification */
1447
 
        ulint           page_no,/*!< in: undo log header page number */
1448
 
        ulint           offset) /*!< in: undo log header byte offset on page */
 
1412
        const XID*      xid,    /* in: X/Open transaction identification */
 
1413
        ulint           page_no,/* in: undo log header page number */
 
1414
        ulint           offset) /* in: undo log header byte offset on page */
1449
1415
{
1450
1416
        trx_undo_t*     undo;
1451
1417
 
1457
1423
                ut_error;
1458
1424
        }
1459
1425
 
1460
 
        undo = static_cast<trx_undo_t *>(mem_alloc(sizeof(trx_undo_t)));
 
1426
        undo = mem_alloc(sizeof(trx_undo_t));
1461
1427
 
1462
1428
        if (undo == NULL) {
1463
1429
 
1489
1455
        return(undo);
1490
1456
}
1491
1457
 
1492
 
/********************************************************************//**
 
1458
/************************************************************************
1493
1459
Initializes a cached undo log object for new use. */
1494
1460
static
1495
1461
void
1496
1462
trx_undo_mem_init_for_reuse(
1497
1463
/*========================*/
1498
 
        trx_undo_t*     undo,   /*!< in: undo log to init */
1499
 
        trx_id_t        trx_id, /*!< in: id of the trx for which the undo log
 
1464
        trx_undo_t*     undo,   /* in: undo log to init */
 
1465
        dulint          trx_id, /* in: id of the trx for which the undo log
1500
1466
                                is created */
1501
 
        const XID*      xid,    /*!< in: X/Open XA transaction identification*/
1502
 
        ulint           offset) /*!< in: undo log header byte offset on page */
 
1467
        const XID*      xid,    /* in: X/Open XA transaction identification*/
 
1468
        ulint           offset) /* in: undo log header byte offset on page */
1503
1469
{
1504
1470
        ut_ad(mutex_own(&((undo->rseg)->mutex)));
1505
1471
 
1522
1488
        undo->empty = TRUE;
1523
1489
}
1524
1490
 
1525
 
/********************************************************************//**
 
1491
/************************************************************************
1526
1492
Frees an undo log memory copy. */
1527
 
UNIV_INTERN
 
1493
static
1528
1494
void
1529
1495
trx_undo_mem_free(
1530
1496
/*==============*/
1531
 
        trx_undo_t*     undo)   /*!< in: the undo object to be freed */
 
1497
        trx_undo_t*     undo)   /* in: the undo object to be freed */
1532
1498
{
1533
1499
        if (undo->id >= TRX_RSEG_N_SLOTS) {
1534
1500
                fprintf(stderr,
1539
1505
        mem_free(undo);
1540
1506
}
1541
1507
 
1542
 
/**********************************************************************//**
1543
 
Creates a new undo log.
1544
 
@return DB_SUCCESS if successful in creating the new undo lob object,
1545
 
possible error codes are: DB_TOO_MANY_CONCURRENT_TRXS
1546
 
DB_OUT_OF_FILE_SPACE DB_OUT_OF_MEMORY */
 
1508
/**************************************************************************
 
1509
Creates a new undo log. */
1547
1510
static
1548
1511
ulint
1549
1512
trx_undo_create(
1550
1513
/*============*/
1551
 
        trx_t*          trx,    /*!< in: transaction */
1552
 
        trx_rseg_t*     rseg,   /*!< in: rollback segment memory copy */
1553
 
        ulint           type,   /*!< in: type of the log: TRX_UNDO_INSERT or
 
1514
                                /* out: DB_SUCCESS if successful in creating
 
1515
                                the new undo lob object, possible error
 
1516
                                codes are: 
 
1517
                                DB_TOO_MANY_CONCURRENT_TRXS
 
1518
                                DB_OUT_OF_FILE_SPACE 
 
1519
                                DB_OUT_OF_MEMORY*/
 
1520
        trx_t*          trx,    /* in: transaction */
 
1521
        trx_rseg_t*     rseg,   /* in: rollback segment memory copy */
 
1522
        ulint           type,   /* in: type of the log: TRX_UNDO_INSERT or
1554
1523
                                TRX_UNDO_UPDATE */
1555
 
        trx_id_t        trx_id, /*!< in: id of the trx for which the undo log
 
1524
        dulint          trx_id, /* in: id of the trx for which the undo log
1556
1525
                                is created */
1557
 
        const XID*      xid,    /*!< in: X/Open transaction identification*/
1558
 
        trx_undo_t**    undo,   /*!< out: the new undo log object, undefined
 
1526
        const XID*      xid,    /* in: X/Open transaction identification*/
 
1527
        trx_undo_t**    undo,   /* out: the new undo log object, undefined
1559
1528
                                 * if did not succeed */
1560
 
        mtr_t*          mtr)    /*!< in: mtr */
 
1529
        mtr_t*          mtr)    /* in: mtr */
1561
1530
{
1562
1531
        trx_rsegf_t*    rseg_header;
1563
1532
        ulint           page_no;
1610
1579
 
1611
1580
/*================ UNDO LOG ASSIGNMENT AND CLEANUP =====================*/
1612
1581
 
1613
 
/********************************************************************//**
1614
 
Reuses a cached undo log.
1615
 
@return the undo log memory object, NULL if none cached */
 
1582
/************************************************************************
 
1583
Reuses a cached undo log. */
1616
1584
static
1617
1585
trx_undo_t*
1618
1586
trx_undo_reuse_cached(
1619
1587
/*==================*/
1620
 
        trx_t*          trx,    /*!< in: transaction */
1621
 
        trx_rseg_t*     rseg,   /*!< in: rollback segment memory object */
1622
 
        ulint           type,   /*!< in: type of the log: TRX_UNDO_INSERT or
 
1588
                                /* out: the undo log memory object, NULL if
 
1589
                                none cached */
 
1590
        trx_t*          trx,    /* in: transaction */
 
1591
        trx_rseg_t*     rseg,   /* in: rollback segment memory object */
 
1592
        ulint           type,   /* in: type of the log: TRX_UNDO_INSERT or
1623
1593
                                TRX_UNDO_UPDATE */
1624
 
        trx_id_t        trx_id, /*!< in: id of the trx for which the undo log
 
1594
        dulint          trx_id, /* in: id of the trx for which the undo log
1625
1595
                                is used */
1626
 
        const XID*      xid,    /*!< in: X/Open XA transaction identification */
1627
 
        mtr_t*          mtr)    /*!< in: mtr */
 
1596
        const XID*      xid,    /* in: X/Open XA transaction identification */
 
1597
        mtr_t*          mtr)    /* in: mtr */
1628
1598
{
1629
1599
        trx_undo_t*     undo;
1630
1600
        page_t*         undo_page;
1690
1660
        return(undo);
1691
1661
}
1692
1662
 
1693
 
/**********************************************************************//**
 
1663
/**************************************************************************
1694
1664
Marks an undo log header as a header of a data dictionary operation
1695
1665
transaction. */
1696
1666
static
1697
1667
void
1698
1668
trx_undo_mark_as_dict_operation(
1699
1669
/*============================*/
1700
 
        trx_t*          trx,    /*!< in: dict op transaction */
1701
 
        trx_undo_t*     undo,   /*!< in: assigned undo log */
1702
 
        mtr_t*          mtr)    /*!< in: mtr */
 
1670
        trx_t*          trx,    /* in: dict op transaction */
 
1671
        trx_undo_t*     undo,   /* in: assigned undo log */
 
1672
        mtr_t*          mtr)    /* in: mtr */
1703
1673
{
1704
1674
        page_t* hdr_page;
1705
1675
 
1711
1681
                ut_error;
1712
1682
        case TRX_DICT_OP_INDEX:
1713
1683
                /* Do not discard the table on recovery. */
1714
 
                undo->table_id = 0;
 
1684
                undo->table_id = ut_dulint_zero;
1715
1685
                break;
1716
1686
        case TRX_DICT_OP_TABLE:
1717
1687
                undo->table_id = trx->table_id;
1722
1692
                         + TRX_UNDO_DICT_TRANS,
1723
1693
                         TRUE, MLOG_1BYTE, mtr);
1724
1694
 
1725
 
        mlog_write_ull(hdr_page + undo->hdr_offset + TRX_UNDO_TABLE_ID,
1726
 
                       undo->table_id, mtr);
 
1695
        mlog_write_dulint(hdr_page + undo->hdr_offset + TRX_UNDO_TABLE_ID,
 
1696
                          undo->table_id, mtr);
1727
1697
 
1728
1698
        undo->dict_operation = TRUE;
1729
1699
}
1730
1700
 
1731
 
/**********************************************************************//**
 
1701
/**************************************************************************
1732
1702
Assigns an undo log for a transaction. A new undo log is created or a cached
1733
 
undo log reused.
1734
 
@return DB_SUCCESS if undo log assign successful, possible error codes
1735
 
are: DB_TOO_MANY_CONCURRENT_TRXS DB_OUT_OF_FILE_SPACE
1736
 
DB_OUT_OF_MEMORY */
 
1703
undo log reused. */
1737
1704
UNIV_INTERN
1738
1705
ulint
1739
1706
trx_undo_assign_undo(
1740
1707
/*=================*/
1741
 
        trx_t*          trx,    /*!< in: transaction */
1742
 
        ulint           type)   /*!< in: TRX_UNDO_INSERT or TRX_UNDO_UPDATE */
 
1708
                                /* out: DB_SUCCESS if undo log assign
 
1709
                                successful, possible error codes are:
 
1710
                                DB_TOO_MANY_CONCURRENT_TRXS
 
1711
                                DB_OUT_OF_FILE_SPACE DB_OUT_OF_MEMORY*/
 
1712
        trx_t*          trx,    /* in: transaction */
 
1713
        ulint           type)   /* in: TRX_UNDO_INSERT or TRX_UNDO_UPDATE */
1743
1714
{
1744
1715
        trx_rseg_t*     rseg;
1745
1716
        trx_undo_t*     undo;
1791
1762
        return err;
1792
1763
}
1793
1764
 
1794
 
/******************************************************************//**
1795
 
Sets the state of the undo log segment at a transaction finish.
1796
 
@return undo log segment header page, x-latched */
 
1765
/**********************************************************************
 
1766
Sets the state of the undo log segment at a transaction finish. */
1797
1767
UNIV_INTERN
1798
1768
page_t*
1799
1769
trx_undo_set_state_at_finish(
1800
1770
/*=========================*/
1801
 
        trx_undo_t*     undo,   /*!< in: undo log memory copy */
1802
 
        mtr_t*          mtr)    /*!< in: mtr */
 
1771
                                /* out: undo log segment header page,
 
1772
                                x-latched */
 
1773
        trx_rseg_t*     rseg,   /* in: rollback segment memory object */
 
1774
        trx_t*          trx __attribute__((unused)), /* in: transaction */
 
1775
        trx_undo_t*     undo,   /* in: undo log memory copy */
 
1776
        mtr_t*          mtr)    /* in: mtr */
1803
1777
{
1804
1778
        trx_usegf_t*    seg_hdr;
1805
1779
        trx_upagef_t*   page_hdr;
1806
1780
        page_t*         undo_page;
1807
1781
        ulint           state;
1808
1782
 
 
1783
        ut_ad(trx);
1809
1784
        ut_ad(undo);
1810
1785
        ut_ad(mtr);
 
1786
        ut_ad(mutex_own(&rseg->mutex));
1811
1787
 
1812
1788
        if (undo->id >= TRX_RSEG_N_SLOTS) {
1813
1789
                fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
1826
1802
            && mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE)
1827
1803
               < TRX_UNDO_PAGE_REUSE_LIMIT) {
1828
1804
 
1829
 
                state = TRX_UNDO_CACHED;
 
1805
                /* This is a heuristic to avoid the problem of all UNDO
 
1806
                slots ending up in one of the UNDO lists. Previously if
 
1807
                the server crashed with all the slots in one of the lists,
 
1808
                transactions that required the slots of a different type
 
1809
                would fail for lack of slots. */
 
1810
 
 
1811
                if (UT_LIST_GET_LEN(rseg->update_undo_list) < 500
 
1812
                    && UT_LIST_GET_LEN(rseg->insert_undo_list) < 500) {
 
1813
 
 
1814
                        state = TRX_UNDO_CACHED;
 
1815
                } else {
 
1816
                        state = TRX_UNDO_TO_FREE;
 
1817
                }
1830
1818
 
1831
1819
        } else if (undo->type == TRX_UNDO_INSERT) {
1832
1820
 
1842
1830
        return(undo_page);
1843
1831
}
1844
1832
 
1845
 
/******************************************************************//**
1846
 
Sets the state of the undo log segment at a transaction prepare.
1847
 
@return undo log segment header page, x-latched */
 
1833
/**********************************************************************
 
1834
Sets the state of the undo log segment at a transaction prepare. */
1848
1835
UNIV_INTERN
1849
1836
page_t*
1850
1837
trx_undo_set_state_at_prepare(
1851
1838
/*==========================*/
1852
 
        trx_t*          trx,    /*!< in: transaction */
1853
 
        trx_undo_t*     undo,   /*!< in: undo log memory copy */
1854
 
        mtr_t*          mtr)    /*!< in: mtr */
 
1839
                                /* out: undo log segment header page,
 
1840
                                x-latched */
 
1841
        trx_t*          trx,    /* in: transaction */
 
1842
        trx_undo_t*     undo,   /* in: undo log memory copy */
 
1843
        mtr_t*          mtr)    /* in: mtr */
1855
1844
{
1856
1845
        trx_usegf_t*    seg_hdr;
 
1846
        trx_upagef_t*   page_hdr;
1857
1847
        trx_ulogf_t*    undo_header;
1858
1848
        page_t*         undo_page;
1859
1849
        ulint           offset;
1871
1861
                                      undo->hdr_page_no, mtr);
1872
1862
 
1873
1863
        seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
 
1864
        page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
1874
1865
 
1875
1866
        /*------------------------------*/
1876
1867
        undo->state = TRX_UNDO_PREPARED;
1891
1882
        return(undo_page);
1892
1883
}
1893
1884
 
1894
 
/**********************************************************************//**
 
1885
/**************************************************************************
1895
1886
Adds the update undo log header as the first in the history list, and
1896
1887
frees the memory object, or puts it to the list of cached update undo log
1897
1888
segments. */
1899
1890
void
1900
1891
trx_undo_update_cleanup(
1901
1892
/*====================*/
1902
 
        trx_t*  trx,            /*!< in: trx owning the update undo log */
1903
 
        page_t* undo_page,      /*!< in: update undo log header page,
 
1893
        trx_t*  trx,            /* in: trx owning the update undo log */
 
1894
        page_t* undo_page,      /* in: update undo log header page,
1904
1895
                                x-latched */
1905
 
        mtr_t*  mtr)            /*!< in: mtr */
 
1896
        mtr_t*  mtr)            /* in: mtr */
1906
1897
{
1907
1898
        trx_rseg_t*     rseg;
1908
1899
        trx_undo_t*     undo;
1922
1913
 
1923
1914
                UT_LIST_ADD_FIRST(undo_list, rseg->update_undo_cached, undo);
1924
1915
        } else {
1925
 
                ut_ad(undo->state == TRX_UNDO_TO_PURGE
1926
 
                      || undo->state == TRX_UNDO_TO_FREE);
 
1916
                ut_ad(undo->state == TRX_UNDO_TO_PURGE);
1927
1917
 
1928
1918
                trx_undo_mem_free(undo);
1929
1919
        }
1930
1920
}
1931
1921
 
1932
 
/******************************************************************//**
 
1922
/**********************************************************************
1933
1923
Frees or caches an insert undo log after a transaction commit or rollback.
1934
1924
Knowledge of inserts is not needed after a commit or rollback, therefore
1935
1925
the data can be discarded. */
1937
1927
void
1938
1928
trx_undo_insert_cleanup(
1939
1929
/*====================*/
1940
 
        trx_t*  trx)    /*!< in: transaction handle */
 
1930
        trx_t*  trx)    /* in: transaction handle */
1941
1931
{
1942
1932
        trx_undo_t*     undo;
1943
1933
        trx_rseg_t*     rseg;
1975
1965
 
1976
1966
        mutex_exit(&(rseg->mutex));
1977
1967
}
1978
 
#endif /* !UNIV_HOTBACKUP */