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
55
UNIV_INTERN ulint trx_n_prepared = 0;
54
57
/*************************************************************//**
55
58
Set detailed error message for the transaction. */
336
339
/********************************************************************//**
340
At shutdown, frees a transaction object that is in the PREPARED state. */
345
trx_t* trx) /*!< in, own: trx object */
347
ut_ad(mutex_own(&kernel_mutex));
348
ut_a(trx->conc_state == TRX_PREPARED);
349
ut_a(trx->magic_n == TRX_MAGIC_N);
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);
359
trx_undo_free_prepared(trx);
361
mutex_free(&trx->undo_mutex);
363
if (trx->undo_no_arr) {
364
trx_undo_arr_free(trx->undo_no_arr);
367
ut_a(UT_LIST_GET_LEN(trx->signals) == 0);
368
ut_a(UT_LIST_GET_LEN(trx->reply_signals) == 0);
370
ut_a(trx->wait_lock == NULL);
371
ut_a(UT_LIST_GET_LEN(trx->wait_thrs) == 0);
373
ut_a(!trx->has_search_latch);
375
ut_a(trx->dict_operation_lock_mode == 0);
377
if (trx->lock_heap) {
378
mem_heap_free(trx->lock_heap);
381
if (trx->global_read_view_heap) {
382
mem_heap_free(trx->global_read_view_heap);
385
ut_a(ib_vector_is_empty(trx->autoinc_locks));
386
ib_vector_free(trx->autoinc_locks);
388
UT_LIST_REMOVE(trx_list, trx_sys->trx_list, trx);
393
/********************************************************************//**
337
394
Frees a transaction object for MySQL. */
820
879
|| trx->conc_state == TRX_PREPARED);
821
880
ut_ad(mutex_own(&kernel_mutex));
882
if (UNIV_UNLIKELY(trx->conc_state == TRX_PREPARED)) {
883
ut_a(trx_n_prepared > 0);
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
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 */
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 */
2023
2087
if (xid == NULL) {
2028
2092
mutex_enter(&kernel_mutex);
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
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) {
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;