Drizzled Public API Documentation

trx0trx.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (C) 1996, 2010, Innobase Oy. 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., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #pragma once
27 #ifndef trx0trx_h
28 #define trx0trx_h
29 
30 #include "univ.i"
31 #include "trx0types.h"
32 #include "dict0types.h"
33 #ifndef UNIV_HOTBACKUP
34 #include "lock0types.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 
42 namespace drizzled { class Session; }
43 
45 extern sess_t* trx_dummy_sess;
46 
49 extern ulint trx_n_mysql_transactions;
50 
51 /********************************************************************/
53 UNIV_INTERN
54 void
56 /*=================================*/
57  trx_t* trx);
58 /******************************************************************/
60 UNIV_INTERN
61 void
63 /*===================*/
64  trx_t* trx,
65  const char* msg);
66 /*************************************************************/
69 UNIV_INTERN
70 void
72 /*=============================*/
73  trx_t* trx,
74  FILE* file);
75 /****************************************************************/
78 UNIV_INLINE
79 ibool
81 /*==============*/
82  const trx_t* trx);
83 /****************************************************************/
86 UNIV_INLINE
87 const dict_index_t*
89 /*===============*/
90  const trx_t* trx);
91 /****************************************************************/
94 UNIV_INTERN
95 trx_t*
97 /*=======*/
98  sess_t* sess)
99  __attribute__((nonnull));
100 /********************************************************************/
103 UNIV_INTERN
104 trx_t*
106 /*========================*/
107 /********************************************************************/
110 UNIV_INTERN
111 trx_t*
113 /*=============================*/
114 /********************************************************************/
116 UNIV_INTERN
117 void
118 trx_free(
119 /*=====*/
120  trx_t* trx);
121 /********************************************************************/
123 UNIV_INTERN
124 void
126 /*===============*/
127  trx_t* trx);
128 /********************************************************************/
130 UNIV_INTERN
131 void
133 /*====================*/
134  trx_t* trx);
135 /****************************************************************/
141 UNIV_INTERN
142 void
144 /*============================*/
145 /****************************************************************/
149 UNIV_INTERN
150 ibool
151 trx_start(
152 /*======*/
153  trx_t* trx,
154  ulint rseg_id);
157 /****************************************************************/
160 UNIV_INTERN
161 ibool
163 /*==========*/
164  trx_t* trx,
165  ulint rseg_id);
168 /*************************************************************/
170 UNIV_INLINE
171 void
173 /*=====================*/
174  trx_t* trx);
175 /*************************************************************/
178 UNIV_INLINE
179 void
181 /*=========================*/
182  trx_t* trx);
183 /****************************************************************/
185 UNIV_INTERN
186 void
188 /*==================*/
189  trx_t* trx);
190 /****************************************************************/
194 UNIV_INTERN
195 void
197 /*======================*/
198  trx_t* trx);
199 /**********************************************************************/
202 UNIV_INTERN
203 ulint
205 /*=================*/
206  trx_t* trx);
207 /**********************************************************************/
210 UNIV_INTERN
211 ulint
213 /*==================*/
214  trx_t* trx);
215 /**********************************************************************/
219 UNIV_INTERN
220 int
222 /*==================*/
223  XID* xid_list,
224  ulint len);
225 /*******************************************************************/
229 UNIV_INTERN
230 trx_t *
232 /*===============*/
233  const XID* xid);
234 /**********************************************************************/
238 UNIV_INTERN
239 ulint
241 /*==========================*/
242  trx_t* trx);
243 /**********************************************************************/
245 UNIV_INTERN
246 void
248 /*==================*/
249  trx_t* trx);
250 /********************************************************************/
255 UNIV_INTERN
258 /*=================*/
259  trx_t* trx);
260 /***********************************************************/
264 UNIV_INTERN
265 void
267 /*==============*/
268  trx_t* trx);
269 /****************************************************************/
271 UNIV_INTERN
272 void
274 /*=========*/
275  trx_t* trx,
276  ulint type,
277  ulint sender,
279  que_thr_t* receiver_thr,
282  trx_savept_t* savept,
284  que_thr_t** next_thr);
290 /****************************************************************/
293 UNIV_INTERN
294 void
296 /*==========*/
297  trx_sig_t* sig,
298  que_thr_t** next_thr);
303 /****************************************************************/
305 UNIV_INTERN
306 void
308 /*===========*/
309  trx_t* trx,
310  trx_sig_t* sig);
311 /****************************************************************/
313 UNIV_INTERN
314 void
316 /*=================*/
317  trx_t* trx,
318  que_thr_t** next_thr);
323 /****************************************************************/
328 UNIV_INTERN
329 void
331 /*====================*/
332  trx_t* trx);
333 /*********************************************************************/
336 UNIV_INTERN
339 /*===============*/
340  mem_heap_t* heap);
341 /***********************************************************/
344 UNIV_INTERN
345 que_thr_t*
347 /*============*/
348  que_thr_t* thr);
350 /**********************************************************************/
353 UNIV_INTERN
354 void
355 trx_print(
356 /*======*/
357  FILE* f,
358  trx_t* trx,
359  ulint max_query_len);
363 typedef enum trx_dict_op {
375 } trx_dict_op_t;
376 
377 /**********************************************************************/
380 UNIV_INLINE
381 enum trx_dict_op
383 /*===================*/
384  const trx_t* trx)
385  __attribute__((pure));
386 /**********************************************************************/
388 UNIV_INLINE
389 void
391 /*===================*/
392  trx_t* trx,
393  enum trx_dict_op op);
396 #ifndef UNIV_HOTBACKUP
397 /**********************************************************************/
400 UNIV_INTERN
401 ibool
403 /*===============*/
404  trx_t* trx);
405 /**********************************************************************/
408 UNIV_INTERN
409 ibool
411 /*==========*/
412  trx_t* trx);
413 #else /* !UNIV_HOTBACKUP */
414 #define trx_is_interrupted(trx) FALSE
415 #endif /* !UNIV_HOTBACKUP */
416 
417 /*******************************************************************/
422 #define TRX_WEIGHT(t) ((t)->undo_no + UT_LIST_GET_LEN((t)->trx_locks))
423 
424 /*******************************************************************/
429 UNIV_INTERN
430 ibool
432 /*==========*/
433  const trx_t* a,
434  const trx_t* b);
436 /* Maximum length of a string that can be returned by
437 trx_get_que_state_str(). */
438 #define TRX_QUE_STATE_STR_MAX_LEN 12 /* "ROLLING BACK" */
439 
440 /*******************************************************************/
444 UNIV_INLINE
445 const char*
447 /*==================*/
448  const trx_t* trx);
450 /* Signal to a transaction */
452  unsigned type:3;
453  unsigned sender:1;
465 };
466 
467 #define TRX_MAGIC_N 91118598
468 
469 /* The transaction handle; every session has a trx object which is freed only
470 when the session is freed; in addition there may be session-less transactions
471 rolling back after a database recovery */
472 
473 struct trx_struct{
474  ulint magic_n;
475 
476  /* These fields are not protected by any mutex. */
477  const char* op_info;
480  ulint conc_state;
484  ulint isolation_level;/* TRX_ISO_REPEATABLE_READ, ... */
485  ulint check_foreigns; /* normally TRUE, but if the user
486  wants to suppress foreign key checks,
487  (in table imports, for example) we
488  set this FALSE */
489  unsigned check_unique_secondary;
490  /* normally TRUE, but if the user
491  wants to speed up inserts by
492  suppressing unique key checks
493  for secondary indexes when we decide
494  if we can use the insert buffer for
495  them, we set this FALSE */
496  unsigned support_xa;
501  unsigned flush_log_later;/* In 2PC, we hold the
502  prepare_commit mutex across
503  both phases. In that case, we
504  defer flush of the logs to disk
505  until after we release the
506  mutex. */
507  unsigned must_flush_log_later;/* this flag is set to TRUE in
508  trx_commit_off_kernel() if
509  flush_log_later was TRUE, and there
510  were modifications by the transaction;
511  in that case we must flush the log
512  in trx_commit_complete_for_mysql() */
513  ulint duplicates;
514  unsigned has_search_latch;
515  /* TRUE if this trx has latched the
516  search system latch in S-mode */
521  /* Fields protected by the srv_conc_mutex. */
522  ulint declared_to_be_inside_innodb;
523  /* this is TRUE if we have declared
524  this transaction in
525  srv_conc_enter_innodb to be inside the
526  InnoDB engine */
527 
528  /* Fields protected by dict_operation_lock. The very latch
529  it is used to track. */
535  /* All the next fields are protected by the kernel mutex, except the
536  undo logs which are protected by undo_mutex */
537  ulint is_purge;
538  ulint is_recovered;
540  ulint que_state;
543  ulint handling_signals;/* this is TRUE as long as the trx
544  is handling signals */
545  time_t start_time;
555  ib_uint64_t commit_lsn;
556  table_id_t table_id;
558  /*------------------------------*/
561  const char* mysql_log_file_name;
562  /* if MySQL binlog is used, this field
563  contains a pointer to the latest file
564  name; this is NULL if binlog is not
565  used */
566  ib_int64_t mysql_log_offset;/* if MySQL binlog is used, this field
567  contains the end offset of the binlog
568  entry */
569  os_thread_id_t mysql_thread_id;/* id of the MySQL thread associated
570  with this transaction object */
571  ulint mysql_process_no;/* since in Linux, 'top' reports
572  process id's and not thread id's, we
573  store the process number too */
574  ulint mysql_n_tables_locked;
575  /* how many tables the current SQL
576  statement uses, except those
577  in consistent read */
578  ulint search_latch_timeout;
579  /* If we notice that someone is
580  waiting for our S-lock on the search
581  latch to be released, we wait in
582  row0sel.c for BTR_SEA_TIMEOUT new
583  searches until we try to keep
584  the search latch again over
585  calls from MySQL; this is intended
586  to reduce contention on the search
587  latch */
588  /*------------------------------*/
589  ulint n_tickets_to_enter_innodb;
590  /* this can be > 0 only when
591  declared_to_... is TRUE; when we come
592  to srv_conc_innodb_enter, if the value
593  here is > 0, we decrement this by 1 */
594  /*------------------------------*/
596  trx_list;
598  mysql_trx_list;
600  /*------------------------------*/
601  ulint error_state;
606  const dict_index_t*error_info;
609  ulint error_key_num;
612  sess_t* sess;
613  que_t* graph;
619  ulint n_active_thrs;
620  que_t* graph_before_signal_handling;
621  /* value of graph when signal handling
622  for this trx started: this is used to
623  return control to the original query
624  graph for error processing */
625  trx_sig_t sig;
636  /*------------------------------*/
637  lock_t* wait_lock;
641  ibool was_chosen_as_deadlock_victim;
642  /* when the transaction decides to wait
643  for a lock, it sets this to FALSE;
644  if another transaction chooses this
645  transaction as a victim in deadlock
646  resolution, it sets this to TRUE */
647  time_t wait_started;
649  wait_thrs;
652  /*------------------------------*/
653  mem_heap_t* lock_heap;
656  trx_locks;
657  /*------------------------------*/
658  mem_heap_t* global_read_view_heap;
659  /* memory heap for the global read
660  view */
661  read_view_t* global_read_view;
662  /* consistent read view associated
663  to a transaction or NULL */
664  read_view_t* read_view;
670  /*------------------------------*/
672  trx_savepoints;
674  /*------------------------------*/
675  mutex_t undo_mutex;
681  undo_no_t undo_no;
688  trx_savept_t last_sql_stat_start;
689  /* undo_no when the last sql statement
690  was started: in case of an error, trx
691  is rolled back down to this undo
692  number; see note at undo_mutex! */
693  trx_rseg_t* rseg;
696  trx_undo_t* insert_undo;
698  trx_undo_t* update_undo;
700  undo_no_t roll_limit;
702  ulint pages_undone;
704  trx_undo_arr_t* undo_no_arr;
707  /*------------------------------*/
708  ulint n_autoinc_rows;
711  ib_vector_t* autoinc_locks; /* AUTOINC locks held by this
712  transaction. Note that these are
713  also in the lock list trx_locks. This
714  vector needs to be freed explicitly
715  when the trx_t instance is desrtoyed */
716  /*------------------------------*/
717  char detailed_error[256];
720  ibool log_commit_id;
722  inline drizzled::Session *session()
723  {
724  return mysql_thd;
725  }
726  inline drizzled::Session *session() const
727  {
728  return mysql_thd;
729  }
730 };
731 
732 #define TRX_MAX_N_THREADS 32 /* maximum number of
733  concurrent threads running a
734  single operation of a
735  transaction, e.g., a parallel
736  query */
737 /* Transaction concurrency states (trx->conc_state) */
738 #define TRX_NOT_STARTED 0
739 #define TRX_ACTIVE 1
740 #define TRX_COMMITTED_IN_MEMORY 2
741 #define TRX_PREPARED 3 /* Support for 2PC/XA */
742 
743 /* Transaction execution states when trx->conc_state == TRX_ACTIVE */
744 #define TRX_QUE_RUNNING 0 /* transaction is running */
745 #define TRX_QUE_LOCK_WAIT 1 /* transaction is waiting for a lock */
746 #define TRX_QUE_ROLLING_BACK 2 /* transaction is rolling back */
747 #define TRX_QUE_COMMITTING 3 /* transaction is committing */
748 
749 /* Transaction isolation levels (trx->isolation_level) */
750 #define TRX_ISO_READ_UNCOMMITTED 0 /* dirty read: non-locking
751  SELECTs are performed so that
752  we do not look at a possible
753  earlier version of a record;
754  thus they are not 'consistent'
755  reads under this isolation
756  level; otherwise like level
757  2 */
758 
759 #define TRX_ISO_READ_COMMITTED 1 /* somewhat Oracle-like
760  isolation, except that in
761  range UPDATE and DELETE we
762  must block phantom rows
763  with next-key locks;
764  SELECT ... FOR UPDATE and ...
765  LOCK IN SHARE MODE only lock
766  the index records, NOT the
767  gaps before them, and thus
768  allow free inserting;
769  each consistent read reads its
770  own snapshot */
771 
772 #define TRX_ISO_REPEATABLE_READ 2 /* this is the default;
773  all consistent reads in the
774  same trx read the same
775  snapshot;
776  full next-key locking used
777  in locking reads to block
778  insertions into gaps */
779 
780 #define TRX_ISO_SERIALIZABLE 3 /* all plain SELECTs are
781  converted to LOCK IN SHARE
782  MODE reads */
783 
784 /* Treatment of duplicate values (trx->duplicates; for example, in inserts).
785 Multiple flags can be combined with bitwise OR. */
786 #define TRX_DUP_IGNORE 1 /* duplicate rows are to be updated */
787 #define TRX_DUP_REPLACE 2 /* duplicate rows are to be replaced */
788 
789 
790 /* Types of a trx signal */
791 #define TRX_SIG_NO_SIGNAL 0
792 #define TRX_SIG_TOTAL_ROLLBACK 1
793 #define TRX_SIG_ROLLBACK_TO_SAVEPT 2
794 #define TRX_SIG_COMMIT 3
795 #define TRX_SIG_ERROR_OCCURRED 4
796 #define TRX_SIG_BREAK_EXECUTION 5
797 
798 /* Sender types of a signal */
799 #define TRX_SIG_SELF 0 /* sent by the session itself, or
800  by an error occurring within this
801  session */
802 #define TRX_SIG_OTHER_SESS 1 /* sent by another session (which
803  must hold rights to this) */
804 
811 };
812 
817  state;
818 };
819 
820 
821 
822 #ifndef UNIV_NONINL
823 #include "trx0trx.ic"
824 #endif
825 #endif /* !UNIV_HOTBACKUP */
826 
827 #endif
UNIV_INLINE void trx_start_if_not_started_low(trx_t *trx)
UNIV_INTERN ibool trx_is_strict(trx_t *trx)
Definition: ha_innodb.cc:1894
UNIV_INTERN int trx_recover_for_mysql(XID *xid_list, ulint len)
Definition: trx0trx.cc:1986
UNIV_INTERN void trx_free_for_mysql(trx_t *trx)
Definition: trx0trx.cc:342
UNIV_INTERN ibool trx_is_interrupted(trx_t *trx)
Definition: ha_innodb.cc:1882
UNIV_INTERN ulint trx_commit_complete_for_mysql(trx_t *trx)
Definition: trx0trx.cc:1627
UNIV_INTERN void trx_cleanup_at_db_startup(trx_t *trx)
Definition: trx0trx.cc:1004
UNIV_INLINE void trx_start_if_not_started(trx_t *trx)
XID xid
Definition: trx0trx.h:549
UNIV_INLINE void trx_set_dict_operation(trx_t *trx, enum trx_dict_op op)
trx_id_t id
Definition: trx0trx.h:548
ulint duplicates
Definition: trx0trx.h:513
UNIV_INTERN read_view_t * trx_assign_read_view(trx_t *trx)
Definition: trx0trx.cc:1028
table_id_t table_id
Definition: trx0trx.h:556
trx_savept_t savept
Definition: trx0trx.h:458
UNIV_INTERN void trx_lists_init_at_db_start(void)
Definition: trx0trx.cc:422
ulint conc_state
Definition: trx0trx.h:480
unsigned sender
Definition: trx0trx.h:453
UNIV_INTERN ulint trx_commit_for_mysql(trx_t *trx)
Definition: trx0trx.cc:1596
ulint que_state
Definition: trx0trx.h:540
UNIV_INTERN void trx_free(trx_t *trx)
Definition: trx0trx.cc:259
UNIV_INTERN void trx_free_for_background(trx_t *trx)
Definition: trx0trx.cc:363
ib_uint64_t commit_lsn
Definition: trx0trx.h:555
trx_dict_op
Definition: trx0trx.h:363
sess_t * trx_dummy_sess
Definition: trx0trx.cc:48
UNIV_INTERN trx_t * trx_allocate_for_background(void)
Definition: trx0trx.cc:226
typedef UT_LIST_BASE_NODE_T(mutex_t) ut_list_base_node_t
UNIV_INTERN trx_t * trx_create(sess_t *sess) __attribute__((nonnull))
Definition: trx0trx.cc:90
UNIV_INTERN void trx_sig_reply(trx_sig_t *sig, que_thr_t **next_thr)
Definition: trx0trx.cc:1473
const char * op_info
Definition: trx0trx.h:477
UNIV_INTERN void trx_search_latch_release_if_reserved(trx_t *trx)
Definition: trx0trx.cc:244
#define UT_LIST_NODE_T(TYPE)
Definition: ut0lst.h:73
UNIV_INTERN void trx_print(FILE *f, trx_t *trx, ulint max_query_len)
Definition: trx0trx.cc:1690
UNIV_INTERN void trx_sig_remove(trx_t *trx, trx_sig_t *sig)
Definition: trx0trx.cc:1507
ulint is_recovered
Definition: trx0trx.h:538
ulint dict_operation_lock_mode
Definition: trx0trx.h:530
Definition: trx0xa.h:41
UNIV_INTERN que_thr_t * trx_commit_step(que_thr_t *thr)
Definition: trx0trx.cc:1548
UNIV_INTERN void trx_sig_send(trx_t *trx, ulint type, ulint sender, que_thr_t *receiver_thr, trx_savept_t *savept, que_thr_t **next_thr)
Definition: trx0trx.cc:1259
UNIV_INTERN void trx_end_lock_wait(trx_t *trx)
Definition: trx0trx.cc:1101
UNIV_INLINE const dict_index_t * trx_get_error_info(const trx_t *trx)
UNIV_INTERN trx_t * trx_get_trx_by_xid(const XID *xid)
Definition: trx0trx.cc:2056
UNIV_INTERN trx_t * trx_allocate_for_mysql(void)
Definition: trx0trx.cc:199
os_thread_t os_thread_id_t
Definition: os0thread.h:53
trx_id_t no
Definition: trx0trx.h:552
UNIV_INTERN void trx_mark_sql_stat_end(trx_t *trx)
Definition: trx0trx.cc:1672
ib_id_t trx_id_t
Definition: trx0types.h:85
UNIV_INTERN void trx_commit_off_kernel(trx_t *trx)
Definition: trx0trx.cc:846
unsigned type
Definition: trx0trx.h:452
UNIV_INTERN void trx_end_signal_handling(trx_t *trx)
Definition: trx0trx.cc:1346
UNIV_INLINE enum trx_dict_op trx_get_dict_operation(const trx_t *trx) __attribute__((pure))
enum trx_dict_op trx_dict_op_t
UNIV_INTERN void trx_set_detailed_error(trx_t *trx, const char *msg)
Definition: trx0trx.cc:63
UNIV_INTERN ibool trx_start(trx_t *trx, ulint rseg_id)
Definition: trx0trx.cc:676
UNIV_INLINE ibool trx_log_commit_id(const trx_t *trx)
unsigned support_xa
Definition: trx0trx.h:496
drizzled::Session * mysql_thd
Definition: trx0trx.h:559
UNIV_INTERN commit_node_t * commit_node_create(mem_heap_t *heap)
Definition: trx0trx.cc:1530
commit_node_state
Definition: trx0trx.h:806
que_common_t common
Definition: trx0trx.h:815
UNIV_INTERN void trx_set_detailed_error_from_file(trx_t *trx, FILE *file)
Definition: trx0trx.cc:76
UNIV_INTERN void trx_sig_start_handle(trx_t *trx, que_thr_t **next_thr)
Definition: trx0trx.cc:1367
ulint trx_n_mysql_transactions
Definition: trx0trx.cc:52
time_t start_time
Definition: trx0trx.h:545
ulint is_purge
Definition: trx0trx.h:537
UNIV_INTERN ibool trx_weight_ge(const trx_t *a, const trx_t *b)
Definition: trx0trx.cc:1804
UNIV_INTERN ulint trx_prepare_for_mysql(trx_t *trx)
Definition: trx0trx.cc:1955
que_thr_t * receiver
Definition: trx0trx.h:455
ib_id_t undo_no_t
Definition: trx0types.h:89
trx_dict_op_t dict_operation
Definition: trx0trx.h:519
UNIV_INTERN ibool trx_start_low(trx_t *trx, ulint rseg_id)
Definition: trx0trx.cc:628
ulint deadlock_mark
Definition: trx0trx.h:517
UNIV_INLINE const char * trx_get_que_state_str(const trx_t *trx)