You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

889 lines
32 KiB

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