1 /***************************************************************************** 2 3 Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify it under 6 the terms of the GNU General Public License as published by the Free Software 7 Foundation; version 2 of the License. 8 9 This program is distributed in the hope that it will be useful, but WITHOUT 10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 this program; if not, write to the Free Software Foundation, Inc., 15 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 17 *****************************************************************************/ 18 19 /**************************************************//** 20 @file include/trx0trx.h 21 The transaction 22 23 Created 3/26/1996 Heikki Tuuri 24 *******************************************************/ 25 26 #ifndef trx0trx_h 27 #define trx0trx_h 28 29 #include "univ.i" 30 #include "trx0types.h" 31 #include "dict0types.h" 32 #ifndef UNIV_HOTBACKUP 33 #include "lock0types.h" 34 #include "usr0types.h" 35 #include "que0types.h" 36 #include "mem0mem.h" 37 #include "read0types.h" 38 #include "trx0xa.h" 39 #include "ut0vec.h" 40 41 /** Dummy session used currently in MySQL interface */ 42 extern sess_t* trx_dummy_sess; 43 44 /** Number of transactions currently allocated for MySQL: protected by 45 the kernel mutex */ 46 extern ulint trx_n_mysql_transactions; 47 /** Number of transactions currently in the XA PREPARED state: protected by 48 the kernel mutex */ 49 extern ulint trx_n_prepared; 50 51 /********************************************************************//** 52 Releases the search latch if trx has reserved it. */ 53 UNIV_INTERN 54 void 55 trx_search_latch_release_if_reserved( 56 /*=================================*/ 57 trx_t* trx); /*!< in: transaction */ 58 /******************************************************************//** 59 Set detailed error message for the transaction. */ 60 UNIV_INTERN 61 void 62 trx_set_detailed_error( 63 /*===================*/ 64 trx_t* trx, /*!< in: transaction struct */ 65 const char* msg); /*!< in: detailed error message */ 66 /*************************************************************//** 67 Set detailed error message for the transaction from a file. Note that the 68 file is rewinded before reading from it. */ 69 UNIV_INTERN 70 void 71 trx_set_detailed_error_from_file( 72 /*=============================*/ 73 trx_t* trx, /*!< in: transaction struct */ 74 FILE* file); /*!< in: file to read message from */ 75 /****************************************************************//** 76 Retrieves the error_info field from a trx. 77 @return the error info */ 78 UNIV_INLINE 79 const dict_index_t* 80 trx_get_error_info( 81 /*===============*/ 82 const trx_t* trx); /*!< in: trx object */ 83 /****************************************************************//** 84 Creates and initializes a transaction object. 85 @return own: the transaction */ 86 UNIV_INTERN 87 trx_t* 88 trx_create( 89 /*=======*/ 90 sess_t* sess) /*!< in: session */ 91 __attribute__((nonnull)); 92 /********************************************************************//** 93 Creates a transaction object for MySQL. 94 @return own: transaction object */ 95 UNIV_INTERN 96 trx_t* 97 trx_allocate_for_mysql(void); 98 /*========================*/ 99 /********************************************************************//** 100 Creates a transaction object for background operations by the master thread. 101 @return own: transaction object */ 102 UNIV_INTERN 103 trx_t* 104 trx_allocate_for_background(void); 105 /*=============================*/ 106 /********************************************************************//** 107 Frees a transaction object. */ 108 UNIV_INTERN 109 void 110 trx_free( 111 /*=====*/ 112 trx_t* trx); /*!< in, own: trx object */ 113 /********************************************************************//** 114 At shutdown, frees a transaction object that is in the PREPARED state. */ 115 UNIV_INTERN 116 void 117 trx_free_prepared( 118 /*==============*/ 119 trx_t* trx) /*!< in, own: trx object */ 120 UNIV_COLD __attribute__((nonnull)); 121 /********************************************************************//** 122 Frees a transaction object for MySQL. */ 123 UNIV_INTERN 124 void 125 trx_free_for_mysql( 126 /*===============*/ 127 trx_t* trx); /*!< in, own: trx object */ 128 /********************************************************************//** 129 Frees a transaction object of a background operation of the master thread. */ 130 UNIV_INTERN 131 void 132 trx_free_for_background( 133 /*====================*/ 134 trx_t* trx); /*!< in, own: trx object */ 135 /****************************************************************//** 136 Creates trx objects for transactions and initializes the trx list of 137 trx_sys at database start. Rollback segment and undo log lists must 138 already exist when this function is called, because the lists of 139 transactions to be rolled back or cleaned up are built based on the 140 undo log lists. */ 141 UNIV_INTERN 142 void 143 trx_lists_init_at_db_start(void); 144 /*============================*/ 145 /****************************************************************//** 146 Starts a new transaction. 147 @return TRUE if success, FALSE if the rollback segment could not 148 support this many transactions */ 149 UNIV_INTERN 150 ibool 151 trx_start( 152 /*======*/ 153 trx_t* trx, /*!< in: transaction */ 154 ulint rseg_id);/*!< in: rollback segment id; if ULINT_UNDEFINED 155 is passed, the system chooses the rollback segment 156 automatically in a round-robin fashion */ 157 /****************************************************************//** 158 Starts a new transaction. 159 @return TRUE */ 160 UNIV_INTERN 161 ibool 162 trx_start_low( 163 /*==========*/ 164 trx_t* trx, /*!< in: transaction */ 165 ulint rseg_id);/*!< in: rollback segment id; if ULINT_UNDEFINED 166 is passed, the system chooses the rollback segment 167 automatically in a round-robin fashion */ 168 /*************************************************************//** 169 Starts the transaction if it is not yet started. */ 170 UNIV_INLINE 171 void 172 trx_start_if_not_started( 173 /*=====================*/ 174 trx_t* trx); /*!< in: transaction */ 175 /*************************************************************//** 176 Starts the transaction if it is not yet started. Assumes we have reserved 177 the kernel mutex! */ 178 UNIV_INLINE 179 void 180 trx_start_if_not_started_low( 181 /*=========================*/ 182 trx_t* trx); /*!< in: transaction */ 183 /****************************************************************//** 184 Commits a transaction. */ 185 UNIV_INTERN 186 void 187 trx_commit_off_kernel( 188 /*==================*/ 189 trx_t* trx); /*!< in: transaction */ 190 /****************************************************************//** 191 Cleans up a transaction at database startup. The cleanup is needed if 192 the transaction already got to the middle of a commit when the database 193 crashed, and we cannot roll it back. */ 194 UNIV_INTERN 195 void 196 trx_cleanup_at_db_startup( 197 /*======================*/ 198 trx_t* trx); /*!< in: transaction */ 199 /**********************************************************************//** 200 Does the transaction commit for MySQL. 201 @return DB_SUCCESS or error number */ 202 UNIV_INTERN 203 ulint 204 trx_commit_for_mysql( 205 /*=================*/ 206 trx_t* trx); /*!< in: trx handle */ 207 /**********************************************************************//** 208 Does the transaction prepare for MySQL. 209 @return 0 or error number */ 210 UNIV_INTERN 211 ulint 212 trx_prepare_for_mysql( 213 /*==================*/ 214 trx_t* trx); /*!< in: trx handle */ 215 /**********************************************************************//** 216 This function is used to find number of prepared transactions and 217 their transaction objects for a recovery. 218 @return number of prepared transactions */ 219 UNIV_INTERN 220 int 221 trx_recover_for_mysql( 222 /*==================*/ 223 XID* xid_list, /*!< in/out: prepared transactions */ 224 ulint len); /*!< in: number of slots in xid_list */ 225 /*******************************************************************//** 226 This function is used to find one X/Open XA distributed transaction 227 which is in the prepared state 228 @return trx or NULL; on match, the trx->xid will be invalidated */ 229 UNIV_INTERN 230 trx_t * 231 trx_get_trx_by_xid( 232 /*===============*/ 233 const XID* xid); /*!< in: X/Open XA transaction identifier */ 234 /**********************************************************************//** 235 If required, flushes the log to disk if we called trx_commit_for_mysql() 236 with trx->flush_log_later == TRUE. 237 @return 0 or error number */ 238 UNIV_INTERN 239 ulint 240 trx_commit_complete_for_mysql( 241 /*==========================*/ 242 trx_t* trx); /*!< in: trx handle */ 243 /**********************************************************************//** 244 Marks the latest SQL statement ended. */ 245 UNIV_INTERN 246 void 247 trx_mark_sql_stat_end( 248 /*==================*/ 249 trx_t* trx); /*!< in: trx handle */ 250 /********************************************************************//** 251 Assigns a read view for a consistent read query. All the consistent reads 252 within the same transaction will get the same read view, which is created 253 when this function is first called for a new started transaction. 254 @return consistent read view */ 255 UNIV_INTERN 256 read_view_t* 257 trx_assign_read_view( 258 /*=================*/ 259 trx_t* trx); /*!< in: active transaction */ 260 /***********************************************************//** 261 The transaction must be in the TRX_QUE_LOCK_WAIT state. Puts it to 262 the TRX_QUE_RUNNING state and releases query threads which were 263 waiting for a lock in the wait_thrs list. */ 264 UNIV_INTERN 265 void 266 trx_end_lock_wait( 267 /*==============*/ 268 trx_t* trx); /*!< in: transaction */ 269 /****************************************************************//** 270 Sends a signal to a trx object. */ 271 UNIV_INTERN 272 void 273 trx_sig_send( 274 /*=========*/ 275 trx_t* trx, /*!< in: trx handle */ 276 ulint type, /*!< in: signal type */ 277 ulint sender, /*!< in: TRX_SIG_SELF or 278 TRX_SIG_OTHER_SESS */ 279 que_thr_t* receiver_thr, /*!< in: query thread which wants the 280 reply, or NULL; if type is 281 TRX_SIG_END_WAIT, this must be NULL */ 282 trx_savept_t* savept, /*!< in: possible rollback savepoint, or 283 NULL */ 284 que_thr_t** next_thr); /*!< in/out: next query thread to run; 285 if the value which is passed in is 286 a pointer to a NULL pointer, then the 287 calling function can start running 288 a new query thread; if the parameter 289 is NULL, it is ignored */ 290 /****************************************************************//** 291 Send the reply message when a signal in the queue of the trx has 292 been handled. */ 293 UNIV_INTERN 294 void 295 trx_sig_reply( 296 /*==========*/ 297 trx_sig_t* sig, /*!< in: signal */ 298 que_thr_t** next_thr); /*!< in/out: next query thread to run; 299 if the value which is passed in is 300 a pointer to a NULL pointer, then the 301 calling function can start running 302 a new query thread */ 303 /****************************************************************//** 304 Removes the signal object from a trx signal queue. */ 305 UNIV_INTERN 306 void 307 trx_sig_remove( 308 /*===========*/ 309 trx_t* trx, /*!< in: trx handle */ 310 trx_sig_t* sig); /*!< in, own: signal */ 311 /****************************************************************//** 312 Starts handling of a trx signal. */ 313 UNIV_INTERN 314 void 315 trx_sig_start_handle( 316 /*=================*/ 317 trx_t* trx, /*!< in: trx handle */ 318 que_thr_t** next_thr); /*!< in/out: next query thread to run; 319 if the value which is passed in is 320 a pointer to a NULL pointer, then the 321 calling function can start running 322 a new query thread */ 323 /****************************************************************//** 324 Ends signal handling. If the session is in the error state, and 325 trx->graph_before_signal_handling != NULL, returns control to the error 326 handling routine of the graph (currently only returns the control to the 327 graph root which then sends an error message to the client). */ 328 UNIV_INTERN 329 void 330 trx_end_signal_handling( 331 /*====================*/ 332 trx_t* trx); /*!< in: trx */ 333 /*********************************************************************//** 334 Creates a commit command node struct. 335 @return own: commit node struct */ 336 UNIV_INTERN 337 commit_node_t* 338 commit_node_create( 339 /*===============*/ 340 mem_heap_t* heap); /*!< in: mem heap where created */ 341 /***********************************************************//** 342 Performs an execution step for a commit type node in a query graph. 343 @return query thread to run next, or NULL */ 344 UNIV_INTERN 345 que_thr_t* 346 trx_commit_step( 347 /*============*/ 348 que_thr_t* thr); /*!< in: query thread */ 349 350 /**********************************************************************//** 351 Prints info about a transaction to the given file. The caller must own the 352 kernel mutex. */ 353 UNIV_INTERN 354 void 355 trx_print( 356 /*======*/ 357 FILE* f, /*!< in: output stream */ 358 trx_t* trx, /*!< in: transaction */ 359 ulint max_query_len); /*!< in: max query length to print, or 0 to 360 use the default max length */ 361 362 /** Type of data dictionary operation */ 363 typedef enum trx_dict_op { 364 /** The transaction is not modifying the data dictionary. */ 365 TRX_DICT_OP_NONE = 0, 366 /** The transaction is creating a table or an index, or 367 dropping a table. The table must be dropped in crash 368 recovery. This and TRX_DICT_OP_NONE are the only possible 369 operation modes in crash recovery. */ 370 TRX_DICT_OP_TABLE = 1, 371 /** The transaction is creating or dropping an index in an 372 existing table. In crash recovery, the data dictionary 373 must be locked, but the table must not be dropped. */ 374 TRX_DICT_OP_INDEX = 2 375 } trx_dict_op_t; 376 377 /**********************************************************************//** 378 Determine if a transaction is a dictionary operation. 379 @return dictionary operation mode */ 380 UNIV_INLINE 381 enum trx_dict_op 382 trx_get_dict_operation( 383 /*===================*/ 384 const trx_t* trx) /*!< in: transaction */ 385 __attribute__((pure)); 386 /**********************************************************************//** 387 Flag a transaction a dictionary operation. */ 388 UNIV_INLINE 389 void 390 trx_set_dict_operation( 391 /*===================*/ 392 trx_t* trx, /*!< in/out: transaction */ 393 enum trx_dict_op op); /*!< in: operation, not 394 TRX_DICT_OP_NONE */ 395 396 #ifndef UNIV_HOTBACKUP 397 /**********************************************************************//** 398 Determines if the currently running transaction has been interrupted. 399 @return TRUE if interrupted */ 400 UNIV_INTERN 401 ibool 402 trx_is_interrupted( 403 /*===============*/ 404 trx_t* trx); /*!< in: transaction */ 405 /**********************************************************************//** 406 Determines if the currently running transaction is in strict mode. 407 @return TRUE if strict */ 408 UNIV_INTERN 409 ibool 410 trx_is_strict( 411 /*==========*/ 412 trx_t* trx); /*!< in: transaction */ 413 #else /* !UNIV_HOTBACKUP */ 414 #define trx_is_interrupted(trx) FALSE 415 #endif /* !UNIV_HOTBACKUP */ 416 417 /*******************************************************************//** 418 Calculates the "weight" of a transaction. The weight of one transaction 419 is estimated as the number of altered rows + the number of locked rows. 420 @param t transaction 421 @return transaction weight */ 422 #define TRX_WEIGHT(t) ((t)->undo_no + UT_LIST_GET_LEN((t)->trx_locks)) 423 424 /*******************************************************************//** 425 Compares the "weight" (or size) of two transactions. Transactions that 426 have edited non-transactional tables are considered heavier than ones 427 that have not. 428 @return TRUE if weight(a) >= weight(b) */ 429 UNIV_INTERN 430 ibool 431 trx_weight_ge( 432 /*==========*/ 433 const trx_t* a, /*!< in: the first transaction to be compared */ 434 const trx_t* b); /*!< in: the second transaction to be compared */ 435 436 /* Maximum length of a string that can be returned by 437 trx_get_que_state_str(). */ 438 #define TRX_QUE_STATE_STR_MAX_LEN 12 /* "ROLLING BACK" */ 439 440 /*******************************************************************//** 441 Retrieves transaction's que state in a human readable string. The string 442 should not be free()'d or modified. 443 @return string in the data segment */ 444 UNIV_INLINE 445 const char* 446 trx_get_que_state_str( 447 /*==================*/ 448 const trx_t* trx); /*!< in: transaction */ 449 450 /* Signal to a transaction */ 451 struct trx_sig_struct{ 452 unsigned type:3; /*!< signal type */ 453 unsigned sender:1; /*!< TRX_SIG_SELF or 454 TRX_SIG_OTHER_SESS */ 455 que_thr_t* receiver; /*!< non-NULL if the sender of the signal 456 wants reply after the operation induced 457 by the signal is completed */ 458 trx_savept_t savept; /*!< possible rollback savepoint */ 459 UT_LIST_NODE_T(trx_sig_t) 460 signals; /*!< queue of pending signals to the 461 transaction */ 462 UT_LIST_NODE_T(trx_sig_t) 463 reply_signals; /*!< list of signals for which the sender 464 transaction is waiting a reply */ 465 }; 466 467 #define TRX_MAGIC_N 91118598 468 469 /* The transaction handle; every session has a trx object which is freed only 470 when the session is freed; in addition there may be session-less transactions 471 rolling back after a database recovery */ 472 473 struct trx_struct{ 474 ulint magic_n; 475 476 /* These fields are not protected by any mutex. */ 477 const char* op_info; /*!< English text describing the 478 current operation, or an empty 479 string */ 480 ulint conc_state; /*!< state of the trx from the point 481 of view of concurrency control: 482 TRX_ACTIVE, TRX_COMMITTED_IN_MEMORY, 483 ... */ 484 /*------------------------------*/ 485 /* MySQL has a transaction coordinator to coordinate two phase 486 commit between multiple storage engines and the binary log. When 487 an engine participates in a transaction, it's responsible for 488 registering itself using the trans_register_ha() API. */ 489 unsigned is_registered:1;/* This flag is set to 1 after the 490 transaction has been registered with 491 the coordinator using the XA API, and 492 is set to 0 after commit or rollback. */ 493 unsigned owns_prepare_mutex:1;/* 1 if owns prepare mutex, if 494 this is set to 1 then registered should 495 also be set to 1. This is used in the 496 XA code */ 497 /*------------------------------*/ 498 ulint isolation_level;/* TRX_ISO_REPEATABLE_READ, ... */ 499 ulint check_foreigns; /* normally TRUE, but if the user 500 wants to suppress foreign key checks, 501 (in table imports, for example) we 502 set this FALSE */ 503 ulint check_unique_secondary; 504 /* normally TRUE, but if the user 505 wants to speed up inserts by 506 suppressing unique key checks 507 for secondary indexes when we decide 508 if we can use the insert buffer for 509 them, we set this FALSE */ 510 ulint support_xa; /*!< normally we do the XA two-phase 511 commit steps, but by setting this to 512 FALSE, one can save CPU time and about 513 150 bytes in the undo log size as then 514 we skip XA steps */ 515 ulint flush_log_later;/* In 2PC, we hold the 516 prepare_commit mutex across 517 both phases. In that case, we 518 defer flush of the logs to disk 519 until after we release the 520 mutex. */ 521 ulint must_flush_log_later;/* this flag is set to TRUE in 522 trx_commit_off_kernel() if 523 flush_log_later was TRUE, and there 524 were modifications by the transaction; 525 in that case we must flush the log 526 in trx_commit_complete_for_mysql() */ 527 ulint duplicates; /*!< TRX_DUP_IGNORE | TRX_DUP_REPLACE */ 528 ulint has_search_latch; 529 /* TRUE if this trx has latched the 530 search system latch in S-mode */ 531 ulint deadlock_mark; /*!< a mark field used in deadlock 532 checking algorithm. */ 533 trx_dict_op_t dict_operation; /**< @see enum trx_dict_op */ 534 535 /* Fields protected by the srv_conc_mutex. */ 536 ulint declared_to_be_inside_innodb; 537 /* this is TRUE if we have declared 538 this transaction in 539 srv_conc_enter_innodb to be inside the 540 InnoDB engine */ 541 542 /* Fields protected by dict_operation_lock. The very latch 543 it is used to track. */ 544 ulint dict_operation_lock_mode; 545 /*!< 0, RW_S_LATCH, or RW_X_LATCH: 546 the latch mode trx currently holds 547 on dict_operation_lock */ 548 549 /* All the next fields are protected by the kernel mutex, except the 550 undo logs which are protected by undo_mutex */ 551 ulint is_purge; /*!< 0=user transaction, 1=purge */ 552 ulint is_recovered; /*!< 0=normal transaction, 553 1=recovered, must be rolled back */ 554 ulint que_state; /*!< valid when conc_state 555 == TRX_ACTIVE: TRX_QUE_RUNNING, 556 TRX_QUE_LOCK_WAIT, ... */ 557 ulint handling_signals;/* this is TRUE as long as the trx 558 is handling signals */ 559 time_t start_time; /*!< time the trx object was created 560 or the state last time became 561 TRX_ACTIVE */ 562 trx_id_t id; /*!< transaction id */ 563 XID xid; /*!< X/Open XA transaction 564 identification to identify a 565 transaction branch */ 566 trx_id_t no; /*!< transaction serialization number == 567 max trx id when the transaction is 568 moved to COMMITTED_IN_MEMORY state */ 569 ib_uint64_t commit_lsn; /*!< lsn at the time of the commit */ 570 table_id_t table_id; /*!< Table to drop iff dict_operation 571 is TRUE, or 0. */ 572 /*------------------------------*/ 573 void* mysql_thd; /*!< MySQL thread handle corresponding 574 to this trx, or NULL */ 575 const char* mysql_log_file_name; 576 /* if MySQL binlog is used, this field 577 contains a pointer to the latest file 578 name; this is NULL if binlog is not 579 used */ 580 ib_int64_t mysql_log_offset;/* if MySQL binlog is used, this field 581 contains the end offset of the binlog 582 entry */ 583 /*------------------------------*/ 584 ulint n_mysql_tables_in_use; /* number of Innobase tables 585 used in the processing of the current 586 SQL statement in MySQL */ 587 ulint mysql_n_tables_locked; 588 /* how many tables the current SQL 589 statement uses, except those 590 in consistent read */ 591 ulint search_latch_timeout; 592 /* If we notice that someone is 593 waiting for our S-lock on the search 594 latch to be released, we wait in 595 row0sel.c for BTR_SEA_TIMEOUT new 596 searches until we try to keep 597 the search latch again over 598 calls from MySQL; this is intended 599 to reduce contention on the search 600 latch */ 601 /*------------------------------*/ 602 ulint n_tickets_to_enter_innodb; 603 /* this can be > 0 only when 604 declared_to_... is TRUE; when we come 605 to srv_conc_innodb_enter, if the value 606 here is > 0, we decrement this by 1 */ 607 /*------------------------------*/ 608 UT_LIST_NODE_T(trx_t) 609 trx_list; /*!< list of transactions */ 610 UT_LIST_NODE_T(trx_t) 611 mysql_trx_list; /*!< list of transactions created for 612 MySQL */ 613 /*------------------------------*/ 614 ulint error_state; /*!< 0 if no error, otherwise error 615 number; NOTE That ONLY the thread 616 doing the transaction is allowed to 617 set this field: this is NOT protected 618 by the kernel mutex */ 619 const dict_index_t*error_info; /*!< if the error number indicates a 620 duplicate key error, a pointer to 621 the problematic index is stored here */ 622 ulint error_key_num; /*!< if the index creation fails to a 623 duplicate key error, a mysql key 624 number of that index is stored here */ 625 sess_t* sess; /*!< session of the trx, NULL if none */ 626 que_t* graph; /*!< query currently run in the session, 627 or NULL if none; NOTE that the query 628 belongs to the session, and it can 629 survive over a transaction commit, if 630 it is a stored procedure with a COMMIT 631 WORK statement, for instance */ 632 ulint n_active_thrs; /*!< number of active query threads */ 633 que_t* graph_before_signal_handling; 634 /* value of graph when signal handling 635 for this trx started: this is used to 636 return control to the original query 637 graph for error processing */ 638 trx_sig_t sig; /*!< one signal object can be allocated 639 in this space, avoiding mem_alloc */ 640 UT_LIST_BASE_NODE_T(trx_sig_t) 641 signals; /*!< queue of processed or pending 642 signals to the trx */ 643 UT_LIST_BASE_NODE_T(trx_sig_t) 644 reply_signals; /*!< list of signals sent by the query 645 threads of this trx for which a thread 646 is waiting for a reply; if this trx is 647 killed, the reply requests in the list 648 must be canceled */ 649 /*------------------------------*/ 650 lock_t* wait_lock; /*!< if trx execution state is 651 TRX_QUE_LOCK_WAIT, this points to 652 the lock request, otherwise this is 653 NULL */ 654 ibool was_chosen_as_deadlock_victim; 655 /* when the transaction decides to wait 656 for a lock, it sets this to FALSE; 657 if another transaction chooses this 658 transaction as a victim in deadlock 659 resolution, it sets this to TRUE */ 660 time_t wait_started; /*!< lock wait started at this time */ 661 UT_LIST_BASE_NODE_T(que_thr_t) 662 wait_thrs; /*!< query threads belonging to this 663 trx that are in the QUE_THR_LOCK_WAIT 664 state */ 665 /*------------------------------*/ 666 mem_heap_t* lock_heap; /*!< memory heap for the locks of the 667 transaction */ 668 UT_LIST_BASE_NODE_T(lock_t) 669 trx_locks; /*!< locks reserved by the transaction */ 670 /*------------------------------*/ 671 mem_heap_t* global_read_view_heap; 672 /* memory heap for the global read 673 view */ 674 read_view_t* global_read_view; 675 /* consistent read view associated 676 to a transaction or NULL */ 677 read_view_t* read_view; /*!< consistent read view used in the 678 transaction or NULL, this read view 679 if defined can be normal read view 680 associated to a transaction (i.e. 681 same as global_read_view) or read view 682 associated to a cursor */ 683 /*------------------------------*/ 684 UT_LIST_BASE_NODE_T(trx_named_savept_t) 685 trx_savepoints; /*!< savepoints set with SAVEPOINT ..., 686 oldest first */ 687 /*------------------------------*/ 688 mutex_t undo_mutex; /*!< mutex protecting the fields in this 689 section (down to undo_no_arr), EXCEPT 690 last_sql_stat_start, which can be 691 accessed only when we know that there 692 cannot be any activity in the undo 693 logs! */ 694 undo_no_t undo_no; /*!< next undo log record number to 695 assign; since the undo log is 696 private for a transaction, this 697 is a simple ascending sequence 698 with no gaps; thus it represents 699 the number of modified/inserted 700 rows in a transaction */ 701 trx_savept_t last_sql_stat_start; 702 /* undo_no when the last sql statement 703 was started: in case of an error, trx 704 is rolled back down to this undo 705 number; see note at undo_mutex! */ 706 trx_rseg_t* rseg; /*!< rollback segment assigned to the 707 transaction, or NULL if not assigned 708 yet */ 709 trx_undo_t* insert_undo; /*!< pointer to the insert undo log, or 710 NULL if no inserts performed yet */ 711 trx_undo_t* update_undo; /*!< pointer to the update undo log, or 712 NULL if no update performed yet */ 713 undo_no_t roll_limit; /*!< least undo number to undo during 714 a rollback */ 715 ulint pages_undone; /*!< number of undo log pages undone 716 since the last undo log truncation */ 717 trx_undo_arr_t* undo_no_arr; /*!< array of undo numbers of undo log 718 records which are currently processed 719 by a rollback operation */ 720 /*------------------------------*/ 721 ulint n_autoinc_rows; /*!< no. of AUTO-INC rows required for 722 an SQL statement. This is useful for 723 multi-row INSERTs */ 724 ib_vector_t* autoinc_locks; /* AUTOINC locks held by this 725 transaction. Note that these are 726 also in the lock list trx_locks. This 727 vector needs to be freed explicitly 728 when the trx_t instance is desrtoyed */ 729 /*------------------------------*/ 730 char detailed_error[256]; /*!< detailed error message for last 731 error, or empty. */ 732 }; 733 734 #define TRX_MAX_N_THREADS 32 /* maximum number of 735 concurrent threads running a 736 single operation of a 737 transaction, e.g., a parallel 738 query */ 739 /* Transaction concurrency states (trx->conc_state) */ 740 #define TRX_NOT_STARTED 0 741 #define TRX_ACTIVE 1 742 #define TRX_COMMITTED_IN_MEMORY 2 743 #define TRX_PREPARED 3 /* Support for 2PC/XA */ 744 745 /* Transaction execution states when trx->conc_state == TRX_ACTIVE */ 746 #define TRX_QUE_RUNNING 0 /* transaction is running */ 747 #define TRX_QUE_LOCK_WAIT 1 /* transaction is waiting for a lock */ 748 #define TRX_QUE_ROLLING_BACK 2 /* transaction is rolling back */ 749 #define TRX_QUE_COMMITTING 3 /* transaction is committing */ 750 751 /* Transaction isolation levels (trx->isolation_level) */ 752 #define TRX_ISO_READ_UNCOMMITTED 0 /* dirty read: non-locking 753 SELECTs are performed so that 754 we do not look at a possible 755 earlier version of a record; 756 thus they are not 'consistent' 757 reads under this isolation 758 level; otherwise like level 759 2 */ 760 761 #define TRX_ISO_READ_COMMITTED 1 /* somewhat Oracle-like 762 isolation, except that in 763 range UPDATE and DELETE we 764 must block phantom rows 765 with next-key locks; 766 SELECT ... FOR UPDATE and ... 767 LOCK IN SHARE MODE only lock 768 the index records, NOT the 769 gaps before them, and thus 770 allow free inserting; 771 each consistent read reads its 772 own snapshot */ 773 774 #define TRX_ISO_REPEATABLE_READ 2 /* this is the default; 775 all consistent reads in the 776 same trx read the same 777 snapshot; 778 full next-key locking used 779 in locking reads to block 780 insertions into gaps */ 781 782 #define TRX_ISO_SERIALIZABLE 3 /* all plain SELECTs are 783 converted to LOCK IN SHARE 784 MODE reads */ 785 786 /* Treatment of duplicate values (trx->duplicates; for example, in inserts). 787 Multiple flags can be combined with bitwise OR. */ 788 #define TRX_DUP_IGNORE 1 /* duplicate rows are to be updated */ 789 #define TRX_DUP_REPLACE 2 /* duplicate rows are to be replaced */ 790 791 792 /* Types of a trx signal */ 793 #define TRX_SIG_NO_SIGNAL 0 794 #define TRX_SIG_TOTAL_ROLLBACK 1 795 #define TRX_SIG_ROLLBACK_TO_SAVEPT 2 796 #define TRX_SIG_COMMIT 3 797 #define TRX_SIG_ERROR_OCCURRED 4 798 #define TRX_SIG_BREAK_EXECUTION 5 799 800 /* Sender types of a signal */ 801 #define TRX_SIG_SELF 0 /* sent by the session itself, or 802 by an error occurring within this 803 session */ 804 #define TRX_SIG_OTHER_SESS 1 /* sent by another session (which 805 must hold rights to this) */ 806 807 /** Commit node states */ 808 enum commit_node_state { 809 COMMIT_NODE_SEND = 1, /*!< about to send a commit signal to 810 the transaction */ 811 COMMIT_NODE_WAIT /*!< commit signal sent to the transaction, 812 waiting for completion */ 813 }; 814 815 /** Commit command node in a query graph */ 816 struct commit_node_struct{ 817 que_common_t common; /*!< node type: QUE_NODE_COMMIT */ 818 enum commit_node_state 819 state; /*!< node execution state */ 820 }; 821 822 823 824 #ifndef UNIV_NONINL 825 #include "trx0trx.ic" 826 #endif 827 #endif /* !UNIV_HOTBACKUP */ 828 829 #endif 830