MySQL 8.0.31
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)
 Number of undo log slots in a rollback segment file copy. More...
 
#define TRX_RSEG_MAX_N_TRXS   (TRX_RSEG_N_SLOTS / 2)
 Maximum number of transactions supported by a single rollback segment. More...
 
#define TRX_RSEG_SLOT_END    (TRX_RSEG_UNDO_SLOTS + TRX_RSEG_SLOT_SIZE * TRX_RSEG_N_SLOTS)
 End of undo slots in rollback segment page. More...
 
#define TRX_RSEG_MAX_TRX_NO   TRX_RSEG_SLOT_END
 

Functions

static 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...
 
static 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...
 
static 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...
 
static 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...
 
static 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)
 Read each rollback segment slot in the TRX_SYS page and the RSEG_ARRAY page of each undo tablespace. More...
 
void trx_rsegs_parallel_init (purge_pq_t *purge_queue)
 Initialize rollback segments in parallel. 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...
 
static 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...
 

Variables

constexpr uint32_t TRX_RSEG_SLOT_PAGE_NO = 0
 Page number of the header page of an undo log segment. More...
 
constexpr uint32_t TRX_RSEG_SLOT_SIZE = 4
 Slot size. More...
 
constexpr uint32_t TRX_RSEG = FSEG_PAGE_DATA
 The offset of the rollback segment header on its page. More...
 
constexpr uint32_t TRX_RSEG_MAX_SIZE = 0
 Maximum allowed size for rollback segment in pages. More...
 
constexpr uint32_t TRX_RSEG_HISTORY_SIZE = 4
 Number of file pages occupied by the logs in the history list. More...
 
constexpr uint32_t TRX_RSEG_HISTORY = 8
 
constexpr uint32_t TRX_RSEG_FSEG_HEADER = 8 + FLST_BASE_NODE_SIZE
 
constexpr uint32_t TRX_RSEG_UNDO_SLOTS
 Undo log segment slots. More...
 
constexpr uint32_t RSEG_ARRAY_HEADER = FSEG_PAGE_DATA
 The offset of the Rollback Segment Directory header on an RSEG_ARRAY page. More...
 
constexpr uint32_t RSEG_ARRAY_VERSION = 0x52534547 + 1
 Rollback Segment Array Header. More...
 
constexpr uint32_t RSEG_ARRAY_VERSION_OFFSET = 0
 The RSEG ARRAY version offset in the header. More...
 
constexpr uint32_t RSEG_ARRAY_SIZE_OFFSET = 4
 The current number of rollback segments being tracked in this array. More...
 
constexpr uint32_t RSEG_ARRAY_FSEG_HEADER_OFFSET = 8
 This is the pointer to the file segment inode that tracks this rseg array page. More...
 
constexpr uint32_t RSEG_ARRAY_PAGES_OFFSET = 8 + FSEG_HEADER_SIZE
 The start of the array of rollback segment header page numbers for this undo tablespace. More...
 
constexpr uint32_t RSEG_ARRAY_RESERVED_BYTES = 200
 Reserved space at the end of an RSEG_ARRAY page reserved for future use. More...
 
constexpr uint32_t RSEG_ARRAY_SLOT_SIZE = 4
 

Detailed Description

Rollback segment.

Created 3/26/1996 Heikki Tuuri

Macro Definition Documentation

◆ TRX_RSEG_MAX_N_TRXS

#define TRX_RSEG_MAX_N_TRXS   (TRX_RSEG_N_SLOTS / 2)

Maximum number of transactions supported by a single rollback segment.

◆ 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)

Number of undo log slots in a rollback segment file copy.

◆ TRX_RSEG_SLOT_END

#define TRX_RSEG_SLOT_END    (TRX_RSEG_UNDO_SLOTS + TRX_RSEG_SLOT_SIZE * TRX_RSEG_N_SLOTS)

End of undo slots in rollback segment page.

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

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()

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

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()

static 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 
)
inlinestatic

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()

static page_no_t trx_rsegf_get_nth_undo ( trx_rsegf_t rsegf,
ulint  n,
mtr_t mtr 
)
inlinestatic

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()

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

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()

static ulint trx_rsegf_undo_find_free ( trx_rsegf_t rsegf,
mtr_t mtr 
)
inlinestatic

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)

Read each rollback segment slot in the TRX_SYS page and the RSEG_ARRAY page of each undo tablespace.

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_rsegs_parallel_init()

void trx_rsegs_parallel_init ( purge_pq_t purge_queue)

Initialize rollback segments in parallel.

Parameters
[in]purge_queuequeue of rsegs to purge
Parameters
purge_queuein: rseg queue

◆ trx_rsegsf_set_page_no()

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

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

Variable Documentation

◆ RSEG_ARRAY_FSEG_HEADER_OFFSET

constexpr uint32_t RSEG_ARRAY_FSEG_HEADER_OFFSET = 8
constexpr

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

◆ RSEG_ARRAY_HEADER

constexpr uint32_t RSEG_ARRAY_HEADER = FSEG_PAGE_DATA
constexpr

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

◆ RSEG_ARRAY_PAGES_OFFSET

constexpr uint32_t RSEG_ARRAY_PAGES_OFFSET = 8 + FSEG_HEADER_SIZE
constexpr

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

constexpr uint32_t RSEG_ARRAY_RESERVED_BYTES = 200
constexpr

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

◆ RSEG_ARRAY_SIZE_OFFSET

constexpr uint32_t RSEG_ARRAY_SIZE_OFFSET = 4
constexpr

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

◆ RSEG_ARRAY_SLOT_SIZE

constexpr uint32_t RSEG_ARRAY_SLOT_SIZE = 4
constexpr

◆ RSEG_ARRAY_VERSION

constexpr uint32_t RSEG_ARRAY_VERSION = 0x52534547 + 1
constexpr

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

constexpr uint32_t RSEG_ARRAY_VERSION_OFFSET = 0
constexpr

The RSEG ARRAY version offset in the header.

◆ TRX_RSEG

constexpr uint32_t TRX_RSEG = FSEG_PAGE_DATA
constexpr

The offset of the rollback segment header on its page.

◆ TRX_RSEG_FSEG_HEADER

constexpr uint32_t TRX_RSEG_FSEG_HEADER = 8 + FLST_BASE_NODE_SIZE
constexpr

◆ TRX_RSEG_HISTORY

constexpr uint32_t TRX_RSEG_HISTORY = 8
constexpr

◆ TRX_RSEG_HISTORY_SIZE

constexpr uint32_t TRX_RSEG_HISTORY_SIZE = 4
constexpr

Number of file pages occupied by the logs in the history list.

◆ TRX_RSEG_MAX_SIZE

constexpr uint32_t TRX_RSEG_MAX_SIZE = 0
constexpr

Maximum allowed size for rollback segment in pages.

◆ TRX_RSEG_SLOT_PAGE_NO

constexpr uint32_t TRX_RSEG_SLOT_PAGE_NO = 0
constexpr

Page number of the header page of an undo log segment.

◆ TRX_RSEG_SLOT_SIZE

constexpr uint32_t TRX_RSEG_SLOT_SIZE = 4
constexpr

Slot size.

◆ TRX_RSEG_UNDO_SLOTS

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

Undo log segment slots.