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);
610 ut_ad(mutex_own(&kernel_mutex));
614 if (rseg == NULL || rseg->
id == max_undo_logs - 1) {
637 ut_ad(mutex_own(&kernel_mutex));
650 ut_a(rseg_id == ULINT_UNDEFINED);
652 rseg = trx_assign_rseg(srv_rollback_segments);
659 trx->
no = IB_ULONGLONG_MAX;
693 mutex_enter(&kernel_mutex);
697 mutex_exit(&kernel_mutex);
706 trx_serialisation_number_get(
716 mutex_enter(&kernel_mutex);
729 rseg_queue.
rseg = rseg;
739 mutex_exit(&kernel_mutex);
746 mutex_exit(&kernel_mutex);
756 trx_write_serialisation_history(
763 ut_ad(!mutex_own(&kernel_mutex));
783 mutex_enter(&rseg->
mutex);
789 trx_serialisation_number_get(trx);
798 mutex_enter(&rseg->
mutex);
805 mutex_exit(&rseg->
mutex);
811 mutex_enter(&commit_id_mutex);
815 mutex_exit(&commit_id_mutex);
852 ut_ad(mutex_own(&kernel_mutex));
854 trx->must_flush_log_later = FALSE;
860 mutex_exit(&kernel_mutex);
862 lsn = trx_write_serialisation_history(trx);
864 mutex_enter(&kernel_mutex);
870 ut_ad(mutex_own(&kernel_mutex));
906 if (trx->global_read_view) {
909 trx->global_read_view = NULL;
916 mutex_exit(&kernel_mutex);
951 if (trx->flush_log_later) {
953 trx->must_flush_log_later = TRUE;
954 }
else if (srv_flush_log_at_trx_commit == 0) {
956 }
else if (srv_flush_log_at_trx_commit == 1) {
968 }
else if (srv_flush_log_at_trx_commit == 2) {
981 mutex_enter(&kernel_mutex);
985 trx_roll_free_all_savepoints(trx);
1038 mutex_enter(&kernel_mutex);
1042 trx->
id, trx->global_read_view_heap);
1046 mutex_exit(&kernel_mutex);
1055 trx_handle_commit_sig_off_kernel(
1067 ut_ad(mutex_own(&kernel_mutex));
1080 while (sig != NULL) {
1083 if (sig->
type == TRX_SIG_COMMIT) {
1107 ut_ad(mutex_own(&kernel_mutex));
1112 while (thr != NULL) {
1128 trx_lock_wait_to_suspended(
1134 ut_ad(mutex_own(&kernel_mutex));
1139 while (thr != NULL) {
1140 thr->
state = QUE_THR_SUSPENDED;
1155 trx_sig_reply_wait_to_suspended(
1162 ut_ad(mutex_own(&kernel_mutex));
1166 while (sig != NULL) {
1171 thr->
state = QUE_THR_SUSPENDED;
1187 trx_sig_is_compatible(
1195 ut_ad(mutex_own(&kernel_mutex));
1202 if (sender == TRX_SIG_SELF) {
1203 if (type == TRX_SIG_ERROR_OCCURRED) {
1207 }
else if (type == TRX_SIG_BREAK_EXECUTION) {
1215 ut_ad(sender == TRX_SIG_OTHER_SESS);
1219 if (type == TRX_SIG_COMMIT) {
1220 while (sig != NULL) {
1222 if (sig->
type == TRX_SIG_TOTAL_ROLLBACK) {
1232 }
else if (type == TRX_SIG_TOTAL_ROLLBACK) {
1233 while (sig != NULL) {
1235 if (sig->
type == TRX_SIG_COMMIT) {
1245 }
else if (type == TRX_SIG_BREAK_EXECUTION) {
1278 trx_t* receiver_trx;
1281 ut_ad(mutex_own(&kernel_mutex));
1283 if (!trx_sig_is_compatible(trx, type, sender)) {
1323 trx_sig_reply_wait_to_suspended(trx);
1326 if ((sender != TRX_SIG_SELF) || (type == TRX_SIG_BREAK_EXECUTION)) {
1350 ut_ad(mutex_own(&kernel_mutex));
1351 ut_ad(trx->handling_signals == TRUE);
1353 trx->handling_signals = FALSE;
1355 trx->
graph = trx->graph_before_signal_handling;
1384 ut_ad(mutex_own(&kernel_mutex));
1401 if (trx->
que_state == TRX_QUE_LOCK_WAIT) {
1403 trx_lock_wait_to_suspended(trx);
1413 trx_sig_reply_wait_to_suspended(trx);
1425 if (trx->handling_signals == FALSE) {
1426 trx->graph_before_signal_handling = trx->
graph;
1428 trx->handling_signals = TRUE;
1434 if (type == TRX_SIG_COMMIT) {
1436 trx_handle_commit_sig_off_kernel(trx, next_thr);
1438 }
else if ((type == TRX_SIG_TOTAL_ROLLBACK)
1439 || (type == TRX_SIG_ROLLBACK_TO_SAVEPT)) {
1448 }
else if (type == TRX_SIG_ERROR_OCCURRED) {
1457 }
else if (type == TRX_SIG_BREAK_EXECUTION) {
1482 trx_t* receiver_trx;
1485 ut_ad(mutex_own(&kernel_mutex));
1513 ut_ad(mutex_own(&kernel_mutex));
1520 if (sig != &(trx->
sig)) {
1564 mutex_enter(&kernel_mutex);
1570 thr->
state = QUE_THR_SIG_REPLY_WAIT;
1575 thr, NULL, &next_thr);
1577 mutex_exit(&kernel_mutex);
1610 mutex_enter(&kernel_mutex);
1614 mutex_exit(&kernel_mutex);
1635 trx->
op_info =
"flushing log";
1637 if (!trx->must_flush_log_later) {
1639 }
else if (srv_flush_log_at_trx_commit == 0) {
1641 }
else if (srv_flush_log_at_trx_commit == 1) {
1652 }
else if (srv_flush_log_at_trx_commit == 2) {
1661 trx->must_flush_log_later = FALSE;
1694 ulint max_query_len)
1702 case TRX_NOT_STARTED:
1703 fputs(
", not started", f);
1706 fprintf(f,
", ACTIVE %lu sec",
1707 (ulong)difftime(time(NULL), trx->
start_time));
1710 fprintf(f,
", ACTIVE (PREPARED) %lu sec",
1711 (ulong)difftime(time(NULL), trx->
start_time));
1713 case TRX_COMMITTED_IN_MEMORY:
1714 fputs(
", COMMITTED IN MEMORY", f);
1717 fprintf(f,
" state %lu", (ulong) trx->
conc_state);
1721 fprintf(f,
", process no %lu", trx->mysql_process_no);
1723 fprintf(f,
", OS thread id %lu",
1732 fputs(
" recovered trx", f);
1736 fputs(
" purge trx", f);
1739 if (trx->declared_to_be_inside_innodb) {
1740 fprintf(f,
", thread declared inside InnoDB %lu",
1741 (ulong) trx->n_tickets_to_enter_innodb);
1746 if (trx->mysql_n_tables_locked > 0) {
1747 fprintf(f,
"mysql tables in locked %lu\n",
1748 (ulong) trx->mysql_n_tables_locked);
1754 case TRX_QUE_RUNNING:
1755 newline = FALSE;
break;
1756 case TRX_QUE_LOCK_WAIT:
1757 fputs(
"LOCK WAIT ", f);
break;
1758 case TRX_QUE_ROLLING_BACK:
1759 fputs(
"ROLLING BACK ", f);
break;
1760 case TRX_QUE_COMMITTING:
1761 fputs(
"COMMITTING ", f);
break;
1763 fprintf(f,
"que state %lu ", (ulong) trx->
que_state);
1770 fprintf(f,
"%lu lock struct(s), heap size %lu,"
1777 if (trx->has_search_latch) {
1779 fputs(
", holds adaptive hash latch", f);
1784 fprintf(f,
", undo log entries %llu",
1809 ibool a_notrans_edit;
1810 ibool b_notrans_edit;
1821 if (a_notrans_edit != b_notrans_edit) {
1823 return(a_notrans_edit);
1832 "%s TRX_WEIGHT(a): %lld+%lu, TRX_WEIGHT(b): %lld+%lu\n",
1845 trx_prepare_off_kernel(
1850 ib_uint64_t lsn = 0;
1853 ut_ad(mutex_own(&kernel_mutex));
1859 mutex_exit(&kernel_mutex);
1868 mutex_enter(&(rseg->
mutex));
1885 mutex_exit(&(rseg->
mutex));
1894 mutex_enter(&kernel_mutex);
1897 ut_ad(mutex_own(&kernel_mutex));
1921 mutex_exit(&kernel_mutex);
1923 if (srv_flush_log_at_trx_commit == 0) {
1925 }
else if (srv_flush_log_at_trx_commit == 1) {
1937 }
else if (srv_flush_log_at_trx_commit == 2) {
1946 mutex_enter(&kernel_mutex);
1969 mutex_enter(&kernel_mutex);
1971 trx_prepare_off_kernel(trx);
1973 mutex_exit(&kernel_mutex);
2000 mutex_enter(&kernel_mutex);
2006 xid_list[count] = trx->
xid;
2011 " InnoDB: Starting recovery for"
2012 " XA transactions...\n");
2018 " prepared state after recovery\n",
2023 " InnoDB: Transaction contains changes"
2037 mutex_exit(&kernel_mutex);
2042 " InnoDB: %lu transactions in prepared state"
2043 " after recovery\n",
2047 return ((
int) count);
2067 mutex_enter(&kernel_mutex);
2085 memset(&trx->
xid, 0,
sizeof(trx->
xid));
2093 mutex_exit(&kernel_mutex);