MySQL 8.4.2
Source Code Documentation
trx0undo.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 2024, 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 designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/trx0undo.h
29 Transaction undo log
30
31 Created 3/26/1996 Heikki Tuuri
32 *******************************************************/
33
34#ifndef trx0undo_h
35#define trx0undo_h
36
37#include "mtr0mtr.h"
38#include "page0types.h"
39#include "sql/xa.h"
40#include "trx0sys.h"
41#include "trx0types.h"
42#include "trx0xa.h"
43#include "univ.i"
44
45#ifndef UNIV_HOTBACKUP
46/** Returns true if the roll pointer is of the insert type.
47 @return true if insert undo log */
48static inline bool trx_undo_roll_ptr_is_insert(
49 roll_ptr_t roll_ptr); /*!< in: roll pointer */
50/** Returns true if the record is of the insert type.
51 @return true if the record was freshly inserted (not updated). */
52[[nodiscard]] static inline bool trx_undo_trx_id_is_insert(
53 const byte *trx_id); /*!< in: DB_TRX_ID, followed by DB_ROLL_PTR */
54#endif /* !UNIV_HOTBACKUP */
55
56/** Writes a roll ptr to an index page. In case that the size changes in
57some future version, this function should be used instead of
58mach_write_...
59@param[in] ptr pointer to memory where written
60@param[in] roll_ptr roll ptr */
61static inline void trx_write_roll_ptr(byte *ptr, roll_ptr_t roll_ptr);
62
63/** Reads a roll ptr from an index page. In case that the roll ptr size
64 changes in some future version, this function should be used instead of
65 mach_read_...
66 @return roll ptr */
68 const byte *ptr); /*!< in: pointer to memory from where to read */
69#ifndef UNIV_HOTBACKUP
70
71/** Gets an undo log page and x-latches it.
72@param[in] page_id Page id
73@param[in] page_size Page size
74@param[in,out] mtr Mini-transaction
75@return pointer to page x-latched */
76static inline page_t *trx_undo_page_get(const page_id_t &page_id,
77 const page_size_t &page_size,
78 mtr_t *mtr);
79
80/** Gets an undo log page and s-latches it.
81@param[in] page_id Page id
82@param[in] page_size Page size
83@param[in,out] mtr Mini-transaction
84@return pointer to page s-latched */
85static inline page_t *trx_undo_page_get_s_latched(const page_id_t &page_id,
86 const page_size_t &page_size,
87 mtr_t *mtr);
88
89/** Returns the previous undo record on the page in the specified log, or
90NULL if none exists.
91@param[in] rec undo log record
92@param[in] page_no undo log header page number
93@param[in] offset undo log header offset on page
94@return pointer to record, NULL if none */
96 page_no_t page_no,
97 ulint offset);
98
99/** Returns the next undo log record on the page in the specified log, or
100NULL if none exists.
101@param[in] rec undo log record
102@param[in] page_no undo log header page number
103@param[in] offset undo log header offset on page
104@return pointer to record, NULL if none */
106 page_no_t page_no,
107 ulint offset);
108
109/** Returns the last undo record on the page in the specified undo log, or
110NULL if none exists.
111@param[in] undo_page undo log page
112@param[in] page_no undo log header page number
113@param[in] offset undo log header offset on page
114@return pointer to record, NULL if none */
116 page_no_t page_no,
117 ulint offset);
118
119/** Returns the first undo record on the page in the specified undo log, or
120NULL if none exists.
121@param[in] undo_page undo log page
122@param[in] page_no undo log header page number
123@param[in] offset undo log header offset on page
124@return pointer to record, NULL if none */
126 page_no_t page_no,
127 ulint offset);
128
129/** Gets the previous record in an undo log.
130 @return undo log record, the page s-latched, NULL if none */
132 trx_undo_rec_t *rec, /*!< in: undo record */
133 page_no_t page_no, /*!< in: undo log header page number */
134 ulint offset, /*!< in: undo log header offset on page */
135 bool shared, /*!< in: true=S-latch, false=X-latch */
136 mtr_t *mtr); /*!< in: mtr */
137/** Gets the next record in an undo log.
138 @return undo log record, the page s-latched, NULL if none */
140 trx_undo_rec_t *rec, /*!< in: undo record */
141 page_no_t page_no, /*!< in: undo log header page number */
142 ulint offset, /*!< in: undo log header offset on page */
143 mtr_t *mtr); /*!< in: mtr */
144
145/** Gets the first record in an undo log.
146@param[out] modifier_trx_id The modifier trx identifier.
147@param[in] space Undo log header space
148@param[in] page_size Page size
149@param[in] page_no Undo log header page number
150@param[in] offset Undo log header offset on page
151@param[in] mode Latching mode: RW_S_LATCH or RW_X_LATCH
152@param[in,out] mtr Mini-transaction
153@return undo log record, the page latched, NULL if none */
155 space_id_t space,
156 const page_size_t &page_size,
157 page_no_t page_no, ulint offset,
158 ulint mode, mtr_t *mtr);
159
160/** Tries to add a page to the undo log segment where the undo log is placed.
161 @return X-latched block if success, else NULL */
162[[nodiscard]] buf_block_t *trx_undo_add_page(
163 trx_t *trx, /*!< in: transaction */
164 trx_undo_t *undo, /*!< in: undo log memory object */
165 trx_undo_ptr_t *undo_ptr, /*!< in: assign undo log from
166 referred rollback segment. */
167 mtr_t *mtr); /*!< in: mtr which does not have
168 a latch to any undo log page;
169 the caller must have reserved
170 the rollback segment mutex */
171/** Frees the last undo log page.
172 The caller must hold the rollback segment mutex.
173 @param[in] trx transaction
174 @param[in,out] undo undo log memory copy
175 @param[in,out] mtr mini-transaction which does not have a latch to any undo log
176 page or which has allocated the undo log page */
178 mtr_t *mtr);
179
180static inline void trx_undo_free_last_page(const trx_t *trx [[maybe_unused]],
181 trx_undo_t *undo, mtr_t *mtr) {
183}
184
185/** Truncates an undo log from the end. This function is used during
186a rollback to free space from an undo log.
187@param[in] trx transaction for this undo log
188@param[in] undo undo log
189@param[in] limit all undo records with undo number;
190 This value should be truncated. */
192 undo_no_t limit);
193
194static inline void trx_undo_truncate_end(const trx_t *trx [[maybe_unused]],
195 trx_undo_t *undo, undo_no_t limit) {
197}
198
199/** Truncate the head of an undo log.
200NOTE that only whole pages are freed; the header page is not
201freed, but emptied, if all the records there are below the limit.
202@param[in,out] rseg rollback segment
203@param[in] hdr_page_no header page number
204@param[in] hdr_offset header offset on the page
205@param[in] limit first undo number to preserve
206(everything below the limit will be truncated) */
207void trx_undo_truncate_start(trx_rseg_t *rseg, page_no_t hdr_page_no,
208 ulint hdr_offset, undo_no_t limit);
209/** Initializes the undo log lists for a rollback segment memory copy.
210 This function is only called when the database is started or a new
211 rollback segment created.
212 @return the combined size of undo log segments in pages */
214 trx_rseg_t *rseg); /*!< in: rollback segment memory object */
215/** Assigns an undo log for a transaction. A new undo log is created or a cached
216 undo log reused.
217 @return DB_SUCCESS if undo log assign successful, possible error codes
218 are: DB_TOO_MANY_CONCURRENT_TRXS DB_OUT_OF_FILE_SPACE DB_READ_ONLY
219 DB_OUT_OF_MEMORY */
220[[nodiscard]] dberr_t trx_undo_assign_undo(
221 trx_t *trx, /*!< in: transaction */
222 trx_undo_ptr_t *undo_ptr, /*!< in: assign undo log from
223 referred rollback segment. */
224 ulint type); /*!< in: TRX_UNDO_INSERT or
225 TRX_UNDO_UPDATE */
226/** Sets the state of the undo log segment at a transaction finish.
227 @return undo log segment header page, x-latched */
229 trx_undo_t *undo, /*!< in: undo log memory copy */
230 mtr_t *mtr); /*!< in: mtr */
231
232/** Set the state of the undo log segment at a XA PREPARE or XA ROLLBACK.
233@param[in,out] trx Transaction
234@param[in,out] undo Insert_undo or update_undo log
235@param[in] rollback false=XA PREPARE, true=XA ROLLBACK
236@param[in,out] mtr Mini-transaction
237@return undo log segment header page, x-latched */
239 bool rollback, mtr_t *mtr);
240
241/** Set the state of the undo log segment as prepared in TC.
242@param[in,out] trx Transaction
243@param[in,out] undo Insert_undo or update_undo log
244@param[in,out] mtr Mini-transaction
245@return undo log segment header page, x-latched */
247
248/** Adds the update undo log header as the first in the history list, and
249 frees the memory object, or puts it to the list of cached update undo log
250 segments.
251@param[in] trx Trx owning the update undo log
252@param[in] undo_ptr Update undo log.
253@param[in] undo_page Update undo log header page, x-latched
254@param[in] update_rseg_history_len If true: update rseg history len else
255skip updating it.
256@param[in] n_added_logs Number of logs added
257@param[in] mtr Mini-transaction */
258void trx_undo_update_cleanup(trx_t *trx, trx_undo_ptr_t *undo_ptr,
259 page_t *undo_page, bool update_rseg_history_len,
260
261 ulint n_added_logs, mtr_t *mtr);
262
263/** Frees an insert undo log after a transaction commit or rollback.
264Knowledge of inserts is not needed after a commit or rollback, therefore
265the data can be discarded.
266@param[in,out] undo_ptr undo log to clean up
267@param[in] noredo whether the undo tablespace is redo logged */
268void trx_undo_insert_cleanup(trx_undo_ptr_t *undo_ptr, bool noredo);
269
270/** At shutdown, frees the undo logs of a transaction which was either
271PREPARED or (ACTIVE and recovered).
272@param[in] trx transaction which undo logs are freed
273@param[in] prepared whether or not the undo segment is in prepared or
274 prepared in tc states */
276 bool prepared) UNIV_COLD;
277
278/* Forward declaration. */
279namespace undo {
280struct Tablespace;
281class Truncate;
282} // namespace undo
283
284/** Truncate UNDO tablespace, reinitialize header and rseg.
285@param[in] marked_space UNDO tablespace to truncate
286@return true if success else false. */
288
289#endif /* !UNIV_HOTBACKUP */
290/** Parses the redo log entry of an undo log page initialization.
291 @return end of log record or NULL */
292byte *trx_undo_parse_page_init(const byte *ptr, /*!< in: buffer */
293 const byte *end_ptr, /*!< in: buffer end */
294 page_t *page, /*!< in: page or NULL */
295 mtr_t *mtr); /*!< in: mtr or NULL */
296/** Parse the redo log entry of an undo log page header create or reuse.
297@param[in] type MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE
298@param[in] ptr Redo log record
299@param[in] end_ptr End of log buffer
300@param[in,out] page Page frame or NULL
301@param[in,out] mtr Mini-transaction or NULL
302@return end of log record or NULL */
303byte *trx_undo_parse_page_header(mlog_id_t type, const byte *ptr,
304 const byte *end_ptr, page_t *page, mtr_t *mtr);
305/************************************************************************
306Frees an undo log memory copy. */
307void trx_undo_mem_free(trx_undo_t *undo); /* in: the undo object to be freed */
308
309/** Types of an undo log segment */
310/** contains undo entries for inserts */
311constexpr uint32_t TRX_UNDO_INSERT = 1;
312/** contains undo entries for updates and delete markings: in short, modifys
313 (the name 'UPDATE' is a historical relic) */
314constexpr uint32_t TRX_UNDO_UPDATE = 2;
315
316/* States of an undo log segment */
317/** contains an undo log of an active transaction */
318constexpr uint32_t TRX_UNDO_ACTIVE = 1;
319/** cached for quick reuse */
320constexpr uint32_t TRX_UNDO_CACHED = 2;
321/** insert undo segment can be freed */
322constexpr uint32_t TRX_UNDO_TO_FREE = 3;
323/** update undo segment will not be reused: it can be freed in purge when all
324 undo data in it is removed */
325constexpr uint32_t TRX_UNDO_TO_PURGE = 4;
326/** contains an undo log of an prepared transaction for a server version older
327 * than 8.0.29 */
328constexpr uint32_t TRX_UNDO_PREPARED_80028 = 5;
329/** contains an undo log of an prepared transaction */
330constexpr uint32_t TRX_UNDO_PREPARED = 6;
331/* contains an undo log of a prepared transaction that has been processed by the
332 * transaction coordinator */
333constexpr uint32_t TRX_UNDO_PREPARED_IN_TC = 7;
334
335#ifndef UNIV_HOTBACKUP
336/** Transaction undo log memory object; this is protected by the undo_mutex
337in the corresponding transaction object */
338
340 /** Undo log may could be allocated to store transaction GTIDs. */
341 enum class Gtid_storage {
342 /* No storage is allocated for GTID. */
343 NONE,
344 /* Storage is allocated for commit GTID. */
345 COMMIT,
346 /* Storage is allocated for both prepare and commit GTID. For external
347 XA transaction, we have GTID fr both prepare and commit. */
349 };
350
351 /** Check if space for GTID is allocated in undo.
352 @param[in] is_prepare if XA prepare GTID
353 @return true iff space for GTID is allocated. */
354 bool gtid_allocated(bool is_prepare) const;
355
356 /** Get offset and flag for GTID stored in undo.
357 @param[in] is_prepare if XA prepare GTID
358 @return GTID flag and offset in a tuple. */
359 std::tuple<int, size_t> gtid_get_details(bool is_prepare) const;
360
361 /* Set undo segment to prepared state and set XID
362 @param[in] in_xid transaction XID. */
363 inline void set_prepared(const XID *in_xid);
364
365 /* Set undo segment to prepared in TC state and set XID */
366 inline void set_prepared_in_tc();
367
368 /* Checks whether or not this undo log segment is in prepared state, meaning,
369 the `state` member variable is either `TRX_UNDO_PREPARED_80028`.
370 `TRX_UNDO_PREPARED` or `TRX_UNDO_PREPARED_IN_TC`.
371 @return true is the undo log segment is in prepared state, false otherwise.*/
372 inline bool is_prepared() const;
373
374 /*-----------------------------*/
375 ulint id; /*!< undo log slot number within the
376 rollback segment */
377 ulint type; /*!< TRX_UNDO_INSERT or
378 TRX_UNDO_UPDATE */
379 ulint state; /*!< state of the corresponding undo log
380 segment */
381 bool del_marks; /*!< relevant only in an update undo
382 log: this is true if the transaction may
383 have delete marked records, because of
384 a delete of a row or an update of an
385 indexed field; purge is then
386 necessary; also true if the transaction
387 has updated an externally stored
388 field */
389 trx_id_t trx_id; /*!< id of the trx assigned to the undo
390 log */
391 XID xid; /*!< X/Open XA transaction
392 identification */
393 ulint flag; /*!< flag for current transaction XID and GTID.
394 Persisted in TRX_UNDO_FLAGS flag of undo header. */
395
396 /** Storage space allocated for GTIDs. */
398
399 bool dict_operation; /*!< true if a dict operation trx */
400 trx_rseg_t *rseg; /*!< rseg where the undo log belongs */
401 /*-----------------------------*/
402 space_id_t space; /*!< space id where the undo log
403 placed */
405 page_no_t hdr_page_no; /*!< page number of the header page in
406 the undo log */
407 ulint hdr_offset; /*!< header offset of the undo log on
408 the page */
409 page_no_t last_page_no; /*!< page number of the last page in the
410 undo log; this may differ from
411 top_page_no during a rollback */
412 ulint size; /*!< current size in pages */
413 /*-----------------------------*/
414 ulint empty; /*!< true if the stack of undo log
415 records is currently empty */
416 page_no_t top_page_no; /*!< page number where the latest undo
417 log record was catenated; during
418 rollback the page from which the latest
419 undo record was chosen */
420 ulint top_offset; /*!< offset of the latest undo record,
421 i.e., the topmost element in the undo
422 log if we think of it as a stack */
423 undo_no_t top_undo_no; /*!< undo number of the latest record */
424 buf_block_t *guess_block; /*!< guess for the buffer block where
425 the top page might reside */
426 /*-----------------------------*/
428 /*!< undo log objects in the rollback
429 segment are chained into lists */
430};
431
433
434/** For saving GTID add update undo slot, if required.
435@param[in] trx transaction
436@param[in] prepare operation is prepare
437@param[in] rollback operation is rollback
438@return innodb error code. */
440
441/** Set GTID flag in undo if transaction has GTID/
442@param[in,out] trx transaction
443@param[in,out] undo undo log memory object
444@param[in] is_xa_prepare GTID is for XA prepared transaction. */
446
447/** Read and persist GTID from undo header during recovery.
448@param[in] undo_log undo log header */
450
451/** Write GTID information to undo log header.
452@param[in,out] trx transaction
453@param[in,out] undo_header undo log header
454@param[in,out] undo undo log memory object
455@param[in,out] mtr minit transaction for write
456@param[in] is_xa_prepare GTID is for XA prepared transaction. */
457void trx_undo_gtid_write(trx_t *trx, trx_ulogf_t *undo_header, trx_undo_t *undo,
458 mtr_t *mtr, bool is_xa_prepare);
459
460#endif /* !UNIV_HOTBACKUP */
461
462/** The offset of the undo log page header on pages of the undo log */
464/*-------------------------------------------------------------*/
465/** Transaction undo log page header offsets */
466/** @{ */
467/** TRX_UNDO_INSERT or TRX_UNDO_UPDATE */
468constexpr uint32_t TRX_UNDO_PAGE_TYPE = 0;
469/** Byte offset where the undo log records for the LATEST transaction start on
470 this page (remember that in an update undo log, the first page can contain
471 several undo logs) */
472constexpr uint32_t TRX_UNDO_PAGE_START = 2;
473/** On each page of the undo log this field contains the byte offset of the
474 first free byte on the page */
475constexpr uint32_t TRX_UNDO_PAGE_FREE = 4;
476/** The file list node in the chain of undo log pages */
477constexpr uint32_t TRX_UNDO_PAGE_NODE = 6;
478/*-------------------------------------------------------------*/
479/** Size of the transaction undo log page header, in bytes */
480constexpr uint32_t TRX_UNDO_PAGE_HDR_SIZE = 6 + FLST_NODE_SIZE;
481
482/** @} */
483
484/** An update undo segment with just one page can be reused if it has
485at most this many bytes used; we must leave space at least for one new undo
486log header on the page */
487
488#define TRX_UNDO_PAGE_REUSE_LIMIT (3 * UNIV_PAGE_SIZE / 4)
489
490/* An update undo log segment may contain several undo logs on its first page
491if the undo logs took so little space that the segment could be cached and
492reused. All the undo log headers are then on the first page, and the last one
493owns the undo log records on subsequent pages if the segment is bigger than
494one page. If an undo log is stored in a segment, then on the first page it is
495allowed to have zero undo records, but if the segment extends to several
496pages, then all the rest of the pages must contain at least one undo log
497record. */
498
499/** The offset of the undo log segment header on the first page of the undo
500log segment */
501
502constexpr uint32_t TRX_UNDO_SEG_HDR =
504/** Undo log segment header */
505/** @{ */
506/*-------------------------------------------------------------*/
507/** TRX_UNDO_ACTIVE, ... */
508constexpr uint32_t TRX_UNDO_STATE = 0;
509/** Offset of the last undo log header on the segment header page, 0 if none */
510constexpr uint32_t TRX_UNDO_LAST_LOG = 2;
511/** Header for the file segment which the undo log segment occupies */
512constexpr uint32_t TRX_UNDO_FSEG_HEADER = 4;
513/** Base node for the list of pages in the undo log segment; defined only on the
514 undo log segment's first page */
515constexpr uint32_t TRX_UNDO_PAGE_LIST = 4 + FSEG_HEADER_SIZE;
516/*-------------------------------------------------------------*/
517/** Size of the undo log segment header */
518constexpr uint32_t TRX_UNDO_SEG_HDR_SIZE =
520/** @} */
521
522/** The undo log header. There can be several undo log headers on the first
523page of an update undo log segment. */
524/** @{ */
525/*-------------------------------------------------------------*/
526/** Transaction id */
527constexpr uint32_t TRX_UNDO_TRX_ID = 0;
528/** Transaction number of the transaction; defined only if the log is in a
529 history list */
530constexpr uint32_t TRX_UNDO_TRX_NO = 8;
531/** Defined only in an update undo log: true if the transaction may have done
532 delete markings of records, and thus purge is necessary */
533constexpr uint32_t TRX_UNDO_DEL_MARKS = 16;
534/** Offset of the first undo log record of this log on the header page; purge
535 may remove undo log record from the log start, and therefore this is not
536 necessarily the same as this log header end offset */
537constexpr uint32_t TRX_UNDO_LOG_START = 18;
538/** Transaction UNDO flags in one byte. This is backward compatible as earlier
539 we were storing either 1 or 0 for TRX_UNDO_XID_EXISTS. */
540constexpr uint32_t TRX_UNDO_FLAGS = 20;
541/** true if undo log header includes X/Open XA transaction identification XID */
542constexpr uint32_t TRX_UNDO_FLAG_XID = 0x01;
543/** true if undo log header includes GTID information from replication */
544constexpr uint32_t TRX_UNDO_FLAG_GTID = 0x02;
545/** true if undo log header includes GTID information for XA PREPARE */
546constexpr uint32_t TRX_UNDO_FLAG_XA_PREPARE_GTID = 0x04;
547/** true if the transaction is a table create, index create, or drop
548 transaction: in recovery the transaction cannot be rolled back in the usual
549 way: a 'rollback' rather means dropping the created or dropped table, if it
550 still exists */
551constexpr uint32_t TRX_UNDO_DICT_TRANS = 21;
552/** Id of the table if the preceding field is true. Note: deprecated */
553constexpr uint32_t TRX_UNDO_TABLE_ID = 22;
554/** Offset of the next undo log header on this page, 0 if none */
555constexpr uint32_t TRX_UNDO_NEXT_LOG = 30;
556/** Offset of the previous undo log header on this page, 0 if none */
557constexpr uint32_t TRX_UNDO_PREV_LOG = 32;
558/** If the log is put to the history list, the file list node is here */
559constexpr uint32_t TRX_UNDO_HISTORY_NODE = 34;
560/*-------------------------------------------------------------*/
561/** Size of the undo log header without XID information */
563
564/* Note: the writing of the undo log old header is coded by a log record
565MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE. The appending of an XID to the
566header is logged separately. In this sense, the XID is not really a member
567of the undo log header. TODO: do not append the XID to the log header if XA
568is not needed by the user. The XID wastes about 150 bytes of space in every
569undo log. In the history list we may have millions of undo logs, which means
570quite a large overhead. */
571/** @} */
572
573/** X/Open XA Transaction Identification (XID) */
574/** @{ */
575/** xid_t::formatID */
577/** xid_t::gtrid_length */
579/** xid_t::bqual_length */
581/** Distributed transaction identifier data */
582constexpr uint32_t TRX_UNDO_XA_XID = TRX_UNDO_XA_BQUAL_LEN + 4;
583/*--------------------------------------------------------------*/
585/*!< Total size of the undo log header
586with the XA XID */
587/** @} */
588
589/* GTID is generated by replication when binlog and GTID mode is on. We
590persist GTID with undo record till it is written to gtid_exeuted table.
591GTID information is present when TRX_UNDO_FLAG_GTID set. It follows XID
592information */
593
594/** GTID version offset */
596
597/** GTID offset */
599
600/** Total length of GTID */
601constexpr uint32_t TRX_UNDO_LOG_GTID_LEN = 64;
602
603/** Total size with GTID information. */
604constexpr uint32_t TRX_UNDO_LOG_GTID_HDR_SIZE =
606
607/** GTID offset for XA Prepare. */
609
610/** Total size with XA GTID information. For external XA transaction we need
611to store both prepare and commit GTID. */
614
615#include "trx0undo.ic"
616#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:47
uint32_t page_no_t
Page number.
Definition: api0api.h:45
Data structure that contains the information about shared tablespaces.
Definition: fsp0space.h:47
Page identifier.
Definition: buf0types.h:207
Page size descriptor.
Definition: page0size.h:50
int page
Definition: ctype-mb.cc:1234
dberr_t
Definition: db0err.h:39
constexpr uint32_t FSEG_PAGE_DATA
On a page of any file segment, data may be put starting from this offset.
Definition: fsp0types.h:79
constexpr uint32_t FSEG_HEADER_SIZE
Length of the file system header, in bytes.
Definition: fsp0types.h:94
constexpr ulint FLST_BASE_NODE_SIZE
Definition: fut0lst.h:50
constexpr ulint FLST_NODE_SIZE
Definition: fut0lst.h:53
Mini-transaction buffer.
mlog_id_t
Definition: mtr0types.h:63
mode
Definition: file_handle.h:61
Definition: trx0purge.h:141
Index page routines.
byte page_t
Type of the index page.
Definition: page0types.h:152
required string type
Definition: replication_group_member_actions.proto:34
static bool rollback(THD *thd)
Abort the current statement and transaction.
Definition: sql_cmd_srs.cc:140
The buffer control block structure.
Definition: buf0buf.h:1747
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
The rollback segment memory object.
Definition: trx0types.h:177
Definition: trx0trx.h:684
The transaction handle.
Definition: trx0trx.h:644
Transaction undo log memory object; this is protected by the undo_mutex in the corresponding transact...
Definition: trx0undo.h:339
page_no_t last_page_no
page number of the last page in the undo log; this may differ from top_page_no during a rollback
Definition: trx0undo.h:409
bool del_marks
relevant only in an update undo log: this is true if the transaction may have delete marked records,...
Definition: trx0undo.h:381
void set_prepared(const XID *in_xid)
Definition: trx0undo.ic:285
bool dict_operation
true if a dict operation trx
Definition: trx0undo.h:399
ulint type
TRX_UNDO_INSERT or TRX_UNDO_UPDATE.
Definition: trx0undo.h:377
page_size_t page_size
Definition: trx0undo.h:404
buf_block_t * guess_block
guess for the buffer block where the top page might reside
Definition: trx0undo.h:424
trx_id_t trx_id
id of the trx assigned to the undo log
Definition: trx0undo.h:389
ulint id
undo log slot number within the rollback segment
Definition: trx0undo.h:375
ulint empty
true if the stack of undo log records is currently empty
Definition: trx0undo.h:414
space_id_t space
space id where the undo log placed
Definition: trx0undo.h:402
page_no_t top_page_no
page number where the latest undo log record was catenated; during rollback the page from which the l...
Definition: trx0undo.h:416
std::tuple< int, size_t > gtid_get_details(bool is_prepare) const
Get offset and flag for GTID stored in undo.
Definition: trx0undo.cc:638
trx_rseg_t * rseg
rseg where the undo log belongs
Definition: trx0undo.h:400
XID xid
X/Open XA transaction identification.
Definition: trx0undo.h:391
bool gtid_allocated(bool is_prepare) const
Check if space for GTID is allocated in undo.
Definition: trx0undo.cc:630
void set_prepared_in_tc()
Definition: trx0undo.ic:291
undo_no_t top_undo_no
undo number of the latest record
Definition: trx0undo.h:423
UT_LIST_NODE_T(trx_undo_t) undo_list
undo log objects in the rollback segment are chained into lists
bool is_prepared() const
Definition: trx0undo.ic:296
ulint state
state of the corresponding undo log segment
Definition: trx0undo.h:379
ulint flag
flag for current transaction XID and GTID.
Definition: trx0undo.h:393
Gtid_storage m_gtid_storage
Storage space allocated for GTIDs.
Definition: trx0undo.h:397
page_no_t hdr_page_no
page number of the header page in the undo log
Definition: trx0undo.h:405
ulint hdr_offset
header offset of the undo log on the page
Definition: trx0undo.h:407
Gtid_storage
Undo log may could be allocated to store transaction GTIDs.
Definition: trx0undo.h:341
ulint top_offset
offset of the latest undo record, i.e., the topmost element in the undo log if we think of it as a st...
Definition: trx0undo.h:420
ulint size
current size in pages
Definition: trx0undo.h:412
An undo::Tablespace object is used to easily convert between undo_space_id and undo_space_num and to ...
Definition: trx0purge.h:314
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification,...
Definition: xa.h:83
Transaction system.
Transaction system global type definitions.
byte trx_undo_rec_t
Undo log record.
Definition: trx0types.h:167
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:142
byte trx_ulogf_t
Undo log header.
Definition: trx0types.h:163
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
ib_id_t roll_ptr_t
Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR)
Definition: trx0types.h:140
constexpr uint32_t TRX_UNDO_STATE
Undo log segment header.
Definition: trx0undo.h:508
constexpr uint32_t TRX_UNDO_DICT_TRANS
true if the transaction is a table create, index create, or drop transaction: in recovery the transac...
Definition: trx0undo.h:551
static trx_undo_rec_t * trx_undo_page_get_prev_rec(trx_undo_rec_t *rec, page_no_t page_no, ulint offset)
Returns the previous undo record on the page in the specified log, or NULL if none exists.
constexpr uint32_t TRX_UNDO_NEXT_LOG
Offset of the next undo log header on this page, 0 if none.
Definition: trx0undo.h:555
constexpr uint32_t TRX_UNDO_XA_FORMAT
X/Open XA Transaction Identification (XID)
Definition: trx0undo.h:576
static page_t * trx_undo_page_get(const page_id_t &page_id, const page_size_t &page_size, mtr_t *mtr)
Gets an undo log page and x-latches it.
constexpr uint32_t TRX_UNDO_PAGE_FREE
On each page of the undo log this field contains the byte offset of the first free byte on the page.
Definition: trx0undo.h:475
constexpr uint32_t TRX_UNDO_PAGE_NODE
The file list node in the chain of undo log pages.
Definition: trx0undo.h:477
static bool trx_undo_trx_id_is_insert(const byte *trx_id)
Returns true if the record is of the insert type.
constexpr uint32_t TRX_UNDO_INSERT
Types of an undo log segment.
Definition: trx0undo.h:311
constexpr uint32_t TRX_UNDO_PAGE_LIST
Base node for the list of pages in the undo log segment; defined only on the undo log segment's first...
Definition: trx0undo.h:515
void trx_undo_gtid_read_and_persist(trx_ulogf_t *undo_log)
Read and persist GTID from undo header during recovery.
Definition: trx0undo.cc:667
constexpr uint32_t TRX_UNDO_HISTORY_NODE
If the log is put to the history list, the file list node is here.
Definition: trx0undo.h:559
trx_undo_rec_t * trx_undo_get_next_rec(trx_undo_rec_t *rec, page_no_t page_no, ulint offset, mtr_t *mtr)
Gets the next record in an undo log.
Definition: trx0undo.cc:261
constexpr uint32_t TRX_UNDO_FLAG_GTID
true if undo log header includes GTID information from replication
Definition: trx0undo.h:544
constexpr uint32_t TRX_UNDO_DEL_MARKS
Defined only in an update undo log: true if the transaction may have done delete markings of records,...
Definition: trx0undo.h:533
constexpr uint32_t TRX_UNDO_LOG_GTID_XA_HDR_SIZE
Total size with XA GTID information.
Definition: trx0undo.h:612
static bool trx_undo_roll_ptr_is_insert(roll_ptr_t roll_ptr)
Returns true if the roll pointer is of the insert type.
constexpr uint32_t TRX_UNDO_FLAG_XID
true if undo log header includes X/Open XA transaction identification XID
Definition: trx0undo.h:542
constexpr uint32_t TRX_UNDO_SEG_HDR_SIZE
Size of the undo log segment header.
Definition: trx0undo.h:518
void trx_undo_update_cleanup(trx_t *trx, trx_undo_ptr_t *undo_ptr, page_t *undo_page, bool update_rseg_history_len, ulint n_added_logs, mtr_t *mtr)
Adds the update undo log header as the first in the history list, and frees the memory object,...
Definition: trx0undo.cc:1922
constexpr uint32_t TRX_UNDO_TO_PURGE
update undo segment will not be reused: it can be freed in purge when all undo data in it is removed
Definition: trx0undo.h:325
static void trx_undo_truncate_end(const trx_t *trx, trx_undo_t *undo, undo_no_t limit)
Definition: trx0undo.h:194
constexpr uint32_t TRX_UNDO_CACHED
cached for quick reuse
Definition: trx0undo.h:320
page_t * trx_undo_set_state_at_finish(trx_undo_t *undo, mtr_t *mtr)
Sets the state of the undo log segment at a transaction finish.
Definition: trx0undo.cc:1799
constexpr uint32_t TRX_UNDO_XA_BQUAL_LEN
xid_t::bqual_length
Definition: trx0undo.h:580
constexpr uint32_t TRX_UNDO_PAGE_HDR_SIZE
Size of the transaction undo log page header, in bytes.
Definition: trx0undo.h:480
constexpr uint32_t TRX_UNDO_PAGE_TYPE
Transaction undo log page header offsets.
Definition: trx0undo.h:468
constexpr uint32_t TRX_UNDO_ACTIVE
contains an undo log of an active transaction
Definition: trx0undo.h:318
byte * trx_undo_parse_page_header(mlog_id_t type, const byte *ptr, const byte *end_ptr, page_t *page, mtr_t *mtr)
Parse the redo log entry of an undo log page header create or reuse.
Definition: trx0undo.cc:841
void trx_undo_free_trx_with_prepared_or_active_logs(trx_t *trx, bool prepared) UNIV_COLD
At shutdown, frees the undo logs of a transaction which was either PREPARED or (ACTIVE and recovered)...
Definition: trx0undo.cc:1995
constexpr uint32_t TRX_UNDO_PAGE_HDR
The offset of the undo log page header on pages of the undo log.
Definition: trx0undo.h:463
constexpr uint32_t TRX_UNDO_LOG_XA_HDR_SIZE
Total size of the undo log header with the XA XID.
Definition: trx0undo.h:584
constexpr uint32_t TRX_UNDO_FSEG_HEADER
Header for the file segment which the undo log segment occupies.
Definition: trx0undo.h:512
byte * trx_undo_parse_page_init(const byte *ptr, const byte *end_ptr, page_t *page, mtr_t *mtr)
Parses the redo log entry of an undo log page initialization.
Definition: trx0undo.cc:345
constexpr uint32_t TRX_UNDO_SEG_HDR
The offset of the undo log segment header on the first page of the undo log segment.
Definition: trx0undo.h:502
dberr_t trx_undo_gtid_add_update_undo(trx_t *trx, bool prepare, bool rollback)
For saving GTID add update undo slot, if required.
Definition: trx0undo.cc:585
constexpr uint32_t TRX_UNDO_FLAG_XA_PREPARE_GTID
true if undo log header includes GTID information for XA PREPARE
Definition: trx0undo.h:546
trx_undo_rec_t * trx_undo_get_first_rec(trx_id_t *modifier_trx_id, space_id_t space, const page_size_t &page_size, page_no_t page_no, ulint offset, ulint mode, mtr_t *mtr)
Gets the first record in an undo log.
Definition: trx0undo.cc:296
constexpr uint32_t TRX_UNDO_TABLE_ID
Id of the table if the preceding field is true.
Definition: trx0undo.h:553
bool trx_undo_truncate_tablespace(undo::Tablespace *marked_space)
Truncate UNDO tablespace, reinitialize header and rseg.
Definition: trx0undo.cc:2038
static trx_undo_rec_t * trx_undo_page_get_next_rec(trx_undo_rec_t *rec, page_no_t page_no, ulint offset)
Returns the next undo log record on the page in the specified log, or NULL if none exists.
ulint trx_undo_lists_init(trx_rseg_t *rseg)
Initializes the undo log lists for a rollback segment memory copy.
Definition: trx0undo.cc:1406
constexpr uint32_t TRX_UNDO_LOG_GTID_VERSION
GTID version offset.
Definition: trx0undo.h:595
static trx_undo_rec_t * trx_undo_page_get_first_rec(page_t *undo_page, page_no_t page_no, ulint offset)
Returns the first undo record on the page in the specified undo log, or NULL if none exists.
constexpr uint32_t TRX_UNDO_LOG_GTID_HDR_SIZE
Total size with GTID information.
Definition: trx0undo.h:604
void trx_undo_insert_cleanup(trx_undo_ptr_t *undo_ptr, bool noredo)
Frees an insert undo log after a transaction commit or rollback.
Definition: trx0undo.cc:1957
constexpr uint32_t TRX_UNDO_LAST_LOG
Offset of the last undo log header on the segment header page, 0 if none.
Definition: trx0undo.h:510
constexpr uint32_t TRX_UNDO_LOG_GTID_LEN
Total length of GTID.
Definition: trx0undo.h:601
page_t * trx_undo_set_prepared_in_tc(trx_t *trx, trx_undo_t *undo, mtr_t *mtr)
Set the state of the undo log segment as prepared in TC.
Definition: trx0undo.cc:1881
constexpr uint32_t TRX_UNDO_LOG_OLD_HDR_SIZE
Size of the undo log header without XID information.
Definition: trx0undo.h:562
static roll_ptr_t trx_read_roll_ptr(const byte *ptr)
Reads a roll ptr from an index page.
constexpr uint32_t TRX_UNDO_PREV_LOG
Offset of the previous undo log header on this page, 0 if none.
Definition: trx0undo.h:557
dberr_t trx_undo_assign_undo(trx_t *trx, trx_undo_ptr_t *undo_ptr, ulint type)
Assigns an undo log for a transaction.
Definition: trx0undo.cc:1688
constexpr uint32_t TRX_UNDO_PREPARED_80028
contains an undo log of an prepared transaction for a server version older than 8....
Definition: trx0undo.h:328
buf_block_t * trx_undo_add_page(trx_t *trx, trx_undo_t *undo, trx_undo_ptr_t *undo_ptr, mtr_t *mtr)
Tries to add a page to the undo log segment where the undo log is placed.
Definition: trx0undo.cc:921
static void trx_undo_free_last_page(const trx_t *trx, trx_undo_t *undo, mtr_t *mtr)
Definition: trx0undo.h:180
void trx_undo_gtid_set(trx_t *trx, trx_undo_t *undo, bool is_xa_prepare)
Set GTID flag in undo if transaction has GTID/.
Definition: trx0undo.cc:645
constexpr uint32_t TRX_UNDO_TRX_NO
Transaction number of the transaction; defined only if the log is in a history list.
Definition: trx0undo.h:530
constexpr uint32_t TRX_UNDO_PREPARED_IN_TC
Definition: trx0undo.h:333
void trx_undo_truncate_start(trx_rseg_t *rseg, page_no_t hdr_page_no, ulint hdr_offset, undo_no_t limit)
Truncate the head of an undo log.
Definition: trx0undo.cc:1181
constexpr uint32_t TRX_UNDO_XA_XID
Distributed transaction identifier data.
Definition: trx0undo.h:582
static trx_undo_rec_t * trx_undo_page_get_last_rec(page_t *undo_page, page_no_t page_no, ulint offset)
Returns the last undo record on the page in the specified undo log, or NULL if none exists.
constexpr uint32_t TRX_UNDO_FLAGS
Transaction UNDO flags in one byte.
Definition: trx0undo.h:540
trx_undo_rec_t * trx_undo_get_prev_rec(trx_undo_rec_t *rec, page_no_t page_no, ulint offset, bool shared, mtr_t *mtr)
Gets the previous record in an undo log.
Definition: trx0undo.cc:192
constexpr uint32_t TRX_UNDO_PAGE_START
Byte offset where the undo log records for the LATEST transaction start on this page (remember that i...
Definition: trx0undo.h:472
void trx_undo_gtid_write(trx_t *trx, trx_ulogf_t *undo_header, trx_undo_t *undo, mtr_t *mtr, bool is_xa_prepare)
Write GTID information to undo log header.
Definition: trx0undo.cc:719
constexpr uint32_t TRX_UNDO_LOG_GTID_XA
GTID offset for XA Prepare.
Definition: trx0undo.h:608
constexpr uint32_t TRX_UNDO_UPDATE
contains undo entries for updates and delete markings: in short, modifys (the name 'UPDATE' is a hist...
Definition: trx0undo.h:314
void trx_undo_truncate_end_func(const trx_t *trx, trx_undo_t *undo, undo_no_t limit)
Truncates an undo log from the end.
Definition: trx0undo.cc:1127
constexpr uint32_t TRX_UNDO_TRX_ID
The undo log header.
Definition: trx0undo.h:527
static void trx_write_roll_ptr(byte *ptr, roll_ptr_t roll_ptr)
Writes a roll ptr to an index page.
constexpr uint32_t TRX_UNDO_XA_TRID_LEN
xid_t::gtrid_length
Definition: trx0undo.h:578
void trx_undo_free_last_page_func(const trx_t *trx, trx_undo_t *undo, mtr_t *mtr)
Frees the last undo log page.
Definition: trx0undo.cc:1034
void trx_undo_mem_free(trx_undo_t *undo)
Frees an undo log memory copy.
Definition: trx0undo.cc:1530
constexpr uint32_t TRX_UNDO_LOG_GTID
GTID offset.
Definition: trx0undo.h:598
page_t * trx_undo_set_state_at_prepare(trx_t *trx, trx_undo_t *undo, bool rollback, mtr_t *mtr)
Set the state of the undo log segment at a XA PREPARE or XA ROLLBACK.
Definition: trx0undo.cc:1839
static page_t * trx_undo_page_get_s_latched(const page_id_t &page_id, const page_size_t &page_size, mtr_t *mtr)
Gets an undo log page and s-latches it.
constexpr uint32_t TRX_UNDO_PREPARED
contains an undo log of an prepared transaction
Definition: trx0undo.h:330
constexpr uint32_t TRX_UNDO_LOG_START
Offset of the first undo log record of this log on the header page; purge may remove undo log record ...
Definition: trx0undo.h:537
constexpr uint32_t TRX_UNDO_TO_FREE
insert undo segment can be freed
Definition: trx0undo.h:322
Transaction undo log.
Version control for database, common definitions, and include files.
#define UNIV_COLD
Definition: univ.i:267
#define IF_DEBUG(...)
Definition: univ.i:674
unsigned long int ulint
Definition: univ.i:406
#define UT_LIST_NODE_GETTER_DEFINITION(t, m)
A helper for the UT_LIST_BASE_NODE_T_EXTERN which declares a node getter struct which extracts member...
Definition: ut0lst.h:270
bool is_xa_prepare(THD *thd)
Checks whether or not the underlying statement is an XA PREPARE.
Definition: xa.cc:696
#define XIDDATASIZE
Definition: xa.h:73
static void prepare(pax_msg *p, pax_op op)
Definition: xcom_base.cc:1588