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