MySQL  8.0.21
Source Code Documentation
trx0rseg.h File Reference

Rollback segment. More...

#include <vector>
#include "fut0lst.h"
#include "trx0sys.h"
#include "trx0types.h"
#include "univ.i"
#include "trx0rseg.ic"

Go to the source code of this file.

Macros

#define TRX_RSEG_N_SLOTS   (UNIV_PAGE_SIZE / 16)
 
#define TRX_RSEG_MAX_N_TRXS   (TRX_RSEG_N_SLOTS / 2)
 
#define TRX_RSEG_SLOT_PAGE_NO
 
#define TRX_RSEG_SLOT_SIZE   4
 
#define TRX_RSEG   FSEG_PAGE_DATA
 
#define TRX_RSEG_MAX_SIZE
 
#define TRX_RSEG_HISTORY_SIZE
 
#define TRX_RSEG_HISTORY
 
#define TRX_RSEG_FSEG_HEADER   (8 + FLST_BASE_NODE_SIZE)
 
#define TRX_RSEG_UNDO_SLOTS   (8 + FLST_BASE_NODE_SIZE + FSEG_HEADER_SIZE)
 
#define TRX_RSEG_SLOT_END   (TRX_RSEG_UNDO_SLOTS + (TRX_RSEG_SLOT_SIZE * TRX_RSEG_N_SLOTS))
 
#define TRX_RSEG_MAX_TRX_NO   TRX_RSEG_SLOT_END
 
#define RSEG_ARRAY_HEADER   FSEG_PAGE_DATA
 The offset of the Rollback Segment Directory header on an RSEG_ARRAY page. More...
 
#define RSEG_ARRAY_VERSION   0x52534547 + 1
 Rollback Segment Array Header. More...
 
#define RSEG_ARRAY_VERSION_OFFSET   0
 The RSEG ARRAY version offset in the header. More...
 
#define RSEG_ARRAY_SIZE_OFFSET   4
 The current number of rollback segments being tracked in this array. More...
 
#define RSEG_ARRAY_FSEG_HEADER_OFFSET   8
 This is the pointer to the file segment inode that tracks this rseg array page. More...
 
#define RSEG_ARRAY_PAGES_OFFSET   (8 + FSEG_HEADER_SIZE)
 The start of the array of rollback segment header page numbers for this undo tablespace. More...
 
#define RSEG_ARRAY_RESERVED_BYTES   200
 Reserved space at the end of an RSEG_ARRAY page reserved for future use. More...
 
#define RSEG_ARRAY_SLOT_SIZE   4
 

Functions

UNIV_INLINE trx_rsegf_ttrx_rsegf_get (space_id_t space, page_no_t page_no, const page_size_t &page_size, mtr_t *mtr)
 Gets a rollback segment header. More...
 
UNIV_INLINE trx_rsegf_ttrx_rsegf_get_new (space_id_t space, page_no_t page_no, const page_size_t &page_size, mtr_t *mtr)
 Gets a newly created rollback segment header. More...
 
UNIV_INLINE page_no_t trx_rsegf_get_nth_undo (trx_rsegf_t *rsegf, ulint n, mtr_t *mtr)
 Gets the file page number of the nth undo log slot. More...
 
UNIV_INLINE void trx_rsegf_set_nth_undo (trx_rsegf_t *rsegf, ulint n, page_no_t page_no, mtr_t *mtr)
 Sets the file page number of the nth undo log slot. More...
 
UNIV_INLINE ulint trx_rsegf_undo_find_free (trx_rsegf_t *rsegf, mtr_t *mtr)
 Looks for a free slot for an undo log segment. More...
 
page_no_t trx_rseg_header_create (space_id_t space_id, const page_size_t &page_size, page_no_t max_size, ulint rseg_slot, mtr_t *mtr)
 Creates a rollback segment header. More...
 
bool trx_rseg_adjust_rollback_segments (ulong target_rollback_segments)
 Add more rsegs to the rseg list in each tablespace until there are srv_rollback_segments of them. More...
 
bool trx_rseg_init_rollback_segments (space_id_t space_id, ulong target_rollback_segments)
 Create the requested number of Rollback Segments in a newly created undo tablespace and add them to the Rsegs object. More...
 
void trx_rsegs_init (purge_pq_t *purge_queue)
 Create the memory copies for rollback segments and initialize the rseg array in trx_sys at a database startup. More...
 
