MySQL 9.1.0
Source Code Documentation
trx0undo.h File Reference

Transaction undo log. More...

#include "mtr0mtr.h"
#include "page0types.h"
#include "sql/xa.h"
#include "trx0sys.h"
#include "trx0types.h"
#include "trx0xa.h"
#include "univ.i"
#include "trx0undo.ic"

Go to the source code of this file.

Classes

struct  trx_undo_t
 Transaction undo log memory object; this is protected by the undo_mutex in the corresponding transaction object. More...
 

Namespaces

namespace  undo
 

Macros

#define TRX_UNDO_PAGE_REUSE_LIMIT   (3 * UNIV_PAGE_SIZE / 4)
 An update undo segment with just one page can be reused if it has at most this many bytes used; we must leave space at least for one new undo log header on the page. More...
 

Functions

static bool trx_undo_roll_ptr_is_insert (roll_ptr_t roll_ptr)
 Returns true if the roll pointer is of the insert type. More...
 
static bool trx_undo_trx_id_is_insert (const byte *trx_id)
 Returns true if the record is of the insert type. More...
 
static void trx_write_roll_ptr (byte *ptr, roll_ptr_t roll_ptr)
 Writes a roll ptr to an index page. More...
 
static roll_ptr_t trx_read_roll_ptr (const byte *ptr)
 Reads a roll ptr from an index page. More...
 
static page_ttrx_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. More...
 
static page_ttrx_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. More...
 
static trx_undo_rec_ttrx_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. More...
 
static trx_undo_rec_ttrx_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. More...
 
static trx_undo_rec_ttrx_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. More...
 
static trx_undo_rec_ttrx_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. More...
 
trx_undo_rec_ttrx_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. More...
 
trx_undo_rec_ttrx_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. More...
 
trx_undo_rec_ttrx_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. More...
 
buf_block_ttrx_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. More...
 
void trx_undo_free_last_page_func (const trx_t *trx, trx_undo_t *undo, mtr_t *mtr)
 Frees the last undo log page. More...
 
static void trx_undo_free_last_page (const trx_t *trx, trx_undo_t *undo, mtr_t *mtr)
 
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. More...
 
static void trx_undo_truncate_end (const trx_t *trx, trx_undo_t *undo, undo_no_t limit)
 
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. More...
 
ulint trx_undo_lists_init (trx_rseg_t *rseg)
 Initializes the undo log lists for a rollback segment memory copy. More...
 
dberr_t trx_undo_assign_undo (trx_t *trx, trx_undo_ptr_t *undo_ptr, ulint type)
 Assigns an undo log for a transaction. More...
 
page_ttrx_undo_set_state_at_finish (trx_undo_t *undo, mtr_t *mtr)
 Sets the state of the undo log segment at a transaction finish. More...
 
page_ttrx_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. More...
 
page_ttrx_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. More...
 
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, or puts it to the list of cached update undo log segments. More...
 
void trx_undo_insert_cleanup (trx_undo_ptr_t *undo_ptr, bool noredo)
 Frees an insert undo log after a transaction commit or rollback. More...
 
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). More...
 
bool trx_undo_truncate_tablespace (undo::Tablespace *marked_space)
 Truncate UNDO tablespace, reinitialize header and rseg. More...
 
bytetrx_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. More...
 
bytetrx_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. More...
 
void trx_undo_mem_free (trx_undo_t *undo)
 Frees an undo log memory copy. More...
 
dberr_t trx_undo_gtid_add_update_undo (trx_t *trx, bool prepare, bool rollback)
 For saving GTID add update undo slot, if required. More...
 
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/. More...
 
void trx_undo_gtid_read_and_persist (trx_ulogf_t *undo_log)
 Read and persist GTID from undo header during recovery. More...
 
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. More...
 

Variables

constexpr uint32_t TRX_UNDO_INSERT = 1
 Types of an undo log segment. More...
 
constexpr uint32_t TRX_UNDO_UPDATE = 2
 contains undo entries for updates and delete markings: in short, modifys (the name 'UPDATE' is a historical relic) More...
 
constexpr uint32_t TRX_UNDO_ACTIVE = 1
 contains an undo log of an active transaction More...
 
