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