1 /***************************************************************************** 2 3 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License along with 22 this program; if not, write to the Free Software Foundation, Inc., 23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 24 25 *****************************************************************************/ 26 27 /**************************************************//** 28 @file include/trx0rec.h 29 Transaction undo log record 30 31 Created 3/26/1996 Heikki Tuuri 32 *******************************************************/ 33 34 #ifndef trx0rec_h 35 #define trx0rec_h 36 37 #include "univ.i" 38 #include "trx0types.h" 39 #include "row0types.h" 40 #include "mtr0mtr.h" 41 #include "dict0types.h" 42 #include "data0data.h" 43 #include "rem0types.h" 44 45 #ifndef UNIV_HOTBACKUP 46 # include "que0types.h" 47 48 /***********************************************************************//** 49 Copies the undo record to the heap. 50 @return own: copy of undo log record */ 51 UNIV_INLINE 52 trx_undo_rec_t* 53 trx_undo_rec_copy( 54 /*==============*/ 55 const trx_undo_rec_t* undo_rec, /*!< in: undo log record */ 56 mem_heap_t* heap); /*!< in: heap where copied */ 57 /**********************************************************************//** 58 Reads the undo log record type. 59 @return record type */ 60 UNIV_INLINE 61 ulint 62 trx_undo_rec_get_type( 63 /*==================*/ 64 const trx_undo_rec_t* undo_rec); /*!< in: undo log record */ 65 /**********************************************************************//** 66 Reads from an undo log record the record compiler info. 67 @return compiler info */ 68 UNIV_INLINE 69 ulint 70 trx_undo_rec_get_cmpl_info( 71 /*=======================*/ 72 const trx_undo_rec_t* undo_rec); /*!< in: undo log record */ 73 /**********************************************************************//** 74 Returns TRUE if an undo log record contains an extern storage field. 75 @return TRUE if extern */ 76 UNIV_INLINE 77 ibool 78 trx_undo_rec_get_extern_storage( 79 /*============================*/ 80 const trx_undo_rec_t* undo_rec); /*!< in: undo log record */ 81 /**********************************************************************//** 82 Reads the undo log record number. 83 @return undo no */ 84 UNIV_INLINE 85 undo_no_t 86 trx_undo_rec_get_undo_no( 87 /*=====================*/ 88 const trx_undo_rec_t* undo_rec); /*!< in: undo log record */ 89 /**********************************************************************//** 90 Returns the start of the undo record data area. 91 @return offset to the data area */ 92 UNIV_INLINE 93 ulint 94 trx_undo_rec_get_offset( 95 /*====================*/ 96 undo_no_t undo_no) /*!< in: undo no read from node */ 97 MY_ATTRIBUTE((const)); 98 99 /**********************************************************************//** 100 Returns the start of the undo record data area. */ 101 #define trx_undo_rec_get_ptr(undo_rec, undo_no) \ 102 ((undo_rec) + trx_undo_rec_get_offset(undo_no)) 103 104 /**********************************************************************//** 105 Reads from an undo log record the general parameters. 106 @return remaining part of undo log record after reading these values */ 107 UNIV_INTERN 108 byte* 109 trx_undo_rec_get_pars( 110 /*==================*/ 111 trx_undo_rec_t* undo_rec, /*!< in: undo log record */ 112 ulint* type, /*!< out: undo record type: 113 TRX_UNDO_INSERT_REC, ... */ 114 ulint* cmpl_info, /*!< out: compiler info, relevant only 115 for update type records */ 116 bool* updated_extern, /*!< out: true if we updated an 117 externally stored fild */ 118 undo_no_t* undo_no, /*!< out: undo log record number */ 119 table_id_t* table_id) /*!< out: table id */ 120 MY_ATTRIBUTE((nonnull)); 121 /*******************************************************************//** 122 Builds a row reference from an undo log record. 123 @return pointer to remaining part of undo record */ 124 UNIV_INTERN 125 byte* 126 trx_undo_rec_get_row_ref( 127 /*=====================*/ 128 byte* ptr, /*!< in: remaining part of a copy of an undo log 129 record, at the start of the row reference; 130 NOTE that this copy of the undo log record must 131 be preserved as long as the row reference is 132 used, as we do NOT copy the data in the 133 record! */ 134 dict_index_t* index, /*!< in: clustered index */ 135 dtuple_t** ref, /*!< out, own: row reference */ 136 mem_heap_t* heap); /*!< in: memory heap from which the memory 137 needed is allocated */ 138 /*******************************************************************//** 139 Skips a row reference from an undo log record. 140 @return pointer to remaining part of undo record */ 141 UNIV_INTERN 142 byte* 143 trx_undo_rec_skip_row_ref( 144 /*======================*/ 145 byte* ptr, /*!< in: remaining part in update undo log 146 record, at the start of the row reference */ 147 dict_index_t* index); /*!< in: clustered index */ 148 /**********************************************************************//** 149 Reads from an undo log update record the system field values of the old 150 version. 151 @return remaining part of undo log record after reading these values */ 152 UNIV_INTERN 153 byte* 154 trx_undo_update_rec_get_sys_cols( 155 /*=============================*/ 156 byte* ptr, /*!< in: remaining part of undo 157 log record after reading 158 general parameters */ 159 trx_id_t* trx_id, /*!< out: trx id */ 160 roll_ptr_t* roll_ptr, /*!< out: roll ptr */ 161 ulint* info_bits); /*!< out: info bits state */ 162 /*******************************************************************//** 163 Builds an update vector based on a remaining part of an undo log record. 164 @return remaining part of the record, NULL if an error detected, which 165 means that the record is corrupted */ 166 UNIV_INTERN 167 byte* 168 trx_undo_update_rec_get_update( 169 /*===========================*/ 170 byte* ptr, /*!< in: remaining part in update undo log 171 record, after reading the row reference 172 NOTE that this copy of the undo log record must 173 be preserved as long as the update vector is 174 used, as we do NOT copy the data in the 175 record! */ 176 dict_index_t* index, /*!< in: clustered index */ 177 ulint type, /*!< in: TRX_UNDO_UPD_EXIST_REC, 178 TRX_UNDO_UPD_DEL_REC, or 179 TRX_UNDO_DEL_MARK_REC; in the last case, 180 only trx id and roll ptr fields are added to 181 the update vector */ 182 trx_id_t trx_id, /*!< in: transaction id from this undorecord */ 183 roll_ptr_t roll_ptr,/*!< in: roll pointer from this undo record */ 184 ulint info_bits,/*!< in: info bits from this undo record */ 185 trx_t* trx, /*!< in: transaction */ 186 mem_heap_t* heap, /*!< in: memory heap from which the memory 187 needed is allocated */ 188 upd_t** upd); /*!< out, own: update vector */ 189 /*******************************************************************//** 190 Builds a partial row from an update undo log record, for purge. 191 It contains the columns which occur as ordering in any index of the table. 192 Any missing columns are indicated by col->mtype == DATA_MISSING. 193 @return pointer to remaining part of undo record */ 194 UNIV_INTERN 195 byte* 196 trx_undo_rec_get_partial_row( 197 /*=========================*/ 198 byte* ptr, /*!< in: remaining part in update undo log 199 record of a suitable type, at the start of 200 the stored index columns; 201 NOTE that this copy of the undo log record must 202 be preserved as long as the partial row is 203 used, as we do NOT copy the data in the 204 record! */ 205 dict_index_t* index, /*!< in: clustered index */ 206 dtuple_t** row, /*!< out, own: partial row */ 207 ibool ignore_prefix, /*!< in: flag to indicate if we 208 expect blob prefixes in undo. Used 209 only in the assertion. */ 210 mem_heap_t* heap) /*!< in: memory heap from which the memory 211 needed is allocated */ 212 MY_ATTRIBUTE((nonnull, warn_unused_result)); 213 /***********************************************************************//** 214 Writes information to an undo log about an insert, update, or a delete marking 215 of a clustered index record. This information is used in a rollback of the 216 transaction and in consistent reads that must look to the history of this 217 transaction. 218 @return DB_SUCCESS or error code */ 219 UNIV_INTERN 220 dberr_t 221 trx_undo_report_row_operation( 222 /*==========================*/ 223 ulint flags, /*!< in: if BTR_NO_UNDO_LOG_FLAG bit is 224 set, does nothing */ 225 ulint op_type, /*!< in: TRX_UNDO_INSERT_OP or 226 TRX_UNDO_MODIFY_OP */ 227 que_thr_t* thr, /*!< in: query thread */ 228 dict_index_t* index, /*!< in: clustered index */ 229 const dtuple_t* clust_entry, /*!< in: in the case of an insert, 230 index entry to insert into the 231 clustered index, otherwise NULL */ 232 const upd_t* update, /*!< in: in the case of an update, 233 the update vector, otherwise NULL */ 234 ulint cmpl_info, /*!< in: compiler info on secondary 235 index updates */ 236 const rec_t* rec, /*!< in: case of an update or delete 237 marking, the record in the clustered 238 index, otherwise NULL */ 239 const ulint* offsets, /*!< in: rec_get_offsets(rec) */ 240 roll_ptr_t* roll_ptr) /*!< out: rollback pointer to the 241 inserted undo log record, 242 0 if BTR_NO_UNDO_LOG 243 flag was specified */ 244 MY_ATTRIBUTE((nonnull(3,4,10), warn_unused_result)); 245 /******************************************************************//** 246 Copies an undo record to heap. This function can be called if we know that 247 the undo log record exists. 248 @return own: copy of the record */ 249 UNIV_INTERN 250 trx_undo_rec_t* 251 trx_undo_get_undo_rec_low( 252 /*======================*/ 253 roll_ptr_t roll_ptr, /*!< in: roll pointer to record */ 254 mem_heap_t* heap) /*!< in: memory heap where copied */ 255 MY_ATTRIBUTE((nonnull, warn_unused_result)); 256 /*******************************************************************//** 257 Build a previous version of a clustered index record. The caller must 258 hold a latch on the index page of the clustered index record. 259 @retval true if previous version was built, or if it was an insert 260 or the table has been rebuilt 261 @retval false if the previous version is earlier than purge_view, 262 which means that it may have been removed */ 263 UNIV_INTERN 264 bool 265 trx_undo_prev_version_build( 266 /*========================*/ 267 const rec_t* index_rec,/*!< in: clustered index record in the 268 index tree */ 269 mtr_t* index_mtr,/*!< in: mtr which contains the latch to 270 index_rec page and purge_view */ 271 const rec_t* rec, /*!< in: version of a clustered index record */ 272 dict_index_t* index, /*!< in: clustered index */ 273 ulint* offsets,/*!< in/out: rec_get_offsets(rec, index) */ 274 mem_heap_t* heap, /*!< in: memory heap from which the memory 275 needed is allocated */ 276 rec_t** old_vers)/*!< out, own: previous version, or NULL if 277 rec is the first inserted version, or if 278 history data has been deleted */ 279 MY_ATTRIBUTE((nonnull)); 280 #endif /* !UNIV_HOTBACKUP */ 281 /***********************************************************//** 282 Parses a redo log record of adding an undo log record. 283 @return end of log record or NULL */ 284 UNIV_INTERN 285 byte* 286 trx_undo_parse_add_undo_rec( 287 /*========================*/ 288 byte* ptr, /*!< in: buffer */ 289 byte* end_ptr,/*!< in: buffer end */ 290 page_t* page); /*!< in: page or NULL */ 291 /***********************************************************//** 292 Parses a redo log record of erasing of an undo page end. 293 @return end of log record or NULL */ 294 UNIV_INTERN 295 byte* 296 trx_undo_parse_erase_page_end( 297 /*==========================*/ 298 byte* ptr, /*!< in: buffer */ 299 byte* end_ptr,/*!< in: buffer end */ 300 page_t* page, /*!< in: page or NULL */ 301 mtr_t* mtr); /*!< in: mtr or NULL */ 302 303 #ifndef UNIV_HOTBACKUP 304 305 /* Types of an undo log record: these have to be smaller than 16, as the 306 compilation info multiplied by 16 is ORed to this value in an undo log 307 record */ 308 309 #define TRX_UNDO_INSERT_REC 11 /* fresh insert into clustered index */ 310 #define TRX_UNDO_UPD_EXIST_REC 12 /* update of a non-delete-marked 311 record */ 312 #define TRX_UNDO_UPD_DEL_REC 13 /* update of a delete marked record to 313 a not delete marked record; also the 314 fields of the record can change */ 315 #define TRX_UNDO_DEL_MARK_REC 14 /* delete marking of a record; fields 316 do not change */ 317 #define TRX_UNDO_CMPL_INFO_MULT 16 /* compilation info is multiplied by 318 this and ORed to the type above */ 319 #define TRX_UNDO_UPD_EXTERN 128 /* This bit can be ORed to type_cmpl 320 to denote that we updated external 321 storage fields: used by purge to 322 free the external storage */ 323 324 /* Operation type flags used in trx_undo_report_row_operation */ 325 #define TRX_UNDO_INSERT_OP 1 326 #define TRX_UNDO_MODIFY_OP 2 327 328 #ifndef UNIV_NONINL 329 #include "trx0rec.ic" 330 #endif 331 332 #endif /* !UNIV_HOTBACKUP */ 333 334 #endif /* trx0rec_h */ 335