1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2017, 2021, MariaDB Corporation.
5 
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
17 
18 *****************************************************************************/
19 
20 /**************************************************//**
21 @file include/trx0types.h
22 Transaction system global type definitions
23 
24 Created 3/26/1996 Heikki Tuuri
25 *******************************************************/
26 
27 #ifndef trx0types_h
28 #define trx0types_h
29 
30 #include "ut0byte.h"
31 #include "ut0mutex.h"
32 
33 #include <vector>
34 
35 /** printf(3) format used for printing DB_TRX_ID and other system fields */
36 #define TRX_ID_FMT	IB_ID_FMT
37 
38 /** maximum length that a formatted trx_t::id could take, not including
39 the terminating NUL character. */
40 static const ulint TRX_ID_MAX_LEN = 17;
41 
42 /** Space id of the transaction system page (the system tablespace) */
43 static const ulint TRX_SYS_SPACE = 0;
44 
45 /** Page number of the transaction system page */
46 #define TRX_SYS_PAGE_NO		FSP_TRX_SYS_PAGE_NO
47 
48 /** Random value to check for corruption of trx_t */
49 static const ulint TRX_MAGIC_N = 91118598;
50 
51 /** Transaction execution states when trx->state == TRX_STATE_ACTIVE */
52 enum trx_que_t {
53 	TRX_QUE_RUNNING,		/*!< transaction is running */
54 	TRX_QUE_LOCK_WAIT,		/*!< transaction is waiting for
55 					a lock */
56 	TRX_QUE_ROLLING_BACK,		/*!< transaction is rolling back */
57 	TRX_QUE_COMMITTING		/*!< transaction is committing */
58 };
59 
60 /** Transaction states (trx_t::state) */
61 enum trx_state_t {
62 	TRX_STATE_NOT_STARTED,
63 
64 	TRX_STATE_ACTIVE,
65 	/** XA PREPARE has been executed; only XA COMMIT or XA ROLLBACK
66 	are possible */
67 	TRX_STATE_PREPARED,
68 	/** XA PREPARE transaction that was returned to ha_recover() */
69 	TRX_STATE_PREPARED_RECOVERED,
70 	TRX_STATE_COMMITTED_IN_MEMORY
71 };
72 
73 /** Type of data dictionary operation */
74 enum trx_dict_op_t {
75 	/** The transaction is not modifying the data dictionary. */
76 	TRX_DICT_OP_NONE = 0,
77 	/** The transaction is creating a table or an index, or
78 	dropping a table.  The table must be dropped in crash
79 	recovery.  This and TRX_DICT_OP_NONE are the only possible
80 	operation modes in crash recovery. */
81 	TRX_DICT_OP_TABLE = 1,
82 	/** The transaction is creating or dropping an index in an
83 	existing table.  In crash recovery, the data dictionary
84 	must be locked, but the table must not be dropped. */
85 	TRX_DICT_OP_INDEX = 2
86 };
87 
88 /** Memory objects */
89 /* @{ */
90 /** Transaction */
91 struct trx_t;
92 /** The locks and state of an active transaction */
93 struct trx_lock_t;
94 /** Rollback segment */
95 struct trx_rseg_t;
96 /** Transaction undo log */
97 struct trx_undo_t;
98 /** Rollback command node in a query graph */
99 struct roll_node_t;
100 /** Commit command node in a query graph */
101 struct commit_node_t;
102 /** SAVEPOINT command node in a query graph */
103 struct trx_named_savept_t;
104 /* @} */
105 
106 /** Row identifier (DB_ROW_ID, DATA_ROW_ID) */
107 typedef ib_id_t	row_id_t;
108 /** Transaction identifier (DB_TRX_ID, DATA_TRX_ID) */
109 typedef ib_id_t	trx_id_t;
110 /** Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR) */
111 typedef ib_id_t	roll_ptr_t;
112 /** Undo number */
113 typedef ib_id_t	undo_no_t;
114 
115 /** Transaction savepoint */
116 struct trx_savept_t{
117 	undo_no_t	least_undo_no;	/*!< least undo number to undo */
118 };
119 
120 /** File objects */
121 /* @{ */
122 /** Rollback segment header */
123 typedef byte	trx_rsegf_t;
124 /** Undo segment header */
125 typedef byte	trx_usegf_t;
126 /** Undo log header */
127 typedef byte	trx_ulogf_t;
128 /** Undo log page header */
129 typedef byte	trx_upagef_t;
130 
131 /** Undo log record */
132 typedef	byte	trx_undo_rec_t;
133 
134 /* @} */
135 
136 typedef ib_mutex_t RsegMutex;
137 typedef ib_mutex_t TrxMutex;
138 typedef ib_mutex_t PQMutex;
139 typedef ib_mutex_t TrxSysMutex;
140 
141 typedef std::vector<trx_id_t, ut_allocator<trx_id_t> >	trx_ids_t;
142 #endif /* trx0types_h */
143