~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/trx/trx0undo.cc

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
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., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
15
St, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
415
415
ulint
416
416
trx_undo_seg_create(
417
417
/*================*/
418
 
        trx_rseg_t*     rseg __attribute__((unused)),/*!< in: rollback segment */
 
418
        trx_rseg_t*     /*rseg*/,/*!< in: rollback segment */
419
419
        trx_rsegf_t*    rseg_hdr,/*!< in: rollback segment header, page
420
420
                                x-latched */
421
421
        ulint           type,   /*!< in: type of the segment: TRX_UNDO_INSERT or
515
515
{
516
516
        mlog_write_initial_log_record(undo_page, MLOG_UNDO_HDR_CREATE, mtr);
517
517
 
518
 
        mlog_catenate_dulint_compressed(mtr, trx_id);
 
518
        mlog_catenate_ull_compressed(mtr, trx_id);
519
519
}
520
520
#else /* !UNIV_HOTBACKUP */
521
521
# define trx_undo_header_create_log(undo_page,trx_id,mtr) ((void) 0)
687
687
{
688
688
        mlog_write_initial_log_record(undo_page, MLOG_UNDO_HDR_REUSE, mtr);
689
689
 
690
 
        mlog_catenate_dulint_compressed(mtr, trx_id);
 
690
        mlog_catenate_ull_compressed(mtr, trx_id);
691
691
}
692
692
#else /* !UNIV_HOTBACKUP */
693
693
# define trx_undo_insert_header_reuse_log(undo_page,trx_id,mtr) ((void) 0)
707
707
        mtr_t*  mtr)    /*!< in: mtr or NULL */
708
708
{
709
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);
710
716
 
711
 
        ptr = mach_dulint_parse_compressed(ptr, end_ptr, &trx_id);
 
717
        ptr = mach_ull_parse_compressed(ptr, end_ptr, &trx_id);
712
718
 
