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