drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
trx0trx.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/**************************************************/
25
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
42namespace drizzled { class Session; }
43
45extern sess_t* trx_dummy_sess;
46
49extern ulint trx_n_mysql_transactions;
50
51/********************************************************************/
53UNIV_INTERN
54void
56/*=================================*/
57 trx_t* trx);
58/******************************************************************/
60UNIV_INTERN
61void
63/*===================*/
64 trx_t* trx,
65 const char* msg);
66/*************************************************************/
69UNIV_INTERN
70void
72/*=============================*/
73 trx_t* trx,
74 FILE* file);
75/****************************************************************/
78UNIV_INLINE
79ibool
81/*==============*/
82 const trx_t* trx);
83/****************************************************************/
86UNIV_INLINE
87const dict_index_t*
89/*===============*/
90 const trx_t* trx);
91/****************************************************************/
94UNIV_INTERN
95trx_t*
97/*=======*/
98 sess_t* sess)
99 __attribute__((nonnull));
100/********************************************************************/
103UNIV_INTERN
104trx_t*
106/*========================*/
107/********************************************************************/
110UNIV_INTERN
111trx_t*
113/*=============================*/
114/********************************************************************/
116UNIV_INTERN
117void
119/*=====*/
120 trx_t* trx);
121/********************************************************************/
123UNIV_INTERN
124void
126/*===============*/
127 trx_t* trx);
128/********************************************************************/
130UNIV_INTERN
131void
133/*====================*/
134 trx_t* trx);
135/****************************************************************/
141UNIV_INTERN
142void
144/*============================*/
145/****************************************************************/
149UNIV_INTERN
150ibool
152/*======*/
153 trx_t* trx,
154 ulint rseg_id);
157/****************************************************************/
160UNIV_INTERN
161ibool
163/*==========*/
164 trx_t* trx,
165 ulint rseg_id);
168/*************************************************************/
170UNIV_INLINE
171void
173/*=====================*/
174 trx_t* trx);
175/*************************************************************/
178UNIV_INLINE
179void
181/*=========================*/
182 trx_t* trx);
183/****************************************************************/
185UNIV_INTERN
186void
188/*==================*/
189 trx_t* trx);
190/****************************************************************/
194UNIV_INTERN
195void
197/*======================*/
198 trx_t* trx);
199/**********************************************************************/
202UNIV_INTERN
203ulint
205/*=================*/
206 trx_t* trx);
207/**********************************************************************/
210UNIV_INTERN
211ulint
213/*==================*/
214 trx_t* trx);
215/**********************************************************************/
219UNIV_INTERN
220int
222/*==================*/
223 XID* xid_list,
224 ulint len);
225/*******************************************************************/
229UNIV_INTERN
230trx_t *
232/*===============*/
233 const XID* xid);
234/**********************************************************************/
238UNIV_INTERN
239ulint
241/*==========================*/
242 trx_t* trx);
243/**********************************************************************/
245UNIV_INTERN
246void
248/*==================*/
249 trx_t* trx);
250/********************************************************************/
255UNIV_INTERN
256read_view_t*
258/*=================*/
259 trx_t* trx);
260/***********************************************************/
264UNIV_INTERN
265void
267/*==============*/
268 trx_t* trx);
269/****************************************************************/
271UNIV_INTERN
272void
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/****************************************************************/
293UNIV_INTERN
294void
296/*==========*/
297 trx_sig_t* sig,
298 que_thr_t** next_thr);
303/****************************************************************/
305UNIV_INTERN
306void
308/*===========*/
309 trx_t* trx,
310 trx_sig_t* sig);
311/****************************************************************/
313UNIV_INTERN
314void
316/*=================*/
317 trx_t* trx,
318 que_thr_t** next_thr);
323/****************************************************************/
328UNIV_INTERN
329void
331/*====================*/
332 trx_t* trx);
333/*********************************************************************/
336UNIV_INTERN
339/*===============*/
340 mem_heap_t* heap);
341/***********************************************************/
344UNIV_INTERN
345que_thr_t*
347/*============*/
348 que_thr_t* thr);
349
350/**********************************************************************/
353UNIV_INTERN
354void
356/*======*/
357 FILE* f,
358 trx_t* trx,
359 ulint max_query_len);
361
376
377/**********************************************************************/
380UNIV_INLINE
381enum trx_dict_op
383/*===================*/
384 const trx_t* trx)
385 __attribute__((pure));
386/**********************************************************************/
388UNIV_INLINE
389void
391/*===================*/
392 trx_t* trx,
393 enum trx_dict_op op);
395
396#ifndef UNIV_HOTBACKUP
397/**********************************************************************/
400UNIV_INTERN
401ibool
403/*===============*/
404 trx_t* trx);
405/**********************************************************************/
408UNIV_INTERN
409ibool
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/*******************************************************************/
429UNIV_INTERN
430ibool
432/*==========*/
433 const trx_t* a,
434 const trx_t* b);
435
436/* Maximum length of a string that can be returned by
437trx_get_que_state_str(). */
438#define TRX_QUE_STATE_STR_MAX_LEN 12 /* "ROLLING BACK" */
439
440/*******************************************************************/
444UNIV_INLINE
445const char*
447/*==================*/
448 const trx_t* trx);
449
450/* Signal to a transaction */
466
467#define TRX_MAGIC_N 91118598
468
469/* The transaction handle; every session has a trx object which is freed only
470when the session is freed; in addition there may be session-less transactions
471rolling back after a database recovery */
472
474 ulint magic_n;
475
476 /* These fields are not protected by any mutex. */
477 const char* op_info;
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() */
514 unsigned has_search_latch;
515 /* TRUE if this trx has latched the
516 search system latch in S-mode */
520
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. */
534
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;
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;
549 XID xid;
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 /*------------------------------*/
595 UT_LIST_NODE_T(trx_t)
597 UT_LIST_NODE_T(trx_t)
600 /*------------------------------*/
606 const dict_index_t*error_info;
612 sess_t* sess;
613 que_t* graph;
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 */
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 */
648 UT_LIST_BASE_NODE_T(que_thr_t)
652 /*------------------------------*/
653 mem_heap_t* lock_heap;
655 UT_LIST_BASE_NODE_T(lock_t)
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 /*------------------------------*/
674 /*------------------------------*/
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! */
707 /*------------------------------*/
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];
719
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).
785Multiple 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
807 COMMIT_NODE_SEND = 1,
811};
812
814struct commit_node_struct{
815 que_common_t common;
817 state;
818};
819
820
821
822#ifndef UNIV_NONINL
823#include "trx0trx.ic"
824#endif
825#endif /* !UNIV_HOTBACKUP */
826
827#endif
TODO: Rename this file - func.h is stupid.
os_thread_t os_thread_id_t
Definition os0thread.h:53
unsigned type
Definition trx0trx.h:452
trx_savept_t savept
Definition trx0trx.h:458
que_thr_t * receiver
Definition trx0trx.h:455
unsigned sender
Definition trx0trx.h:453
trx_id_t no
Definition trx0trx.h:552
ibool log_commit_id
Definition trx0trx.h:720
read_view_t * read_view
Definition trx0trx.h:664
table_id_t table_id
Definition trx0trx.h:556
trx_undo_t * insert_undo
Definition trx0trx.h:696
mem_heap_t * lock_heap
Definition trx0trx.h:653
unsigned support_xa
Definition trx0trx.h:496
sess_t * sess
Definition trx0trx.h:612
que_t * graph
Definition trx0trx.h:613
ulint que_state
Definition trx0trx.h:540
const char * op_info
Definition trx0trx.h:477
drizzled::Session * mysql_thd
Definition trx0trx.h:559
ulint error_state
Definition trx0trx.h:601
undo_no_t roll_limit
Definition trx0trx.h:700
trx_rseg_t * rseg
Definition trx0trx.h:693
ulint pages_undone
Definition trx0trx.h:702
trx_undo_t * update_undo
Definition trx0trx.h:698
const dict_index_t * error_info
Definition trx0trx.h:606
mutex_t undo_mutex
Definition trx0trx.h:675
ib_uint64_t commit_lsn
Definition trx0trx.h:555
char detailed_error[256]
Definition trx0trx.h:717
time_t wait_started
Definition trx0trx.h:647
lock_t * wait_lock
Definition trx0trx.h:637
undo_no_t undo_no
Definition trx0trx.h:681
trx_sig_t sig
Definition trx0trx.h:625
ulint dict_operation_lock_mode
Definition trx0trx.h:530
ulint is_purge
Definition trx0trx.h:537
ulint n_autoinc_rows
Definition trx0trx.h:708
trx_id_t id
Definition trx0trx.h:548
ulint conc_state
Definition trx0trx.h:480
ulint deadlock_mark
Definition trx0trx.h:517
trx_undo_arr_t * undo_no_arr
Definition trx0trx.h:704
ulint error_key_num
Definition trx0trx.h:609
ulint n_active_thrs
Definition trx0trx.h:619
ulint is_recovered
Definition trx0trx.h:538
ulint duplicates
Definition trx0trx.h:513
time_t start_time
Definition trx0trx.h:545
trx_dict_op_t dict_operation
Definition trx0trx.h:519
#define mutex_t
Definition sync0types.h:31
UNIV_INTERN void trx_mark_sql_stat_end(trx_t *trx)
Definition trx0trx.cc:1672
UNIV_INTERN ibool trx_start(trx_t *trx, ulint rseg_id)
Definition trx0trx.cc:676
UNIV_INLINE void trx_start_if_not_started(trx_t *trx)
UNIV_INTERN que_thr_t * trx_commit_step(que_thr_t *thr)
Definition trx0trx.cc:1548
ulint trx_n_mysql_transactions
Definition trx0trx.cc:52
sess_t * trx_dummy_sess
Definition trx0trx.cc:48
UNIV_INTERN void trx_set_detailed_error(trx_t *trx, const char *msg)
Definition trx0trx.cc:63
UNIV_INTERN read_view_t * trx_assign_read_view(trx_t *trx)
Definition trx0trx.cc:1028
UNIV_INTERN void trx_search_latch_release_if_reserved(trx_t *trx)
Definition trx0trx.cc:244
UNIV_INTERN ulint trx_prepare_for_mysql(trx_t *trx)
Definition trx0trx.cc:1955
UNIV_INLINE const char * trx_get_que_state_str(const trx_t *trx)
UNIV_INTERN trx_t * trx_allocate_for_mysql(void)
Definition trx0trx.cc:199
UNIV_INLINE ibool trx_log_commit_id(const trx_t *trx)
UNIV_INTERN int trx_recover_for_mysql(XID *xid_list, ulint len)
Definition trx0trx.cc:1986
UNIV_INTERN void trx_cleanup_at_db_startup(trx_t *trx)
Definition trx0trx.cc:1004
UNIV_INTERN ulint trx_commit_for_mysql(trx_t *trx)
Definition trx0trx.cc:1596
UNIV_INTERN trx_t * trx_get_trx_by_xid(const XID *xid)
Definition trx0trx.cc:2056
UNIV_INTERN void trx_free_for_background(trx_t *trx)
Definition trx0trx.cc:363
UNIV_INTERN void trx_set_detailed_error_from_file(trx_t *trx, FILE *file)
Definition trx0trx.cc:76
UNIV_INTERN void trx_end_lock_wait(trx_t *trx)
Definition trx0trx.cc:1101
UNIV_INTERN ibool trx_weight_ge(const trx_t *a, const trx_t *b)
Definition trx0trx.cc:1804
UNIV_INLINE enum trx_dict_op trx_get_dict_operation(const trx_t *trx) __attribute__((pure))
UNIV_INTERN void trx_end_signal_handling(trx_t *trx)
Definition trx0trx.cc:1346
UNIV_INTERN commit_node_t * commit_node_create(mem_heap_t *heap)
Definition trx0trx.cc:1530
UNIV_INTERN ibool trx_is_interrupted(trx_t *trx)
enum trx_dict_op trx_dict_op_t
UNIV_INTERN void trx_sig_reply(trx_sig_t *sig, que_thr_t **next_thr)
Definition trx0trx.cc:1473
UNIV_INTERN void trx_sig_remove(trx_t *trx, trx_sig_t *sig)
Definition trx0trx.cc:1507
UNIV_INTERN void trx_commit_off_kernel(trx_t *trx)
Definition trx0trx.cc:846
UNIV_INTERN ulint trx_commit_complete_for_mysql(trx_t *trx)
Definition trx0trx.cc:1627
UNIV_INTERN void trx_lists_init_at_db_start(void)
Definition trx0trx.cc:422
trx_dict_op
Definition trx0trx.h:363
@ TRX_DICT_OP_TABLE
Definition trx0trx.h:370
@ TRX_DICT_OP_NONE
Definition trx0trx.h:365
@ TRX_DICT_OP_INDEX
Definition trx0trx.h:374
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_INLINE void trx_start_if_not_started_low(trx_t *trx)
UNIV_INTERN ibool trx_is_strict(trx_t *trx)
UNIV_INTERN void trx_sig_start_handle(trx_t *trx, que_thr_t **next_thr)
Definition trx0trx.cc:1367
UNIV_INTERN void trx_print(FILE *f, trx_t *trx, ulint max_query_len)
Definition trx0trx.cc:1690
UNIV_INTERN trx_t * trx_allocate_for_background(void)
Definition trx0trx.cc:226
UNIV_INLINE const dict_index_t * trx_get_error_info(const trx_t *trx)
UNIV_INTERN void trx_free_for_mysql(trx_t *trx)
Definition trx0trx.cc:342
UNIV_INTERN ibool trx_start_low(trx_t *trx, ulint rseg_id)
Definition trx0trx.cc:628
commit_node_state
Definition trx0trx.h:773
@ COMMIT_NODE_SEND
Definition trx0trx.h:774
@ COMMIT_NODE_WAIT
Definition trx0trx.h:776
UNIV_INTERN trx_t * trx_create(sess_t *sess) __attribute__((nonnull))
Definition trx0trx.cc:90
UNIV_INTERN void trx_free(trx_t *trx)
Definition trx0trx.cc:259
UNIV_INLINE void trx_set_dict_operation(trx_t *trx, enum trx_dict_op op)
ib_id_t undo_no_t
Definition trx0types.h:89
struct trx_sig_struct trx_sig_t
Definition trx0types.h:48
struct trx_savept_struct trx_savept_t
Definition trx0types.h:92
ib_id_t trx_id_t
Definition trx0types.h:85
struct trx_undo_struct trx_undo_t
Definition trx0types.h:52
struct trx_undo_arr_struct trx_undo_arr_t
Definition trx0types.h:54
struct trx_named_savept_struct trx_named_savept_t
Definition trx0types.h:64
struct commit_node_struct commit_node_t
Definition trx0types.h:62
struct trx_rseg_struct trx_rseg_t
Definition trx0types.h:50
#define UT_LIST_NODE_T(TYPE)
Definition ut0lst.h:73
#define UT_LIST_BASE_NODE_T(TYPE)
Definition ut0lst.h:54
struct ib_vector_struct ib_vector_t
Definition ut0vec.h:34