713
719
        if (ptr == NULL) {
714
720
 
811
817
trx_undo_parse_discard_latest(
812
818
/*==========================*/
813
819
        byte*   ptr,    /*!< in: buffer */
814
 
        byte*   end_ptr __attribute__((unused)), /*!< in: buffer end */
 
820
        byte*   /*end_ptr*/, /*!< in: buffer end */
815
821
        page_t* page,   /*!< in: page or NULL */
816
822
        mtr_t*  mtr)    /*!< in: mtr or NULL */
817
823
{
1003
1009
void
1004
1010
trx_undo_free_page_in_rollback(
1005
1011
/*===========================*/
1006
 
        trx_t*          trx __attribute__((unused)), /*!< in: transaction */
 
1012
        trx_t*          /*trx*/, /*!< in: transaction */
1007
1013
        trx_undo_t*     undo,   /*!< in: undo log memory copy */
1008
1014
        ulint           page_no,/*!< in: page number to free: must not be the
1009
1015
                                header page */
1066
1072
        ulint           last_page_no;
1067
1073
        trx_undo_rec_t* rec;
1068
1074
        trx_undo_rec_t* trunc_here;
1069
 
        trx_rseg_t*     rseg;
1070
1075
        mtr_t           mtr;
1071
1076
 
1072
1077
        ut_ad(mutex_own(&(trx->undo_mutex)));
1073
1078
        ut_ad(mutex_own(&(trx->rseg->mutex)));
1074
1079
 
1075
 
        rseg = trx->rseg;
1076
 
 
1077
1080
        for (;;) {
1078
1081
                mtr_start(&mtr);
1079
1082
 
1098
1101
                                break;
1099
1102
                        }
1100
1103
 
1101
 
                        if (ut_dulint_cmp(trx_undo_rec_get_undo_no(rec), limit)
1102
 
                            >= 0) {
 
1104
                        if (trx_undo_rec_get_undo_no(rec) >= limit) {
1103
1105
                                /* Truncate at least this record off, maybe
1104
1106
                                more */
1105
1107
                                trunc_here = rec;
1152
1154
 
1153
1155
        ut_ad(mutex_own(&(rseg->mutex)));
1154
1156
 
1155
 
        if (ut_dulint_is_zero(limit)) {
 
1157
        if (!limit) {
1156
1158
 
1157
1159
                return;
1158
1160
        }
1174
1176
 
1175
1177
        last_rec = trx_undo_page_get_last_rec(undo_page, hdr_page_no,
1176
1178
                                              hdr_offset);
1177
 
        if (ut_dulint_cmp(trx_undo_rec_get_undo_no(last_rec), limit) >= 0) {
 
1179
        if (trx_undo_rec_get_undo_no(last_rec) >= limit) {
1178
1180
 
1179
1181
                mtr_commit(&mtr);
1180
1182
 
1296
1298
 
1297
1299
        undo_header = undo_page + offset;
1298
1300
 
1299
 
        trx_id = mtr_read_dulint(undo_header + TRX_UNDO_TRX_ID, mtr);
 
1301
        trx_id = mach_read_from_8(undo_header + TRX_UNDO_TRX_ID);
1300
1302
 
1301
1303
        xid_exists = mtr_read_ulint(undo_header + TRX_UNDO_XID_EXISTS,
1302
1304
                                    MLOG_1BYTE, mtr);
1320
1322
        undo->dict_operation =  mtr_read_ulint(
1321
1323
                undo_header + TRX_UNDO_DICT_TRANS, MLOG_1BYTE, mtr);
1322
1324
 
1323
 
        undo->table_id = mtr_read_dulint(undo_header + TRX_UNDO_TABLE_ID, mtr);
 
1325
        undo->table_id = mach_read_from_8(undo_header + TRX_UNDO_TABLE_ID);
1324
1326
        undo->state = state;
1325
1327
        undo->size = flst_get_len(seg_header + TRX_UNDO_PAGE_LIST, mtr);
1326
1328
 
1455
1457
                ut_error;
1456
1458
        }
1457
1459
 
1458
 
        undo = mem_alloc(sizeof(trx_undo_t));
 
1460
        undo = static_cast<trx_undo_t *>(mem_alloc(sizeof(trx_undo_t)));
1459
1461
 
1460
1462
        if (undo == NULL) {
1461
1463
 
1522
1524
 
1523
1525
/********************************************************************//**
1524
1526
Frees an undo log memory copy. */
1525
 
static
 
1527
UNIV_INTERN
1526
1528
void
1527
1529
trx_undo_mem_free(
1528
1530
/*==============*/
1709
1711
                ut_error;
1710
1712
        case TRX_DICT_OP_INDEX:
1711
1713
                /* Do not discard the table on recovery. */
1712
 
                undo->table_id = ut_dulint_zero;
 
1714
                undo->table_id = 0;
1713
1715
                break;
1714
1716
        case TRX_DICT_OP_TABLE:
1715
1717
                undo->table_id = trx->table_id;
1720
1722
                         + TRX_UNDO_DICT_TRANS,
1721
1723
                         TRUE, MLOG_1BYTE, mtr);
1722
1724
 
1723
 
        mlog_write_dulint(hdr_page + undo->hdr_offset + TRX_UNDO_TABLE_ID,
1724
 
                          undo->table_id, mtr);
 
1725
        mlog_write_ull(hdr_page + undo->hdr_offset + TRX_UNDO_TABLE_ID,
 
1726
                       undo->table_id, mtr);
1725
1727
 
1726
1728
        undo->dict_operation = TRUE;
1727
1729
}
1796
1798
page_t*
1797
1799
trx_undo_set_state_at_finish(
1798
1800
/*=========================*/
1799
 
        trx_rseg_t*     rseg,   /*!< in: rollback segment memory object */
1800
 
        trx_t*          trx __attribute__((unused)), /*!< in: transaction */
1801
1801
        trx_undo_t*     undo,   /*!< in: undo log memory copy */
1802
1802
        mtr_t*          mtr)    /*!< in: mtr */
1803
1803
{
1806
1806
        page_t*         undo_page;
1807
1807
        ulint           state;
1808
1808
 
1809
 
        ut_ad(trx);
1810
1809
        ut_ad(undo);
1811
1810
        ut_ad(mtr);
1812
 
        ut_ad(mutex_own(&rseg->mutex));
1813
1811
 
1814
1812
        if (undo->id >= TRX_RSEG_N_SLOTS) {
1815
1813
                fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
1828
1826
            && mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE)
1829
1827
               < TRX_UNDO_PAGE_REUSE_LIMIT) {
1830
1828
 
1831
 
                /* This is a heuristic to avoid the problem of all UNDO
1832
 
                slots ending up in one of the UNDO lists. Previously if
1833
 
                the server crashed with all the slots in one of the lists,
1834
 
                transactions that required the slots of a different type
1835
 
                would fail for lack of slots. */
1836
 
 
1837
 
                if (UT_LIST_GET_LEN(rseg->update_undo_list) < 500
1838
 
                    && UT_LIST_GET_LEN(rseg->insert_undo_list) < 500) {
1839
 
 
1840
 
                        state = TRX_UNDO_CACHED;
1841
 
                } else {
1842
 
                        state = TRX_UNDO_TO_FREE;
1843
 
                }
 
1829
                state = TRX_UNDO_CACHED;
1844
1830
 
1845
1831
        } else if (undo->type == TRX_UNDO_INSERT) {
1846
1832
 
1868
1854
        mtr_t*          mtr)    /*!< in: mtr */
1869
1855
{
1870
1856
        trx_usegf_t*    seg_hdr;
1871
 
        trx_upagef_t*   page_hdr;
1872
1857
        trx_ulogf_t*    undo_header;
1873
1858
        page_t*         undo_page;
1874
1859
        ulint           offset;
1886
1871
                                      undo->hdr_page_no, mtr);
1887
1872
 
1888
1873
        seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
1889
 
        page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
1890
1874
 
1891
1875
        /*------------------------------*/
1892
1876
        undo->state = TRX_UNDO_PREPARED;
1938
1922
 
1939
1923
                UT_LIST_ADD_FIRST(undo_list, rseg->update_undo_cached, undo);
1940
1924
        } else {
1941
 
                ut_ad(undo->state == TRX_UNDO_TO_PURGE);
 
1925
                ut_ad(undo->state == TRX_UNDO_TO_PURGE
 
1926
                      || undo->state == TRX_UNDO_TO_FREE);
1942
1927
 
1943
1928
                trx_undo_mem_free(undo);
1944
1929
        }