trx_rseg_ttrx_rseg_mem_create (ulint id, space_id_t space_id, page_no_t page_no, const page_size_t &page_size, trx_id_t gtid_trx_no, purge_pq_t *purge_queue, mtr_t *mtr)
 Create and initialize a rollback segment object. More...
 
page_no_t trx_rseg_create (space_id_t space_id, ulint rseg_id)
 Create a rollback segment in the given tablespace. More...
 
void trx_rseg_get_n_undo_tablespaces (Space_Ids *spaces_to_open)
 Build a list of unique undo tablespaces found in the TRX_SYS page. More...
 
void trx_rseg_upgrade_undo_tablespaces ()
 Upgrade the TRX_SYS page so that it no longer tracks rsegs in undo tablespaces other than the system tablespace. More...
 
void trx_rseg_array_create (space_id_t space_id, mtr_t *mtr)
 Create the file page for the rollback segment directory in an undo tablespace. More...
 
UNIV_INLINE void trx_rsegsf_set_page_no (trx_rsegsf_t *rsegs_header, ulint slot, page_no_t page_no, mtr_t *mtr)
 Sets the page number of the nth rollback segment slot in the independent undo tablespace. More...
 

Detailed Description

Rollback segment.

Created 3/26/1996 Heikki Tuuri

Macro Definition Documentation

◆ RSEG_ARRAY_FSEG_HEADER_OFFSET

#define RSEG_ARRAY_FSEG_HEADER_OFFSET   8

This is the pointer to the file segment inode that tracks this rseg array page.

◆ RSEG_ARRAY_HEADER

#define RSEG_ARRAY_HEADER   FSEG_PAGE_DATA

The offset of the Rollback Segment Directory header on an RSEG_ARRAY page.

◆ RSEG_ARRAY_PAGES_OFFSET

#define RSEG_ARRAY_PAGES_OFFSET   (8 + FSEG_HEADER_SIZE)

The start of the array of rollback segment header page numbers for this undo tablespace.

The potential size of this array is limited only by the page size minus overhead. The actual size of the array is limited by srv_rollback_segments.

◆ RSEG_ARRAY_RESERVED_BYTES

#define RSEG_ARRAY_RESERVED_BYTES   200

Reserved space at the end of an RSEG_ARRAY page reserved for future use.

◆ RSEG_ARRAY_SIZE_OFFSET

#define RSEG_ARRAY_SIZE_OFFSET   4

The current number of rollback segments being tracked in this array.

◆ RSEG_ARRAY_SLOT_SIZE

#define RSEG_ARRAY_SLOT_SIZE   4

◆ RSEG_ARRAY_VERSION

#define RSEG_ARRAY_VERSION   0x52534547 + 1

Rollback Segment Array Header.

The RSEG ARRAY base version is a number derived from the string 'RSEG' [0x 52 53 45 47] for extra validation. Each new version increments the base version by 1.

◆ RSEG_ARRAY_VERSION_OFFSET

#define RSEG_ARRAY_VERSION_OFFSET   0

The RSEG ARRAY version offset in the header.

◆ TRX_RSEG

#define TRX_RSEG   FSEG_PAGE_DATA

◆ TRX_RSEG_FSEG_HEADER

#define TRX_RSEG_FSEG_HEADER   (8 + FLST_BASE_NODE_SIZE)

◆ TRX_RSEG_HISTORY

#define TRX_RSEG_HISTORY
Value:
8 /* The update undo logs for committed \
transactions */

◆ TRX_RSEG_HISTORY_SIZE

#define TRX_RSEG_HISTORY_SIZE
Value:
4 /* Number of file pages occupied \
by the logs in the history list */

◆ TRX_RSEG_MAX_N_TRXS

#define TRX_RSEG_MAX_N_TRXS   (TRX_RSEG_N_SLOTS / 2)

◆ TRX_RSEG_MAX_SIZE

#define TRX_RSEG_MAX_SIZE
Value:
0 /* Maximum allowed size for rollback \
segment in pages */

◆ TRX_RSEG_MAX_TRX_NO

#define TRX_RSEG_MAX_TRX_NO   TRX_RSEG_SLOT_END

◆ TRX_RSEG_N_SLOTS

#define TRX_RSEG_N_SLOTS   (UNIV_PAGE_SIZE / 16)