constexpr uint32_t TRX_UNDO_CACHED = 2
 cached for quick reuse More...
 
constexpr uint32_t TRX_UNDO_TO_FREE = 3
 insert undo segment can be freed More...
 
constexpr uint32_t TRX_UNDO_TO_PURGE = 4
 update undo segment will not be reused: it can be freed in purge when all undo data in it is removed More...
 
constexpr uint32_t TRX_UNDO_PREPARED_80028 = 5
 contains an undo log of an prepared transaction for a server version older than 8.0.29 More...
 
constexpr uint32_t TRX_UNDO_PREPARED = 6
 contains an undo log of an prepared transaction More...
 
constexpr uint32_t TRX_UNDO_PREPARED_IN_TC = 7
 
constexpr uint32_t TRX_UNDO_PAGE_HDR = FSEG_PAGE_DATA
 The offset of the undo log page header on pages of the undo log. More...
 
constexpr uint32_t TRX_UNDO_SEG_HDR
 The offset of the undo log segment header on the first page of the undo log segment. More...
 
constexpr uint32_t TRX_UNDO_LOG_GTID_VERSION = TRX_UNDO_LOG_XA_HDR_SIZE
 GTID version offset. More...
 
constexpr uint32_t TRX_UNDO_LOG_GTID = TRX_UNDO_LOG_XA_HDR_SIZE + 1
 GTID offset. More...
 
constexpr uint32_t TRX_UNDO_LOG_GTID_LEN = 64
 Total length of GTID. More...
 
constexpr uint32_t TRX_UNDO_LOG_GTID_HDR_SIZE
 Total size with GTID information. More...
 
constexpr uint32_t TRX_UNDO_LOG_GTID_XA = TRX_UNDO_LOG_GTID_HDR_SIZE
 GTID offset for XA Prepare. More...
 
constexpr uint32_t TRX_UNDO_LOG_GTID_XA_HDR_SIZE
 Total size with XA GTID information. More...
 
constexpr uint32_t TRX_UNDO_PAGE_TYPE = 0
 Transaction undo log page header offsets. More...
 
constexpr uint32_t TRX_UNDO_PAGE_START = 2
 Byte offset where the undo log records for the LATEST transaction start on this page (remember that in an update undo log, the first page can contain several undo logs) More...
 
constexpr uint32_t TRX_UNDO_PAGE_FREE = 4
 On each page of the undo log this field contains the byte offset of the first free byte on the page. More...
 
constexpr uint32_t TRX_UNDO_PAGE_NODE = 6
 The file list node in the chain of undo log pages. More...
 
constexpr uint32_t TRX_UNDO_PAGE_HDR_SIZE = 6 + FLST_NODE_SIZE
 Size of the transaction undo log page header, in bytes. More...
 
constexpr uint32_t TRX_UNDO_STATE = 0
 Undo log segment header. More...
 
constexpr uint32_t TRX_UNDO_LAST_LOG = 2
 Offset of the last undo log header on the segment header page, 0 if none. More...
 
constexpr uint32_t TRX_UNDO_FSEG_HEADER = 4
 Header for the file segment which the undo log segment occupies. More...
 
constexpr uint32_t TRX_UNDO_PAGE_LIST = 4 + FSEG_HEADER_SIZE
 Base node for the list of pages in the undo log segment; defined only on the undo log segment's first page. More...
 
constexpr uint32_t TRX_UNDO_SEG_HDR_SIZE
 Size of the undo log segment header. More...
 
constexpr uint32_t TRX_UNDO_TRX_ID = 0
 The undo log header. More...
 
constexpr uint32_t TRX_UNDO_TRX_NO = 8
 Transaction number of the transaction; defined only if the log is in a history list. More...
 
constexpr uint32_t TRX_UNDO_DEL_MARKS = 16
 Defined only in an update undo log: true if the transaction may have done delete markings of records, and thus purge is necessary. More...
 
constexpr uint32_t TRX_UNDO_LOG_START = 18
 Offset of the first undo log record of this log on the header page; purge may remove undo log record from the log start, and therefore this is not necessarily the same as this log header end offset. More...
 
constexpr uint32_t TRX_UNDO_FLAGS = 20
 Transaction UNDO flags in one byte. More...
 
