Debian Codegraph @

storage/innobase/include/trx0rseg.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 1996, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work 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 either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 <vector>
38 #include "fut0lst.h"
39 #include "trx0sys.h"
40 #include "trx0types.h"
41 #include "univ.i"
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 static inline trx_rsegf_t *trx_rsegf_get(space_id_t space, page_no_t page_no,
50 const page_size_t &page_size,
51 mtr_t *mtr);
52
53 /** Gets a newly created rollback segment header.
54 @param[in] space Space where placed
55 @param[in] page_no Page number of the header
56 @param[in] page_size Page size
57 @param[in,out] mtr Mini-transaction
58 @return rollback segment header, page x-latched */
59 static inline trx_rsegf_t *trx_rsegf_get_new(space_id_t space,
60 page_no_t page_no,
61 const page_size_t &page_size,
62 mtr_t *mtr);
63
64 /** Gets the file page number of the nth undo log slot.
65 @param[in] rsegf rollback segment header
66 @param[in] n index of slot
67 @param[in] mtr mtr
68 @return page number of the undo log segment */
69 static inline page_no_t trx_rsegf_get_nth_undo(trx_rsegf_t *rsegf, ulint n,
70 mtr_t *mtr);
71
72 /** Sets the file page number of the nth undo log slot.
73 @param[in] rsegf rollback segment header
74 @param[in] n index of slot
75 @param[in] page_no page number of the undo log segment
76 @param[in] mtr mtr */
77 static inline void trx_rsegf_set_nth_undo(trx_rsegf_t *rsegf, ulint n,
78 page_no_t page_no, mtr_t *mtr);
79
80 /** Looks for a free slot for an undo log segment.
81 @param[in] rsegf rollback segment header
82 @param[in] mtr mtr
83 @return slot index or ULINT_UNDEFINED if not found */
84 static inline ulint trx_rsegf_undo_find_free(trx_rsegf_t *rsegf, mtr_t *mtr);
85
86 /** Creates a rollback segment header.
87 This function is called only when a new rollback segment is created in
88 the database.
89 @param[in] space_id Space id
90 @param[in] page_size Page size
91 @param[in] max_size Max size in pages
92 @param[in] rseg_slot Rseg id == slot number in RSEG_ARRAY
93 @param[in,out] mtr Mini-transaction
94 @return page number of the created segment, FIL_NULL if fail */
95 page_no_t trx_rseg_header_create(space_id_t space_id,
96 const page_size_t &page_size,
97 page_no_t max_size, ulint rseg_slot,
98 mtr_t *mtr);
99
100 /** Add more rsegs to the rseg list in each tablespace until there are
101 srv_rollback_segments of them. Use any rollback segment that already
102 exists so that the purge_queue can be filled and processed with any
103 existing undo log. If the rollback segments do not exist in this
104 tablespace and we need them according to target_rollback_segments,
105 then build them in the tablespace.
106 @param[in] target_rollback_segments new number of rollback
107 segments per space
108 @return true if all necessary rollback segments and trx_rseg_t objects
109 were created. */
110 bool trx_rseg_adjust_rollback_segments(ulong target_rollback_segments);
111
112 /** Create the requested number of Rollback Segments in a newly created undo
113 tablespace and add them to the Rsegs object.
114 @param[in] space_id undo tablespace ID
115 @param[in] target_rollback_segments number of rollback segments per space
116 @return true if all necessary rollback segments and trx_rseg_t objects
117 were created. */
118 bool trx_rseg_init_rollback_segments(space_id_t space_id,
119 ulong target_rollback_segments);
120
121 /** Read each rollback segment slot in the TRX_SYS page and the RSEG_ARRAY
122 page of each undo tablespace. Create trx_rseg_t objects for all rollback
123 segments found. This runs at database startup and initializes the in-memory
124 lists of trx_rseg_t objects. We need to look at all slots in TRX_SYS and
125 each RSEG_ARRAY page because we need to look for any existing undo log that
126 may need to be recovered by purge. No latch is needed since this is still
127 single-threaded startup. If we find existing rseg slots in TRX_SYS page
128 that reference undo tablespaces and have active undo logs, then quit.
129 They require an upgrade of undo tablespaces and that cannot happen with
130 active undo logs.
131 @param[in] purge_queue queue of rsegs to purge */
132 void trx_rsegs_init(purge_pq_t *purge_queue);
133
134 /** Initialize rollback segments in parallel
135 @param[in] purge_queue queue of rsegs to purge */
136 void trx_rsegs_parallel_init(purge_pq_t *purge_queue);
137
138 /** Create and initialize a rollback segment object. Some of
139 the values for the fields are read from the segment header page.
140 The caller must insert it into the correct list.
141 @param[in] id Rollback segment id
142 @param[in] space_id Space where the segment is placed
143 @param[in] page_no Page number of the segment header
144 @param[in] page_size Page size
145 @param[in] gtid_trx_no Trx number up to which GTID is persisted
146 @param[in,out] purge_queue Rseg queue
147 @param[in,out] mtr Mini-transaction
148 @return own: rollback segment object */
149 trx_rseg_t *trx_rseg_mem_create(ulint id, space_id_t space_id,
150 page_no_t page_no, const page_size_t &page_size,
151 trx_id_t gtid_trx_no, purge_pq_t *purge_queue,
152 mtr_t *mtr);
153
154 /** Create a rollback segment in the given tablespace. This could be either
155 the system tablespace, the temporary tablespace, or an undo tablespace.
156 @param[in] space_id tablespace to get the rollback segment
157 @param[in] rseg_id slot number of the rseg within this tablespace
158 @return page number of the rollback segment header page created */
159 page_no_t trx_rseg_create(space_id_t space_id, ulint rseg_id);
160
161 /** Build a list of unique undo tablespaces found in the TRX_SYS page.
162 Do not count the system tablespace. The vector will be sorted on space id.
163 @param[in,out] spaces_to_open list of undo tablespaces found. */
164 void trx_rseg_get_n_undo_tablespaces(Space_Ids *spaces_to_open);
165
166 /** Upgrade the TRX_SYS page so that it no longer tracks rsegs in undo
167 tablespaces other than the system tablespace. Add these tablespaces to
168 undo::spaces and put FIL_NULL in the slots in TRX_SYS.*/
169 void trx_rseg_upgrade_undo_tablespaces();
170
171 /** Create the file page for the rollback segment directory in an undo
172 tablespace. This function is called just after an undo tablespace is
173 created so the next page created here should by FSP_FSEG_DIR_PAGE_NUM.
174 @param[in] space_id Undo Tablespace ID
175 @param[in] mtr mtr */
176 void trx_rseg_array_create(space_id_t space_id, mtr_t *mtr);
177
178 /** Sets the page number of the nth rollback segment slot in the
179 independent undo tablespace.
180 @param[in] rsegs_header rollback segment array page header
181 @param[in] slot slot number on page == rseg id
182 @param[in] page_no rollback regment header page number
183 @param[in] mtr mtr */
184 static inline void trx_rsegsf_set_page_no(trx_rsegsf_t *rsegs_header,
185 ulint slot, page_no_t page_no,
186 mtr_t *mtr);
187
188 /** Number of undo log slots in a rollback segment file copy */
189 #define TRX_RSEG_N_SLOTS (UNIV_PAGE_SIZE / 16)
190
191 /** Maximum number of transactions supported by a single rollback segment */
192 #define TRX_RSEG_MAX_N_TRXS (TRX_RSEG_N_SLOTS / 2)
193
194 /* Undo log segment slot in a rollback segment header */
195 /*-------------------------------------------------------------*/
196 /** Page number of the header page of an undo log segment */
197 constexpr uint32_t TRX_RSEG_SLOT_PAGE_NO = 0;
198 /*-------------------------------------------------------------*/
199 /** Slot size */
200 constexpr uint32_t TRX_RSEG_SLOT_SIZE = 4;
201
202 /** The offset of the rollback segment header on its page */
203 constexpr uint32_t TRX_RSEG = FSEG_PAGE_DATA;
204
205 /* Transaction rollback segment header */
206 /*-------------------------------------------------------------*/
207 /** Maximum allowed size for rollback segment in pages */
208 constexpr uint32_t TRX_RSEG_MAX_SIZE = 0;
209 /** Number of file pages occupied by the logs in the history list */
210 constexpr uint32_t TRX_RSEG_HISTORY_SIZE = 4;
211 /* The update undo logs for committed transactions */
212 constexpr uint32_t TRX_RSEG_HISTORY = 8;
213 /* Header for the file segment where this page is placed */
214 constexpr uint32_t TRX_RSEG_FSEG_HEADER = 8 + FLST_BASE_NODE_SIZE;
215 /** Undo log segment slots */
216 constexpr uint32_t TRX_RSEG_UNDO_SLOTS =
217 8 + FLST_BASE_NODE_SIZE + FSEG_HEADER_SIZE;
218
219 /** End of undo slots in rollback segment page. */
220 #define TRX_RSEG_SLOT_END \
221 (TRX_RSEG_UNDO_SLOTS + TRX_RSEG_SLOT_SIZE * TRX_RSEG_N_SLOTS)
222
223 /* Maximum transaction number ever added to this rollback segment history
224 list. It is always increasing number over lifetime starting from zero.
225 The size is 8 bytes. */
226 #define TRX_RSEG_MAX_TRX_NO TRX_RSEG_SLOT_END
227
228 /*-------------------------------------------------------------*/
229
230 /** The offset of the Rollback Segment Directory header on an RSEG_ARRAY
231 page */
232 constexpr uint32_t RSEG_ARRAY_HEADER = FSEG_PAGE_DATA;
233
234 /** Rollback Segment Array Header */
235 /*------------------------------------------------------------- */
236 /** The RSEG ARRAY base version is a number derived from the string
237 'RSEG' [0x 52 53 45 47] for extra validation. Each new version
238 increments the base version by 1. */
239 constexpr uint32_t RSEG_ARRAY_VERSION = 0x52534547 + 1;
240
241 /** The RSEG ARRAY version offset in the header. */
242 constexpr uint32_t RSEG_ARRAY_VERSION_OFFSET = 0;
243
244 /** The current number of rollback segments being tracked in this array */
245 constexpr uint32_t RSEG_ARRAY_SIZE_OFFSET = 4;
246
247 /** This is the pointer to the file segment inode that tracks this
248 rseg array page. */
249 constexpr uint32_t RSEG_ARRAY_FSEG_HEADER_OFFSET = 8;
250
251 /** The start of the array of rollback segment header page numbers for this
252 undo tablespace. The potential size of this array is limited only by the
253 page size minus overhead. The actual size of the array is limited by
254 srv_rollback_segments. */
255 constexpr uint32_t RSEG_ARRAY_PAGES_OFFSET = 8 + FSEG_HEADER_SIZE;
256
257 /** Reserved space at the end of an RSEG_ARRAY page reserved for future use.
258 */
259 constexpr uint32_t RSEG_ARRAY_RESERVED_BYTES = 200;
260
261 /* Slot size of the array of rollback segment header page numbers */
262 constexpr uint32_t RSEG_ARRAY_SLOT_SIZE = 4;
263 /*------------------------------------------------------------- */
264
265 #include "trx0rseg.ic"
266
267 #endif