1 /***************************************************************************** 2 3 Copyright (c) 1996, 2021, Oracle and/or its affiliates. 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/trx0rseg.h 29 Rollback segment 30 31 Created 3/26/1996 Heikki Tuuri 32 *******************************************************/ 33 34 #ifndef trx0rseg_h 35 #define trx0rseg_h 36 37 #include "univ.i" 38 #include "trx0types.h" 39 #include "trx0sys.h" 40 #include "fut0lst.h" 41 #include <vector> 42 43 /** Gets a rollback segment header. 44 @param[in] space space where placed 45 @param[in] page_no page number of the header 46 @param[in] page_size page size 47 @param[in,out] mtr mini-transaction 48 @return rollback segment header, page x-latched */ 49 UNIV_INLINE 50 trx_rsegf_t* 51 trx_rsegf_get( 52 ulint space, 53 ulint page_no, 54 const page_size_t& page_size, 55 mtr_t* mtr); 56 57 /** Gets a newly created rollback segment header. 58 @param[in] space space where placed 59 @param[in] page_no page number of the header 60 @param[in] page_size page size 61 @param[in,out] mtr mini-transaction 62 @return rollback segment header, page x-latched */ 63 UNIV_INLINE 64 trx_rsegf_t* 65 trx_rsegf_get_new( 66 ulint space, 67 ulint page_no, 68 const page_size_t& page_size, 69 mtr_t* mtr); 70 71 /***************************************************************//** 72 Gets the file page number of the nth undo log slot. 73 @return page number of the undo log segment */ 74 UNIV_INLINE 75 ulint 76 trx_rsegf_get_nth_undo( 77 /*===================*/ 78 trx_rsegf_t* rsegf, /*!< in: rollback segment header */ 79 ulint n, /*!< in: index of slot */ 80 mtr_t* mtr); /*!< in: mtr */ 81 /***************************************************************//** 82 Sets the file page number of the nth undo log slot. */ 83 UNIV_INLINE 84 void 85 trx_rsegf_set_nth_undo( 86 /*===================*/ 87 trx_rsegf_t* rsegf, /*!< in: rollback segment header */ 88 ulint n, /*!< in: index of slot */ 89 ulint page_no,/*!< in: page number of the undo log segment */ 90 mtr_t* mtr); /*!< in: mtr */ 91 /****************************************************************//** 92 Looks for a free slot for an undo log segment. 93 @return slot index or ULINT_UNDEFINED if not found */ 94 UNIV_INLINE 95 ulint 96 trx_rsegf_undo_find_free( 97 /*=====================*/ 98 trx_rsegf_t* rsegf, /*!< in: rollback segment header */ 99 mtr_t* mtr); /*!< in: mtr */ 100 /******************************************************************//** 101 Looks for a rollback segment, based on the rollback segment id. 102 @return rollback segment */ 103 UNIV_INLINE 104 trx_rseg_t* 105 trx_rseg_get_on_id( 106 /*===============*/ 107 ulint id, /*!< in: rollback segment id */ 108 bool is_redo_rseg); /*!< in: true if redo rseg else false. */ 109 110 /** Creates a rollback segment header. 111 This function is called only when a new rollback segment is created in 112 the database. 113 @param[in] space space id 114 @param[in] page_size page size 115 @param[in] max_size max size in pages 116 @param[in] rseg_slot_no rseg id == slot number in trx sys 117 @param[in,out] mtr mini-transaction 118 @return page number of the created segment, FIL_NULL if fail */ 119 ulint 120 trx_rseg_header_create( 121 ulint space, 122 const page_size_t& page_size, 123 ulint max_size, 124 ulint rseg_slot_no, 125 mtr_t* mtr); 126 127 /*********************************************************************//** 128 Creates the memory copies for rollback segments and initializes the 129 rseg array in trx_sys at a database startup. */ 130 void 131 trx_rseg_array_init( 132 /*================*/ 133 purge_pq_t* purge_queue); /*!< in: rseg queue */ 134 135 /*************************************************************************** 136 Free's an instance of the rollback segment in memory. */ 137 void 138 trx_rseg_mem_free( 139 /*==============*/ 140 trx_rseg_t* rseg, /*!< in, own: instance to free */ 141 trx_rseg_t** rseg_array); /*!< out: add rseg reference to this 142 central array. */ 143 /********************************************************************* 144 Creates a rollback segment. */ 145 trx_rseg_t* 146 trx_rseg_create( 147 /*============*/ 148 ulint space_id, /*!< in: id of UNDO tablespace */ 149 ulint nth_free_slot); /*!< in: allocate nth free slot. 150 0 means next free slots. */ 151 152 /******************************************************************** 153 Get the number of unique rollback tablespaces in use except space id 0. 154 The last space id will be the sentinel value ULINT_UNDEFINED. The array 155 will be sorted on space id. Note: space_ids should have have space for 156 TRX_SYS_N_RSEGS + 1 elements. 157 @return number of unique rollback tablespaces in use. */ 158 ulint 159 trx_rseg_get_n_undo_tablespaces( 160 /*============================*/ 161 ulint* space_ids); /*!< out: array of space ids of 162 UNDO tablespaces */ 163 164 /** Reset no-redo rseg slots on disk used by pre-5.7.2 rsegs. All data for 165 these rsegs are already purged. This is a deferred action to be done post 166 redo log recovery. */ 167 void trx_rseg_reset_pending(); 168 169 /* Number of undo log slots in a rollback segment file copy */ 170 #define TRX_RSEG_N_SLOTS (UNIV_PAGE_SIZE / 16) 171 172 /* Maximum number of transactions supported by a single rollback segment */ 173 #define TRX_RSEG_MAX_N_TRXS (TRX_RSEG_N_SLOTS / 2) 174 175 /** The rollback segment memory object */ 176 struct trx_rseg_t { 177 /*--------------------------------------------------------*/ 178 /** rollback segment id == the index of its slot in the trx 179 system file copy */ 180 ulint id; 181 182 /** mutex protecting the fields in this struct except id,space,page_no 183 which are constant */ 184 RsegMutex mutex; 185 186 /** space where the rollback segment header is placed */ 187 ulint space; 188 189 /** page number of the rollback segment header */ 190 ulint page_no; 191 192 /** page size of the relevant tablespace */ 193 page_size_t page_size; 194 195 /** maximum allowed size in pages */ 196 ulint max_size; 197 198 /** current size in pages */ 199 ulint curr_size; 200 201 /*--------------------------------------------------------*/ 202 /* Fields for update undo logs */ 203 /** List of update undo logs */ 204 UT_LIST_BASE_NODE_T(trx_undo_t) update_undo_list; 205 206 /** List of update undo log segments cached for fast reuse */ 207 UT_LIST_BASE_NODE_T(trx_undo_t) update_undo_cached; 208 209 /*--------------------------------------------------------*/ 210 /* Fields for insert undo logs */ 211 /** List of insert undo logs */ 212 UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_list; 213 214 /** List of insert undo log segments cached for fast reuse */ 215 UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_cached; 216 217 /*--------------------------------------------------------*/ 218 219 /** Page number of the last not yet purged log header in the history 220 list; FIL_NULL if all list purged */ 221 ulint last_page_no; 222 223 /** Byte offset of the last not yet purged log header */ 224 ulint last_offset; 225 226 /** Transaction number of the last not yet purged log */ 227 trx_id_t last_trx_no; 228 229 /** TRUE if the last not yet purged log needs purging */ 230 ibool last_del_marks; 231 232 /** Reference counter to track rseg allocated transactions. */ 233 ulint trx_ref_count; 234 235 /** If true, then skip allocating this rseg as it reside in 236 UNDO-tablespace marked for truncate. */ 237 bool skip_allocation; 238 }; 239 240 /* Undo log segment slot in a rollback segment header */ 241 /*-------------------------------------------------------------*/ 242 #define TRX_RSEG_SLOT_PAGE_NO 0 /* Page number of the header page of 243 an undo log segment */ 244 /*-------------------------------------------------------------*/ 245 /* Slot size */ 246 #define TRX_RSEG_SLOT_SIZE 4 247 248 /* The offset of the rollback segment header on its page */ 249 #define TRX_RSEG FSEG_PAGE_DATA 250 251 /* Transaction rollback segment header */ 252 /*-------------------------------------------------------------*/ 253 #define TRX_RSEG_MAX_SIZE 0 /* Maximum allowed size for rollback 254 segment in pages */ 255 #define TRX_RSEG_HISTORY_SIZE 4 /* Number of file pages occupied 256 by the logs in the history list */ 257 #define TRX_RSEG_HISTORY 8 /* The update undo logs for committed 258 transactions */ 259 #define TRX_RSEG_FSEG_HEADER (8 + FLST_BASE_NODE_SIZE) 260 /* Header for the file segment where 261 this page is placed */ 262 #define TRX_RSEG_UNDO_SLOTS (8 + FLST_BASE_NODE_SIZE + FSEG_HEADER_SIZE) 263 /* Undo log segment slots */ 264 /*-------------------------------------------------------------*/ 265 266 #ifndef UNIV_NONINL 267 #include "trx0rseg.ic" 268 #endif 269 270 #endif 271