constexpr uint32_t TRX_UNDO_FLAG_XID = 0x01
 true if undo log header includes X/Open XA transaction identification XID More...
 
constexpr uint32_t TRX_UNDO_FLAG_GTID = 0x02
 true if undo log header includes GTID information from replication More...
 
constexpr uint32_t TRX_UNDO_FLAG_XA_PREPARE_GTID = 0x04
 true if undo log header includes GTID information for XA PREPARE More...
 
constexpr uint32_t TRX_UNDO_DICT_TRANS = 21
 true if the transaction is a table create, index create, or drop transaction: in recovery the transaction cannot be rolled back in the usual way: a 'rollback' rather means dropping the created or dropped table, if it still exists More...
 
constexpr uint32_t TRX_UNDO_TABLE_ID = 22
 Id of the table if the preceding field is true. More...
 
constexpr uint32_t TRX_UNDO_NEXT_LOG = 30
 Offset of the next undo log header on this page, 0 if none. More...
 
constexpr uint32_t TRX_UNDO_PREV_LOG = 32
 Offset of the previous undo log header on this page, 0 if none. More...
 
constexpr uint32_t TRX_UNDO_HISTORY_NODE = 34
 If the log is put to the history list, the file list node is here. More...
 
constexpr uint32_t TRX_UNDO_LOG_OLD_HDR_SIZE = 34 + FLST_NODE_SIZE
 Size of the undo log header without XID information. More...
 
constexpr uint32_t TRX_UNDO_XA_FORMAT = TRX_UNDO_LOG_OLD_HDR_SIZE
 X/Open XA Transaction Identification (XID) More...
 
constexpr uint32_t TRX_UNDO_XA_TRID_LEN = TRX_UNDO_XA_FORMAT + 4
 xid_t::gtrid_length More...
 
constexpr uint32_t TRX_UNDO_XA_BQUAL_LEN = TRX_UNDO_XA_TRID_LEN + 4
 xid_t::bqual_length More...
 
constexpr uint32_t TRX_UNDO_XA_XID = TRX_UNDO_XA_BQUAL_LEN + 4
 Distributed transaction identifier data. More...
 
constexpr uint32_t TRX_UNDO_LOG_XA_HDR_SIZE = TRX_UNDO_XA_XID + XIDDATASIZE
 Total size of the undo log header with the XA XID. More...
 

Detailed Description

Transaction undo log.

Created 3/26/1996 Heikki Tuuri

Macro Definition Documentation

◆ TRX_UNDO_PAGE_REUSE_LIMIT

#define TRX_UNDO_PAGE_REUSE_LIMIT   (3 * UNIV_PAGE_SIZE / 4)

An update undo segment with just one page can be reused if it has at most this many bytes used; we must leave space at least for one new undo log header on the page.

Function Documentation

◆ trx_read_roll_ptr()

static roll_ptr_t trx_read_roll_ptr ( const byte ptr)
inlinestatic

Reads a roll ptr from an index page.

In case that the roll ptr size changes in some future version, this function should be used instead of mach_read_...

Returns
roll ptr in: pointer to memory from where to read

◆ trx_undo_add_page()

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.

Returns
X-latched block if success, else NULL in: mtr which does not have a latch to any undo log page; the caller must have reserved the rollback segment mutex
X-latched block if success, else NULL
Parameters
trxin: transaction
undoin: undo log memory object
undo_ptrin: assign undo log from referred rollback segment.
mtrin: mtr which does not have a latch to any undo log page; the caller must have reserved the rollback segment mutex

◆ trx_undo_assign_undo()

dberr_t trx_undo_assign_undo ( trx_t trx,
trx_undo_ptr_t undo_ptr,
ulint  type 
)

Assigns an undo log for a transaction.

A new undo log is created or a cached undo log reused.

Returns
DB_SUCCESS if undo log assign successful, possible error codes are: DB_TOO_MANY_CONCURRENT_TRXS DB_OUT_OF_FILE_SPACE DB_READ_ONLY DB_OUT_OF_MEMORY in: TRX_UNDO_INSERT or TRX_UNDO_UPDATE

A new undo log is created or a cached undo log reused.

