~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/trx/trx0trx.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
/** Number of transactions currently allocated for MySQL: protected by
51
51
the kernel mutex */
52
52
UNIV_INTERN ulint       trx_n_mysql_transactions = 0;
 
53
/* Number of transactions currently in the XA PREPARED state: protected by
 
54
the kernel mutex */
 
55
UNIV_INTERN ulint       trx_n_prepared = 0;
53
56
 
54
57
/*************************************************************//**
55
58
Set detailed error message for the transaction. */
334
337
}
335
338
 
336
339
/********************************************************************//**
 
340
At shutdown, frees a transaction object that is in the PREPARED state. */
 
341
UNIV_INTERN
 
342
void
 
343
trx_free_prepared(
 
344
/*==============*/
 
345
        trx_t*  trx)    /*!< in, own: trx object */
 
346
{
 
347
        ut_ad(mutex_own(&kernel_mutex));
 
348
        ut_a(trx->conc_state == TRX_PREPARED);
 
349
        ut_a(trx->magic_n == TRX_MAGIC_N);
 
350
 
 
351
        /* Prepared transactions are sort of active; they allow
 
352
        ROLLBACK and COMMIT operations. Because the system does not
 
353
        contain any other transactions than prepared transactions at
 
354
        the shutdown stage and because a transaction cannot become
 
355
        PREPARED while holding locks, it is safe to release the locks
 
356
        held by PREPARED transactions here at shutdown.*/
 
357
        lock_release_off_kernel(trx);
 
358
 
 
359
        trx_undo_free_prepared(trx);
 
360
 
 
361
        mutex_free(&trx->undo_mutex);
 
362
 
 
363
        if (trx->undo_no_arr) {
 
364
                trx_undo_arr_free(trx->undo_no_arr);
 
365
        }
 
366
 
 
367
        ut_a(UT_LIST_GET_LEN(trx->signals) == 0);
 
368
        ut_a(UT_LIST_GET_LEN(trx->reply_signals) == 0);
 
369
 
 
370
        ut_a(trx->wait_lock == NULL);
 
371
        ut_a(UT_LIST_GET_LEN(trx->wait_thrs) == 0);
 
372
 
 
373
        ut_a(!trx->has_search_latch);
 
374
 
 
375
        ut_a(trx->dict_operation_lock_mode == 0);
 
376
 
 
377
        if (trx->lock_heap) {
 
378
                mem_heap_free(trx->lock_heap);
 
379
        }
 
380
 
 
381
        if (trx->global_read_view_heap) {
 
382
                mem_heap_free(trx->global_read_view_heap);
 
383
        }
 
384
 
 
385
        ut_a(ib_vector_is_empty(trx->autoinc_locks));
 
386
        ib_vector_free(trx->autoinc_locks);
 
387
 
 
388
        UT_LIST_REMOVE(trx_list, trx_sys->trx_list, trx);
 
389
 
 
390
        mem_free(trx);
 
391
}
 
392
 
 
393
/********************************************************************//**
337
394
Frees a transaction object for MySQL. */
338
395
UNIV_INTERN
339
396
void
463
520
                                        if (srv_force_recovery == 0) {
464
521
 
465
522
                                                trx->conc_state = TRX_PREPARED;
 
523
                                                trx_n_prepared++;
466
524
                                        } else {
467
525
                                                fprintf(stderr,
468
526
                                                        "InnoDB: Since"
541
599
 
542
600
                                                        trx->conc_state
543
601
                                                                = TRX_PREPARED;
 
602
                                                        trx_n_prepared++;
544
603
                                                } else {
545
604
                                                        fprintf(stderr,
546
605
                                                                "InnoDB: Since"
820
879
              || trx->conc_state == TRX_PREPARED);
821
880
        ut_ad(mutex_own(&kernel_mutex));
822
881
 
 
882
        if (UNIV_UNLIKELY(trx->conc_state == TRX_PREPARED)) {
 
883
                ut_a(trx_n_prepared > 0);
 
884
                trx_n_prepared--;
 
885
        }
 
886
 
823
887
        /* The following assignment makes the transaction committed in memory
824
888
        and makes its changes to data visible to other transactions.
825
889
        NOTE that there is a small discrepancy from the strict formal
1805
1869
/*===================*/
1806
1870
        trx_t*  trx)    /*!< in: transaction */
1807
1871
{
1808
 
        page_t*         update_hdr_page;
1809
1872
        trx_rseg_t*     rseg;
1810
1873
        ib_uint64_t     lsn             = 0;
1811
1874
        mtr_t           mtr;
1838
1901
                }
1839
1902
 
1840
1903
                if (trx->update_undo) {
1841
 
                        update_hdr_page = trx_undo_set_state_at_prepare(
 
1904
                        trx_undo_set_state_at_prepare(
1842
1905
                                trx, trx->update_undo, &mtr);
1843
1906
                }
1844
1907
 
1858
1921
 
1859
1922
        /*--------------------------------------*/
1860
1923
        trx->conc_state = TRX_PREPARED;
 
1924
        trx_n_prepared++;
1861
1925
        /*--------------------------------------*/
1862
1926
 
1863
1927
        if (lsn) {
2011
2075
/*******************************************************************//**
2012
2076
This function is used to find one X/Open XA distributed transaction
2013
2077
which is in the prepared state
2014
 
@return trx or NULL */
 
2078
@return trx or NULL; on match, the trx->xid will be invalidated */
2015
2079
UNIV_INTERN
2016
2080
trx_t*
2017
2081
trx_get_trx_by_xid(
2018
2082
/*===============*/
2019
 
        XID*    xid)    /*!< in: X/Open XA transaction identification */
 
2083
        const XID*      xid)    /*!< in: X/Open XA transaction identifier */
2020
2084
{
2021
2085
        trx_t*  trx;
2022
2086
 
2023
2087
        if (xid == NULL) {
2024
2088
 
2025
 
                return (NULL);
 
2089
                return(NULL);
2026
2090
        }
2027
2091
 
2028
2092
        mutex_enter(&kernel_mutex);
2032
2096
        while (trx) {
2033
2097
                /* Compare two X/Open XA transaction id's: their
2034
2098
                length should be the same and binary comparison
2035
 
                of gtrid_lenght+bqual_length bytes should be
 
2099
                of gtrid_length+bqual_length bytes should be
2036
2100
                the same */
2037
2101
 
2038
 
                if (xid->gtrid_length == trx->xid.gtrid_length
 
2102
                if (trx->is_recovered
 
2103
                    && trx->conc_state == TRX_PREPARED
 
2104
                    && xid->gtrid_length == trx->xid.gtrid_length
2039
2105
                    && xid->bqual_length == trx->xid.bqual_length
2040
2106
                    && memcmp(xid->data, trx->xid.data,
2041
2107
                              xid->gtrid_length + xid->bqual_length) == 0) {
 
2108
 
 
2109
                        /* Invalidate the XID, so that subsequent calls
 
2110
                        will not find it. */
 
2111
                        memset(&trx->xid, 0, sizeof(trx->xid));
 
2112
                        trx->xid.formatID = -1;
2042
2113
                        break;
2043
2114
                }
2044
2115
 
2047
2118
 
2048
2119
        mutex_exit(&kernel_mutex);
2049
2120
 
2050
 
        if (trx) {
2051
 
                if (trx->conc_state != TRX_PREPARED) {
2052
 
 
2053
 
                        return(NULL);
2054
 
                }
2055
 
 
2056
 
                return(trx);
2057
 
        } else {
2058
 
                return(NULL);
2059
 
        }
 
2121
        return(trx);
2060
2122
}