1 /***************************************************************************** 2 3 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 Copyright (c) 2015, 2020, 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/trx0roll.h 22 Transaction rollback 23 24 Created 3/26/1996 Heikki Tuuri 25 *******************************************************/ 26 27 #ifndef trx0roll_h 28 #define trx0roll_h 29 30 #include "trx0trx.h" 31 #include "mtr0mtr.h" 32 #include "trx0sys.h" 33 34 extern bool trx_rollback_is_active; 35 extern const trx_t* trx_roll_crash_recv_trx; 36 37 /*******************************************************************//** 38 Returns a transaction savepoint taken at this point in time. 39 @return savepoint */ 40 trx_savept_t 41 trx_savept_take( 42 /*============*/ 43 trx_t* trx); /*!< in: transaction */ 44 45 /** Report progress when rolling back a row of a recovered transaction. */ 46 void trx_roll_report_progress(); 47 /*******************************************************************//** 48 Rollback or clean up any incomplete transactions which were 49 encountered in crash recovery. If the transaction already was 50 committed, then we clean up a possible insert undo log. If the 51 transaction was not yet committed, then we roll it back. 52 @param all true=roll back all recovered active transactions; 53 false=roll back any incomplete dictionary transaction */ 54 void 55 trx_rollback_recovered(bool all); 56 /*******************************************************************//** 57 Rollback or clean up any incomplete transactions which were 58 encountered in crash recovery. If the transaction already was 59 committed, then we clean up a possible insert undo log. If the 60 transaction was not yet committed, then we roll it back. 61 Note: this is done in a background thread. 62 @return a dummy parameter */ 63 extern "C" 64 os_thread_ret_t 65 DECLARE_THREAD(trx_rollback_all_recovered)(void*); 66 /*********************************************************************//** 67 Creates a rollback command node struct. 68 @return own: rollback node struct */ 69 roll_node_t* 70 roll_node_create( 71 /*=============*/ 72 mem_heap_t* heap); /*!< in: mem heap where created */ 73 /***********************************************************//** 74 Performs an execution step for a rollback command node in a query graph. 75 @return query thread to run next, or NULL */ 76 que_thr_t* 77 trx_rollback_step( 78 /*==============*/ 79 que_thr_t* thr); /*!< in: query thread */ 80 /*******************************************************************//** 81 Rollback a transaction used in MySQL. 82 @return error code or DB_SUCCESS */ 83 dberr_t 84 trx_rollback_for_mysql( 85 /*===================*/ 86 trx_t* trx) /*!< in/out: transaction */ 87 MY_ATTRIBUTE((nonnull)); 88 /*******************************************************************//** 89 Rollback the latest SQL statement for MySQL. 90 @return error code or DB_SUCCESS */ 91 dberr_t 92 trx_rollback_last_sql_stat_for_mysql( 93 /*=================================*/ 94 trx_t* trx) /*!< in/out: transaction */ 95 MY_ATTRIBUTE((nonnull)); 96 /*******************************************************************//** 97 Rolls back a transaction back to a named savepoint. Modifications after the 98 savepoint are undone but InnoDB does NOT release the corresponding locks 99 which are stored in memory. If a lock is 'implicit', that is, a new inserted 100 row holds a lock where the lock information is carried by the trx id stored in 101 the row, these locks are naturally released in the rollback. Savepoints which 102 were set after this savepoint are deleted. 103 @return if no savepoint of the name found then DB_NO_SAVEPOINT, 104 otherwise DB_SUCCESS */ 105 dberr_t 106 trx_rollback_to_savepoint_for_mysql( 107 /*================================*/ 108 trx_t* trx, /*!< in: transaction handle */ 109 const char* savepoint_name, /*!< in: savepoint name */ 110 int64_t* mysql_binlog_cache_pos) /*!< out: the MySQL binlog cache 111 position corresponding to this 112 savepoint; MySQL needs this 113 information to remove the 114 binlog entries of the queries 115 executed after the savepoint */ 116 MY_ATTRIBUTE((nonnull, warn_unused_result)); 117 /*******************************************************************//** 118 Creates a named savepoint. If the transaction is not yet started, starts it. 119 If there is already a savepoint of the same name, this call erases that old 120 savepoint and replaces it with a new. Savepoints are deleted in a transaction 121 commit or rollback. 122 @return always DB_SUCCESS */ 123 dberr_t 124 trx_savepoint_for_mysql( 125 /*====================*/ 126 trx_t* trx, /*!< in: transaction handle */ 127 const char* savepoint_name, /*!< in: savepoint name */ 128 int64_t binlog_cache_pos) /*!< in: MySQL binlog cache 129 position corresponding to this 130 connection at the time of the 131 savepoint */ 132 MY_ATTRIBUTE((nonnull)); 133 /*******************************************************************//** 134 Releases a named savepoint. Savepoints which 135 were set after this savepoint are deleted. 136 @return if no savepoint of the name found then DB_NO_SAVEPOINT, 137 otherwise DB_SUCCESS */ 138 dberr_t 139 trx_release_savepoint_for_mysql( 140 /*============================*/ 141 trx_t* trx, /*!< in: transaction handle */ 142 const char* savepoint_name) /*!< in: savepoint name */ 143 MY_ATTRIBUTE((nonnull, warn_unused_result)); 144 /*******************************************************************//** 145 Frees savepoint structs starting from savep. */ 146 void 147 trx_roll_savepoints_free( 148 /*=====================*/ 149 trx_t* trx, /*!< in: transaction handle */ 150 trx_named_savept_t* savep); /*!< in: free all savepoints > this one; 151 if this is NULL, free all savepoints 152 of trx */ 153 /** Rollback node states */ 154 enum roll_node_state { 155 ROLL_NODE_NONE = 0, /*!< Unknown state */ 156 ROLL_NODE_SEND, /*!< about to send a rollback signal to 157 the transaction */ 158 ROLL_NODE_WAIT /*!< rollback signal sent to the 159 transaction, waiting for completion */ 160 }; 161 162 /** Rollback command node in a query graph */ 163 struct roll_node_t{ 164 que_common_t common; /*!< node type: QUE_NODE_ROLLBACK */ 165 enum roll_node_state state; /*!< node execution state */ 166 const trx_savept_t* savept; /*!< savepoint to which to 167 roll back, in the case of a 168 partial rollback */ 169 que_thr_t* undo_thr;/*!< undo query graph */ 170 }; 171 172 /** A savepoint set with SQL's "SAVEPOINT savepoint_id" command */ 173 struct trx_named_savept_t{ 174 char* name; /*!< savepoint name */ 175 trx_savept_t savept; /*!< the undo number corresponding to 176 the savepoint */ 177 int64_t mysql_binlog_cache_pos; 178 /*!< the MySQL binlog cache position 179 corresponding to this savepoint, not 180 defined if the MySQL binlogging is not 181 enabled */ 182 UT_LIST_NODE_T(trx_named_savept_t) 183 trx_savepoints; /*!< the list of savepoints of a 184 transaction */ 185 }; 186 187 #endif 188