Returns
DB_SUCCESS if undo log assign successful, possible error codes are: DB_TOO_MANY_CONCURRENT_TRXS DB_OUT_OF_FILE_SPACE DB_READ_ONLY DB_OUT_OF_MEMORY
Parameters
trxin: transaction
undo_ptrin: assign undo log from referred rollback segment.
typein: TRX_UNDO_INSERT or TRX_UNDO_UPDATE

◆ trx_undo_free_last_page()

static void trx_undo_free_last_page ( const trx_t trx,
trx_undo_t undo,
mtr_t mtr 
)
inlinestatic

◆ trx_undo_free_last_page_func()

void trx_undo_free_last_page_func ( const trx_t trx,
trx_undo_t undo,
mtr_t mtr 
)

Frees the last undo log page.

The caller must hold the rollback segment mutex.

Parameters
[in]trxtransaction
[in,out]undoundo log memory copy
[in,out]mtrmini-transaction which does not have a latch to any undo log page or which has allocated the undo log page

◆ trx_undo_free_trx_with_prepared_or_active_logs()

void trx_undo_free_trx_with_prepared_or_active_logs ( trx_t trx,
bool  prepared 
)

At shutdown, frees the undo logs of a transaction which was either PREPARED or (ACTIVE and recovered).

Parameters
[in]trxtransaction which undo logs are freed
[in]preparedwhether or not the undo segment is in prepared or prepared in tc states

◆ trx_undo_get_first_rec()

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.

Parameters
[out]modifier_trx_idThe modifier trx identifier.
[in]spaceUndo log header space
[in]page_sizePage size
[in]page_noUndo log header page number
[in]offsetUndo log header offset on page
[in]modeLatching mode: RW_S_LATCH or RW_X_LATCH
[in,out]mtrMini-transaction
Returns
undo log record, the page latched, NULL if none

◆ trx_undo_get_next_rec()

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.

Returns
undo log record, the page s-latched, NULL if none in: mtr
undo log record, the page s-latched, NULL if none
Parameters
recin: undo record
page_noin: undo log header page number
offsetin: undo log header offset on page
mtrin: mtr

◆ trx_undo_get_prev_rec()

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.

Returns
undo log record, the page s-latched, NULL if none in: mtr
undo log record, the page s-latched, NULL if none
Parameters
recin: undo record
page_noin: undo log header page number
offsetin: undo log header offset on page
sharedin: true=S-latch, false=X-latch
mtrin: mtr

◆ trx_undo_gtid_add_update_undo()

dberr_t trx_undo_gtid_add_update_undo ( trx_t trx,
bool  prepare,
bool  rollback 
)

For saving GTID add update undo slot, if required.

Parameters
[in]trxtransaction
[in]prepareoperation is prepare
[in]rollbackoperation is rollback
Returns
innodb error code.

◆ trx_undo_gtid_read_and_persist()

void trx_undo_gtid_read_and_persist ( trx_ulogf_t undo_log)

Read and persist GTID from undo header during recovery.

Parameters
[in]undo_logundo log header

◆ trx_undo_gtid_set()

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/.

Parameters
[in,out]trxtransaction
[in,out]undoundo log memory object
[in]is_xa_prepareGTID is for XA prepared transaction.

◆ trx_undo_gtid_write()

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.

Parameters
[in,out]trxtransaction
[in,out]undo_headerundo log header
[in,out]undoundo log memory object
[in,out]mtrminit transaction for write
[in]is_xa_prepareGTID is for XA prepared transaction.

◆ trx_undo_insert_cleanup()

void trx_undo_insert_cleanup ( trx_undo_ptr_t undo_ptr,
bool  noredo 
)

Frees an insert undo log after a transaction commit or rollback.

Knowledge of inserts is not needed after a commit or rollback, therefore the data can be discarded.

Parameters
[in,out]undo_ptrundo log to clean up
[in]noredowhether the undo tablespace is redo logged

◆ trx_undo_lists_init()

ulint trx_undo_lists_init ( trx_rseg_t rseg)

Initializes the undo log lists for a rollback segment memory copy.

This function is only called when the database is started or a new rollback segment created.

Returns
the combined size of undo log segments in pages in: rollback segment memory object

This function is only called when the database is started or a new rollback segment is created.

Returns
the combined size of undo log segments in pages
Parameters
rsegin: rollback segment memory object

