MySQL 9.1.0
Source Code Documentation
|
Transaction undo log. More...
#include <stddef.h>
#include <sql_thd_internal_api.h>
#include "fsp0fsp.h"
#include "ha_prototypes.h"
#include "trx0undo.h"
#include "my_dbug.h"
#include "clone0clone.h"
#include "current_thd.h"
#include "dict0dd.h"
#include "fil0fil.h"
#include "log0chkp.h"
#include "log0write.h"
#include "mach0data.h"
#include "mtr0log.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "trx0purge.h"
#include "trx0rec.h"
#include "trx0rseg.h"
#include "trx0trx.h"
Functions | |
static void | trx_undo_page_init (page_t *undo_page, ulint type, mtr_t *mtr) |
Initializes the fields in an undo log segment page. More... | |
static trx_undo_t * | trx_undo_mem_create (trx_rseg_t *rseg, ulint id, ulint type, trx_id_t trx_id, const XID *xid, page_no_t page_no, ulint offset) |
Creates and initializes an undo log memory object. More... | |
static ulint | trx_undo_insert_header_reuse (page_t *undo_page, trx_id_t trx_id, mtr_t *mtr) |
Initializes a cached insert undo log header page for new use. More... | |
static trx_undo_rec_t * | trx_undo_get_prev_rec_from_prev_page (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 from the previous page. More... | |
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. More... | |
static trx_undo_rec_t * | trx_undo_get_next_rec_from_next_page (space_id_t space, const page_size_t &page_size, const page_t *undo_page, page_no_t page_no, ulint offset, ulint mode, mtr_t *mtr) |
Gets the next record in an undo log from the next page. More... | |
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. More... | |
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. More... | |
static void | trx_undo_page_init_log (page_t *undo_page, ulint type, mtr_t *mtr) |
Writes the mtr log entry of an undo log page initialization. More... | |
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. More... | |
static dberr_t | trx_undo_seg_create (trx_rseg_t *rseg, trx_rsegf_t *rseg_hdr, ulint type, ulint *id, page_t **undo_page, mtr_t *mtr) |
Creates a new undo log segment in file. More... | |
static void | trx_undo_header_create_log (const page_t *undo_page, trx_id_t trx_id, mtr_t *mtr) |
Writes the mtr log entry of an undo log header initialization. More... | |
static ulint | trx_undo_header_create (page_t *undo_page, trx_id_t trx_id, mtr_t *mtr) |
Creates a new undo log header in file. More... | |
static void | trx_undo_write_xid (trx_ulogf_t *log_hdr, const XID *xid, mtr_t *mtr) |
Write X/Open XA Transaction Identification (XID) to undo log header. 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_header) |
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... | |
static void | trx_undo_read_xid (trx_ulogf_t *log_hdr, XID *xid) |
Read X/Open XA Transaction Identification (XID) from undo log header. More... | |
static void | trx_undo_header_add_space_for_xid (page_t *undo_page, trx_ulogf_t *log_hdr, mtr_t *mtr, trx_undo_t::Gtid_storage gtid_storage) |
Adds space for the XA XID after an undo log old-style header. More... | |
static void | trx_undo_insert_header_reuse_log (const page_t *undo_page, trx_id_t trx_id, mtr_t *mtr) |
Writes the mtr log entry of an undo log header reuse. More... | |
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. More... | |
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. More... | |
static page_no_t | trx_undo_free_page (trx_rseg_t *rseg, bool in_history, space_id_t space, page_no_t hdr_page_no, page_no_t page_no, mtr_t *mtr) |
Frees an undo log page that is not the header page. 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_empty_header_page (space_id_t space_id, const page_size_t &page_size, page_no_t hdr_page_no, ulint hdr_offset, mtr_t *mtr) |
Empties an undo log header page of undo records for that undo log. More... | |
int | trx_undo_page_truncate_offset (trx_undo_t *undo, page_t *undo_page, undo_no_t limit) |
Get page offset up to which undo logs can be truncated. More... | |
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... | |
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... | |
static void | trx_undo_seg_free (const trx_undo_t *undo, bool noredo) |
Frees an undo log segment which is not in the history list. More... | |
static trx_undo_t * | trx_undo_mem_init (trx_rseg_t *rseg, ulint id, page_no_t page_no, mtr_t *mtr) |
Creates and initializes an undo log memory object for a newly created rseg. More... | |
ulint | trx_undo_lists_init (trx_rseg_t *rseg) |
Initializes the undo log lists for a rollback segment memory copy. More... | |
static void | trx_undo_mem_init_for_reuse (trx_undo_t *undo, trx_id_t trx_id, const XID *xid, ulint offset) |
Initializes a cached undo log object for new use. More... | |
void | trx_undo_mem_free (trx_undo_t *undo) |
Frees an undo log memory copy. More... | |
static dberr_t | trx_undo_create (trx_rseg_t *rseg, ulint type, trx_id_t trx_id, const XID *xid, trx_undo_t::Gtid_storage gtid_storage, trx_undo_t **undo, mtr_t *mtr) |
Create a new undo log in the given rollback segment. More... | |
static trx_undo_t * | trx_undo_reuse_cached (trx_rseg_t *rseg, ulint type, trx_id_t trx_id, const XID *xid, trx_undo_t::Gtid_storage gtid_storage, mtr_t *mtr) |
Reuses a cached undo log. More... | |
static void | trx_undo_mark_as_dict_operation (trx_undo_t *undo, mtr_t *mtr) |
Marks an undo log header as a header of a data dictionary operation transaction. 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_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. More... | |
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. More... | |
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. 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) |
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... | |
Transaction undo log.
Created 3/26/1996 Heikki Tuuri
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.
trx | in: transaction |
undo | in: undo log memory object |
undo_ptr | in: assign undo log from referred rollback segment. |
mtr | in: mtr which does not have a latch to any undo log page; the caller must have reserved the rollback segment mutex |
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.
trx | in: transaction |
undo_ptr | in: assign undo log from referred rollback segment. |
type | in: TRX_UNDO_INSERT or TRX_UNDO_UPDATE |
|
static |
Create a new undo log in the given rollback segment.
[in] | rseg | rollback segment memory copy |
[in] | type | type of the log: TRX_UNDO_INSERT or TRX_UNDO_UPDATE |
[in] | trx_id | id of the trx for which the undo log is created |
[in] | xid | X/Open transaction identification |
[in] | gtid_storage | GTID storage type |
[out] | undo | the new undo log object, undefined if did not succeed |
[in] | mtr | mini-transation |
DB_SUCCESS | if successful in creating the new undo lob object, |
DB_TOO_MANY_CONCURRENT_TRXS | too many concurrent trxs |
DB_OUT_OF_FILE_SPACE | out of file-space |
DB_OUT_OF_MEMORY | out of memory |
|
static |
Empties an undo log header page of undo records for that undo log.
Other undo logs may still have records on that page, if it is an update undo log.
[in] | space_id | Tablespace ID |
[in] | page_size | Page size |
[in] | hdr_page_no | Header page number |
[in] | hdr_offset | Header offset |
[in,out] | mtr | Mini-transaction |
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.
[in] | trx | transaction |
[in,out] | undo | undo log memory copy |
[in,out] | mtr | mini-transaction which does not have a latch to any undo log page or which has allocated the undo log page |
|
static |
Frees an undo log page that is not the header page.
rseg | in: rollback segment |
in_history | in: true if the undo log is in the history list |
space | in: space |
hdr_page_no | in: header page number |
page_no | in: page number to free: must not be the header page |
mtr | in: mtr which does not have a latch to any undo log page; the caller must have reserved the rollback segment mutex |
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).
[in] | trx | transaction which undo logs are freed |
[in] | prepared | whether or not the undo segment is in prepared or prepared in tc states |
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.
[out] | modifier_trx_id | The modifier trx identifier. |
[in] | space | Undo log header space |
[in] | page_size | Page size |
[in] | page_no | Undo log header page number |
[in] | offset | Undo log header offset on page |
[in] | mode | Latching mode: RW_S_LATCH or RW_X_LATCH |
[in,out] | mtr | Mini-transaction |
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.
rec | in: undo record |
page_no | in: undo log header page number |
offset | in: undo log header offset on page |
mtr | in: mtr |
|
static |
Gets the next record in an undo log from the next page.
[in] | space | Undo log header space |
[in] | page_size | Page size |
[in] | undo_page | Undo log page |
[in] | page_no | Undo log header page number |
[in] | offset | Undo log header offset on page |
[in] | mode | Latch mode: RW_S_LATCH or RW_X_LATCH |
[in,out] | mtr | Mini-transaction |
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.
rec | in: undo record |
page_no | in: undo log header page number |
offset | in: undo log header offset on page |
shared | in: true=S-latch, false=X-latch |
mtr | in: mtr |
|
static |
Gets the previous record in an undo log from the previous page.
rec | in: undo record |
page_no | in: undo log header page number |
offset | in: undo log header offset on page |
shared | in: true=S-latch, false=X-latch |
mtr | in: mtr |
For saving GTID add update undo slot, if required.
[in] | trx | transaction |
[in] | prepare | operation is prepare |
[in] | rollback | operation is rollback |
void trx_undo_gtid_read_and_persist | ( | trx_ulogf_t * | undo_log | ) |
Read and persist GTID from undo header during recovery.
[in] | undo_log | undo log header |
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/.
[in,out] | trx | transaction |
[in,out] | undo | undo log memory object |
[in] | is_xa_prepare | GTID is for XA prepared transaction. |
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.
[in,out] | trx | transaction |
[in,out] | undo_header | undo log header |
[in,out] | undo | undo log memory object |
[in,out] | mtr | minit transaction for write |
[in] | is_xa_prepare | GTID is for XA prepared transaction. |
|
static |
Adds space for the XA XID after an undo log old-style header.
[in,out] | undo_page | Undo log segment header page |
[in,out] | log_hdr | Undo log header |
[in,out] | mtr | Mini-transaction |
[in] | gtid_storage | GTID storage type |
Creates a new undo log header in file.
NOTE that this function has its own log record type MLOG_UNDO_HDR_CREATE. You must NOT change the operation of this function!
undo_page | in/out: undo log segment header page, x-latched; it is assumed that there is TRX_UNDO_LOG_HDR_SIZE bytes free space on it |
trx_id | in: transaction id |
mtr | in: mtr |
|
inlinestatic |
Writes the mtr log entry of an undo log header initialization.
undo_page | in: undo log header page |
trx_id | in: transaction id |
mtr | in: mtr |
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.
[in,out] | undo_ptr | undo log to clean up |
[in] | noredo | whether the undo tablespace is redo logged |
|
static |
Initializes a cached insert undo log header page for new use.
NOTE that this function has its own log record type MLOG_UNDO_HDR_REUSE. You must NOT change the operation of this function!
NOTE that this function has its own log record type MLOG_UNDO_HDR_REUSE. You must NOT change the operation of this function!
undo_page | in/out: insert undo log segment header page, x-latched |
trx_id | in: transaction id |
mtr | in: mtr |
|
inlinestatic |
Writes the mtr log entry of an undo log header reuse.
undo_page | in: undo log header page |
trx_id | in: transaction id |
mtr | in: mtr |
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 is created.
rseg | in: rollback segment memory object |
|
static |
Marks an undo log header as a header of a data dictionary operation transaction.
undo | in: assigned undo log |
mtr | in: mtr |
|
static |
Creates and initializes an undo log memory object.
[in] | rseg | rollback segment memory object |
[in] | id | slot index within rseg |
[in] | type | type of the log: TRX_UNDO_INSERT or TRX_UNDO_UPDATE |
[in] | trx_id | id of the trx for which the undo log is created |
[in] | xid | X/Open XA transaction identification |
[in] | page_no | undo log header page number |
[in] | offset | undo log header byte offset on page |
void trx_undo_mem_free | ( | trx_undo_t * | undo | ) |
Frees an undo log memory copy.
undo | in: the undo object to be freed |
|
static |
Creates and initializes an undo log memory object for a newly created rseg.
The memory object is inserted in the appropriate list in the rseg.
rseg | in: rollback segment memory object |
id | in: slot index within rseg |
page_no | in: undo log segment page number |
mtr | in: mtr |
|
static |
Initializes a cached undo log object for new use.
undo | in: undo log to init |
trx_id | in: id of the trx for which the undo log is created |
xid | in: X/Open XA transaction identification |
offset | in: undo log header byte offset on page |
Initializes the fields in an undo log segment page.
in: mtr
undo_page | in: undo log segment page |
type | in: undo log segment type |
mtr | in: mtr |
Writes the mtr log entry of an undo log page initialization.
undo_page | in: undo log page |
type | in: undo log type |
mtr | in: mtr |
int trx_undo_page_truncate_offset | ( | trx_undo_t * | undo, |
page_t * | undo_page, | ||
undo_no_t | limit | ||
) |
Get page offset up to which undo logs can be truncated.
There are three possibilities.
[in] | undo | undo log to truncate |
[in] | undo_page | undo log page to check |
[in] | limit | limit up to which undo logs to be truncated |
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.
[in] | type | MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE |
[in] | ptr | Redo log record |
[in] | end_ptr | End of log buffer |
[in,out] | page | Page frame or NULL |
[in,out] | mtr | Mini-transaction or NULL |
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.
ptr | in: buffer |
end_ptr | in: buffer end |
page | in: page or NULL |
mtr | in: mtr or NULL |
|
static |
Read X/Open XA Transaction Identification (XID) from undo log header.
log_hdr | in: undo log header |
xid | out: X/Open XA Transaction Identification |
|
static |
Reuses a cached undo log.
[in,out] | rseg | Rollback segment memory object |
[in] | type | Type of the log: TRX_UNDO_INSERT or TRX_UNDO_UPDATE |
[in] | trx_id | Id of the trx for which the undo log is used |
[in] | xid | X/Open XA transaction identification |
[in] | gtid_storage | GTID storage type |
[in,out] | mtr | Mini-transaction |
|
static |
Creates a new undo log segment in file.
rseg | in: rollback segment |
rseg_hdr | in: rollback segment header, page x-latched |
type | in: type of the segment: TRX_UNDO_INSERT or TRX_UNDO_UPDATE |
id | out: slot index within rseg header |
undo_page | out: segment header page x-latched, NULL if there was an error |
mtr | in: mtr |
|
static |
Frees an undo log segment which is not in the history list.
[in] | undo | undo log |
[in] | noredo | whether the undo tablespace is redo logged |
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.
[in,out] | trx | Transaction |
[in,out] | undo | Insert_undo or update_undo log |
[in,out] | mtr | Mini-transaction |
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.
undo | in: undo log memory copy |
mtr | in: mtr |
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.
[in,out] | trx | Transaction |
[in,out] | undo | Insert_undo or update_undo log |
[in] | rollback | false=XA PREPARE, true=XA ROLLBACK |
[in,out] | mtr | Mini-transaction |
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.
[in] | trx | transaction for this undo log |
[in] | undo | undo log |
[in] | limit | all undo records with undo number; This value should be truncated. |
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.
[in,out] | rseg | rollback segment |
[in] | hdr_page_no | header page number |
[in] | hdr_offset | header offset on the page |
[in] | limit | first undo number to preserve (everything below the limit will be truncated) |
bool trx_undo_truncate_tablespace | ( | undo::Tablespace * | marked_space | ) |
Truncate UNDO tablespace, reinitialize header and rseg.
[in] | marked_space | UNDO tablespace to truncate |
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.
[in] | trx | Trx owning the update undo log |
[in] | undo_ptr | Update undo log. |
[in] | undo_page | Update undo log header page, x-latched |
[in] | update_rseg_history_len | If true: update rseg history len else skip updating it. |
[in] | n_added_logs | Number of logs added |
[in] | mtr | Mini-transaction |
|
static |
Write X/Open XA Transaction Identification (XID) to undo log header.
log_hdr | in: undo log header |
xid | in: X/Open XA Transaction Identification |
mtr | in: mtr |