◆ TRX_RSEG_SLOT_END

#define TRX_RSEG_SLOT_END   (TRX_RSEG_UNDO_SLOTS + (TRX_RSEG_SLOT_SIZE * TRX_RSEG_N_SLOTS))

◆ TRX_RSEG_SLOT_PAGE_NO

#define TRX_RSEG_SLOT_PAGE_NO
Value:
0 /* Page number of the header page of \
an undo log segment */

◆ TRX_RSEG_SLOT_SIZE

#define TRX_RSEG_SLOT_SIZE   4

◆ TRX_RSEG_UNDO_SLOTS

#define TRX_RSEG_UNDO_SLOTS   (8 + FLST_BASE_NODE_SIZE + FSEG_HEADER_SIZE)

Function Documentation

◆ trx_rseg_adjust_rollback_segments()

bool trx_rseg_adjust_rollback_segments ( ulong  target_rollback_segments)

Add more rsegs to the rseg list in each tablespace until there are srv_rollback_segments of them.

Use any rollback segment that already exists so that the purge_queue can be filled and processed with any existing undo log. If the rollback segments do not exist in this tablespace and we need them according to target_rollback_segments, then build them in the tablespace.

Parameters
[in]target_rollback_segmentsnew number of rollback segments per space
Returns
true if all necessary rollback segments and trx_rseg_t objects were created.

The number of rollback segments created in the datafile.

◆ trx_rseg_array_create()

void trx_rseg_array_create ( space_id_t  space_id,
mtr_t mtr 
)

Create the file page for the rollback segment directory in an undo tablespace.

This function is called just after an undo tablespace is created so the next page created here should by FSP_FSEG_DIR_PAGE_NUM.

Parameters
[in]space_idUndo Tablespace ID
[in]mtrmtr

◆ trx_rseg_create()

page_no_t trx_rseg_create ( space_id_t  space_id,
ulint  rseg_id 
)

Create a rollback segment in the given tablespace.

This could be either the system tablespace, the temporary tablespace, or an undo tablespace.

Parameters
[in]space_idtablespace to get the rollback segment
[in]rseg_idslot number of the rseg within this tablespace
Returns
page number of the rollback segment header page created

◆ trx_rseg_get_n_undo_tablespaces()

void trx_rseg_get_n_undo_tablespaces ( Space_Ids spaces_to_open)

Build a list of unique undo tablespaces found in the TRX_SYS page.

Do not count the system tablespace. The vector will be sorted on space id.

Parameters
[in,out]spaces_to_openlist of undo tablespaces found.

◆ trx_rseg_header_create()

page_no_t trx_rseg_header_create ( space_id_t  space_id,
const page_size_t page_size,
page_no_t  max_size,
ulint  rseg_slot,
mtr_t mtr 
)

Creates a rollback segment header.

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

Parameters
[in]space_idspace id
[in]page_sizepage size
[in]max_sizemax size in pages
[in]rseg_slotrseg id == slot number in trx sys
[in,out]mtrmini-transaction
Returns
page number of the created segment, FIL_NULL if fail

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

Parameters
[in]space_idspace id
[in]page_sizepage size
[in]max_sizemax size in pages
[in]rseg_slotrseg id == slot number in RSEG_ARRAY
[in,out]mtrmini-transaction
Returns
page number of the created segment, FIL_NULL if fail

◆ trx_rseg_init_rollback_segments()

bool trx_rseg_init_rollback_segments ( space_id_t  space_id,
ulong  target_rollback_segments 
)

Create the requested number of Rollback Segments in a newly created undo tablespace and add them to the Rsegs object.

Parameters
[in]space_idundo tablespace ID
[in]target_rollback_segmentsnumber of rollback segments per space
Returns
true if all necessary rollback segments and trx_rseg_t objects were created.

Create the requested number of Rollback Segments in a newly created undo tablespace and add them to the Rsegs object.

Parameters
[in]space_idundo tablespace ID
[in]target_rollback_segmentsnumber of rollback segments per space
Returns
true if all necessary rollback segments and trx_rseg_t objects were created.

The number of rollback segments created in the datafile.

◆ trx_rseg_mem_create()

trx_rseg_t* trx_rseg_mem_create ( ulint  id,
space_id_t  space_id,
page_no_t  page_no,
const page_size_t page_size,
trx_id_t  gtid_trx_no,
purge_pq_t purge_queue,
mtr_t mtr 
)

