56 UNIV_INTERN mysql_pfs_key_t trx_undo_mutex_key;
96 ut_ad(mutex_own(&kernel_mutex));
99 trx =
static_cast<trx_t *
>(mem_alloc(
sizeof(
trx_t)));
101 trx->magic_n = TRX_MAGIC_N;
110 trx->isolation_level = TRX_ISO_REPEATABLE_READ;
113 trx->
no = IB_ULONGLONG_MAX;
117 trx->check_foreigns = TRUE;
118 trx->check_unique_secondary = TRUE;
120 trx->flush_log_later = FALSE;
121 trx->must_flush_log_later = FALSE;
129 trx->mysql_n_tables_locked = 0;
131 trx->mysql_log_file_name = NULL;
132 trx->mysql_log_offset = 0;
134 mutex_create(trx_undo_mutex_key, &trx->
undo_mutex, SYNC_TRX_UNDO);
152 trx->handling_signals = FALSE;
160 trx->was_chosen_as_deadlock_victim = FALSE;
169 trx->has_search_latch = FALSE;
172 trx->declared_to_be_inside_innodb = FALSE;
173 trx->n_tickets_to_enter_innodb = 0;
176 trx->global_read_view = NULL;
180 memset(&trx->
xid, 0,
sizeof(trx->
xid));
204 mutex_enter(&kernel_mutex);
212 mutex_exit(&kernel_mutex);
231 mutex_enter(&kernel_mutex);
235 mutex_exit(&kernel_mutex);
248 if (trx->has_search_latch) {
251 trx->has_search_latch = FALSE;
263 ut_ad(mutex_own(&kernel_mutex));
265 if (trx->declared_to_be_inside_innodb) {
267 fputs(
" InnoDB: Error: Freeing a trx which is declared"
268 " to be processing\n"
269 "InnoDB: inside InnoDB.\n", stderr);
278 if (trx->mysql_n_tables_locked != 0) {
282 " InnoDB: Error: MySQL is freeing a thd\n"
283 "InnoDB: and trx->mysql_n_tables_locked is %lu.\n",
284 (ulong)trx->mysql_n_tables_locked);
292 ut_a(trx->magic_n == TRX_MAGIC_N);
294 trx->magic_n = 11112222;
313 ut_a(!trx->has_search_latch);
323 if (trx->global_read_view_heap) {
327 trx->global_read_view = NULL;
346 mutex_enter(&kernel_mutex);
356 mutex_exit(&kernel_mutex);
367 mutex_enter(&kernel_mutex);
371 mutex_exit(&kernel_mutex);
381 trx_list_insert_ordered(
387 ut_ad(mutex_own(&kernel_mutex));
391 while (trx2 != NULL) {
392 if (trx->
id >= trx2->
id) {
429 ut_ad(mutex_own(&kernel_mutex));
437 while (rseg != NULL) {
440 while (undo != NULL) {
450 if (undo->
state != TRX_UNDO_ACTIVE) {
456 if (undo->
state == TRX_UNDO_PREPARED) {
459 "InnoDB: Transaction "
462 " XA prepared state.\n",
465 if (srv_force_recovery == 0) {
471 " innodb_force_recovery"
480 = TRX_COMMITTED_IN_MEMORY;
497 trx->
no = IB_ULONGLONG_MAX;
510 trx_list_insert_ordered(trx);
517 while (undo != NULL) {
527 if (undo->
state != TRX_UNDO_ACTIVE) {
533 if (undo->
state == TRX_UNDO_PREPARED) {
535 "InnoDB: Transaction "
537 " XA prepared state.\n",
540 if (srv_force_recovery == 0) {
547 " innodb_force_recovery"
557 = TRX_COMMITTED_IN_MEMORY;
571 trx->
no = IB_ULONGLONG_MAX;
575 trx_list_insert_ordered(trx);
605 trx_assign_rseg(
void)
610 ut_ad(mutex_own(&kernel_mutex));
623 if ((rseg->
id == TRX_SYS_SYSTEM_RSEG_ID)
647 ut_ad(mutex_own(&kernel_mutex));
660 if (rseg_id == ULINT_UNDEFINED) {
662 rseg_id = trx_assign_rseg();
672 trx->
no = IB_ULONGLONG_MAX;
706 mutex_enter(&kernel_mutex);
710 mutex_exit(&kernel_mutex);
729 ut_ad(mutex_own(&kernel_mutex));
731 trx->must_flush_log_later = FALSE;
737 mutex_exit(&kernel_mutex);
747 mutex_enter(&(rseg->
mutex));
756 mutex_enter(&kernel_mutex);
758 mutex_exit(&kernel_mutex);
775 mutex_exit(&(rseg->
mutex));
780 mutex_enter(&commit_id_mutex);
784 mutex_exit(&commit_id_mutex);
809 mutex_enter(&kernel_mutex);
814 ut_ad(mutex_own(&kernel_mutex));
850 if (trx->global_read_view) {
853 trx->global_read_view = NULL;
860 mutex_exit(&kernel_mutex);
895 if (trx->flush_log_later) {
897 trx->must_flush_log_later = TRUE;
898 }
else if (srv_flush_log_at_trx_commit == 0) {
900 }
else if (srv_flush_log_at_trx_commit == 1) {
912 }
else if (srv_flush_log_at_trx_commit == 2) {
925 mutex_enter(&kernel_mutex);
929 trx_roll_free_all_savepoints(trx);
982 mutex_enter(&kernel_mutex);
986 trx->
id, trx->global_read_view_heap);
990 mutex_exit(&kernel_mutex);
999 trx_handle_commit_sig_off_kernel(
1011 ut_ad(mutex_own(&kernel_mutex));
1024 while (sig != NULL) {
1027 if (sig->
type == TRX_SIG_COMMIT) {
1051 ut_ad(mutex_own(&kernel_mutex));
1056 while (thr != NULL) {
1072 trx_lock_wait_to_suspended(
1078 ut_ad(mutex_own(&kernel_mutex));
1083 while (thr != NULL) {
1084 thr->
state = QUE_THR_SUSPENDED;
1099 trx_sig_reply_wait_to_suspended(
1106 ut_ad(mutex_own(&kernel_mutex));
1110 while (sig != NULL) {
1115 thr->
state = QUE_THR_SUSPENDED;
1131 trx_sig_is_compatible(
1139 ut_ad(mutex_own(&kernel_mutex));
1146 if (sender == TRX_SIG_SELF) {
1147 if (type == TRX_SIG_ERROR_OCCURRED) {
1151 }
else if (type == TRX_SIG_BREAK_EXECUTION) {
1159 ut_ad(sender == TRX_SIG_OTHER_SESS);
1163 if (type == TRX_SIG_COMMIT) {
1164 while (sig != NULL) {
1166 if (sig->
type == TRX_SIG_TOTAL_ROLLBACK) {
1176 }
else if (type == TRX_SIG_TOTAL_ROLLBACK) {
1177 while (sig != NULL) {
1179 if (sig->
type == TRX_SIG_COMMIT) {
1189 }
else if (type == TRX_SIG_BREAK_EXECUTION) {
1222 trx_t* receiver_trx;
1225 ut_ad(mutex_own(&kernel_mutex));
1227 if (!trx_sig_is_compatible(trx, type, sender)) {
1267 trx_sig_reply_wait_to_suspended(trx);
1270 if ((sender != TRX_SIG_SELF) || (type == TRX_SIG_BREAK_EXECUTION)) {
1294 ut_ad(mutex_own(&kernel_mutex));
1295 ut_ad(trx->handling_signals == TRUE);
1297 trx->handling_signals = FALSE;
1299 trx->
graph = trx->graph_before_signal_handling;
1328 ut_ad(mutex_own(&kernel_mutex));
1345 if (trx->
que_state == TRX_QUE_LOCK_WAIT) {
1347 trx_lock_wait_to_suspended(trx);
1357 trx_sig_reply_wait_to_suspended(trx);
1369 if (trx->handling_signals == FALSE) {
1370 trx->graph_before_signal_handling = trx->
graph;
1372 trx->handling_signals = TRUE;
1378 if (type == TRX_SIG_COMMIT) {
1380 trx_handle_commit_sig_off_kernel(trx, next_thr);
1382 }
else if ((type == TRX_SIG_TOTAL_ROLLBACK)
1383 || (type == TRX_SIG_ROLLBACK_TO_SAVEPT)) {
1392 }
else if (type == TRX_SIG_ERROR_OCCURRED) {
1401 }
else if (type == TRX_SIG_BREAK_EXECUTION) {
1426 trx_t* receiver_trx;
1429 ut_ad(mutex_own(&kernel_mutex));
1457 ut_ad(mutex_own(&kernel_mutex));
1464 if (sig != &(trx->
sig)) {
1508 mutex_enter(&kernel_mutex);
1514 thr->
state = QUE_THR_SIG_REPLY_WAIT;
1519 thr, NULL, &next_thr);
1521 mutex_exit(&kernel_mutex);
1554 mutex_enter(&kernel_mutex);
1558 mutex_exit(&kernel_mutex);
1579 trx->
op_info =
"flushing log";
1581 if (!trx->must_flush_log_later) {
1583 }
else if (srv_flush_log_at_trx_commit == 0) {
1585 }
else if (srv_flush_log_at_trx_commit == 1) {
1596 }
else if (srv_flush_log_at_trx_commit == 2) {
1605 trx->must_flush_log_later = FALSE;
1638 ulint max_query_len)
1646 case TRX_NOT_STARTED:
1647 fputs(
", not started", f);
1650 fprintf(f,
", ACTIVE %lu sec",
1651 (ulong)difftime(time(NULL), trx->
start_time));
1654 fprintf(f,
", ACTIVE (PREPARED) %lu sec",
1655 (ulong)difftime(time(NULL), trx->
start_time));
1657 case TRX_COMMITTED_IN_MEMORY:
1658 fputs(
", COMMITTED IN MEMORY", f);
1661 fprintf(f,
" state %lu", (ulong) trx->
conc_state);
1665 fprintf(f,
", process no %lu", trx->mysql_process_no);
1667 fprintf(f,
", OS thread id %lu",
1676 fputs(
" recovered trx", f);
1680 fputs(
" purge trx", f);
1683 if (trx->declared_to_be_inside_innodb) {
1684 fprintf(f,
", thread declared inside InnoDB %lu",
1685 (ulong) trx->n_tickets_to_enter_innodb);
1690 if (trx->mysql_n_tables_locked > 0) {
1691 fprintf(f,
"mysql tables in locked %lu\n",
1692 (ulong) trx->mysql_n_tables_locked);
1698 case TRX_QUE_RUNNING:
1699 newline = FALSE;
break;
1700 case TRX_QUE_LOCK_WAIT:
1701 fputs(
"LOCK WAIT ", f);
break;
1702 case TRX_QUE_ROLLING_BACK:
1703 fputs(
"ROLLING BACK ", f);
break;
1704 case TRX_QUE_COMMITTING:
1705 fputs(
"COMMITTING ", f);
break;
1707 fprintf(f,
"que state %lu ", (ulong) trx->
que_state);
1714 fprintf(f,
"%lu lock struct(s), heap size %lu,"
1721 if (trx->has_search_latch) {
1723 fputs(
", holds adaptive hash latch", f);
1728 fprintf(f,
", undo log entries %llu",
1753 ibool a_notrans_edit;
1754 ibool b_notrans_edit;
1765 if (a_notrans_edit != b_notrans_edit) {
1767 return(a_notrans_edit);
1776 "%s TRX_WEIGHT(a): %lld+%lu, TRX_WEIGHT(b): %lld+%lu\n",
1789 trx_prepare_off_kernel(
1794 ib_uint64_t lsn = 0;
1797 ut_ad(mutex_own(&kernel_mutex));
1803 mutex_exit(&kernel_mutex);
1812 mutex_enter(&(rseg->
mutex));
1829 mutex_exit(&(rseg->
mutex));
1838 mutex_enter(&kernel_mutex);
1841 ut_ad(mutex_own(&kernel_mutex));
1865 mutex_exit(&kernel_mutex);
1867 if (srv_flush_log_at_trx_commit == 0) {
1869 }
else if (srv_flush_log_at_trx_commit == 1) {
1881 }
else if (srv_flush_log_at_trx_commit == 2) {
1890 mutex_enter(&kernel_mutex);
1913 mutex_enter(&kernel_mutex);
1915 trx_prepare_off_kernel(trx);
1917 mutex_exit(&kernel_mutex);
1944 mutex_enter(&kernel_mutex);
1950 xid_list[count] = trx->
xid;
1955 " InnoDB: Starting recovery for"
1956 " XA transactions...\n");
1962 " prepared state after recovery\n",
1967 " InnoDB: Transaction contains changes"
1981 mutex_exit(&kernel_mutex);
1986 " InnoDB: %lu transactions in prepared state"
1987 " after recovery\n",
1991 return ((
int) count);
2011 mutex_enter(&kernel_mutex);
2031 mutex_exit(&kernel_mutex);