InnoDB Plugin  1.0
trx0trx.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2013, 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 as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #ifndef trx0trx_h
27 #define trx0trx_h
28 
29 #include "univ.i"
30 #include "trx0types.h"
31 #include "dict0types.h"
32 #ifndef UNIV_HOTBACKUP
33 #include "lock0types.h"
34 #include "log0log.h"
35 #include "usr0types.h"
36 #include "que0types.h"
37 #include "mem0mem.h"
38 #include "read0types.h"
39 #include "trx0xa.h"
40 #include "ut0vec.h"
41 #include "fts0fts.h"
42 
44 extern sess_t* trx_dummy_sess;
45 
46 /********************************************************************/
48 UNIV_INLINE
49 void
51 /*=================================*/
52  trx_t* trx);
53 /******************************************************************/
55 UNIV_INTERN
56 void
58 /*===================*/
59  trx_t* trx,
60  const char* msg);
61 /*************************************************************/
64 UNIV_INTERN
65 void
67 /*=============================*/
68  trx_t* trx,
69  FILE* file);
70 /****************************************************************/
73 UNIV_INLINE
74 const dict_index_t*
76 /*===============*/
77  const trx_t* trx);
78 /********************************************************************/
81 UNIV_INTERN
82 trx_t*
84 /*========================*/
85 /********************************************************************/
88 UNIV_INTERN
89 trx_t*
91 /*=============================*/
92 /********************************************************************/
94 UNIV_INTERN
95 void
97 /*====================*/
98  trx_t* trx);
99 /********************************************************************/
101 UNIV_INTERN
102 void
104 /*==============*/
105  trx_t* trx)
106  UNIV_COLD __attribute__((nonnull));
107 /********************************************************************/
109 UNIV_INTERN
110 void
112 /*===============*/
113  trx_t* trx);
114 /****************************************************************/
120 UNIV_INTERN
121 void
123 /*============================*/
124 
125 #ifdef UNIV_DEBUG
126 #define trx_start_if_not_started_xa(t) \
127  { \
128  (t)->start_line = __LINE__; \
129  (t)->start_file = __FILE__; \
130  trx_start_if_not_started_xa_low((t)); \
131  }
132 #else
133 #define trx_start_if_not_started_xa(t) \
134  trx_start_if_not_started_xa_low((t))
135 #endif /* UNIV_DEBUG */
136 
137 /*************************************************************/
139 UNIV_INTERN
140 void
142 /*============================*/
143  trx_t* trx);
144 /*************************************************************/
146 UNIV_INTERN
147 void
149 /*=========================*/
150  trx_t* trx);
152 #ifdef UNIV_DEBUG
153 #define trx_start_if_not_started(t) \
154  { \
155  (t)->start_line = __LINE__; \
156  (t)->start_file = __FILE__; \
157  trx_start_if_not_started_low((t)); \
158  }
159 #else
160 #define trx_start_if_not_started(t) \
161  trx_start_if_not_started_low((t))
162 #endif /* UNIV_DEBUG */
163 
164 /*************************************************************/
166 UNIV_INTERN
167 void
169 /*==================*/
170  trx_t* trx,
171  trx_dict_op_t op)
172  __attribute__((nonnull));
173 
174 #ifdef UNIV_DEBUG
175 #define trx_start_for_ddl(t, o) \
176  { \
177  ut_ad((t)->start_file == 0); \
178  (t)->start_line = __LINE__; \
179  (t)->start_file = __FILE__; \
180  trx_start_for_ddl_low((t), (o)); \
181  }
182 #else
183 #define trx_start_for_ddl(t, o) \
184  trx_start_for_ddl_low((t), (o))
185 #endif /* UNIV_DEBUG */
186 
187 /****************************************************************/
189 UNIV_INTERN
190 void
191 trx_commit(
192 /*=======*/
193  trx_t* trx)
194  __attribute__((nonnull));
195 /****************************************************************/
197 UNIV_INTERN
198 void
200 /*===========*/
201  trx_t* trx,
202  mtr_t* mtr)
204  __attribute__((nonnull(1)));
205 /****************************************************************/
209 UNIV_INTERN
210 void
212 /*======================*/
213  trx_t* trx);
214 /**********************************************************************/
217 UNIV_INTERN
218 dberr_t
220 /*=================*/
221  trx_t* trx);
222 /**********************************************************************/
224 UNIV_INTERN
225 void
227 /*==================*/
228  trx_t* trx);
229 /**********************************************************************/
233 UNIV_INTERN
234 int
236 /*==================*/
237  XID* xid_list,
238  ulint len);
239 /*******************************************************************/
245 UNIV_INTERN
246 trx_t *
248 /*===============*/
249  const XID* xid);
250 /**********************************************************************/
253 UNIV_INTERN
254 void
256 /*==========================*/
257  trx_t* trx)
258  __attribute__((nonnull));
259 /**********************************************************************/
261 UNIV_INTERN
262 void
264 /*==================*/
265  trx_t* trx);
266 /********************************************************************/
271 UNIV_INTERN
274 /*=================*/
275  trx_t* trx);
276 /****************************************************************/
278 UNIV_INTERN
279 void
281 /*===========================*/
282  trx_t* trx);
283 /*********************************************************************/
286 UNIV_INTERN
289 /*===================*/
290  mem_heap_t* heap);
291 /***********************************************************/
294 UNIV_INTERN
295 que_thr_t*
297 /*============*/
298  que_thr_t* thr);
300 /**********************************************************************/
303 UNIV_INTERN
304 void
306 /*==========*/
307  FILE* f,
309  const trx_t* trx,
311  ulint max_query_len,
314  ulint n_rec_locks,
316  ulint n_trx_locks,
318  ulint heap_size)
320  __attribute__((nonnull));
321 
322 /**********************************************************************/
326 UNIV_INTERN
327 void
329 /*==============*/
330  FILE* f,
331  const trx_t* trx,
332  ulint max_query_len)
334  __attribute__((nonnull));
335 
336 /**********************************************************************/
339 UNIV_INTERN
340 void
341 trx_print(
342 /*======*/
343  FILE* f,
344  const trx_t* trx,
345  ulint max_query_len)
347  __attribute__((nonnull));
348 
349 /**********************************************************************/
352 UNIV_INLINE
353 enum trx_dict_op_t
355 /*===================*/
356  const trx_t* trx)
357  __attribute__((pure));
358 /**********************************************************************/
360 UNIV_INLINE
361 void
363 /*===================*/
364  trx_t* trx,
365  enum trx_dict_op_t op);
368 #ifndef UNIV_HOTBACKUP
369 /**********************************************************************/
377 UNIV_INLINE
378 ibool
380 /*=========*/
381  const trx_t* trx,
382  trx_state_t state)
386  __attribute__((nonnull, warn_unused_result));
387 # ifdef UNIV_DEBUG
388 /**********************************************************************/
392 UNIV_INTERN
393 ibool
395 /*===============*/
396  const trx_t* trx)
397  __attribute__((nonnull, warn_unused_result));
398 # endif /* UNIV_DEBUG */
399 
400 /**********************************************************************/
403 UNIV_INTERN
404 ibool
406 /*===============*/
407  const trx_t* trx);
408 /**********************************************************************/
411 UNIV_INTERN
412 ibool
414 /*==========*/
415  trx_t* trx);
416 #else /* !UNIV_HOTBACKUP */
417 #define trx_is_interrupted(trx) FALSE
418 #endif /* !UNIV_HOTBACKUP */
419 
420 /*******************************************************************/
425 #define TRX_WEIGHT(t) ((t)->undo_no + UT_LIST_GET_LEN((t)->lock.trx_locks))
426 
427 /*******************************************************************/
432 UNIV_INTERN
433 ibool
435 /*==========*/
436  const trx_t* a,
437  const trx_t* b);
439 /* Maximum length of a string that can be returned by
440 trx_get_que_state_str(). */
441 #define TRX_QUE_STATE_STR_MAX_LEN 12 /* "ROLLING BACK" */
442 
443 /*******************************************************************/
447 UNIV_INLINE
448 const char*
450 /*==================*/
451  const trx_t* trx);
453 /****************************************************************/
456 UNIV_INTERN
457 void
459 /*============*/
460  trx_t* trx);
462 /*******************************************************************/
469 #define trx_lock_wait_timeout_get(trx) \
470  ((trx)->mysql_thd != NULL \
471  ? thd_lock_wait_timeout((trx)->mysql_thd) \
472  : 0)
473 
474 /*******************************************************************/
479 #define trx_is_autocommit_non_locking(t) \
480 ((t)->auto_commit && (t)->will_lock == 0)
481 
482 /*******************************************************************/
487 #define trx_is_ac_nl_ro(t) \
488 ((t)->read_only && trx_is_autocommit_non_locking((t)))
489 
490 /*******************************************************************/
492 #define assert_trx_in_rw_list(t) do { \
493  ut_ad(!(t)->read_only); \
494  assert_trx_in_list(t); \
495 } while (0)
496 
497 /*******************************************************************/
501 #define assert_trx_in_list(t) do { \
502  ut_ad((t)->in_ro_trx_list == (t)->read_only); \
503  ut_ad((t)->in_rw_trx_list == !(t)->read_only); \
504  ut_ad(!trx_is_autocommit_non_locking((t))); \
505  switch ((t)->state) { \
506  case TRX_STATE_PREPARED: \
507  /* fall through */ \
508  case TRX_STATE_ACTIVE: \
509  case TRX_STATE_COMMITTED_IN_MEMORY: \
510  continue; \
511  case TRX_STATE_NOT_STARTED: \
512  break; \
513  } \
514  ut_error; \
515 } while (0)
516 
517 #ifdef UNIV_DEBUG
518 /*******************************************************************/
522 # define assert_trx_nonlocking_or_in_list(t) \
523  do { \
524  if (trx_is_autocommit_non_locking(t)) { \
525  trx_state_t t_state = (t)->state; \
526  ut_ad((t)->read_only); \
527  ut_ad(!(t)->is_recovered); \
528  ut_ad(!(t)->in_ro_trx_list); \
529  ut_ad(!(t)->in_rw_trx_list); \
530  ut_ad((t)->in_mysql_trx_list); \
531  ut_ad(t_state == TRX_STATE_NOT_STARTED \
532  || t_state == TRX_STATE_ACTIVE); \
533  } else { \
534  assert_trx_in_list(t); \
535  } \
536  } while (0)
537 #else /* UNIV_DEBUG */
538 /*******************************************************************/
542 # define assert_trx_nonlocking_or_in_list(trx) ((void)0)
543 #endif /* UNIV_DEBUG */
544 
545 /*******************************************************************/
567 struct trx_lock_t {
584  ib_uint64_t deadlock_mark;
594  time_t wait_started;
608  UT_LIST_BASE_NODE_T(lock_t)
629 };
630 
631 #define TRX_MAGIC_N 91118598
632 
676 struct trx_t{
677  ulint magic_n;
678 
679  ib_mutex_t mutex;
741 
742  trx_lock_t lock;
746  ulint is_recovered;
751  /* These fields are not protected by any mutex. */
752  const char* op_info;
756  ulint check_foreigns;
760  /*------------------------------*/
761  /* MySQL has a transaction coordinator to coordinate two phase
762  commit between multiple storage engines and the binary log. When
763  an engine participates in a transaction, it's responsible for
764  registering itself using the trans_register_ha() API. */
765  unsigned is_registered:1;/* This flag is set to 1 after the
766  transaction has been registered with
767  the coordinator using the XA API, and
768  is set to 0 after commit or rollback. */
769  unsigned owns_prepare_mutex:1;/* 1 if owns prepare mutex, if
770  this is set to 1 then registered should
771  also be set to 1. This is used in the
772  XA code */
773  /*------------------------------*/
774  ulint check_unique_secondary;
781  ulint support_xa;
786  ulint flush_log_later;/* In 2PC, we hold the
787  prepare_commit mutex across
788  both phases. In that case, we
789  defer flush of the logs to disk
790  until after we release the
791  mutex. */
792  ulint must_flush_log_later;
798  ulint duplicates;
799  ulint has_search_latch;
802  ulint search_latch_timeout;
814  /* Fields protected by the srv_conc_mutex. */
815  ulint declared_to_be_inside_innodb;
820  ulint n_tickets_to_enter_innodb;
825  ulint dict_operation_lock_mode;
831  trx_id_t no;
839  time_t start_time;
842  XID xid;
845  lsn_t commit_lsn;
846  table_id_t table_id;
848  /*------------------------------*/
849  THD* mysql_thd;
851  const char* mysql_log_file_name;
856  ib_int64_t mysql_log_offset;
860  /*------------------------------*/
861  ulint n_mysql_tables_in_use;
864  ulint mysql_n_tables_locked;
868  /*------------------------------*/
869  UT_LIST_NODE_T(trx_t)
870  trx_list;
875 #ifdef UNIV_DEBUG
876 
877  /* @{ */
878 
881  /* @} */
882 #endif /* UNIV_DEBUG */
883  UT_LIST_NODE_T(trx_t)
884  mysql_trx_list;
886 #ifdef UNIV_DEBUG
887  ibool in_mysql_trx_list;
890 #endif /* UNIV_DEBUG */
891  /*------------------------------*/
892  dberr_t error_state;
897  const dict_index_t*error_info;
900  ulint error_key_num;
904  que_t* graph;
910  mem_heap_t* global_read_view_heap;
913  read_view_t* global_read_view;
916  read_view_t* read_view;
922  /*------------------------------*/
923  UT_LIST_BASE_NODE_T(trx_named_savept_t)
924  trx_savepoints;
926  /*------------------------------*/
927  ib_mutex_t undo_mutex;
933  undo_no_t undo_no;
940  trx_savept_t last_sql_stat_start;
945  trx_rseg_t* rseg;
948  trx_undo_t* insert_undo;
950  trx_undo_t* update_undo;
952  undo_no_t roll_limit;
954  ulint pages_undone;
956  trx_undo_arr_t* undo_no_arr;
959  /*------------------------------*/
960  ulint n_autoinc_rows;
963  ib_vector_t* autoinc_locks; /* AUTOINC locks held by this
964  transaction. Note that these are
965  also in the lock list trx_locks. This
966  vector needs to be freed explicitly
967  when the trx instance is destroyed.
968  Protected by lock_sys->mutex. */
969  /*------------------------------*/
970  ibool read_only;
979  ibool auto_commit;
980  ulint will_lock;
983  bool ddl;
985  /*------------------------------*/
986  fts_trx_t* fts_trx;
989  doc_id_t fts_next_doc_id;/* The document id used for updates */
990  /*------------------------------*/
991  ulint flush_tables;
994  /*------------------------------*/
995 #ifdef UNIV_DEBUG
996  ulint start_line;
997  const char* start_file;
998 #endif /* UNIV_DEBUG */
999  /*------------------------------*/
1000  bool api_trx;
1002  bool read_write;
1004  /*------------------------------*/
1005  char detailed_error[256];
1007 };
1008 
1009 /* Transaction isolation levels (trx->isolation_level) */
1010 #define TRX_ISO_READ_UNCOMMITTED 0 /* dirty read: non-locking
1011  SELECTs are performed so that
1012  we do not look at a possible
1013  earlier version of a record;
1014  thus they are not 'consistent'
1015  reads under this isolation
1016  level; otherwise like level
1017  2 */
1018 
1019 #define TRX_ISO_READ_COMMITTED 1 /* somewhat Oracle-like
1020  isolation, except that in
1021  range UPDATE and DELETE we
1022  must block phantom rows
1023  with next-key locks;
1024  SELECT ... FOR UPDATE and ...
1025  LOCK IN SHARE MODE only lock
1026  the index records, NOT the
1027  gaps before them, and thus
1028  allow free inserting;
1029  each consistent read reads its
1030  own snapshot */
1031 
1032 #define TRX_ISO_REPEATABLE_READ 2 /* this is the default;
1033  all consistent reads in the
1034  same trx read the same
1035  snapshot;
1036  full next-key locking used
1037  in locking reads to block
1038  insertions into gaps */
1040 #define TRX_ISO_SERIALIZABLE 3 /* all plain SELECTs are
1041  converted to LOCK IN SHARE
1042  MODE reads */
1043 
1044 /* Treatment of duplicate values (trx->duplicates; for example, in inserts).
1045 Multiple flags can be combined with bitwise OR. */
1046 #define TRX_DUP_IGNORE 1 /* duplicate rows are to be updated */
1047 #define TRX_DUP_REPLACE 2 /* duplicate rows are to be replaced */
1048 
1049 
1050 /* Types of a trx signal */
1051 #define TRX_SIG_NO_SIGNAL 0
1052 #define TRX_SIG_TOTAL_ROLLBACK 1
1053 #define TRX_SIG_ROLLBACK_TO_SAVEPT 2
1054 #define TRX_SIG_COMMIT 3
1055 #define TRX_SIG_BREAK_EXECUTION 5
1056 
1057 /* Sender types of a signal */
1058 #define TRX_SIG_SELF 0 /* sent by the session itself, or
1059  by an error occurring within this
1060  session */
1061 #define TRX_SIG_OTHER_SESS 1 /* sent by another session (which
1062  must hold rights to this) */
1063 
1065 enum commit_node_state {
1066  COMMIT_NODE_SEND = 1,
1070 };
1071 
1073 struct commit_node_t{
1074  que_common_t common;
1075  enum commit_node_state
1076  state;
1077 };
1078 
1079 
1081 #define trx_mutex_own(t) mutex_own(&t->mutex)
1082 
1084 #define trx_mutex_enter(t) do { \
1085  mutex_enter(&t->mutex); \
1086 } while (0)
1087 
1089 #define trx_mutex_exit(t) do { \
1090  mutex_exit(&t->mutex); \
1091 } while (0)
1092 
1107 
1109 #define btr_search_latch (*btr_search_latch_temp)
1110 
1111 #ifndef UNIV_NONINL
1112 #include "trx0trx.ic"
1113 #endif
1114 #endif /* !UNIV_HOTBACKUP */
1115 
1116 #endif