MySQL 8.0.39
Source Code Documentation
trx0rseg.cc File Reference

Rollback segment. More...

#include "trx0rseg.h"
#include <stddef.h>
#include <algorithm>
#include "clone0clone.h"
#include "fsp0sysspace.h"
#include "fut0lst.h"
#include "log0chkp.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "trx0purge.h"
#include "trx0undo.h"

Functions

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...
 
void trx_rseg_mem_free (trx_rseg_t *rseg)
 Free an instance of the rollback segment in memory. More...
 
static void trx_rseg_persist_gtid (trx_rseg_t *rseg, trx_id_t gtid_trx_no)
 
static trx_rseg_ttrx_rseg_mem_initialize (ulint id, space_id_t space_id, page_no_t page_no, const page_size_t &page_size)
 
static trx_rseg_ttrx_rseg_physical_initialize (trx_rseg_t *rseg, purge_pq_t *purge_queue, trx_id_t gtid_trx_no, mtr_t *mtr)
 
page_no_t trx_rseg_get_page_no (space_id_t space_id, ulint rseg_id)
 Return a page number from a slot in the rseg_array page of an undo tablespace. More...
 
void trx_rseg_init_thread (void *arg, trx_id_t gtid_trx_no)
 Thread to 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...
 
void trx_rsegs_init_start (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_init_end ()
 
void trx_rsegs_parallel_init (purge_pq_t *purge_queue)
 Initialize rollback segments in parallel. 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...
 
page_no_t trx_rseg_create (space_id_t space_id, ulint rseg_id)
 Create a rollback segment in the given tablespace. More...
 
bool trx_rseg_add_rollback_segments (space_id_t space_id, ulong target_rsegs, Rsegs *rsegs, ulint *const n_total_created)
 This does two things to the target tablespace. 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_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. 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...
 

Variables

static std::atomic< uint32_t > active_rseg_init_threads {1}
 

Detailed Description

Rollback segment.

Created 3/26/1996 Heikki Tuuri

Function Documentation

◆ trx_rseg_add_rollback_segments()

bool trx_rseg_add_rollback_segments ( space_id_t  space_id,
ulong  target_rsegs,
Rsegs rsegs,
ulint *const  n_total_created 
)

This does two things to the target tablespace.

  1. Find or create (trx_rseg_create) the requested number of rollback segments.
  2. Make sure each rollback segment is tracked in memory (trx_rseg_mem_create). All existing rollback segments were found earlier in trx_rsegs_init(). This will add new ones if we need them according to target_rsegs.
    Parameters
    [in]space_idtablespace ID that should contain rollback segments
    [in]target_rsegstarget number of rollback segments per tablespace
    [in]rsegslist of rsegs to add to
    [in,out]n_total_createdA running total of rollback segment created in undo tablespaces
    Returns
    true if all rsegs are added, false if not.

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

page_no_t trx_rseg_get_page_no ( space_id_t  space_id,
ulint  rseg_id 
)

Return a page number from a slot in the rseg_array page of an undo tablespace.

Parameters
[in]space_idundo tablespace ID
[in]rseg_idrollback segment ID
Returns
page_no Page number of the rollback segment header page

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

void trx_rseg_init_thread ( void *  arg,
trx_id_t  gtid_trx_no 
)

Thread to initialize rollback segments in parallel.

Parameters
[in]argpurge queue
[in]gtid_trx_noGTID to be set in the rollback segment

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

void trx_rseg_mem_free ( trx_rseg_t rseg)

Free an instance of the rollback segment in memory.

Parameters
[in]rsegpointer to an rseg to free

◆ trx_rseg_mem_initialize()

static trx_rseg_t * trx_rseg_mem_initialize ( ulint  id,
space_id_t  space_id,
page_no_t  page_no,
const page_size_t page_size 
)
static

◆ trx_rseg_persist_gtid()

static void trx_rseg_persist_gtid ( trx_rseg_t rseg,
trx_id_t  gtid_trx_no 
)
static

◆ trx_rseg_physical_initialize()

static trx_rseg_t * trx_rseg_physical_initialize ( trx_rseg_t rseg,
purge_pq_t purge_queue,
trx_id_t  gtid_trx_no,
mtr_t mtr 
)
static

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

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

void trx_rsegs_init_end ( )

◆ trx_rsegs_init_start()

void trx_rsegs_init_start ( 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

Variable Documentation

◆ active_rseg_init_threads

std::atomic<uint32_t> active_rseg_init_threads {1}
static