~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merge Stewart's dead code removal

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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
415
415
ulint
416
416
trx_undo_seg_create(
417
417
/*================*/
418
 
        trx_rseg_t*     /*rseg*/,/*!< in: rollback segment */
 
418
        trx_rseg_t*     rseg __attribute__((unused)),/*!< 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_ull_compressed(mtr, trx_id);
 
518
        mlog_catenate_dulint_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_ull_compressed(mtr, trx_id);
 
690
        mlog_catenate_dulint_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);
716
710
 
717
 
        ptr = mach_ull_parse_compressed(ptr, end_ptr, &trx_id);
 
711
        ptr = mach_dulint_parse_compressed(ptr, end_ptr, &trx_id);
718
712
 
719
713
        if (ptr == NULL) {
720
714
 
817
811
trx_undo_parse_discard_latest(
818
812
/*==========================*/
819
813
        byte*   ptr,    /*!< in: buffer */
820
 
        byte*   /*end_ptr*/, /*!< in: buffer end */
 
814
        byte*   end_ptr __attribute__((unused)), /*!< in: buffer end */
821
815
        page_t* page,   /*!< in: page or NULL */
822
816
        mtr_t*  mtr)    /*!< in: mtr or NULL */
823
817
{
1009
1003
void
1010
1004
trx_undo_free_page_in_rollback(
1011
1005
/*===========================*/
1012
 
        trx_t*          /*trx*/, /*!< in: transaction */
 
1006
        trx_t*          trx __attribute__((unused)), /*!< in: transaction */
1013
1007
        trx_undo_t*     undo,   /*!< in: undo log memory copy */
1014
1008
        ulint           page_no,/*!< in: page number to free: must not be the
1015
1009
                                header page */
1072
1066
        ulint           last_page_no;
1073
1067
        trx_undo_rec_t* rec;
1074
1068
        trx_undo_rec_t* trunc_here;
 
1069
        trx_rseg_t*     rseg;
1075
1070
        mtr_t           mtr;
1076
1071
 
1077
1072
        ut_ad(mutex_own(&(trx->undo_mutex)));
1078
1073
        ut_ad(mutex_own(&(trx->rseg->mutex)));
1079
1074
 
 
1075
        rseg = trx->rseg;
 
1076
 
1080
1077
        for (;;) {
1081
1078
                mtr_start(&mtr);
1082
1079
 
1101
1098
                                break;
1102
1099
                        }
1103
1100
 
1104
 
                        if (trx_undo_rec_get_undo_no(rec) >= limit) {
 
1101
                        if (ut_dulint_cmp(trx_undo_rec_get_undo_no(rec), limit)
 
1102
                            >= 0) {
1105
1103
                                /* Truncate at least this record off, maybe
1106
1104
                                more */
1107
1105
                                trunc_here = rec;
1154
1152
 
1155
1153
        ut_ad(mutex_own(&(rseg->mutex)));
1156
1154
 
1157
 
        if (!limit) {
 
1155
        if (ut_dulint_is_zero(limit)) {
1158
1156
 
1159
1157
                return;
1160
1158
        }
1176
1174
 
1177
1175
        last_rec = trx_undo_page_get_last_rec(undo_page, hdr_page_no,
1178
1176
                                              hdr_offset);
1179
 
        if (trx_undo_rec_get_undo_no(last_rec) >= limit) {
 
1177
        if (ut_dulint_cmp(trx_undo_rec_get_undo_no(last_rec), limit) >= 0) {
1180
1178
 
1181
1179
                mtr_commit(&mtr);
1182
1180
 
1298
1296
 
1299
1297
        undo_header = undo_page + offset;
1300
1298
 
1301
 
        trx_id = mach_read_from_8(undo_header + TRX_UNDO_TRX_ID);
 
1299
        trx_id = mtr_read_dulint(undo_header + TRX_UNDO_TRX_ID, mtr);
1302
1300
 
1303
1301
        xid_exists = mtr_read_ulint(undo_header + TRX_UNDO_XID_EXISTS,
1304
1302
                                    MLOG_1BYTE, mtr);
1322
1320
        undo->dict_operation =  mtr_read_ulint(
1323
1321
                undo_header + TRX_UNDO_DICT_TRANS, MLOG_1BYTE, mtr);
1324
1322
 
1325
 
        undo->table_id = mach_read_from_8(undo_header + TRX_UNDO_TABLE_ID);
 
1323
        undo->table_id = mtr_read_dulint(undo_header + TRX_UNDO_TABLE_ID, mtr);
1326
1324
        undo->state = state;
1327
1325
        undo->size = flst_get_len(seg_header + TRX_UNDO_PAGE_LIST, mtr);
1328
1326
 
1457
1455
                ut_error;
1458
1456
        }
1459
1457
 
1460
 
        undo = static_cast<trx_undo_t *>(mem_alloc(sizeof(trx_undo_t)));
 
1458
        undo = mem_alloc(sizeof(trx_undo_t));
1461
1459
 
1462
1460
        if (undo == NULL) {
1463
1461
 
1524
1522
 
1525
1523
/********************************************************************//**
1526
1524
Frees an undo log memory copy. */
1527
 
UNIV_INTERN
 
1525
static
1528
1526
void
1529
1527
trx_undo_mem_free(
1530
1528
/*==============*/
1711
1709
                ut_error;
1712
1710
        case TRX_DICT_OP_INDEX:
1713
1711
                /* Do not discard the table on recovery. */
1714
 
                undo->table_id = 0;
 
1712
                undo->table_id = ut_dulint_zero;
1715
1713
                break;
1716
1714
        case TRX_DICT_OP_TABLE:
1717
1715
                undo->table_id = trx->table_id;
1722
1720
                         + TRX_UNDO_DICT_TRANS,
1723
1721
                         TRUE, MLOG_1BYTE, mtr);
1724
1722
 
1725
 
        mlog_write_ull(hdr_page + undo->hdr_offset + TRX_UNDO_TABLE_ID,
1726
 
                       undo->table_id, mtr);
 
1723
        mlog_write_dulint(hdr_page + undo->hdr_offset + TRX_UNDO_TABLE_ID,
 
1724
                          undo->table_id, mtr);
1727
1725
 
1728
1726
        undo->dict_operation = TRUE;
1729
1727
}
1798
1796
page_t*
1799
1797
trx_undo_set_state_at_finish(
1800
1798
/*=========================*/
 
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);
1809
1810
        ut_ad(undo);
1810
1811
        ut_ad(mtr);
 
1812
        ut_ad(mutex_own(&rseg->mutex));
1811
1813
 
1812
1814
        if (undo->id >= TRX_RSEG_N_SLOTS) {
1813
1815
                fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
1826
1828
            && mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE)
1827
1829
               < TRX_UNDO_PAGE_REUSE_LIMIT) {
1828
1830
 
1829
 
                state = TRX_UNDO_CACHED;
 
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
                }
1830
1844
 
1831
1845
        } else if (undo->type == TRX_UNDO_INSERT) {
1832
1846
 
1854
1868
        mtr_t*          mtr)    /*!< in: mtr */
1855
1869
{
1856
1870
        trx_usegf_t*    seg_hdr;
 
1871
        trx_upagef_t*   page_hdr;
1857
1872
        trx_ulogf_t*    undo_header;
1858
1873
        page_t*         undo_page;
1859
1874
        ulint           offset;
1871
1886
                                      undo->hdr_page_no, mtr);
1872
1887
 
1873
1888
        seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
 
1889
        page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
1874
1890
 
1875
1891
        /*------------------------------*/
1876
1892
        undo->state = TRX_UNDO_PREPARED;
1922
1938
 
1923
1939
                UT_LIST_ADD_FIRST(undo_list, rseg->update_undo_cached, undo);
1924
1940
        } else {
1925
 
                ut_ad(undo->state == TRX_UNDO_TO_PURGE
1926
 
                      || undo->state == TRX_UNDO_TO_FREE);
 
1941
                ut_ad(undo->state == TRX_UNDO_TO_PURGE);
1927
1942
 
1928
1943
                trx_undo_mem_free(undo);
1929
1944
        }