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