◆ trx_undo_mem_free()

void trx_undo_mem_free ( trx_undo_t undo)

Frees an undo log memory copy.

Parameters
undoin: the undo object to be freed

◆ trx_undo_page_get()

static page_t * trx_undo_page_get ( const page_id_t page_id,
const page_size_t page_size,
mtr_t mtr 
)
inlinestatic

Gets an undo log page and x-latches it.

Parameters
[in]page_idPage id
[in]page_sizePage size
[in,out]mtrMini-transaction
Returns
pointer to page x-latched

◆ trx_undo_page_get_first_rec()

static trx_undo_rec_t * trx_undo_page_get_first_rec ( page_t undo_page,
page_no_t  page_no,
ulint  offset 
)
inlinestatic

Returns the first undo record on the page in the specified undo log, or NULL if none exists.

Parameters
[in]undo_pageundo log page
[in]page_noundo log header page number
[in]offsetundo log header offset on page
Returns
pointer to record, NULL if none

◆ trx_undo_page_get_last_rec()

static trx_undo_rec_t * trx_undo_page_get_last_rec ( page_t undo_page,
page_no_t  page_no,
ulint  offset 
)
inlinestatic

Returns the last undo record on the page in the specified undo log, or NULL if none exists.

Parameters
[in]undo_pageundo log page
[in]page_noundo log header page number
[in]offsetundo log header offset on page
Returns
pointer to record, NULL if none

◆ trx_undo_page_get_next_rec()

static trx_undo_rec_t * trx_undo_page_get_next_rec ( trx_undo_rec_t rec,
page_no_t  page_no,
ulint  offset 
)
inlinestatic

Returns the next undo log record on the page in the specified log, or NULL if none exists.

Parameters
[in]recundo log record
[in]page_noundo log header page number
[in]offsetundo log header offset on page
Returns
pointer to record, NULL if none

◆ trx_undo_page_get_prev_rec()

static trx_undo_rec_t * trx_undo_page_get_prev_rec ( trx_undo_rec_t rec,
page_no_t  page_no,
ulint  offset 
)
inlinestatic

Returns the previous undo record on the page in the specified log, or NULL if none exists.

Parameters
[in]recundo log record
[in]page_noundo log header page number
[in]offsetundo log header offset on page
Returns
pointer to record, NULL if none

◆ trx_undo_page_get_s_latched()

static page_t * trx_undo_page_get_s_latched ( const page_id_t page_id,
const page_size_t page_size,
mtr_t mtr 
)
inlinestatic

Gets an undo log page and s-latches it.

Parameters
[in]page_idPage id
[in]page_sizePage size
[in,out]mtrMini-transaction
Returns
pointer to page s-latched

◆ trx_undo_parse_page_header()

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.

Parameters
[in]typeMLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE
[in]ptrRedo log record
[in]end_ptrEnd of log buffer
[in,out]pagePage frame or NULL
[in,out]mtrMini-transaction or NULL
Returns
end of log record or NULL

◆ trx_undo_parse_page_init()

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.

Returns
end of log record or NULL in: mtr or NULL
end of log record or NULL
Parameters
ptrin: buffer
end_ptrin: buffer end
pagein: page or NULL
mtrin: mtr or NULL

◆ trx_undo_roll_ptr_is_insert()

static bool trx_undo_roll_ptr_is_insert ( roll_ptr_t  roll_ptr)
inlinestatic

Returns true if the roll pointer is of the insert type.

Returns
true if insert undo log in: roll pointer

◆ trx_undo_set_prepared_in_tc()

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.

Parameters
[in,out]trxTransaction
[in,out]undoInsert_undo or update_undo log
[in,out]mtrMini-transaction
Returns
undo log segment header page, x-latched

◆ trx_undo_set_state_at_finish()

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.

Returns
undo log segment header page, x-latched in: mtr
undo log segment header page, x-latched
Parameters
undoin: undo log memory copy
mtrin: mtr

◆ trx_undo_set_state_at_prepare()

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.

Parameters
[in,out]trxTransaction
[in,out]undoInsert_undo or update_undo log
[in]rollbackfalse=XA PREPARE, true=XA ROLLBACK
[in,out]mtrMini-transaction
Returns
undo log segment header page, x-latched

