61 UNIV_INTERN mysql_pfs_key_t trx_mutex_key;
63 UNIV_INTERN mysql_pfs_key_t trx_undo_mutex_key;
108 mutex_create(trx_mutex_key, &trx->
mutex, SYNC_TRX);
110 trx->magic_n = TRX_MAGIC_N;
112 trx->
state = TRX_STATE_NOT_STARTED;
125 mutex_create(trx_undo_mutex_key, &trx->
undo_mutex, SYNC_TRX_UNDO);
132 256, MEM_HEAP_FOR_LOCK_HEAP);
143 heap_alloc = ib_heap_allocator_create(heap);
146 trx->autoinc_locks = ib_vector_create(heap_alloc,
sizeof(
void**), 4);
150 heap_alloc = ib_heap_allocator_create(heap);
153 heap_alloc,
sizeof(
void**), 32);
189 ut_d(trx->in_mysql_trx_list = TRUE);
205 ut_a(trx->magic_n == TRX_MAGIC_N);
206 ut_ad(!trx->in_ro_trx_list);
207 ut_ad(!trx->in_rw_trx_list);
208 ut_ad(!trx->in_mysql_trx_list);
235 ib_vector_free(trx->autoinc_locks);
242 mutex_free(&trx->
mutex);
258 "Freeing a trx (%p, " TRX_ID_FMT ") which is declared "
259 "to be processing inside InnoDB", trx, trx->
id);
273 "MySQL is freeing a thd though "
274 "trx->n_mysql_tables_in_use is %lu and "
275 "trx->mysql_n_tables_locked is %lu.",
284 ut_a(trx->
state == TRX_STATE_NOT_STARTED);
303 ut_a(trx->magic_n == TRX_MAGIC_N);
312 ut_d(trx->in_rw_trx_list = FALSE);
330 ut_ad(trx->in_mysql_trx_list);
331 ut_d(trx->in_mysql_trx_list = FALSE);
334 ut_ad(trx_sys_validate_trx_list());
348 trx_list_rw_insert_ordered(
356 ut_d(trx->start_file = __FILE__);
357 ut_d(trx->start_line = __LINE__);
360 ut_ad(!trx->in_ro_trx_list);
361 ut_ad(!trx->in_rw_trx_list);
371 if (trx->
id >= trx2->
id) {
392 ut_ad(!trx->in_rw_trx_list);
393 ut_d(trx->in_rw_trx_list = TRUE);
400 trx_resurrect_table_locks(
433 if (undo_rec_page != undo_page) {
436 MTR_MEMO_PAGE_X_FIX)) {
444 undo_page = undo_rec_page;
448 undo_rec, &type, &cmpl_info,
449 &updated_extern, &undo_no, &table_id);
450 tables.insert(table_id);
459 for (table_id_set::const_iterator
i = tables.begin();
460 i != tables.end();
i++) {
463 if (
table->ibd_file_missing
476 " table '%s' IX lock from %s undo",
479 ?
"insert" :
"update"));
492 trx_resurrect_insert(
510 if (undo->
state != TRX_UNDO_ACTIVE) {
515 if (undo->
state == TRX_UNDO_PREPARED) {
518 "InnoDB: Transaction " TRX_ID_FMT " was in the"
519 " XA prepared state.\n", trx->
id);
523 trx->
state = TRX_STATE_PREPARED;
528 "InnoDB: Since innodb_force_recovery"
529 " > 0, we will rollback it anyway.\n");
531 trx->
state = TRX_STATE_ACTIVE;
534 trx->
state = TRX_STATE_COMMITTED_IN_MEMORY;
545 trx->
state = TRX_STATE_ACTIVE;
570 trx_resurrect_update_in_prepared_state(
578 if (undo->
state == TRX_UNDO_PREPARED) {
581 " was in the XA prepared state.\n", trx->
id);
591 trx->
state = TRX_STATE_PREPARED;
594 "InnoDB: Since innodb_force_recovery"
595 " > 0, we will rollback it anyway.\n");
597 trx->
state = TRX_STATE_ACTIVE;
600 trx->
state = TRX_STATE_COMMITTED_IN_MEMORY;
609 trx_resurrect_update(
624 if (undo->
state != TRX_UNDO_ACTIVE) {
625 trx_resurrect_update_in_prepared_state(trx, undo);
632 trx->
state = TRX_STATE_ACTIVE;
672 for (i = 0; i < TRX_SYS_N_RSEGS; ++
i) {
688 trx = trx_resurrect_insert(undo, rseg);
690 trx_list_rw_insert_ordered(trx);
692 trx_resurrect_table_locks(trx, undo);
714 trx_resurrect_update(trx, undo, rseg);
717 trx_list_rw_insert_ordered(trx);
720 trx_resurrect_table_locks(trx, undo);
737 static ulint latest_rseg = 0;
740 ut_a(max_undo_logs == ULONG_UNDEFINED);
746 ut_a(max_undo_logs > 0 && max_undo_logs <= TRX_SYS_N_RSEGS);
763 ut_a(rseg == NULL || i == rseg->
id);
765 i = (rseg == NULL) ? 0 : i + 1;
767 }
while (rseg == NULL
803 ut_ad(trx->start_file != 0);
804 ut_ad(trx->start_line != 0);
823 trx->
rseg = trx_assign_rseg_low(
842 trx->
state = TRX_STATE_ACTIVE;
846 ut_ad(!trx->in_rw_trx_list);
847 ut_ad(!trx->in_ro_trx_list);
857 ut_d(trx->in_ro_trx_list = TRUE);
866 ut_d(trx->in_rw_trx_list = TRUE);
870 ut_ad(trx_sys_validate_trx_list());
883 trx_serialisation_number_get(
906 rseg_queue.
rseg = rseg;
930 static __attribute__((nonnull))
932 trx_write_serialisation_history(
947 if (trx->update_undo != NULL) {
956 mutex_enter(&rseg->
mutex);
962 trx_serialisation_number_get(trx);
972 mutex_enter(&rseg->
mutex);
975 if (trx->insert_undo != NULL) {
979 mutex_exit(&rseg->
mutex);
987 if (trx->mysql_log_file_name
988 && trx->mysql_log_file_name[0] !=
'\0') {
991 trx->mysql_log_file_name,
992 trx->mysql_log_offset,
995 trx->mysql_log_file_name = NULL;
1001 static __attribute__((nonnull))
1003 trx_finalize_for_fts_table(
1007 fts_t* fts = ftt->table->fts;
1028 ftt->added_doc_ids = NULL;
1034 static __attribute__((nonnull))
1036 trx_finalize_for_fts(
1048 ib_vector_last(trx->fts_trx->savepoints));
1050 tables = savepoint->
tables;
1059 if ((*ftt)->added_doc_ids) {
1060 trx_finalize_for_fts_table(*ftt);
1066 trx->fts_trx = NULL;
1074 trx_flush_log_if_needed_low(
1079 switch (srv_flush_log_at_trx_commit) {
1101 static __attribute__((nonnull))
1103 trx_flush_log_if_needed(
1109 trx->op_info =
"flushing log";
1110 trx_flush_log_if_needed_low(lsn);
1116 static __attribute__((nonnull))
1118 trx_commit_in_memory(
1125 trx->must_flush_log_later = FALSE;
1128 ut_ad(trx->read_only);
1129 ut_a(!trx->is_recovered);
1130 ut_ad(trx->rseg == NULL);
1131 ut_ad(!trx->in_ro_trx_list);
1132 ut_ad(!trx->in_rw_trx_list);
1150 trx->state = TRX_STATE_NOT_STARTED;
1167 if (trx->read_only) {
1169 ut_d(trx->in_ro_trx_list = FALSE);
1173 ut_d(trx->in_rw_trx_list = FALSE);
1183 trx->state = TRX_STATE_NOT_STARTED;
1189 ut_ad(trx_sys_validate_trx_list());
1194 if (trx->global_read_view != NULL) {
1198 trx->global_read_view = NULL;
1201 trx->read_view = NULL;
1204 if (trx->insert_undo != NULL) {
1237 if (trx->flush_log_later) {
1239 trx->must_flush_log_later = TRUE;
1240 }
else if (srv_flush_log_at_trx_commit == 0
1242 == HA_IGNORE_DURABILITY) {
1245 trx_flush_log_if_needed(lsn, trx);
1248 trx->commit_lsn =
lsn;
1252 bool not_rollback = trx->undo_no != 0;
1259 trx->last_sql_stat_start.least_undo_no = 0;
1263 ut_ad(trx->start_file != 0);
1264 ut_ad(trx->start_line != 0);
1265 trx->start_file = 0;
1266 trx->start_line = 0;
1270 trx->read_only = FALSE;
1271 trx->auto_commit = FALSE;
1274 trx_finalize_for_fts(trx, not_rollback);
1277 ut_ad(trx->lock.wait_thr == NULL);
1279 ut_ad(!trx->in_ro_trx_list);
1280 ut_ad(!trx->in_rw_trx_list);
1284 trx->error_state = DB_SUCCESS;
1305 ut_ad(!mtr || mtr->state == MTR_ACTIVE);
1321 if (error != DB_SUCCESS && error != DB_DUPLICATE_KEY) {
1331 trx_write_serialisation_history(trx, mtr);
1357 trx_commit_in_memory(trx, lsn);
1409 ut_d(trx->in_rw_trx_list = FALSE);
1417 ut_ad(!trx->in_ro_trx_list);
1418 ut_ad(!trx->in_rw_trx_list);
1419 ut_ad(!trx->in_mysql_trx_list);
1420 trx->
state = TRX_STATE_NOT_STARTED;
1464 switch (trx->
state) {
1465 case TRX_STATE_NOT_STARTED:
1468 case TRX_STATE_ACTIVE:
1469 case TRX_STATE_PREPARED:
1484 case TRX_STATE_COMMITTED_IN_MEMORY:
1575 switch (trx->
state) {
1576 case TRX_STATE_NOT_STARTED:
1588 ut_d(trx->start_file = __FILE__);
1589 ut_d(trx->start_line = __LINE__);
1593 case TRX_STATE_ACTIVE:
1594 case TRX_STATE_PREPARED:
1597 MONITOR_DEC(MONITOR_TRX_ACTIVE);
1600 case TRX_STATE_COMMITTED_IN_MEMORY:
1620 == HA_IGNORE_DURABILITY) {
1624 trx_flush_log_if_needed(trx->
commit_lsn, trx);
1639 switch (trx->
state) {
1640 case TRX_STATE_PREPARED:
1641 case TRX_STATE_COMMITTED_IN_MEMORY:
1643 case TRX_STATE_NOT_STARTED:
1646 case TRX_STATE_ACTIVE:
1670 ulint max_query_len,
1681 const char* op_info;
1690 switch (trx->
state) {
1691 case TRX_STATE_NOT_STARTED:
1692 fputs(
", not started", f);
1694 case TRX_STATE_ACTIVE:
1695 fprintf(f,
", ACTIVE %lu sec",
1696 (ulong) difftime(time(NULL), trx->
start_time));
1698 case TRX_STATE_PREPARED:
1699 fprintf(f,
", ACTIVE (PREPARED) %lu sec",
1700 (ulong) difftime(time(NULL), trx->
start_time));
1702 case TRX_STATE_COMMITTED_IN_MEMORY:
1703 fputs(
", COMMITTED IN MEMORY", f);
1706 fprintf(f,
", state %lu", (ulong) trx->
state);
1719 fputs(
" recovered trx", f);
1723 fprintf(f,
", thread declared inside InnoDB %lu",
1730 fprintf(f,
"mysql tables in use %lu, locked %lu\n",
1743 newline = FALSE;
break;
1745 fputs(
"LOCK WAIT ", f);
break;
1747 fputs(
"ROLLING BACK ", f);
break;
1749 fputs(
"COMMITTING ", f);
break;
1754 if (n_trx_locks > 0 || heap_size > 400) {
1757 fprintf(f,
"%lu lock struct(s), heap size %lu,"
1759 (ulong) n_trx_locks,
1761 (ulong) n_rec_locks);
1766 fputs(
", holds adaptive hash latch", f);
1793 ulint max_query_len)
1814 ulint max_query_len)
1829 n_rec_locks, n_trx_locks, heap_size);
1855 switch (trx->
state) {
1856 case TRX_STATE_PREPARED:
1859 case TRX_STATE_ACTIVE:
1860 case TRX_STATE_COMMITTED_IN_MEMORY:
1863 case TRX_STATE_NOT_STARTED:
1884 ibool a_notrans_edit;
1885 ibool b_notrans_edit;
1896 if (a_notrans_edit != b_notrans_edit) {
1898 return(a_notrans_edit);
1907 "%s TRX_WEIGHT(a): %lld+%lu, TRX_WEIGHT(b): %lld+%lu\n",
1942 mutex_enter(&rseg->
mutex);
1959 mutex_exit(&rseg->
mutex);
1975 trx->
state = TRX_STATE_PREPARED;
1998 trx_flush_log_if_needed(lsn, trx);
2010 trx_start_if_not_started_xa(trx);
2052 xid_list[count] = trx->
xid;
2057 " InnoDB: Starting recovery for"
2058 " XA transactions...\n");
2064 " prepared state after recovery\n",
2069 " InnoDB: Transaction contains changes"
2086 " InnoDB: %d transactions in prepared state"
2087 " after recovery\n",
2091 return(
int (count));
2100 static __attribute__((nonnull, warn_unused_result))
2102 trx_get_trx_by_xid_low(
2126 && memcmp(xid->data, trx->
xid.
data,
2127 xid->gtrid_length + xid->bqual_length) == 0) {
2131 memset(&trx->
xid, 0,
sizeof(trx->
xid));
2163 trx = trx_get_trx_by_xid_low(xid);
2178 switch (trx->
state) {
2179 case TRX_STATE_NOT_STARTED:
2194 case TRX_STATE_ACTIVE:
2196 case TRX_STATE_PREPARED:
2197 case TRX_STATE_COMMITTED_IN_MEMORY:
2212 switch (trx->
state) {
2213 case TRX_STATE_NOT_STARTED:
2216 case TRX_STATE_ACTIVE:
2218 case TRX_STATE_PREPARED:
2219 case TRX_STATE_COMMITTED_IN_MEMORY:
2235 switch (trx->
state) {
2236 case TRX_STATE_NOT_STARTED:
2251 case TRX_STATE_ACTIVE:
2259 case TRX_STATE_PREPARED:
2260 case TRX_STATE_COMMITTED_IN_MEMORY: