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