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