◆ trx_undo_truncate_end()

static void trx_undo_truncate_end ( const trx_t trx,
trx_undo_t undo,
undo_no_t  limit 
)
inlinestatic

◆ trx_undo_truncate_end_func()

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.

This function is used during a rollback to free space from an undo log.

Parameters
[in]trxtransaction for this undo log
[in]undoundo log
[in]limitall undo records with undo number; This value should be truncated.

◆ trx_undo_truncate_start()

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.

NOTE that only whole pages are freed; the header page is not freed, but emptied, if all the records there are below the limit.

Parameters
[in,out]rsegrollback segment
[in]hdr_page_noheader page number
[in]hdr_offsetheader offset on the page
[in]limitfirst undo number to preserve (everything below the limit will be truncated)

◆ trx_undo_truncate_tablespace()

bool trx_undo_truncate_tablespace ( undo::Tablespace marked_space)

Truncate UNDO tablespace, reinitialize header and rseg.

Parameters
[in]marked_spaceUNDO tablespace to truncate
Returns
true if success else false.

◆ trx_undo_trx_id_is_insert()

static bool trx_undo_trx_id_is_insert ( const byte trx_id)
inlinestatic

Returns true if the record is of the insert type.

Returns
true if the record was freshly inserted (not updated). in: DB_TRX_ID, followed by DB_ROLL_PTR

◆ trx_undo_update_cleanup()

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, or puts it to the list of cached update undo log segments.

Parameters
[in]trxTrx owning the update undo log
[in]undo_ptrUpdate undo log.
[in]undo_pageUpdate undo log header page, x-latched
[in]update_rseg_history_lenIf true: update rseg history len else skip updating it.
[in]n_added_logsNumber of logs added
[in]mtrMini-transaction

◆ trx_write_roll_ptr()

static void trx_write_roll_ptr ( byte ptr,
roll_ptr_t  roll_ptr 
)
inlinestatic

Writes a roll ptr to an index page.

In case that the size changes in some future version, this function should be used instead of mach_write_...

Parameters
[in]ptrpointer to memory where written
[in]roll_ptrroll ptr

Variable Documentation

◆ TRX_UNDO_ACTIVE

constexpr uint32_t TRX_UNDO_ACTIVE = 1
constexpr

contains an undo log of an active transaction

◆ TRX_UNDO_CACHED

constexpr uint32_t TRX_UNDO_CACHED = 2
constexpr

cached for quick reuse

◆ TRX_UNDO_DEL_MARKS

constexpr uint32_t TRX_UNDO_DEL_MARKS = 16
constexpr

Defined only in an update undo log: true if the transaction may have done delete markings of records, and thus purge is necessary.

◆ TRX_UNDO_DICT_TRANS

constexpr uint32_t TRX_UNDO_DICT_TRANS = 21
constexpr

true if the transaction is a table create, index create, or drop transaction: in recovery the transaction cannot be rolled back in the usual way: a 'rollback' rather means dropping the created or dropped table, if it still exists

◆ TRX_UNDO_FLAG_GTID

constexpr uint32_t TRX_UNDO_FLAG_GTID = 0x02
constexpr

true if undo log header includes GTID information from replication

◆ TRX_UNDO_FLAG_XA_PREPARE_GTID

constexpr uint32_t TRX_UNDO_FLAG_XA_PREPARE_GTID = 0x04
constexpr

true if undo log header includes GTID information for XA PREPARE

◆ TRX_UNDO_FLAG_XID

constexpr uint32_t TRX_UNDO_FLAG_XID = 0x01
constexpr

true if undo log header includes X/Open XA transaction identification XID

◆ TRX_UNDO_FLAGS

constexpr uint32_t TRX_UNDO_FLAGS = 20
constexpr

Transaction UNDO flags in one byte.

This is backward compatible as earlier we were storing either 1 or 0 for TRX_UNDO_XID_EXISTS.

◆ TRX_UNDO_FSEG_HEADER

constexpr uint32_t TRX_UNDO_FSEG_HEADER = 4
constexpr

Header for the file segment which the undo log segment occupies.

◆ TRX_UNDO_HISTORY_NODE

