00001 /****************************************************** 00002 Transaction rollback 00003 00004 (c) 1996 Innobase Oy 00005 00006 Created 3/26/1996 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef trx0roll_h 00010 #define trx0roll_h 00011 00012 #include "univ.i" 00013 #include "trx0trx.h" 00014 #include "trx0types.h" 00015 #include "mtr0mtr.h" 00016 #include "trx0sys.h" 00017 00018 /*********************************************************************** 00019 Returns a transaction savepoint taken at this point in time. */ 00020 00021 trx_savept_t 00022 trx_savept_take( 00023 /*============*/ 00024 /* out: savepoint */ 00025 trx_t* trx); /* in: transaction */ 00026 /*********************************************************************** 00027 Creates an undo number array. */ 00028 00029 trx_undo_arr_t* 00030 trx_undo_arr_create(void); 00031 /*=====================*/ 00032 /*********************************************************************** 00033 Frees an undo number array. */ 00034 00035 void 00036 trx_undo_arr_free( 00037 /*==============*/ 00038 trx_undo_arr_t* arr); /* in: undo number array */ 00039 /*********************************************************************** 00040 Returns pointer to nth element in an undo number array. */ 00041 UNIV_INLINE 00042 trx_undo_inf_t* 00043 trx_undo_arr_get_nth_info( 00044 /*======================*/ 00045 /* out: pointer to the nth element */ 00046 trx_undo_arr_t* arr, /* in: undo number array */ 00047 ulint n); /* in: position */ 00048 /*************************************************************************** 00049 Tries truncate the undo logs. */ 00050 00051 void 00052 trx_roll_try_truncate( 00053 /*==================*/ 00054 trx_t* trx); /* in: transaction */ 00055 /************************************************************************ 00056 Pops the topmost record when the two undo logs of a transaction are seen 00057 as a single stack of records ordered by their undo numbers. Inserts the 00058 undo number of the popped undo record to the array of currently processed 00059 undo numbers in the transaction. When the query thread finishes processing 00060 of this undo record, it must be released with trx_undo_rec_release. */ 00061 00062 trx_undo_rec_t* 00063 trx_roll_pop_top_rec_of_trx( 00064 /*========================*/ 00065 /* out: undo log record copied to heap, NULL 00066 if none left, or if the undo number of the 00067 top record would be less than the limit */ 00068 trx_t* trx, /* in: transaction */ 00069 dulint limit, /* in: least undo number we need */ 00070 dulint* roll_ptr,/* out: roll pointer to undo record */ 00071 mem_heap_t* heap); /* in: memory heap where copied */ 00072 /************************************************************************ 00073 Reserves an undo log record for a query thread to undo. This should be 00074 called if the query thread gets the undo log record not using the pop 00075 function above. */ 00076 00077 ibool 00078 trx_undo_rec_reserve( 00079 /*=================*/ 00080 /* out: TRUE if succeeded */ 00081 trx_t* trx, /* in: transaction */ 00082 dulint undo_no);/* in: undo number of the record */ 00083 /*********************************************************************** 00084 Releases a reserved undo record. */ 00085 00086 void 00087 trx_undo_rec_release( 00088 /*=================*/ 00089 trx_t* trx, /* in: transaction */ 00090 dulint undo_no);/* in: undo number */ 00091 /************************************************************************* 00092 Starts a rollback operation. */ 00093 00094 void 00095 trx_rollback( 00096 /*=========*/ 00097 trx_t* trx, /* in: transaction */ 00098 trx_sig_t* sig, /* in: signal starting the rollback */ 00099 que_thr_t** next_thr);/* in/out: next query thread to run; 00100 if the value which is passed in is 00101 a pointer to a NULL pointer, then the 00102 calling function can start running 00103 a new query thread */ 00104 /*********************************************************************** 00105 Rollback or clean up transactions which have no user session. If the 00106 transaction already was committed, then we clean up a possible insert 00107 undo log. If the transaction was not yet committed, then we roll it back. 00108 Note: this is done in a background thread. */ 00109 00110 os_thread_ret_t 00111 trx_rollback_or_clean_all_without_sess( 00112 /*===================================*/ 00113 /* out: a dummy parameter */ 00114 void* arg __attribute__((unused))); 00115 /* in: a dummy parameter required by 00116 os_thread_create */ 00117 /******************************************************************** 00118 Finishes a transaction rollback. */ 00119 00120 void 00121 trx_finish_rollback_off_kernel( 00122 /*===========================*/ 00123 que_t* graph, /* in: undo graph which can now be freed */ 00124 trx_t* trx, /* in: transaction */ 00125 que_thr_t** next_thr);/* in/out: next query thread to run; 00126 if the value which is passed in is 00127 a pointer to a NULL pointer, then the 00128 calling function can start running 00129 a new query thread; if this parameter is 00130 NULL, it is ignored */ 00131 /******************************************************************** 00132 Builds an undo 'query' graph for a transaction. The actual rollback is 00133 performed by executing this query graph like a query subprocedure call. 00134 The reply about the completion of the rollback will be sent by this 00135 graph. */ 00136 00137 que_t* 00138 trx_roll_graph_build( 00139 /*=================*/ 00140 /* out, own: the query graph */ 00141 trx_t* trx); /* in: trx handle */ 00142 /************************************************************************* 00143 Creates a rollback command node struct. */ 00144 00145 roll_node_t* 00146 roll_node_create( 00147 /*=============*/ 00148 /* out, own: rollback node struct */ 00149 mem_heap_t* heap); /* in: mem heap where created */ 00150 /*************************************************************** 00151 Performs an execution step for a rollback command node in a query graph. */ 00152 00153 que_thr_t* 00154 trx_rollback_step( 00155 /*==============*/ 00156 /* out: query thread to run next, or NULL */ 00157 que_thr_t* thr); /* in: query thread */ 00158 /*********************************************************************** 00159 Rollback a transaction used in MySQL. */ 00160 00161 int 00162 trx_rollback_for_mysql( 00163 /*===================*/ 00164 /* out: error code or DB_SUCCESS */ 00165 trx_t* trx); /* in: transaction handle */ 00166 /*********************************************************************** 00167 Rollback the latest SQL statement for MySQL. */ 00168 00169 int 00170 trx_rollback_last_sql_stat_for_mysql( 00171 /*=================================*/ 00172 /* out: error code or DB_SUCCESS */ 00173 trx_t* trx); /* in: transaction handle */ 00174 /*********************************************************************** 00175 Rollback a transaction used in MySQL. */ 00176 00177 int 00178 trx_general_rollback_for_mysql( 00179 /*===========================*/ 00180 /* out: error code or DB_SUCCESS */ 00181 trx_t* trx, /* in: transaction handle */ 00182 ibool partial,/* in: TRUE if partial rollback requested */ 00183 trx_savept_t* savept);/* in: pointer to savepoint undo number, if 00184 partial rollback requested */ 00185 /*********************************************************************** 00186 Rolls back a transaction back to a named savepoint. Modifications after the 00187 savepoint are undone but InnoDB does NOT release the corresponding locks 00188 which are stored in memory. If a lock is 'implicit', that is, a new inserted 00189 row holds a lock where the lock information is carried by the trx id stored in 00190 the row, these locks are naturally released in the rollback. Savepoints which 00191 were set after this savepoint are deleted. */ 00192 00193 ulint 00194 trx_rollback_to_savepoint_for_mysql( 00195 /*================================*/ 00196 /* out: if no savepoint 00197 of the name found then 00198 DB_NO_SAVEPOINT, 00199 otherwise DB_SUCCESS */ 00200 trx_t* trx, /* in: transaction handle */ 00201 const char* savepoint_name, /* in: savepoint name */ 00202 ib_longlong* mysql_binlog_cache_pos);/* out: the MySQL binlog cache 00203 position corresponding to this 00204 savepoint; MySQL needs this 00205 information to remove the 00206 binlog entries of the queries 00207 executed after the savepoint */ 00208 /*********************************************************************** 00209 Creates a named savepoint. If the transaction is not yet started, starts it. 00210 If there is already a savepoint of the same name, this call erases that old 00211 savepoint and replaces it with a new. Savepoints are deleted in a transaction 00212 commit or rollback. */ 00213 00214 ulint 00215 trx_savepoint_for_mysql( 00216 /*====================*/ 00217 /* out: always DB_SUCCESS */ 00218 trx_t* trx, /* in: transaction handle */ 00219 const char* savepoint_name, /* in: savepoint name */ 00220 ib_longlong binlog_cache_pos); /* in: MySQL binlog cache 00221 position corresponding to this 00222 connection at the time of the 00223 savepoint */ 00224 00225 /*********************************************************************** 00226 Releases a named savepoint. Savepoints which 00227 were set after this savepoint are deleted. */ 00228 00229 ulint 00230 trx_release_savepoint_for_mysql( 00231 /*============================*/ 00232 /* out: if no savepoint 00233 of the name found then 00234 DB_NO_SAVEPOINT, 00235 otherwise DB_SUCCESS */ 00236 trx_t* trx, /* in: transaction handle */ 00237 const char* savepoint_name); /* in: savepoint name */ 00238 00239 /*********************************************************************** 00240 Frees savepoint structs. */ 00241 00242 void 00243 trx_roll_savepoints_free( 00244 /*=====================*/ 00245 trx_t* trx, /* in: transaction handle */ 00246 trx_named_savept_t* savep); /* in: free all savepoints > this one; 00247 if this is NULL, free all savepoints 00248 of trx */ 00249 00250 extern sess_t* trx_dummy_sess; 00251 00252 /* A cell in the array used during a rollback and a purge */ 00253 struct trx_undo_inf_struct{ 00254 dulint trx_no; /* transaction number: not defined during 00255 a rollback */ 00256 dulint undo_no; /* undo number of an undo record */ 00257 ibool in_use; /* TRUE if the cell is in use */ 00258 }; 00259 00260 /* During a rollback and a purge, undo numbers of undo records currently being 00261 processed are stored in this array */ 00262 00263 struct trx_undo_arr_struct{ 00264 ulint n_cells; /* number of cells in the array */ 00265 ulint n_used; /* number of cells currently in use */ 00266 trx_undo_inf_t* infos; /* the array of undo infos */ 00267 mem_heap_t* heap; /* memory heap from which allocated */ 00268 }; 00269 00270 /* Rollback command node in a query graph */ 00271 struct roll_node_struct{ 00272 que_common_t common; /* node type: QUE_NODE_ROLLBACK */ 00273 ulint state; /* node execution state */ 00274 ibool partial;/* TRUE if we want a partial rollback */ 00275 trx_savept_t savept; /* savepoint to which to roll back, in the 00276 case of a partial rollback */ 00277 }; 00278 00279 /* A savepoint set with SQL's "SAVEPOINT savepoint_id" command */ 00280 struct trx_named_savept_struct{ 00281 char* name; /* savepoint name */ 00282 trx_savept_t savept; /* the undo number corresponding to 00283 the savepoint */ 00284 ib_longlong mysql_binlog_cache_pos; 00285 /* the MySQL binlog cache position 00286 corresponding to this savepoint, not 00287 defined if the MySQL binlogging is not 00288 enabled */ 00289 UT_LIST_NODE_T(trx_named_savept_t) 00290 trx_savepoints; /* the list of savepoints of a 00291 transaction */ 00292 }; 00293 00294 /* Rollback node states */ 00295 #define ROLL_NODE_SEND 1 00296 #define ROLL_NODE_WAIT 2 00297 00298 #ifndef UNIV_NONINL 00299 #include "trx0roll.ic" 00300 #endif 00301 00302 #endif
1.4.7