Create and initialize a rollback segment object.

Some of the values for the fields are read from the segment header page. The caller must insert it into the correct list.

Parameters
[in]idrollback segment id
[in]space_idspace where the segment is placed
[in]page_nopage number of the segment header
[in]page_sizepage size
[in]gtid_trx_notrx number up to which GTID is persisted
[in,out]purge_queuerseg queue
[in,out]mtrmini-transaction
Returns
own: rollback segment object

◆ trx_rseg_upgrade_undo_tablespaces()

void trx_rseg_upgrade_undo_tablespaces ( )

Upgrade the TRX_SYS page so that it no longer tracks rsegs in undo tablespaces other than the system tablespace.

Add these tablespaces to undo::spaces and put FIL_NULL in the slots in TRX_SYS.

Upgrade the TRX_SYS page so that it no longer tracks rsegs in undo tablespaces other than the system tablespace.

It should only track rollback segments in the system tablespace. Put FIL_NULL in the slots in TRX_SYS. Latch protection is not needed since this is during single-threaded startup.

◆ trx_rsegf_get()

UNIV_INLINE trx_rsegf_t* trx_rsegf_get ( space_id_t  space,
page_no_t  page_no,
const page_size_t page_size,
mtr_t mtr 
)

Gets a rollback segment header.

Parameters
[in]spacespace where placed
[in]page_nopage number of the header
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
rollback segment header, page x-latched

◆ trx_rsegf_get_new()

UNIV_INLINE trx_rsegf_t* trx_rsegf_get_new ( space_id_t  space,
page_no_t  page_no,
const page_size_t page_size,
mtr_t mtr 
)

Gets a newly created rollback segment header.

Parameters
[in]spacespace where placed
[in]page_nopage number of the header
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
rollback segment header, page x-latched

◆ trx_rsegf_get_nth_undo()

UNIV_INLINE page_no_t trx_rsegf_get_nth_undo ( trx_rsegf_t rsegf,
ulint  n,
mtr_t mtr 
)

Gets the file page number of the nth undo log slot.

Parameters
[in]rsegfrollback segment header
[in]nindex of slot
[in]mtrmtr
Returns
page number of the undo log segment

◆ trx_rsegf_set_nth_undo()

UNIV_INLINE void trx_rsegf_set_nth_undo ( trx_rsegf_t rsegf,
ulint  n,
page_no_t  page_no,
mtr_t mtr 
)

Sets the file page number of the nth undo log slot.

Parameters
[in]rsegfrollback segment header
[in]nindex of slot
[in]page_nopage number of the undo log segment
[in]mtrmtr

◆ trx_rsegf_undo_find_free()

UNIV_INLINE ulint trx_rsegf_undo_find_free ( trx_rsegf_t rsegf,
mtr_t mtr 
)

Looks for a free slot for an undo log segment.

Parameters
[in]rsegfrollback segment header
[in]mtrmtr
Returns
slot index or ULINT_UNDEFINED if not found

◆ trx_rsegs_init()

void trx_rsegs_init ( purge_pq_t purge_queue)

Create the memory copies for rollback segments and initialize the rseg array in trx_sys at a database startup.

Parameters
[in]purge_queuequeue of rsegs to purge

Create the memory copies for rollback segments and initialize the rseg array in trx_sys at a database startup.

Create trx_rseg_t objects for all rollback segments found. This runs at database startup and initializes the in-memory lists of trx_rseg_t objects. We need to look at all slots in TRX_SYS and each RSEG_ARRAY page because we need to look for any existing undo log that may need to be recovered by purge. No latch is needed since this is still single-threaded startup. If we find existing rseg slots in TRX_SYS page that reference undo tablespaces and have active undo logs, then quit. They require an upgrade of undo tablespaces and that cannot happen with active undo logs.

Parameters
[in]purge_queuequeue of rsegs to purge

◆ trx_rsegsf_set_page_no()

UNIV_INLINE void trx_rsegsf_set_page_no ( trx_rsegsf_t rsegs_header,
ulint  slot,
page_no_t  page_no,
mtr_t mtr 
)

Sets the page number of the nth rollback segment slot in the independent undo tablespace.

Parameters
[in]rsegs_headerrollback segment array page header
[in]slotslot number on page == rseg id
[in]page_norollback regment header page number
[in]mtrmtr