constexpr uint32_t TRX_UNDO_HISTORY_NODE = 34
constexpr

If the log is put to the history list, the file list node is here.

◆ TRX_UNDO_INSERT

constexpr uint32_t TRX_UNDO_INSERT = 1
constexpr

Types of an undo log segment.

contains undo entries for inserts

◆ TRX_UNDO_LAST_LOG

constexpr uint32_t TRX_UNDO_LAST_LOG = 2
constexpr

Offset of the last undo log header on the segment header page, 0 if none.

◆ TRX_UNDO_LOG_GTID

constexpr uint32_t TRX_UNDO_LOG_GTID = TRX_UNDO_LOG_XA_HDR_SIZE + 1
constexpr

GTID offset.

◆ TRX_UNDO_LOG_GTID_HDR_SIZE

constexpr uint32_t TRX_UNDO_LOG_GTID_HDR_SIZE
constexpr
Initial value:
=
constexpr uint32_t TRX_UNDO_LOG_GTID_LEN
Total length of GTID.
Definition: trx0undo.h:601
constexpr uint32_t TRX_UNDO_LOG_GTID
GTID offset.
Definition: trx0undo.h:598

Total size with GTID information.

◆ TRX_UNDO_LOG_GTID_LEN

constexpr uint32_t TRX_UNDO_LOG_GTID_LEN = 64
constexpr

Total length of GTID.

◆ TRX_UNDO_LOG_GTID_VERSION

constexpr uint32_t TRX_UNDO_LOG_GTID_VERSION = TRX_UNDO_LOG_XA_HDR_SIZE
constexpr

GTID version offset.

◆ TRX_UNDO_LOG_GTID_XA

constexpr uint32_t TRX_UNDO_LOG_GTID_XA = TRX_UNDO_LOG_GTID_HDR_SIZE
constexpr

GTID offset for XA Prepare.

◆ TRX_UNDO_LOG_GTID_XA_HDR_SIZE

constexpr uint32_t TRX_UNDO_LOG_GTID_XA_HDR_SIZE
constexpr
Initial value:
=
constexpr uint32_t TRX_UNDO_LOG_GTID_HDR_SIZE
Total size with GTID information.
Definition: trx0undo.h:604

Total size with XA GTID information.

For external XA transaction we need to store both prepare and commit GTID.

◆ TRX_UNDO_LOG_OLD_HDR_SIZE

constexpr uint32_t TRX_UNDO_LOG_OLD_HDR_SIZE = 34 + FLST_NODE_SIZE
constexpr

Size of the undo log header without XID information.

◆ TRX_UNDO_LOG_START

constexpr uint32_t TRX_UNDO_LOG_START = 18
constexpr

Offset of the first undo log record of this log on the header page; purge may remove undo log record from the log start, and therefore this is not necessarily the same as this log header end offset.

◆ TRX_UNDO_LOG_XA_HDR_SIZE

constexpr uint32_t TRX_UNDO_LOG_XA_HDR_SIZE = TRX_UNDO_XA_XID + XIDDATASIZE
constexpr

Total size of the undo log header with the XA XID.

◆ TRX_UNDO_NEXT_LOG

constexpr uint32_t TRX_UNDO_NEXT_LOG = 30
constexpr

Offset of the next undo log header on this page, 0 if none.

◆ TRX_UNDO_PAGE_FREE

constexpr uint32_t TRX_UNDO_PAGE_FREE = 4
constexpr

On each page of the undo log this field contains the byte offset of the first free byte on the page.

◆ TRX_UNDO_PAGE_HDR

constexpr uint32_t TRX_UNDO_PAGE_HDR = FSEG_PAGE_DATA
constexpr

The offset of the undo log page header on pages of the undo log.

◆ TRX_UNDO_PAGE_HDR_SIZE

constexpr uint32_t TRX_UNDO_PAGE_HDR_SIZE = 6 + FLST_NODE_SIZE
constexpr

Size of the transaction undo log page header, in bytes.

◆ TRX_UNDO_PAGE_LIST

constexpr uint32_t TRX_UNDO_PAGE_LIST = 4 + FSEG_HEADER_SIZE
constexpr

Base node for the list of pages in the undo log segment; defined only on the undo log segment's first page.

◆ TRX_UNDO_PAGE_NODE

