MySQL  8.0.12
Source Code Documentation
trx0trx.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 1996, 2018, Oracle and/or its affiliates. All Rights Reserved.
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24  The lines above are intentionally left blank
25 */
26 
27 /** @file include/trx0trx.h
28  The transaction
29 
30  Created 3/26/1996 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef trx0trx_h
34 #define trx0trx_h
35 
36 #include <list>
37 #include <set>
38 
39 #include "ha_prototypes.h"
40 
41 #include "dict0types.h"
42 #include "sql/handler.h"
43 #include "trx0types.h"
44 #include "ut0new.h"
45 
46 #include "lock0types.h"
47 #include "log0log.h"
48 #include "mem0mem.h"
49 #include "que0types.h"
50 #include "trx0xa.h"
51 #include "usr0types.h"
52 #include "ut0vec.h"
53 #ifndef UNIV_HOTBACKUP
54 #include "fts0fts.h"
55 #endif /* !UNIV_HOTBACKUP */
56 #include "srv0srv.h"
57 
58 // Forward declaration
59 struct mtr_t;
60 
61 // Forward declaration
62 class ReadView;
63 
64 // Forward declaration
65 class FlushObserver;
66 
67 /** Dummy session used currently in MySQL interface */
68 extern sess_t *trx_dummy_sess;
69 
70 #ifndef UNIV_HOTBACKUP
71 /** Set flush observer for the transaction
72 @param[in,out] trx transaction struct
73 @param[in] observer flush observer */
74 void trx_set_flush_observer(trx_t *trx, FlushObserver *observer);
75 
76 /** Set detailed error message for the transaction. */
77 void trx_set_detailed_error(trx_t *trx, /*!< in: transaction struct */
78  const char *msg); /*!< in: detailed error message */
79 /** Set detailed error message for the transaction from a file. Note that the
80  file is rewinded before reading from it. */
82  trx_t *trx, /*!< in: transaction struct */
83  FILE *file); /*!< in: file to read message from */
84 /** Retrieves the error_info field from a trx.
85  @return the error info */
86 UNIV_INLINE
87 const dict_index_t *trx_get_error_info(const trx_t *trx); /*!< in: trx object */
88 /** Creates a transaction object for MySQL.
89  @return own: transaction object */
91 /** Creates a transaction object for background operations by the master thread.
92  @return own: transaction object */
94 
95 /** Resurrect table locks for resurrected transactions. */
96 void trx_resurrect_locks();
97 
98 /** Free and initialize a transaction object instantiated during recovery.
99 @param[in,out] trx transaction object to free and initialize */
100 void trx_free_resurrected(trx_t *trx);
101 
102 /** Free a transaction that was allocated by background or user threads.
103 @param[in,out] trx transaction object to free */
104 void trx_free_for_background(trx_t *trx);
105 
106 /** At shutdown, frees a transaction object that is in the PREPARED state. */
107 void trx_free_prepared(trx_t *trx); /*!< in, own: trx object */
108 
109 /** Free a transaction object for MySQL.
110 @param[in,out] trx transaction */
111 void trx_free_for_mysql(trx_t *trx);
112 
113 /** Disconnect a transaction from MySQL.
114 @param[in,out] trx transaction */
115 void trx_disconnect_plain(trx_t *trx);
116 
117 /** Disconnect a prepared transaction from MySQL.
118 @param[in,out] trx transaction */
119 void trx_disconnect_prepared(trx_t *trx);
120 
121 /** Creates trx objects for transactions and initializes the trx list of
122  trx_sys at database start. Rollback segment and undo log lists must
123  already exist when this function is called, because the lists of
124  transactions to be rolled back or cleaned up are built based on the
125  undo log lists. */
126 void trx_lists_init_at_db_start(void);
127 
128 /** Starts the transaction if it is not yet started. */
130  trx_t *trx, /*!< in/out: transaction */
131  bool read_write); /*!< in: true if read write transaction */
132 /** Starts the transaction if it is not yet started. */
134  trx_t *trx, /*!< in/out: transaction */
135  bool read_write); /*!< in: true if read write transaction */
136 
137 /** Starts a transaction for internal processing. */
138 void trx_start_internal_low(trx_t *trx); /*!< in/out: transaction */
139 
140 /** Starts a read-only transaction for internal processing.
141 @param[in,out] trx transaction to be started */
143 
144 #ifdef UNIV_DEBUG
145 #define trx_start_if_not_started_xa(t, rw) \
146  do { \
147  (t)->start_line = __LINE__; \
148  (t)->start_file = __FILE__; \
149  trx_start_if_not_started_xa_low((t), rw); \
150  } while (false)
151 
152 #define trx_start_if_not_started(t, rw) \
153  do { \
154  (t)->start_line = __LINE__; \
155  (t)->start_file = __FILE__; \
156  trx_start_if_not_started_low((t), rw); \
157  } while (false)
158 
159 #define trx_start_internal(t) \
160  do { \
161  (t)->start_line = __LINE__; \
162  (t)->start_file = __FILE__; \
163  trx_start_internal_low((t)); \
164  } while (false)
165 
166 #define trx_start_internal_read_only(t) \
167  do { \
168  (t)->start_line = __LINE__; \
169  (t)->start_file = __FILE__; \
170  trx_start_internal_read_only_low(t); \
171  } while (false)
172 #else
173 #define trx_start_if_not_started(t, rw) trx_start_if_not_started_low((t), rw)
174 
175 #define trx_start_internal(t) trx_start_internal_low((t))
176 
177 #define trx_start_internal_read_only(t) trx_start_internal_read_only_low(t)
178 
179 #define trx_start_if_not_started_xa(t, rw) \
180  trx_start_if_not_started_xa_low((t), (rw))
181 #endif /* UNIV_DEBUG */
182 
183 /** Commits a transaction. */
184 void trx_commit(trx_t *trx); /*!< in/out: transaction */
185 
186 /** Commits a transaction and a mini-transaction. */
187 void trx_commit_low(
188  trx_t *trx, /*!< in/out: transaction */
189  mtr_t *mtr); /*!< in/out: mini-transaction (will be committed),
190  or NULL if trx made no modifications */
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 void trx_cleanup_at_db_startup(trx_t *trx); /*!< in: transaction */
195 /** Does the transaction commit for MySQL.
196  @return DB_SUCCESS or error number */
197 dberr_t trx_commit_for_mysql(trx_t *trx); /*!< in/out: transaction */
198 
199 /**
200 Does the transaction prepare for MySQL.
201 @param[in, out] trx Transaction instance to prepare */
202 
204 
205 /** This function is used to find number of prepared transactions and
206  their transaction objects for a recovery.
207  @return number of prepared transactions */
208 int trx_recover_for_mysql(XID *xid_list, /*!< in/out: prepared transactions */
209  ulint len); /*!< in: number of slots in xid_list */
210 /** This function is used to find one X/Open XA distributed transaction
211  which is in the prepared state
212  @return trx or NULL; on match, the trx->xid will be invalidated;
213  note that the trx may have been committed, unless the caller is
214  holding lock_sys->mutex */
216  const XID *xid); /*!< in: X/Open XA transaction identifier */
217 /** If required, flushes the log to disk if we called trx_commit_for_mysql()
218  with trx->flush_log_later == TRUE. */
219 void trx_commit_complete_for_mysql(trx_t *trx); /*!< in/out: transaction */
220 /** Marks the latest SQL statement ended. */
221 void trx_mark_sql_stat_end(trx_t *trx); /*!< in: trx handle */
222 /** Assigns a read view for a consistent read query. All the consistent reads
223  within the same transaction will get the same read view, which is created
224  when this function is first called for a new started transaction. */
225 ReadView *trx_assign_read_view(trx_t *trx); /*!< in: active transaction */
226 
227 /** @return the transaction's read view or NULL if one not assigned. */
228 UNIV_INLINE
230 
231 /** @return the transaction's read view or NULL if one not assigned. */
232 UNIV_INLINE
233 const ReadView *trx_get_read_view(const trx_t *trx);
234 
235 /** Prepares a transaction for commit/rollback. */
236 void trx_commit_or_rollback_prepare(trx_t *trx); /*!< in/out: transaction */
237 /** Creates a commit command node struct.
238  @return own: commit node struct */
240  mem_heap_t *heap); /*!< in: mem heap where created */
241 /** Performs an execution step for a commit type node in a query graph.
242  @return query thread to run next, or NULL */
243 que_thr_t *trx_commit_step(que_thr_t *thr); /*!< in: query thread */
244 
245 /** Prints info about a transaction.
246  Caller must hold trx_sys->mutex. */
247 void trx_print_low(FILE *f,
248  /*!< in: output stream */
249  const trx_t *trx,
250  /*!< in: transaction */
251  ulint max_query_len,
252  /*!< in: max query length to print,
253  or 0 to use the default max length */
254  ulint n_rec_locks,
255  /*!< in: lock_number_of_rows_locked(&trx->lock) */
256  ulint n_trx_locks,
257  /*!< in: length of trx->lock.trx_locks */
258  ulint heap_size);
259 /*!< in: mem_heap_get_size(trx->lock.lock_heap) */
260 
261 /** Prints info about a transaction.
262  The caller must hold lock_sys->mutex and trx_sys->mutex.
263  When possible, use trx_print() instead. */
264 void trx_print_latched(
265  FILE *f, /*!< in: output stream */
266  const trx_t *trx, /*!< in: transaction */
267  ulint max_query_len); /*!< in: max query length to print,
268  or 0 to use the default max length */
269 
270 /** Prints info about a transaction.
271  Acquires and releases lock_sys->mutex and trx_sys->mutex. */
272 void trx_print(FILE *f, /*!< in: output stream */
273  const trx_t *trx, /*!< in: transaction */
274  ulint max_query_len); /*!< in: max query length to print,
275  or 0 to use the default max length */
276 
277 /** Determine if a transaction is a dictionary operation.
278  @return dictionary operation mode */
279 UNIV_INLINE
281  const trx_t *trx) /*!< in: transaction */
282  MY_ATTRIBUTE((warn_unused_result));
283 
284 /** Flag a transaction a dictionary operation.
285 @param[in,out] trx transaction
286 @param[in] op operation, not TRX_DICT_OP_NONE */
287 UNIV_INLINE
288 void trx_set_dict_operation(trx_t *trx, enum trx_dict_op_t op);
289 
290 /** Determines if a transaction is in the given state.
291  The caller must hold trx_sys->mutex, or it must be the thread
292  that is serving a running transaction.
293  A running RW transaction must be in trx_sys->rw_trx_list.
294  @return true if trx->state == state */
295 UNIV_INLINE
296 bool trx_state_eq(const trx_t *trx, /*!< in: transaction */
297  trx_state_t state) /*!< in: state */
298  MY_ATTRIBUTE((warn_unused_result));
299 #ifdef UNIV_DEBUG
300 /** Asserts that a transaction has been started.
301  The caller must hold trx_sys->mutex.
302  @return true if started */
303 ibool trx_assert_started(const trx_t *trx) /*!< in: transaction */
304  MY_ATTRIBUTE((warn_unused_result));
305 #endif /* UNIV_DEBUG */
306 
307 /** Determines if the currently running transaction has been interrupted.
308  @return true if interrupted */
309 ibool trx_is_interrupted(const trx_t *trx); /*!< in: transaction */
310 /** Determines if the currently running transaction is in strict mode.
311  @return true if strict */
312 ibool trx_is_strict(trx_t *trx); /*!< in: transaction */
313 
314 /** Calculates the "weight" of a transaction. The weight of one transaction
315  is estimated as the number of altered rows + the number of locked rows.
316  @param t transaction
317  @return transaction weight */
318 #define TRX_WEIGHT(t) ((t)->undo_no + UT_LIST_GET_LEN((t)->lock.trx_locks))
319 
320 /** Compares the "weight" (or size) of two transactions. Transactions that
321  have edited non-transactional tables are considered heavier than ones
322  that have not.
323  @return true if weight(a) >= weight(b) */
324 bool trx_weight_ge(const trx_t *a, /*!< in: the transaction to be compared */
325  const trx_t *b); /*!< in: the transaction to be compared */
326 /* Maximum length of a string that can be returned by
327 trx_get_que_state_str(). */
328 #define TRX_QUE_STATE_STR_MAX_LEN 12 /* "ROLLING BACK" */
329 
330 /** Retrieves transaction's que state in a human readable string. The string
331  should not be free()'d or modified.
332  @return string in the data segment */
333 UNIV_INLINE
334 const char *trx_get_que_state_str(const trx_t *trx); /*!< in: transaction */
335 
336 /** Retreieves the transaction ID.
337 In a given point in time it is guaranteed that IDs of the running
338 transactions are unique. The values returned by this function for readonly
339 transactions may be reused, so a subsequent RO transaction may get the same ID
340 as a RO transaction that existed in the past. The values returned by this
341 function should be used for printing purposes only.
342 @param[in] trx transaction whose id to retrieve
343 @return transaction id */
344 UNIV_INLINE
346 
347 /** Assign a temp-tablespace bound rollback-segment to a transaction.
348 @param[in,out] trx transaction that involves write to temp-table. */
349 void trx_assign_rseg_temp(trx_t *trx);
350 
351 /** Create the trx_t pool */
352 void trx_pool_init();
353 
354 /** Destroy the trx_t pool */
355 void trx_pool_close();
356 
357 /**
358 Set the transaction as a read-write transaction if it is not already
359 tagged as such.
360 @param[in,out] trx Transaction that needs to be "upgraded" to RW from RO */
361 void trx_set_rw_mode(trx_t *trx);
362 
363 /**
364 Increase the reference count. If the transaction is in state
365 TRX_STATE_COMMITTED_IN_MEMORY then the transaction is considered
366 committed and the reference count is not incremented.
367 @param trx Transaction that is being referenced
368 @param do_ref_count Increment the reference iff this is true
369 @return transaction instance if it is not committed */
370 UNIV_INLINE
371 trx_t *trx_reference(trx_t *trx, bool do_ref_count);
372 
373 /**
374 Release the transaction. Decrease the reference count.
375 @param trx Transaction that is being released */
376 UNIV_INLINE
377 void trx_release_reference(trx_t *trx);
378 
379 /**
380 Check if the transaction is being referenced. */
381 #define trx_is_referenced(t) ((t)->n_ref > 0)
382 
383 /**
384 @param[in] requestor Transaction requesting the lock
385 @param[in] holder Transaction holding the lock
386 @return the transaction that will be rolled back, null don't care */
387 
388 UNIV_INLINE
389 const trx_t *trx_arbitrate(const trx_t *requestor, const trx_t *holder);
390 
391 /**
392 @param[in] trx Transaction to check
393 @return true if the transaction is a high priority transaction.*/
394 UNIV_INLINE
395 bool trx_is_high_priority(const trx_t *trx);
396 
397 /**
398 Kill all transactions that are blocking this transaction from acquiring locks.
399 @param[in,out] trx High priority transaction */
400 
401 void trx_kill_blocking(trx_t *trx);
402 
403 /**
404 Check if redo/noredo rseg is modified for insert/update.
405 @param[in] trx Transaction to check */
406 UNIV_INLINE
407 bool trx_is_rseg_updated(const trx_t *trx);
408 
409 /**
410 Transactions that aren't started by the MySQL server don't set
411 the trx_t::mysql_thd field. For such transactions we set the lock
412 wait timeout to 0 instead of the user configured value that comes
413 from innodb_lock_wait_timeout via trx_t::mysql_thd.
414 @param t transaction
415 @return lock wait timeout in seconds */
416 #define trx_lock_wait_timeout_get(t) \
417  ((t)->mysql_thd != NULL ? thd_lock_wait_timeout((t)->mysql_thd) : 0)
418 
419 /**
420 Determine if the transaction is a non-locking autocommit select
421 (implied read-only).
422 @param t transaction
423 @return true if non-locking autocommit select transaction. */
424 #define trx_is_autocommit_non_locking(t) \
425  ((t)->auto_commit && (t)->will_lock == 0)
426 
427 /**
428 Determine if the transaction is a non-locking autocommit select
429 with an explicit check for the read-only status.
430 @param t transaction
431 @return true if non-locking autocommit read-only transaction. */
432 #define trx_is_ac_nl_ro(t) \
433  ((t)->read_only && trx_is_autocommit_non_locking((t)))
434 
435 /**
436 Assert that the transaction is in the trx_sys_t::rw_trx_list */
437 #define assert_trx_in_rw_list(t) \
438  do { \
439  ut_ad(!(t)->read_only); \
440  ut_ad((t)->in_rw_trx_list == \
441  !((t)->read_only || !(t)->rsegs.m_redo.rseg)); \
442  check_trx_state(t); \
443  } while (0)
444 
445 /**
446 Check transaction state */
447 #define check_trx_state(t) \
448  do { \
449  ut_ad(!trx_is_autocommit_non_locking((t))); \
450  switch ((t)->state) { \
451  case TRX_STATE_PREPARED: \
452  /* fall through */ \
453  case TRX_STATE_ACTIVE: \
454  case TRX_STATE_COMMITTED_IN_MEMORY: \
455  continue; \
456  case TRX_STATE_NOT_STARTED: \
457  case TRX_STATE_FORCED_ROLLBACK: \
458  break; \
459  } \
460  ut_error; \
461  } while (0)
462 
463 /** Check if transaction is free so that it can be re-initialized.
464 @param t transaction handle */
465 #define assert_trx_is_free(t) \
466  do { \
467  ut_ad(trx_state_eq((t), TRX_STATE_NOT_STARTED) || \
468  trx_state_eq((t), TRX_STATE_FORCED_ROLLBACK)); \
469  ut_ad(!trx_is_rseg_updated(trx)); \
470  ut_ad(!MVCC::is_view_active((t)->read_view)); \
471  ut_ad((t)->lock.wait_thr == NULL); \
472  ut_ad(UT_LIST_GET_LEN((t)->lock.trx_locks) == 0); \
473  ut_ad((t)->dict_operation == TRX_DICT_OP_NONE); \
474  } while (0)
475 
476 /** Check if transaction is in-active so that it can be freed and put back to
477 transaction pool.
478 @param t transaction handle */
479 #define assert_trx_is_inactive(t) \
480  do { \
481  assert_trx_is_free((t)); \
482  ut_ad((t)->dict_operation_lock_mode == 0); \
483  } while (0)
484 
485 #ifdef UNIV_DEBUG
486 /** Assert that an autocommit non-locking select cannot be in the
487  rw_trx_list and that it is a read-only transaction.
488  The tranasction must be in the mysql_trx_list. */
489 #define assert_trx_nonlocking_or_in_list(t) \
490  do { \
491  if (trx_is_autocommit_non_locking(t)) { \
492  trx_state_t t_state = (t)->state; \
493  ut_ad((t)->read_only); \
494  ut_ad(!(t)->is_recovered); \
495  ut_ad(!(t)->in_rw_trx_list); \
496  ut_ad((t)->in_mysql_trx_list); \
497  ut_ad(t_state == TRX_STATE_NOT_STARTED || \
498  t_state == TRX_STATE_FORCED_ROLLBACK || \
499  t_state == TRX_STATE_ACTIVE); \
500  } else { \
501  check_trx_state(t); \
502  } \
503  } while (0)
504 #else /* UNIV_DEBUG */
505 /** Assert that an autocommit non-locking slect cannot be in the
506  rw_trx_list and that it is a read-only transaction.
507  The tranasction must be in the mysql_trx_list. */
508 #define assert_trx_nonlocking_or_in_list(trx) ((void)0)
509 #endif /* UNIV_DEBUG */
510 #endif /* !UNIV_HOTBACKUP */
511 
512 typedef std::vector<ib_lock_t *, ut_allocator<ib_lock_t *>> lock_pool_t;
513 
514 /** Latching protocol for trx_lock_t::que_state. trx_lock_t::que_state
515  captures the state of the query thread during the execution of a query.
516  This is different from a transaction state. The query state of a transaction
517  can be updated asynchronously by other threads. The other threads can be
518  system threads, like the timeout monitor thread or user threads executing
519  other queries. Another thing to be mindful of is that there is a delay between
520  when a query thread is put into LOCK_WAIT state and before it actually starts
521  waiting. Between these two events it is possible that the query thread is
522  granted the lock it was waiting for, which implies that the state can be
523  changed asynchronously.
524 
525  All these operations take place within the context of locking. Therefore state
526  changes within the locking code must acquire both the lock mutex and the
527  trx->mutex when changing trx->lock.que_state to TRX_QUE_LOCK_WAIT or
528  trx->lock.wait_lock to non-NULL but when the lock wait ends it is sufficient
529  to only acquire the trx->mutex.
530  To query the state either of the mutexes is sufficient within the locking
531  code and no mutex is required when the query thread is no longer waiting. */
532 
533 /** The locks and state of an active transaction. Protected by
534 lock_sys->mutex, trx->mutex or both. */
535 struct trx_lock_t {
536  ulint n_active_thrs; /*!< number of active query threads */
537 
538  trx_que_t que_state; /*!< valid when trx->state
539  == TRX_STATE_ACTIVE: TRX_QUE_RUNNING,
540  TRX_QUE_LOCK_WAIT, ... */
541 
542  lock_t *wait_lock; /*!< if trx execution state is
543  TRX_QUE_LOCK_WAIT, this points to
544  the lock request, otherwise this is
545  NULL; set to non-NULL when holding
546  both trx->mutex and lock_sys->mutex;
547  set to NULL when holding
548  lock_sys->mutex; readers should
549  hold lock_sys->mutex, except when
550  they are holding trx->mutex and
551  wait_lock==NULL */
552  ib_uint64_t deadlock_mark; /*!< A mark field that is initialized
553  to and checked against lock_mark_counter
554  by lock_deadlock_recursive(). */
556  /*!< when the transaction decides to
557  wait for a lock, it sets this to false;
558  if another transaction chooses this
559  transaction as a victim in deadlock
560  resolution, it sets this to true.
561  Protected by trx->mutex. */
562  time_t wait_started; /*!< lock wait started at this time,
563  protected only by lock_sys->mutex */
564 
565  que_thr_t *wait_thr; /*!< query thread belonging to this
566  trx that is in QUE_THR_LOCK_WAIT
567  state. For threads suspended in a
568  lock wait, this is protected by
569  lock_sys->mutex. Otherwise, this may
570  only be modified by the thread that is
571  serving the running transaction. */
572 
573  lock_pool_t rec_pool; /*!< Pre-allocated record locks */
574 
575  lock_pool_t table_pool; /*!< Pre-allocated table locks */
576 
577  ulint rec_cached; /*!< Next free rec lock in pool */
578 
579  ulint table_cached; /*!< Next free table lock in pool */
580 
581  mem_heap_t *lock_heap; /*!< memory heap for trx_locks;
582  protected by lock_sys->mutex */
583 
584  trx_lock_list_t trx_locks; /*!< locks requested by the transaction;
585  insertions are protected by trx->mutex
586  and lock_sys->mutex; removals are
587  protected by lock_sys->mutex */
588 
589  lock_pool_t table_locks; /*!< All table locks requested by this
590  transaction, including AUTOINC locks */
591 
592  bool cancel; /*!< true if the transaction is being
593  rolled back either via deadlock
594  detection or due to lock timeout. The
595  caller has to acquire the trx_t::mutex
596  in order to cancel the locks. In
597  lock_trx_table_locks_remove() we
598  check for this cancel of a transaction's
599  locks and avoid reacquiring the trx
600  mutex to prevent recursive deadlocks.
601  Protected by both the lock sys mutex
602  and the trx_t::mutex. */
603  ulint n_rec_locks; /*!< number of rec locks in this trx */
604 #ifdef UNIV_DEBUG
605  /** When a transaction is forced to rollback due to a deadlock
606  check or by another high priority transaction this is true. Used
607  by debug checks in lock0lock.cc */
609 #endif /* UNIV_DEBUG */
610 
611  /** The transaction called ha_innobase::start_stmt() to
612  lock a table. Most likely a temporary table. */
614 };
615 
616 /** Type used to store the list of tables that are modified by a given
617 transaction. We store pointers to the table objects in memory because
618 we know that a table object will not be destroyed while a transaction
619 that modified it is running. */
620 typedef std::set<dict_table_t *, std::less<dict_table_t *>,
623 
624 /** The transaction handle
625 
626 Normally, there is a 1:1 relationship between a transaction handle
627 (trx) and a session (client connection). One session is associated
628 with exactly one user transaction. There are some exceptions to this:
629 
630 * For DDL operations, a subtransaction is allocated that modifies the
631 data dictionary tables. Lock waits and deadlocks are prevented by
632 acquiring the dict_operation_lock before starting the subtransaction
633 and releasing it after committing the subtransaction.
634 
635 * The purge system uses a special transaction that is not associated
636 with any session.
637 
638 * If the system crashed or it was quickly shut down while there were
639 transactions in the ACTIVE or PREPARED state, these transactions would
640 no longer be associated with a session when the server is restarted.
641 
642 A session may be served by at most one thread at a time. The serving
643 thread of a session might change in some MySQL implementations.
644 Therefore we do not have os_thread_get_curr_id() assertions in the code.
645 
646 Normally, only the thread that is currently associated with a running
647 transaction may access (read and modify) the trx object, and it may do
648 so without holding any mutex. The following are exceptions to this:
649 
650 * trx_rollback_resurrected() may access resurrected (connectionless)
651 transactions while the system is already processing new user
652 transactions. The trx_sys->mutex prevents a race condition between it
653 and lock_trx_release_locks() [invoked by trx_commit()].
654 
655 * Print of transactions may access transactions not associated with
656 the current thread. The caller must be holding trx_sys->mutex and
657 lock_sys->mutex.
658 
659 * When a transaction handle is in the trx_sys->mysql_trx_list or
660 trx_sys->trx_list, some of its fields must not be modified without
661 holding trx_sys->mutex exclusively.
662 
663 * The locking code (in particular, deadlock checking and implicit to
664 explicit conversion) will access transactions associated to other
665 connections. The locks of transactions are protected by lock_sys->mutex
666 and sometimes by trx->mutex.
667 
668 * Killing of asynchronous transactions. */
669 
670 /** Represents an instance of rollback segment along with its state variables.*/
672  trx_rseg_t *rseg; /*!< rollback segment assigned to the
673  transaction, or NULL if not assigned
674  yet */
675  trx_undo_t *insert_undo; /*!< pointer to the insert undo log, or
676  NULL if no inserts performed yet */
677  trx_undo_t *update_undo; /*!< pointer to the update undo log, or
678  NULL if no update performed yet */
679 };
680 
681 /** Rollback segments assigned to a transaction for undo logging. */
682 struct trx_rsegs_t {
683  /** undo log ptr holding reference to a rollback segment that resides in
684  system/undo tablespace used for undo logging of tables that needs
685  to be recovered on crash. */
687 
688  /** undo log ptr holding reference to a rollback segment that resides in
689  temp tablespace used for undo logging of tables that doesn't need
690  to be recovered on crash. */
692 };
693 
695  TRX_RSEG_TYPE_NONE = 0, /*!< void rollback segment type. */
696  TRX_RSEG_TYPE_REDO, /*!< redo rollback segment. */
697  TRX_RSEG_TYPE_NOREDO /*!< non-redo rollback segment. */
698 };
699 
700 struct TrxVersion {
701  TrxVersion(trx_t *trx);
702 
703  /**
704  @return true if the trx_t instance is the same */
705  bool operator==(const TrxVersion &rhs) const { return (rhs.m_trx == m_trx); }
706 
708  ulint m_version;
709 };
710 
711 typedef std::list<TrxVersion, ut_allocator<TrxVersion>> hit_list_t;
712 
713 struct trx_t {
715 
716  /** dirty read: non-locking SELECTs are performed so that we
717  do not look at a possible earlier version of a record; thus
718  they are not 'consistent' reads under this isolation level;
719  otherwise like level 2 */
721 
722  /** somewhat Oracle-like isolation, except that in range UPDATE
723  and DELETE we must block phantom rows with next-key locks;
724  SELECT ... FOR UPDATE and ... LOCK IN SHARE MODE only lock
725  the index records, NOT the gaps before them, and thus allow
726  free inserting; each consistent read reads its own snapshot */
728 
729  /** this is the default; all consistent reads in the same trx
730  read the same snapshot; full next-key locking used in locking
731  reads to block insertions into gaps */
733 
734  /** all plain SELECTs are converted to LOCK IN SHARE MODE
735  reads */
736  SERIALIZABLE
737  };
738 
739  TrxMutex mutex; /*!< Mutex protecting the fields
740  state and lock (except some fields
741  of lock, which are protected by
742  lock_sys->mutex) */
743 
744  bool owns_mutex; /*!< Set to the transaction that owns
745  the mutex during lock acquire and/or
746  release.
747 
748  This is used to avoid taking the
749  trx_t::mutex recursively. */
750 
751  /* Note: in_depth was split from in_innodb for fixing a RO
752  performance issue. Acquiring the trx_t::mutex for each row
753  costs ~3% in performance. It is not required for correctness.
754  Therefore we increment/decrement in_depth without holding any
755  mutex. The assumption is that the Server will only ever call
756  the handler from one thread. This is not true for kill_connection.
757  Therefore in innobase_kill_connection. We don't increment this
758  counter via TrxInInnoDB. */
759 
760  ib_uint32_t in_depth; /*!< Track nested TrxInInnoDB
761  count */
762 
763  ib_uint32_t in_innodb; /*!< if the thread is executing
764  in the InnoDB context count > 0. */
765 
766  bool abort; /*!< if this flag is set then
767  this transaction must abort when
768  it can */
769 
770  trx_id_t id; /*!< transaction id */
771 
772  trx_id_t no; /*!< transaction serialization number:
773  max trx id shortly before the
774  transaction is moved to
775  COMMITTED_IN_MEMORY state.
776  Protected by trx_sys_t::mutex
777  when trx->in_rw_trx_list. Initially
778  set to TRX_ID_MAX. */
779 
780  /** State of the trx from the point of view of concurrency control
781  and the valid state transitions.
782 
783  Possible states:
784 
785  TRX_STATE_NOT_STARTED
786  TRX_STATE_FORCED_ROLLBACK
787  TRX_STATE_ACTIVE
788  TRX_STATE_PREPARED
789  TRX_STATE_COMMITTED_IN_MEMORY (alias below COMMITTED)
790 
791  Valid state transitions are:
792 
793  Regular transactions:
794  * NOT_STARTED -> ACTIVE -> COMMITTED -> NOT_STARTED
795 
796  Auto-commit non-locking read-only:
797  * NOT_STARTED -> ACTIVE -> NOT_STARTED
798 
799  XA (2PC):
800  * NOT_STARTED -> ACTIVE -> PREPARED -> COMMITTED -> NOT_STARTED
801 
802  Recovered XA:
803  * NOT_STARTED -> PREPARED -> COMMITTED -> (freed)
804 
805  XA (2PC) (shutdown or disconnect before ROLLBACK or COMMIT):
806  * NOT_STARTED -> PREPARED -> (freed)
807 
808  Disconnected XA can become recovered:
809  * ... -> ACTIVE -> PREPARED (connected) -> PREPARED (disconnected)
810  Disconnected means from mysql e.g due to the mysql client disconnection.
811  Latching and various transaction lists membership rules:
812 
813  XA (2PC) transactions are always treated as non-autocommit.
814 
815  Transitions to ACTIVE or NOT_STARTED occur when
816  !in_rw_trx_list (no trx_sys->mutex needed).
817 
818  Autocommit non-locking read-only transactions move between states
819  without holding any mutex. They are !in_rw_trx_list.
820 
821  All transactions, unless they are determined to be ac-nl-ro,
822  explicitly tagged as read-only or read-write, will first be put
823  on the read-only transaction list. Only when a !read-only transaction
824  in the read-only list tries to acquire an X or IX lock on a table
825  do we remove it from the read-only list and put it on the read-write
826  list. During this switch we assign it a rollback segment.
827 
828  When a transaction is NOT_STARTED, it can be in_mysql_trx_list if
829  it is a user transaction. It cannot be in rw_trx_list.
830 
831  ACTIVE->PREPARED->COMMITTED is only possible when trx->in_rw_trx_list.
832  The transition ACTIVE->PREPARED is protected by trx_sys->mutex.
833 
834  ACTIVE->COMMITTED is possible when the transaction is in
835  rw_trx_list.
836 
837  Transitions to COMMITTED are protected by both lock_sys->mutex
838  and trx->mutex.
839 
840  NOTE: Some of these state change constraints are an overkill,
841  currently only required for a consistent view for printing stats.
842  This unnecessarily adds a huge cost for the general case. */
843 
845 
846  /* If set, this transaction should stop inheriting (GAP)locks.
847  Generally set to true during transaction prepare for RC or lower
848  isolation, if requested. Needed for replication replay where
849  we don't want to get blocked on GAP locks taken for protecting
850  concurrent unique insert or replace operation. */
852 
853  ReadView *read_view; /*!< consistent read view used in the
854  transaction, or NULL if not yet set */
855 
857  trx_list; /*!< list of transactions;
858  protected by trx_sys->mutex. */
860  no_list; /*!< Required during view creation
861  to check for the view limit for
862  transactions that are committing */
863 
864  trx_lock_t lock; /*!< Information about the transaction
865  locks and state. Protected by
866  trx->mutex or lock_sys->mutex
867  or both */
868  bool is_recovered; /*!< 0=normal transaction,
869  1=recovered, must be rolled back,
870  protected by trx_sys->mutex when
871  trx->in_rw_trx_list holds */
872 
873  hit_list_t hit_list; /*!< List of transactions to kill,
874  when a high priority transaction
875  is blocked on a lock wait. */
876 
877  os_thread_id_t killed_by; /*!< The thread ID that wants to
878  kill this transaction asynchronously.
879  This is required because we recursively
880  enter the handlerton methods and need
881  to distinguish between the kill thread
882  and the transaction thread.
883 
884  Note: We need to be careful w.r.t the
885  Thread Pool. The thread doing the kill
886  should not leave InnoDB between the
887  mark and the actual async kill because
888  the running thread can change. */
889 
890  /* These fields are not protected by any mutex. */
891  const char *op_info; /*!< English text describing the
892  current operation, or an empty
893  string */
894  ulint isolation_level; /*!< TRX_ISO_REPEATABLE_READ, ... */
895  bool check_foreigns; /*!< normally TRUE, but if the user
896  wants to suppress foreign key checks,
897  (in table imports, for example) we
898  set this FALSE */
899  /*------------------------------*/
900  /* MySQL has a transaction coordinator to coordinate two phase
901  commit between multiple storage engines and the binary log. When
902  an engine participates in a transaction, it's responsible for
903  registering itself using the trans_register_ha() API. */
904  bool is_registered; /* This flag is set to true after the
905  transaction has been registered with
906  the coordinator using the XA API, and
907  is set to false after commit or
908  rollback. */
909  /*------------------------------*/
910  bool check_unique_secondary;
911  /*!< normally TRUE, but if the user
912  wants to speed up inserts by
913  suppressing unique key checks
914  for secondary indexes when we decide
915  if we can use the insert buffer for
916  them, we set this FALSE */
917  bool flush_log_later; /* In 2PC, we hold the
918  prepare_commit mutex across
919  both phases. In that case, we
920  defer flush of the logs to disk
921  until after we release the
922  mutex. */
923  bool must_flush_log_later; /*!< this flag is set to TRUE in
924  trx_commit() if flush_log_later was
925  TRUE, and there were modifications by
926  the transaction; in that case we must
927  flush the log in
928  trx_commit_complete_for_mysql() */
929  ulint duplicates; /*!< TRX_DUP_IGNORE | TRX_DUP_REPLACE */
930  bool has_search_latch;
931  /*!< TRUE if this trx has latched the
932  search system latch in S-mode.
933  This now can only be true in
934  row_search_mvcc, the btr search latch
935  must has been released before exiting,
936  and this flag would be set to false */
937  trx_dict_op_t dict_operation; /**< @see enum trx_dict_op_t */
938 
939  bool ddl_operation; /*!< True if this trx involves dd table
940  change */
941  bool ddl_must_flush; /*!< True if this trx involves dd table
942  change, and must flush */
943  bool in_truncate; /* This trx is doing truncation */
944 
945  /* Fields protected by the srv_conc_mutex. */
946  bool declared_to_be_inside_innodb;
947  /*!< this is TRUE if we have declared
948  this transaction in
949  srv_conc_enter_innodb to be inside the
950  InnoDB engine */
951  ib_uint32_t n_tickets_to_enter_innodb;
952  /*!< this can be > 0 only when
953  declared_to_... is TRUE; when we come
954  to srv_conc_innodb_enter, if the value
955  here is > 0, we decrement this by 1 */
956  ib_uint32_t dict_operation_lock_mode;
957  /*!< 0, RW_S_LATCH, or RW_X_LATCH:
958  the latch mode trx currently holds
959  on dict_operation_lock. Protected
960  by dict_operation_lock. */
961 
962  time_t start_time; /*!< time the state last time became
963  TRX_STATE_ACTIVE */
964 
965  /** Weight/Age of the transaction in the record lock wait queue. */
966  int32_t age;
967 
968  /** For tracking if Weight/age has been updated. */
969  uint64_t age_updated;
970 
971  lsn_t commit_lsn; /*!< lsn at the time of the commit */
972 
973  /*------------------------------*/
974  THD *mysql_thd; /*!< MySQL thread handle corresponding
975  to this trx, or NULL */
976 
977  const char *mysql_log_file_name;
978  /*!< if MySQL binlog is used, this field
979  contains a pointer to the latest file
980  name; this is NULL if binlog is not
981  used */
982  int64_t mysql_log_offset;
983  /*!< if MySQL binlog is used, this
984  field contains the end offset of the
985  binlog entry */
986  /*------------------------------*/
987  ib_uint32_t n_mysql_tables_in_use; /*!< number of Innobase tables
988  used in the processing of the current
989  SQL statement in MySQL */
990  ib_uint32_t mysql_n_tables_locked;
991  /*!< how many tables the current SQL
992  statement uses, except those
993  in consistent read */
994  /*------------------------------*/
995 #ifdef UNIV_DEBUG
996  /** The following two fields are mutually exclusive. */
997  /* @{ */
998 
999  bool in_rw_trx_list; /*!< true if in trx_sys->rw_trx_list */
1000  /* @} */
1001 #endif /* UNIV_DEBUG */
1003  mysql_trx_list; /*!< list of transactions created for
1004  MySQL; protected by trx_sys->mutex */
1005 #ifdef UNIV_DEBUG
1007  /*!< true if in
1008  trx_sys->mysql_trx_list */
1009 #endif /* UNIV_DEBUG */
1010  /*------------------------------*/
1011  dberr_t error_state; /*!< 0 if no error, otherwise error
1012  number; NOTE That ONLY the thread
1013  doing the transaction is allowed to
1014  set this field: this is NOT protected
1015  by any mutex */
1016  const dict_index_t *error_info; /*!< if the error number indicates a
1017  duplicate key error, a pointer to
1018  the problematic index is stored here */
1019  ulint error_key_num; /*!< if the index creation fails to a
1020  duplicate key error, a mysql key
1021  number of that index is stored here */
1022  sess_t *sess; /*!< session of the trx, NULL if none */
1023  que_t *graph; /*!< query currently run in the session,
1024  or NULL if none; NOTE that the query
1025  belongs to the session, and it can
1026  survive over a transaction commit, if
1027  it is a stored procedure with a COMMIT
1028  WORK statement, for instance */
1029  /*------------------------------*/
1031  trx_savepoints; /*!< savepoints set with SAVEPOINT ...,
1032  oldest first */
1033  /*------------------------------*/
1034  UndoMutex undo_mutex; /*!< mutex protecting the fields in this
1035  section (down to undo_no_arr), EXCEPT
1036  last_sql_stat_start, which can be
1037  accessed only when we know that there
1038  cannot be any activity in the undo
1039  logs! */
1040  undo_no_t undo_no; /*!< next undo log record number to
1041  assign; since the undo log is
1042  private for a transaction, this
1043  is a simple ascending sequence
1044  with no gaps; thus it represents
1045  the number of modified/inserted
1046  rows in a transaction */
1047  space_id_t undo_rseg_space;
1048  /*!< space id where last undo record
1049  was written */
1050  trx_savept_t last_sql_stat_start;
1051  /*!< undo_no when the last sql statement
1052  was started: in case of an error, trx
1053  is rolled back down to this undo
1054  number; see note at undo_mutex! */
1055  trx_rsegs_t rsegs; /* rollback segments for undo logging */
1056  undo_no_t roll_limit; /*!< least undo number to undo during
1057  a partial rollback; 0 otherwise */
1058 #ifdef UNIV_DEBUG
1059  bool in_rollback; /*!< true when the transaction is
1060  executing a partial or full rollback */
1061 #endif /* UNIV_DEBUG */
1062  ulint pages_undone; /*!< number of undo log pages undone
1063  since the last undo log truncation */
1064  /*------------------------------*/
1065  ulint n_autoinc_rows; /*!< no. of AUTO-INC rows required for
1066  an SQL statement. This is useful for
1067  multi-row INSERTs */
1068  ib_vector_t *autoinc_locks; /* AUTOINC locks held by this
1069  transaction. Note that these are
1070  also in the lock list trx_locks. This
1071  vector needs to be freed explicitly
1072  when the trx instance is destroyed.
1073  Protected by lock_sys->mutex. */
1074  /*------------------------------*/
1075  bool read_only; /*!< true if transaction is flagged
1076  as a READ-ONLY transaction.
1077  if auto_commit && will_lock == 0
1078  then it will be handled as a
1079  AC-NL-RO-SELECT (Auto Commit Non-Locking
1080  Read Only Select). A read only
1081  transaction will not be assigned an
1082  UNDO log. */
1083  bool auto_commit; /*!< true if it is an autocommit */
1084  ib_uint32_t will_lock; /*!< Will acquire some locks. Increment
1085  each time we determine that a lock will
1086  be acquired by the MySQL layer. */
1087 #ifndef UNIV_HOTBACKUP
1088  /*------------------------------*/
1089  fts_trx_t *fts_trx; /*!< FTS information, or NULL if
1090  transaction hasn't modified tables
1091  with FTS indexes (yet). */
1092  doc_id_t fts_next_doc_id; /* The document id used for updates */
1093  /*------------------------------*/
1094  ib_uint32_t flush_tables; /*!< if "covering" the FLUSH TABLES",
1095  count of tables being flushed. */
1096 
1097  /*------------------------------*/
1098  bool internal; /*!< true if it is a system/internal
1099  transaction background task. Such
1100  transactions are always treated as
1101  read-write. */
1102  /*------------------------------*/
1103 #ifdef UNIV_DEBUG
1104  ulint start_line; /*!< Track where it was started from */
1105  const char *start_file; /*!< Filename where it was started */
1106 #endif /* UNIV_DEBUG */
1107 
1108  lint n_ref; /*!< Count of references, protected
1109  by trx_t::mutex. We can't release the
1110  locks nor commit the transaction until
1111  this reference is 0. We can change
1112  the state to COMMITTED_IN_MEMORY to
1113  signify that it is no longer
1114  "active". */
1115 
1116  /** Version of this instance. It is incremented each time the
1117  instance is re-used in trx_start_low(). It is used to track
1118  whether a transaction has been restarted since it was tagged
1119  for asynchronous rollback. */
1120  ulint version;
1121 
1122  XID *xid; /*!< X/Open XA transaction
1123  identification to identify a
1124  transaction branch */
1125  trx_mod_tables_t mod_tables; /*!< List of tables that were modified
1126  by this transaction */
1127 #endif /* !UNIV_HOTBACKUP */
1128  /*------------------------------*/
1129  bool api_trx; /*!< trx started by InnoDB API */
1130  bool api_auto_commit; /*!< automatic commit */
1131  bool read_write; /*!< if read and write operation */
1132 
1133  /*------------------------------*/
1134  char *detailed_error; /*!< detailed error message for last
1135  error, or empty. */
1136  FlushObserver *flush_observer; /*!< flush observer */
1137 
1138 #ifdef UNIV_DEBUG
1139  bool is_dd_trx; /*!< True if the transaction is used for
1140  doing Non-locking Read-only Read
1141  Committed on DD tables */
1142 #endif /* UNIV_DEBUG */
1143  ulint magic_n;
1144 
1145  bool skip_gap_locks() const {
1146  switch (isolation_level) {
1147  case READ_UNCOMMITTED:
1148  case READ_COMMITTED:
1149  return (true);
1150  case REPEATABLE_READ:
1151  case SERIALIZABLE:
1152  return (false);
1153  }
1154  ut_ad(0);
1155  return (false);
1156  }
1157 
1158  bool allow_semi_consistent() const { return (skip_gap_locks()); }
1159 };
1160 #ifndef UNIV_HOTBACKUP
1161 
1162 /* Transaction isolation levels (trx->isolation_level) */
1163 #define TRX_ISO_READ_UNCOMMITTED trx_t::READ_UNCOMMITTED
1164 #define TRX_ISO_READ_COMMITTED trx_t::READ_COMMITTED
1165 #define TRX_ISO_REPEATABLE_READ trx_t::REPEATABLE_READ
1166 #define TRX_ISO_SERIALIZABLE trx_t::SERIALIZABLE
1167 
1168 /**
1169 Check if transaction is started.
1170 @param[in] trx Transaction whose state we need to check
1171 @return true if transaction is in state started */
1172 inline bool trx_is_started(const trx_t *trx) {
1173  return (trx->state != TRX_STATE_NOT_STARTED &&
1175 }
1176 
1177 /* Treatment of duplicate values (trx->duplicates; for example, in inserts).
1178 Multiple flags can be combined with bitwise OR. */
1179 #define TRX_DUP_IGNORE 1 /* duplicate rows are to be updated */
1180 #define TRX_DUP_REPLACE 2 /* duplicate rows are to be replaced */
1181 
1182 /** Commit node states */
1184  COMMIT_NODE_SEND = 1, /*!< about to send a commit signal to
1185  the transaction */
1186  COMMIT_NODE_WAIT /*!< commit signal sent to the transaction,
1187  waiting for completion */
1188 };
1189 
1190 /** Commit command node in a query graph */
1192  que_common_t common; /*!< node type: QUE_NODE_COMMIT */
1193  enum commit_node_state state; /*!< node execution state */
1194 };
1195 
1196 /** Test if trx->mutex is owned. */
1197 #define trx_mutex_own(t) mutex_own(&t->mutex)
1198 
1199 /** Acquire the trx->mutex. */
1200 #define trx_mutex_enter(t) \
1201  do { \
1202  mutex_enter(&t->mutex); \
1203  } while (0)
1204 
1205 /** Release the trx->mutex. */
1206 #define trx_mutex_exit(t) \
1207  do { \
1208  mutex_exit(&t->mutex); \
1209  } while (0)
1210 
1211 /** Track if a transaction is executing inside InnoDB code. It acts
1212 like a gate between the Server and InnoDB. */
1214  public:
1215  /**
1216  @param[in,out] trx Transaction entering InnoDB via the handler
1217  @param[in] disable true if called from COMMIT/ROLLBACK method */
1218  TrxInInnoDB(trx_t *trx, bool disable = false) : m_trx(trx) {
1219  enter(trx, disable);
1220  }
1221 
1222  /**
1223  Destructor */
1224  ~TrxInInnoDB() { exit(m_trx); }
1225 
1226  /**
1227  @return true if the transaction has been marked for asynchronous
1228  rollback */
1229  bool is_aborted() const { return (is_aborted(m_trx)); }
1230 
1231  /**
1232  @return true if the transaction can't be rolled back asynchronously */
1233  bool is_rollback_disabled() const {
1234  return ((m_trx->in_innodb & TRX_FORCE_ROLLBACK_DISABLE) > 0);
1235  }
1236 
1237  /**
1238  @return true if the transaction has been marked for asynchronous
1239  rollback */
1240  static bool is_aborted(const trx_t *trx) {
1241  if (trx->state == TRX_STATE_NOT_STARTED) {
1242  return (false);
1243  }
1244 
1245  ut_ad(srv_read_only_mode || trx->in_depth > 0);
1246  ut_ad(srv_read_only_mode || trx->in_innodb > 0);
1247 
1248  return (trx->abort || trx->state == TRX_STATE_FORCED_ROLLBACK);
1249  }
1250 
1251  /**
1252  Start statement requested for transaction.
1253  @param[in, out] trx Transaction at the start of a SQL statement */
1254  static void begin_stmt(trx_t *trx) { enter(trx, false); }
1255 
1256  /**
1257  Note an end statement for transaction
1258  @param[in, out] trx Transaction at end of a SQL statement */
1259  static void end_stmt(trx_t *trx) { exit(trx); }
1260 
1261  /**
1262  @return true if the rollback is being initiated by the thread that
1263  marked the transaction for asynchronous rollback */
1264  static bool is_async_rollback(const trx_t *trx) {
1265  return (trx->killed_by == os_thread_get_curr_id());
1266  }
1267 
1268  private:
1269  /** Note that we have crossed into InnoDB code.
1270  @param[in] trx transaction
1271  @param[in] disable true if called from COMMIT/ROLLBACK method */
1272  static void enter(trx_t *trx, bool disable) {
1273  if (srv_read_only_mode) {
1274  return;
1275  }
1276 
1277  ut_ad(!is_async_rollback(trx));
1278 
1279  /* If it hasn't already been marked for async rollback.
1280  and it will be committed/rolled back. */
1281  if (disable) {
1282  trx_mutex_enter(trx);
1283  if (!is_forced_rollback(trx) && is_started(trx) &&
1285  ut_ad(trx->killed_by == 0);
1286 
1287  /* This transaction has crossed the point of
1288  no return and cannot be rolled back
1289  asynchronously now. It must commit or rollback
1290  synhronously. */
1291 
1293  }
1294  trx_mutex_exit(trx);
1295  }
1296 
1297  /* Avoid excessive mutex acquire/release */
1298  ++trx->in_depth;
1299 
1300  /* If trx->in_depth is greater than 1 then
1301  transaction is already in InnoDB. */
1302  if (trx->in_depth > 1) {
1303  return;
1304  }
1305 
1306  trx_mutex_enter(trx);
1307 
1308  wait(trx);
1309 
1310  ut_ad((trx->in_innodb & TRX_FORCE_ROLLBACK_MASK) == 0);
1311 
1312  ++trx->in_innodb;
1313 
1314  trx_mutex_exit(trx);
1315  }
1316 
1317  /**
1318  Note that we are exiting InnoDB code */
1319  static void exit(trx_t *trx) {
1320  if (srv_read_only_mode) {
1321  return;
1322  }
1323 
1324  /* Avoid excessive mutex acquire/release */
1325 
1326  ut_ad(trx->in_depth > 0);
1327 
1328  --trx->in_depth;
1329 
1330  if (trx->in_depth > 0) {
1331  return;
1332  }
1333 
1334  trx_mutex_enter(trx);
1335 
1336  ut_ad((trx->in_innodb & TRX_FORCE_ROLLBACK_MASK) > 0);
1337 
1338  --trx->in_innodb;
1339 
1340  trx_mutex_exit(trx);
1341  }
1342 
1343  /*
1344  @return true if it is a forced rollback, asynchronously */
1345  static bool is_forced_rollback(const trx_t *trx) {
1346  ut_ad(trx_mutex_own(trx));
1347 
1348  return ((trx->in_innodb & TRX_FORCE_ROLLBACK)) > 0;
1349  }
1350 
1351  /**
1352  Wait for the asynchronous rollback to complete, if it is in progress */
1353  static void wait(trx_t *trx) {
1354  ut_ad(trx_mutex_own(trx));
1355 
1356  ulint loop_count = 0;
1357  /* start with optimistic sleep time - 20 micro seconds. */
1358  ulint sleep_time = 20;
1359 
1360  while (is_forced_rollback(trx)) {
1361  /* Wait for the async rollback to complete */
1362 
1363  trx_mutex_exit(trx);
1364 
1365  loop_count++;
1366  /* If the wait is long, don't hog the cpu. */
1367  if (loop_count < 100) {
1368  /* 20 microseconds */
1369  sleep_time = 20;
1370  } else if (loop_count < 1000) {
1371  /* 1 millisecond */
1372  sleep_time = 1000;
1373  } else {
1374  /* 100 milliseconds */
1375  sleep_time = 100000;
1376  }
1377 
1378  os_thread_sleep(sleep_time);
1379 
1380  trx_mutex_enter(trx);
1381  }
1382  }
1383 
1384  /**
1385  @return true if transaction is started */
1386  static bool is_started(const trx_t *trx) {
1387  ut_ad(trx_mutex_own(trx));
1388 
1389  return (trx_is_started(trx));
1390  }
1391 
1392  private:
1393  /**
1394  Transaction instance crossing the handler boundary from the Server. */
1396 };
1397 
1398 #include "trx0trx.ic"
1399 #endif /* !UNIV_HOTBACKUP */
1400 
1401 #endif
ibool trx_assert_started(const trx_t *trx)
Asserts that a transaction has been started.
Definition: trx0trx.cc:2416
Allocator class for allocating memory from inside std::* containers.
Definition: ut0new.h:501
#define trx_mutex_own(t)
Test if trx->mutex is owned.
Definition: trx0trx.h:1197
static bool is_started(const trx_t *trx)
Definition: trx0trx.h:1386
que_thr_t * wait_thr
query thread belonging to this trx that is in QUE_THR_LOCK_WAIT state.
Definition: trx0trx.h:565
void trx_free_for_background(trx_t *trx)
Free a transaction that was allocated by background or user threads.
Definition: trx0trx.cc:558
A vector of pointers to data items.
trx_t * trx_allocate_for_mysql(void)
Creates a transaction object for MySQL.
Definition: trx0trx.cc:498
ulint n_rec_locks
number of rec locks in this trx
Definition: trx0trx.h:603
Definition: trx0trx.h:700
os_thread_id_t killed_by
The thread ID that wants to kill this transaction asynchronously.
Definition: trx0trx.h:877
que_thr_t * trx_commit_step(que_thr_t *thr)
Performs an execution step for a commit type node in a query graph.
Definition: trx0trx.cc:2115
ib_mutex_t TrxMutex
Definition: trx0types.h:181
void trx_set_detailed_error_from_file(trx_t *trx, FILE *file)
Set detailed error message for the transaction from a file.
Definition: trx0trx.cc:106
UNIV_INLINE trx_id_t trx_get_id_for_print(const trx_t *trx)
Retreieves the transaction ID.
trx_lock_list_t trx_locks
locks requested by the transaction; insertions are protected by trx->mutex and lock_sys->mutex; remov...
Definition: trx0trx.h:584
uint64_t lsn_t
Type used for all log sequence number storage and arithmetics.
Definition: log0types.h:59
trx_state_t
Transaction states (trx_t::state)
Definition: trx0types.h:90
static void end_stmt(trx_t *trx)
Note an end statement for transaction.
Definition: trx0trx.h:1259
Prototypes for global functions in ha_innodb.cc that are called by InnoDB C code. ...
sess_t * sess
session of the trx, NULL if none
Definition: trx0trx.h:1022
trx_t * trx_allocate_for_background(void)
Creates a transaction object for background operations by the master thread.
Definition: trx0trx.cc:486
ulint rec_cached
Next free rec lock in pool.
Definition: trx0trx.h:577
bool trx_is_started(const trx_t *trx)
Check if transaction is started.
Definition: trx0trx.h:1172
isolation_level_t
Definition: trx0trx.h:714
void trx_set_detailed_error(trx_t *trx, const char *msg)
Set detailed error message for the transaction.
Definition: trx0trx.cc:98
void trx_start_internal_read_only_low(trx_t *trx)
Starts a read-only transaction for internal processing.
Definition: trx0trx.cc:2823
UNIV_INLINE bool trx_state_eq(const trx_t *trx, trx_state_t state)
Determines if a transaction is in the given state.
void trx_lists_init_at_db_start(void)
Creates trx objects for transactions and initializes the trx list of trx_sys at database start...
Definition: trx0trx.cc:944
ulint pages_undone
number of undo log pages undone since the last undo log truncation
Definition: trx0trx.h:1062
non-redo rollback segment.
Definition: trx0trx.h:697
Lock struct; protected by lock_sys->mutex.
Definition: lock0priv.h:109
Definition: trx0trx.h:713
std::set< dict_table_t *, std::less< dict_table_t * >, ut_allocator< dict_table_t * > > trx_mod_tables_t
Type used to store the list of tables that are modified by a given transaction.
Definition: trx0trx.h:622
ib_uint32_t will_lock
Will acquire some locks.
Definition: trx0trx.h:1084
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:47
ulint start_line
Track where it was started from.
Definition: trx0trx.h:1104
static bool is_aborted(const trx_t *trx)
Definition: trx0trx.h:1240
The transaction lock system global types.
ReadView * read_view
consistent read view used in the transaction, or NULL if not yet set
Definition: trx0trx.h:853
#define os_thread_sleep(usecs)
The thread sleeps at least the time given in microseconds.
Definition: os0thread.h:70
dberr_t error_state
0 if no error, otherwise error number; NOTE That ONLY the thread doing the transaction is allowed to ...
Definition: trx0trx.h:1011
#define trx_is_autocommit_non_locking(t)
Determine if the transaction is a non-locking autocommit select (implied read-only).
Definition: trx0trx.h:424
bool was_chosen_as_deadlock_victim
when the transaction decides to wait for a lock, it sets this to false; if another transaction choose...
Definition: trx0trx.h:555
trx_undo_ptr_t m_noredo
undo log ptr holding reference to a rollback segment that resides in temp tablespace used for undo lo...
Definition: trx0trx.h:691
void trx_commit_complete_for_mysql(trx_t *trx)
If required, flushes the log to disk if we called trx_commit_for_mysql() with trx->flush_log_later ==...
Definition: trx0trx.cc:2205
Information about changes in a single transaction affecting the FTS system.
Definition: fts0fts.h:227
Same as not started but with additional semantics that it was rolled back asynchronously the last tim...
Definition: trx0types.h:96
somewhat Oracle-like isolation, except that in range UPDATE and DELETE we must block phantom rows wit...
Definition: trx0trx.h:727
static void enter(trx_t *trx, bool disable)
Note that we have crossed into InnoDB code.
Definition: trx0trx.h:1272
void trx_print(FILE *f, const trx_t *trx, ulint max_query_len)
Prints info about a transaction.
Definition: trx0trx.cc:2390
ulint n_autoinc_rows
no.
Definition: trx0trx.h:1065
ReadView * trx_assign_read_view(trx_t *trx)
Assigns a read view for a consistent read query.
Definition: trx0trx.cc:2045
bool read_write
if read and write operation
Definition: trx0trx.h:1131
void trx_set_flush_observer(trx_t *trx, FlushObserver *observer)
Set flush observer for the transaction.
Definition: trx0trx.cc:93
trx_undo_ptr_t m_redo
undo log ptr holding reference to a rollback segment that resides in system/undo tablespace used for ...
Definition: trx0trx.h:686
bool is_dd_trx
True if the transaction is used for doing Non-locking Read-only Read Committed on DD tables...
Definition: trx0trx.h:1139
void trx_kill_blocking(trx_t *trx)
Kill all transactions that are blocking this transaction from acquiring locks.
Definition: trx0trx.cc:2893
Commit command node in a query graph.
Definition: trx0trx.h:1191
trx_rseg_t * rseg
rollback segment assigned to the transaction, or NULL if not assigned yet
Definition: trx0trx.h:672
void trx_assign_rseg_temp(trx_t *trx)
Assign a temp-tablespace bound rollback-segment to a transaction.
Definition: trx0trx.cc:1149
void rollback segment type.
Definition: trx0trx.h:695
static void exit(trx_t *trx)
Note that we are exiting InnoDB code.
Definition: trx0trx.h:1319
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:343
Redo log constants and functions.
dirty read: non-locking SELECTs are performed so that we do not look at a possible earlier version of...
Definition: trx0trx.h:720
ibool trx_is_strict(trx_t *trx)
Determines if the currently running transaction is in strict mode.
Definition: ha_innodb.cc:2782
static const ib_uint32_t TRX_FORCE_ROLLBACK_MASK
For masking out the above four flags.
Definition: trx0types.h:78
void trx_commit_or_rollback_prepare(trx_t *trx)
Prepares a transaction for commit/rollback.
Definition: trx0trx.cc:2061
The rollback segment memory object.
Definition: trx0types.h:187
Definition: que0que.h:297
commit_node_t * trx_commit_node_create(mem_heap_t *heap)
Creates a commit command node struct.
Definition: trx0trx.cc:2101
Transaction savepoint.
Definition: trx0types.h:158
trx_mod_tables_t mod_tables
List of tables that were modified by this transaction.
Definition: trx0trx.h:1125
The server main program.
Query graph global types.
Definition: trx0types.h:92
Full text search header file.
static bool is_forced_rollback(const trx_t *trx)
Definition: trx0trx.h:1345
que_t * graph
query currently run in the session, or NULL if none; NOTE that the query belongs to the session...
Definition: trx0trx.h:1023
sess_t * trx_dummy_sess
Dummy session used currently in MySQL interface.
Definition: trx0trx.cc:83
#define exit(A)
Definition: lexyy.cc:917
void trx_print_latched(FILE *f, const trx_t *trx, ulint max_query_len)
Prints info about a transaction.
Definition: trx0trx.cc:2374
bool in_rollback
When a transaction is forced to rollback due to a deadlock check or by another high priority transact...
Definition: trx0trx.h:608
void trx_commit_low(trx_t *trx, mtr_t *mtr)
Commits a transaction and a mini-transaction.
Definition: trx0trx.cc:1894
UNIV_INLINE enum trx_dict_op_t trx_get_dict_operation(const trx_t *trx)
Determine if a transaction is a dictionary operation.
ib_uint64_t doc_id_t
Document id type.
Definition: fts0fts.h:76
Data dictionary global types.
about to send a commit signal to the transaction
Definition: trx0trx.h:1184
ulint table_cached
Next free table lock in pool.
Definition: trx0trx.h:579
void trx_disconnect_plain(trx_t *trx)
Disconnect a transaction from MySQL.
Definition: trx0trx.cc:628
bool operator==(const TrxVersion &rhs) const
Definition: trx0trx.h:705
static void begin_stmt(trx_t *trx)
Start statement requested for transaction.
Definition: trx0trx.h:1254
void trx_free_resurrected(trx_t *trx)
Free and initialize a transaction object instantiated during recovery.
Definition: trx0trx.cc:548
void trx_mark_sql_stat_end(trx_t *trx)
Marks the latest SQL statement ended.
Definition: trx0trx.cc:2219
ib_vector_t * autoinc_locks
Definition: trx0trx.h:1068
lock_pool_t rec_pool
Pre-allocated record locks.
Definition: trx0trx.h:573
commit signal sent to the transaction, waiting for completion
Definition: trx0trx.h:1186
trx_t * m_trx
Definition: trx0trx.h:707
que_common_t common
node type: QUE_NODE_COMMIT
Definition: trx0trx.h:1192
doc_id_t fts_next_doc_id
Definition: trx0trx.h:1092
ib_uint32_t flush_tables
if "covering" the FLUSH TABLES", count of tables being flushed.
Definition: trx0trx.h:1094
dberr_t
Definition: db0err.h:38
ulint m_version
Definition: trx0trx.h:708
Definition: usr0sess.h:53
redo rollback segment.
Definition: trx0trx.h:696
static const ib_uint32_t TRX_FORCE_ROLLBACK
Mark the transaction for forced rollback.
Definition: trx0types.h:75
We use FlushObserver to track flushing of non-redo logged pages in bulk create index(BtrBulk.cc).Since we disable redo logging during a index build, we need to make sure that all dirty pages modifed by the index build are flushed to disk before any redo logged operations go to the index.
Definition: buf0flu.h:262
Instrumented memory allocator.
char * detailed_error
detailed error message for last error, or empty.
Definition: trx0trx.h:1134
bool auto_commit
true if it is an autocommit
Definition: trx0trx.h:1083
Definition: que0que.h:247
unsigned int len
Definition: dbug_analyze.cc:216
Definition: ut0vec.h:229
bool read_only
true if transaction is flagged as a READ-ONLY transaction.
Definition: trx0trx.h:1075
trx_que_t que_state
valid when trx->state == TRX_STATE_ACTIVE: TRX_QUE_RUNNING, TRX_QUE_LOCK_WAIT, ...
Definition: trx0trx.h:538
time_t wait_started
lock wait started at this time, protected only by lock_sys->mutex
Definition: trx0trx.h:562
UNIV_INLINE void trx_release_reference(trx_t *trx)
Release the transaction.
void trx_print_low(FILE *f, const trx_t *trx, ulint max_query_len, ulint n_rec_locks, ulint n_trx_locks, ulint heap_size)
Prints info about a transaction.
Definition: trx0trx.cc:2247
~TrxInInnoDB()
Destructor.
Definition: trx0trx.h:1224
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification, Distributed Transaction Processing: The XA Specification, X/Open Company Ltd., 1991.
Definition: xa.h:203
char msg[1024]
Definition: test_sql_9_sessions.cc:282
void trx_cleanup_at_db_startup(trx_t *trx)
Cleans up a transaction at database startup.
Definition: trx0trx.cc:2005
UNIV_INLINE void trx_set_dict_operation(trx_t *trx, enum trx_dict_op_t op)
Flag a transaction a dictionary operation.
Transaction system global type definitions.
bool allow_semi_consistent() const
Definition: trx0trx.h:1158
UNIV_INLINE trx_t * trx_reference(trx_t *trx, bool do_ref_count)
Increase the reference count.
TrxInInnoDB(trx_t *trx, bool disable=false)
Definition: trx0trx.h:1218
trx_undo_t * update_undo
pointer to the update undo log, or NULL if no update performed yet
Definition: trx0trx.h:677
Definition: que0types.h:50
UNIV_INLINE ReadView * trx_get_read_view(trx_t *trx)
FlushObserver * flush_observer
flush observer
Definition: trx0trx.h:1136
trx_state_t state
State of the trx from the point of view of concurrency control and the valid state transitions...
Definition: trx0trx.h:844
ulint version
Version of this instance.
Definition: trx0trx.h:1120
bool is_aborted() const
Definition: trx0trx.h:1229
The memory management.
trx_que_t
Transaction execution states when trx->state == TRX_STATE_ACTIVE.
Definition: trx0types.h:81
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
void trx_free_prepared(trx_t *trx)
At shutdown, frees a transaction object that is in the PREPARED state.
Definition: trx0trx.cc:565
void trx_resurrect_locks()
Resurrect table locks for resurrected transactions.
Definition: trx0trx.cc:702
UNIV_INLINE const dict_index_t * trx_get_error_info(const trx_t *trx)
Retrieves the error_info field from a trx.
bool in_mysql_trx_list
true if in trx_sys->mysql_trx_list
Definition: trx0trx.h:1006
void trx_start_internal_low(trx_t *trx)
Starts a transaction for internal processing.
Definition: trx0trx.cc:2809
#define trx_mutex_exit(t)
Release the trx->mutex.
Definition: trx0trx.h:1206
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:60
ib_uint32_t in_innodb
if the thread is executing in the InnoDB context count > 0.
Definition: trx0trx.h:763
bool trx_weight_ge(const trx_t *a, const trx_t *b)
Compares the "weight" (or size) of two transactions.
Definition: trx0trx.cc:2450
A savepoint set with SQL&#39;s "SAVEPOINT savepoint_id" command.
Definition: trx0roll.h:168
bool skip_lock_inheritance
Definition: trx0trx.h:851
ib_uint32_t in_depth
Track nested TrxInInnoDB count.
Definition: trx0trx.h:760
void trx_disconnect_prepared(trx_t *trx)
Disconnect a prepared transaction from MySQL.
Definition: trx0trx.cc:634
static void wait(trx_t *trx)
Wait for the asynchronous rollback to complete, if it is in progress.
Definition: trx0trx.h:1353
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:148
void trx_free_for_mysql(trx_t *trx)
Free a transaction object for MySQL.
Definition: trx0trx.cc:640
dberr_t trx_commit_for_mysql(trx_t *trx)
Does the transaction commit for MySQL.
Definition: trx0trx.cc:2161
#define UT_LIST_BASE_NODE_T(TYPE)
Definition: innodb_utility.h:47
lock_t * wait_lock
if trx execution state is TRX_QUE_LOCK_WAIT, this points to the lock request, otherwise this is NULL;...
Definition: trx0trx.h:542
trx_id_t id
transaction id
Definition: trx0trx.h:770
ib_mutex_t UndoMutex
Definition: trx0types.h:182
trx_undo_t * insert_undo
pointer to the insert undo log, or NULL if no inserts performed yet
Definition: trx0trx.h:675
os_thread_id_t os_thread_get_curr_id()
Returns the thread identifier of current thread.
Definition: os0thread.cc:58
bool in_rw_trx_list
The following two fields are mutually exclusive.
Definition: trx0trx.h:999
bool abort
if this flag is set then this transaction must abort when it can
Definition: trx0trx.h:766
trx_dict_op_t
Type of data dictionary operation.
Definition: trx0types.h:107
trx_rseg_type_t
Definition: trx0trx.h:694
bool skip_gap_locks() const
Definition: trx0trx.h:1145
this is the default; all consistent reads in the same trx read the same snapshot; full next-key locki...
Definition: trx0trx.h:732
Transaction undo log memory object; this is protected by the undo_mutex in the corresponding transact...
Definition: trx0undo.h:335
lint n_ref
Count of references, protected by trx_t::mutex.
Definition: trx0trx.h:1108
#define trx_mutex_enter(t)
Acquire the trx->mutex.
Definition: trx0trx.h:1200
Users and sessions global types.
Rollback segments assigned to a transaction for undo logging.
Definition: trx0trx.h:682
bool owns_mutex
Set to the transaction that owns the mutex during lock acquire and/or release.
Definition: trx0trx.h:744
void trx_start_if_not_started_low(trx_t *trx, bool read_write)
Starts the transaction if it is not yet started.
Definition: trx0trx.cc:2782
std::thread::native_handle_type os_thread_id_t
Operating system thread native handle.
Definition: os0thread.h:40
UNIV_INLINE bool trx_is_rseg_updated(const trx_t *trx)
Check if redo/noredo rseg is modified for insert/update.
Track if a transaction is executing inside InnoDB code.
Definition: trx0trx.h:1213
TrxMutex mutex
Mutex protecting the fields state and lock (except some fields of lock, which are protected by lock_s...
Definition: trx0trx.h:739
The transaction handle.
Definition: trx0trx.h:671
UNIV_INLINE const trx_t * trx_arbitrate(const trx_t *requestor, const trx_t *holder)
void trx_pool_init()
Create the trx_t pool.
Definition: trx0trx.cc:401
bool start_stmt
The transaction called ha_innobase::start_stmt() to lock a table.
Definition: trx0trx.h:613
commit_node_state
Commit node states.
Definition: trx0trx.h:1183
ib_uint64_t deadlock_mark
A mark field that is initialized to and checked against lock_mark_counter by lock_deadlock_recursive(...
Definition: trx0trx.h:552
UNIV_INLINE bool trx_is_high_priority(const trx_t *trx)
const char * start_file
Filename where it was started.
Definition: trx0trx.h:1105
bool cancel
true if the transaction is being rolled back either via deadlock detection or due to lock timeout...
Definition: trx0trx.h:592
bool srv_read_only_mode
Set if InnoDB must operate in read-only mode.
Definition: srv0srv.cc:168
std::vector< ib_lock_t *, ut_allocator< ib_lock_t * > > lock_pool_t
Definition: trx0trx.h:512
trx_t * trx_get_trx_by_xid(const XID *xid)
This function is used to find one X/Open XA distributed transaction which is in the prepared state...
Definition: trx0trx.cc:2729
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:164
lock_pool_t table_locks
All table locks requested by this transaction, including AUTOINC locks.
Definition: trx0trx.h:589
static bool is_async_rollback(const trx_t *trx)
Definition: trx0trx.h:1264
void trx_start_if_not_started_xa_low(trx_t *trx, bool read_write)
Starts the transaction if it is not yet started.
Definition: trx0trx.cc:2750
fts_trx_t * fts_trx
FTS information, or NULL if transaction hasn&#39;t modified tables with FTS indexes (yet).
Definition: trx0trx.h:1089
std::list< TrxVersion, ut_allocator< TrxVersion > > hit_list_t
Definition: trx0trx.h:711
bool is_rollback_disabled() const
Definition: trx0trx.h:1233
Latching protocol for trx_lock_t::que_state.
Definition: trx0trx.h:535
int trx_recover_for_mysql(XID *xid_list, ulint len)
This function is used to find number of prepared transactions and their transaction objects for a rec...
Definition: trx0trx.cc:2635
static const ib_uint32_t TRX_FORCE_ROLLBACK_DISABLE
If this flag is set then the transaction cannot be rolled back asynchronously.
Definition: trx0types.h:67
void trx_commit(trx_t *trx)
Commits a transaction.
Definition: trx0trx.cc:1980
#define UT_LIST_NODE_T(TYPE)
Definition: innodb_utility.h:40
XID * xid
X/Open XA transaction identification to identify a transaction branch.
Definition: trx0trx.h:1122
mem_heap_t * lock_heap
memory heap for trx_locks; protected by lock_sys->mutex
Definition: trx0trx.h:581
void trx_set_rw_mode(trx_t *trx)
Set the transaction as a read-write transaction if it is not already tagged as such.
Definition: trx0trx.cc:2840
const dict_index_t * error_info
if the error number indicates a duplicate key error, a pointer to the problematic index is stored her...
Definition: trx0trx.h:1016
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:152
dberr_t trx_prepare_for_mysql(trx_t *trx)
Does the transaction prepare for MySQL.
Definition: trx0trx.cc:2614
bool in_rollback
true when the transaction is executing a partial or full rollback
Definition: trx0trx.h:1059
ulint error_key_num
if the index creation fails to a duplicate key error, a mysql key number of that index is stored here...
Definition: trx0trx.h:1019
bool api_trx
trx started by InnoDB API
Definition: trx0trx.h:1129
trx_id_t no
transaction serialization number: max trx id shortly before the transaction is moved to COMMITTED_IN_...
Definition: trx0trx.h:772
void trx_pool_close()
Destroy the trx_t pool.
Definition: trx0trx.cc:408
ulint n_active_thrs
number of active query threads
Definition: trx0trx.h:536
ibool trx_is_interrupted(const trx_t *trx)
Determines if the currently running transaction has been interrupted.
Definition: ha_innodb.cc:2775
lock_pool_t table_pool
Pre-allocated table locks.
Definition: trx0trx.h:575
bool api_auto_commit
automatic commit
Definition: trx0trx.h:1130
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:747
trx_t * m_trx
Transaction instance crossing the handler boundary from the Server.
Definition: trx0trx.h:1395
UNIV_INLINE const char * trx_get_que_state_str(const trx_t *trx)
Retrieves transaction&#39;s que state in a human readable string.
ulint magic_n
Definition: trx0trx.h:1143
Data structure for an index.
Definition: dict0mem.h:870