| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | Copyright (c) 2017, 2018, 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, Suite 500, 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 | #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 |
| 41 | the terminating NUL character. */ |
| 42 | static const ulint TRX_ID_MAX_LEN = 17; |
| 43 | |
| 44 | /** Space id of the transaction system page (the system tablespace) */ |
| 45 | static 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 */ |
| 51 | static const ulint TRX_MAGIC_N = 91118598; |
| 52 | |
| 53 | /** Transaction execution states when trx->state == TRX_STATE_ACTIVE */ |
| 54 | enum 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) */ |
| 63 | enum 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 */ |
| 75 | enum 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 */ |
| 92 | struct trx_t; |
| 93 | /** The locks and state of an active transaction */ |
| 94 | struct trx_lock_t; |
| 95 | /** Signal */ |
| 96 | struct trx_sig_t; |
| 97 | /** Rollback segment */ |
| 98 | struct trx_rseg_t; |
| 99 | /** Transaction undo log */ |
| 100 | struct trx_undo_t; |
| 101 | /** Rollback command node in a query graph */ |
| 102 | struct roll_node_t; |
| 103 | /** Commit command node in a query graph */ |
| 104 | struct commit_node_t; |
| 105 | /** SAVEPOINT command node in a query graph */ |
| 106 | struct trx_named_savept_t; |
| 107 | /* @} */ |
| 108 | |
| 109 | /** Row identifier (DB_ROW_ID, DATA_ROW_ID) */ |
| 110 | typedef ib_id_t row_id_t; |
| 111 | /** Transaction identifier (DB_TRX_ID, DATA_TRX_ID) */ |
| 112 | typedef ib_id_t trx_id_t; |
| 113 | /** Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR) */ |
| 114 | typedef ib_id_t roll_ptr_t; |
| 115 | /** Undo number */ |
| 116 | typedef ib_id_t undo_no_t; |
| 117 | |
| 118 | /** Transaction savepoint */ |
| 119 | struct 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 */ |
| 126 | typedef byte trx_rsegf_t; |
| 127 | /** Undo segment header */ |
| 128 | typedef byte trx_usegf_t; |
| 129 | /** Undo log header */ |
| 130 | typedef byte trx_ulogf_t; |
| 131 | /** Undo log page header */ |
| 132 | typedef byte trx_upagef_t; |
| 133 | |
| 134 | /** Undo log record */ |
| 135 | typedef byte trx_undo_rec_t; |
| 136 | |
| 137 | /* @} */ |
| 138 | |
| 139 | typedef ib_mutex_t RsegMutex; |
| 140 | typedef ib_mutex_t TrxMutex; |
| 141 | typedef ib_mutex_t PQMutex; |
| 142 | typedef ib_mutex_t TrxSysMutex; |
| 143 | |
| 144 | typedef std::vector<trx_id_t, ut_allocator<trx_id_t> > trx_ids_t; |
| 145 | #endif /* trx0types_h */ |
| 146 | |