constexpr uint32_t TRX_UNDO_PAGE_NODE = 6
constexpr

The file list node in the chain of undo log pages.

◆ TRX_UNDO_PAGE_START

constexpr uint32_t TRX_UNDO_PAGE_START = 2
constexpr

Byte offset where the undo log records for the LATEST transaction start on this page (remember that in an update undo log, the first page can contain several undo logs)

◆ TRX_UNDO_PAGE_TYPE

constexpr uint32_t TRX_UNDO_PAGE_TYPE = 0
constexpr

Transaction undo log page header offsets.

TRX_UNDO_INSERT or TRX_UNDO_UPDATE

◆ TRX_UNDO_PREPARED

constexpr uint32_t TRX_UNDO_PREPARED = 6
constexpr

contains an undo log of an prepared transaction

◆ TRX_UNDO_PREPARED_80028

constexpr uint32_t TRX_UNDO_PREPARED_80028 = 5
constexpr

contains an undo log of an prepared transaction for a server version older than 8.0.29

◆ TRX_UNDO_PREPARED_IN_TC

constexpr uint32_t TRX_UNDO_PREPARED_IN_TC = 7
constexpr

◆ TRX_UNDO_PREV_LOG

constexpr uint32_t TRX_UNDO_PREV_LOG = 32
constexpr

Offset of the previous undo log header on this page, 0 if none.

◆ TRX_UNDO_SEG_HDR

constexpr uint32_t TRX_UNDO_SEG_HDR
constexpr
Initial value:
=
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_HDR
The offset of the undo log page header on pages of the undo log.
Definition: trx0undo.h:463

The offset of the undo log segment header on the first page of the undo log segment.

◆ TRX_UNDO_SEG_HDR_SIZE

constexpr uint32_t TRX_UNDO_SEG_HDR_SIZE
constexpr
Initial value:
=
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

Size of the undo log segment header.

◆ TRX_UNDO_STATE

constexpr uint32_t TRX_UNDO_STATE = 0
constexpr

Undo log segment header.

TRX_UNDO_ACTIVE, ...

◆ TRX_UNDO_TABLE_ID

constexpr uint32_t TRX_UNDO_TABLE_ID = 22
constexpr

Id of the table if the preceding field is true.

Note: deprecated

◆ TRX_UNDO_TO_FREE

constexpr uint32_t TRX_UNDO_TO_FREE = 3
constexpr

insert undo segment can be freed

◆ TRX_UNDO_TO_PURGE

constexpr uint32_t TRX_UNDO_TO_PURGE = 4
constexpr

update undo segment will not be reused: it can be freed in purge when all undo data in it is removed

◆ TRX_UNDO_TRX_ID

constexpr uint32_t TRX_UNDO_TRX_ID = 0
constexpr

The undo log header.

There can be several undo log headers on the first page of an update undo log segment. Transaction id

◆ TRX_UNDO_TRX_NO

constexpr uint32_t TRX_UNDO_TRX_NO = 8
constexpr

Transaction number of the transaction; defined only if the log is in a history list.

◆ TRX_UNDO_UPDATE

constexpr uint32_t TRX_UNDO_UPDATE = 2
constexpr

contains undo entries for updates and delete markings: in short, modifys (the name 'UPDATE' is a historical relic)

◆ TRX_UNDO_XA_BQUAL_LEN

constexpr uint32_t TRX_UNDO_XA_BQUAL_LEN = TRX_UNDO_XA_TRID_LEN + 4
constexpr

xid_t::bqual_length

◆ TRX_UNDO_XA_FORMAT

constexpr uint32_t TRX_UNDO_XA_FORMAT = TRX_UNDO_LOG_OLD_HDR_SIZE
constexpr

X/Open XA Transaction Identification (XID)

xid_t::formatID

◆ TRX_UNDO_XA_TRID_LEN

constexpr uint32_t TRX_UNDO_XA_TRID_LEN = TRX_UNDO_XA_FORMAT + 4
constexpr

xid_t::gtrid_length

◆ TRX_UNDO_XA_XID

constexpr uint32_t TRX_UNDO_XA_XID = TRX_UNDO_XA_BQUAL_LEN + 4
constexpr

Distributed transaction identifier data.