MySQL  8.0.21
Source Code Documentation
undo Namespace Reference

Classes

class  Inject_failure_once
 Inject a failure in the undo truncation debug compiled code at various places so that it fails the first time it hits and succeeds after that. More...
 
struct  space_id_account
 The currently used undo space IDs for an undo space number along with a boolean showing whether the undo space number is in use. More...
 
struct  Tablespace
 An undo::Tablespace object is used to easily convert between undo_space_id and undo_space_num and to create the automatic file_name and space name. More...
 
class  Tablespaces
 List of undo tablespaces, each containing a list of rollback segments. More...
 
class  Truncate
 Track an UNDO tablespace marked for truncate. More...
 

Functions

bool is_reserved (space_id_t space_id)
 Check if the space_id is an undo space ID in the reserved range. More...
 
space_id_t num2id (space_id_t space_num, size_t ndx)
 Convert an undo space number (from 1 to 127) into the undo space_id, given an index indicating which space_id from the pool assigned to that undo number. More...
 
space_id_t num2id (space_id_t space_num)
 Convert an undo space number (from 1 to 127) into an undo space_id. More...
 
space_id_t id2num (space_id_t space_id)
 Convert an undo space ID into an undo space number. More...
 
space_id_t id2next_id (space_id_t space_id)
 
void init_space_id_bank ()
 Initialize the undo tablespace space_id bank which is a lock free repository for information about the space IDs used for undo tablespaces. More...
 
void use_space_id (space_id_t space_id)
 Note that the undo space number for a space ID is being used. More...
 
space_id_t use_next_space_id (space_id_t space_num)
 Mark that the given undo space number is being used and return the next available space_id for that space number. More...
 
void unuse_space_id (space_id_t space_id)
 Mark an undo number associated with a given space_id as unused and available to be resused. More...
 
space_id_t next_space_id (space_id_t space_id, space_id_t space_num)
 Given a valid undo space_id or SPACE_UNKNOWN, return the next space_id for the given space number. More...
 
space_id_t next_space_id (space_id_t space_id)
 Given a valid undo space_id, return the next space_id for that space number. More...
 
space_id_t get_next_available_space_num ()
 Return the next available undo space ID to be used for a new explicit undo tablespaces. More...
 
char * make_space_name (space_id_t space_id)
 Build a standard undo tablespace name from a space_id. More...
 
char * make_file_name (space_id_t space_id)
 Build a standard undo tablespace file name from a space_id. More...
 
void inject_crash (const char *injection_point_name)
 Inject a crash if a certain SET GLOBAL DEBUG has been set. More...
 
dberr_t start_logging (Tablespace *undo_space)
 Create the truncate log file. More...
 
void done_logging (space_id_t space_num)
 Mark completion of undo truncate action by writing magic number to the log file and then removing it from the disk. More...
 
bool is_active_truncate_log_present (space_id_t space_num)
 Check if TRUNCATE_DDL_LOG file exist. More...
 
void add_space_to_construction_list (space_id_t space_id)
 Add undo tablespace to s_under_construction vector. More...
 
void clear_construction_list ()
 Clear the s_under_construction vector. More...
 
bool is_under_construction (space_id_t space_id)
 Is an undo tablespace under constuction at the moment. More...
 
void set_active (space_id_t space_id)
 Set an undo tablespace active. More...
 
bool is_active (space_id_t space_id, bool get_latch=true)
 

Variables

const ib_uint32_t s_magic = 76845412
 Magic Number to indicate truncate action is complete. More...
 
const char *const s_log_prefix = "undo_"
 Truncate Log file Prefix. More...
 
const char *const s_log_ext = "trunc.log"
 Truncate Log file Extension. More...
 
struct space_id_accountspace_id_bank
 List of currently used undo space IDs for each undo space number along with a boolean showing whether the undo space number is in use. More...
 
ib_mutex_t ddl_mutex
 Mutext for serializing undo tablespace related DDL. More...
 
Tablespacesspaces
 A global object that contains a vector of undo::Tablespace structs. More...
 
Space_Ids s_under_construction
 list of undo tablespaces that need header pages and rollback segments written to them at startup. More...
 
constexpr ulint TRUNCATE_FREQUENCY = 128
 

Function Documentation

◆ add_space_to_construction_list()

void undo::add_space_to_construction_list ( space_id_t  space_id)

Add undo tablespace to s_under_construction vector.

Parameters
[in]space_idspace id of tablespace to truncate

◆ clear_construction_list()

void undo::clear_construction_list ( )

Clear the s_under_construction vector.

◆ done_logging()

void undo::done_logging ( space_id_t  space_num)

Mark completion of undo truncate action by writing magic number to the log file and then removing it from the disk.

If we are going to remove it from disk then why write magic number? This is to safeguard from unlink (file-system) anomalies that will keep the link to the file even after unlink action is successful and ref-count = 0.

Parameters
[in]space_numnumber of the undo tablespace to truncate.

If we are going to remove it from disk then why write magic number ? This is to safeguard from unlink (file-system) anomalies that will keep the link to the file even after unlink action is successful and ref-count = 0.

Parameters
[in]space_numnumber of the undo tablespace to truncate.

◆ get_next_available_space_num()

space_id_t undo::get_next_available_space_num ( )

Return the next available undo space ID to be used for a new explicit undo tablespaces.

Return the next available undo space number to be used for a new explicit undo tablespace.

Return values
ifsuccess, next available undo space number.
iffailure, SPACE_UNKNOWN

The slot will be marked as in-use.

Return values
ifsuccess, next available undo space number.
iffailure, SPACE_UNKNOWN

◆ id2next_id()

space_id_t undo::id2next_id ( space_id_t  space_id)
inline

◆ id2num()

space_id_t undo::id2num ( space_id_t  space_id)
inline

Convert an undo space ID into an undo space number.

NOTE: This may be an undo space_id from a pre-exisiting 5.7 database which used space_ids from 1 to 127. If so, the space_id is the space_num. The space_ids are assigned to number ranges in reverse from high to low. In addition, the first space IDs for each undo number occur sequentionally and descending before the second space_id.

Since s_max_undo_space_id = 0xFFFFFFEF, FSP_MAX_UNDO_TABLESPACES = 127 and undo_space_id_range = 512: Space ID Space Num Space ID Space Num ... Space ID Space Num 0xFFFFFFEF 1 0xFFFFFFEe 2 ... 0xFFFFFF71 127 0xFFFFFF70 1 0xFFFFFF6F 2 ... 0xFFFFFEF2 127 0xFFFFFEF1 1 0xFFFFFEF0 2 ... 0xFFFFFE73 127 ...

This is done to maintain backward compatibility to when there was only one space_id per undo space number.

Parameters
[in]space_idundo tablespace ID
Returns
space number of the undo tablespace

◆ init_space_id_bank()

void undo::init_space_id_bank ( )

Initialize the undo tablespace space_id bank which is a lock free repository for information about the space IDs used for undo tablespaces.

It is used during creation in order to assign an unused space number and during truncation in order to assign the next space_id within that space_number range.

It is used during creation in order to assign an unused space number and during truncation in order to assign the next space_id within that space_number range. It is initialized with the minimum value in the range so that if a new space ID is needed in that range the max space ID will be used first. As truncation occurs, the space_ids are assigned from max down to min.

◆ inject_crash()

void undo::inject_crash ( const char *  injection_point_name)

Inject a crash if a certain SET GLOBAL DEBUG has been set.

Before DBUG_SUICIDE(), write an entry about this crash to the error log and flush the redo log.

◆ is_active()

bool undo::is_active ( space_id_t  space_id,
bool  get_latch = true 
)

◆ is_active_truncate_log_present()

bool undo::is_active_truncate_log_present ( space_id_t  space_num)

Check if TRUNCATE_DDL_LOG file exist.

Parameters
[in]space_numundo tablespace number
Returns
true if exist else false.

◆ is_reserved()

bool undo::is_reserved ( space_id_t  space_id)
inline

Check if the space_id is an undo space ID in the reserved range.

Parameters
[in]space_idundo tablespace ID
Returns
true if it is in the reserved undo space ID range.

◆ is_under_construction()

bool undo::is_under_construction ( space_id_t  space_id)

Is an undo tablespace under constuction at the moment.

Parameters
[in]space_idspace id to check
Returns
true if marked for truncate, else false.

◆ make_file_name()

char * undo::make_file_name ( space_id_t  space_id)

Build a standard undo tablespace file name from a space_id.

Parameters
[in]space_idid of the undo tablespace.
Returns
file_name of the undo tablespace file

This will create a name like 'undo_001' if the space_id is in the reserved range, else it will be like 'undo001'.

Parameters
[in]space_idid of the undo tablespace.
Returns
file_name of the undo tablespace file

◆ make_space_name()

char * undo::make_space_name ( space_id_t  space_id)

Build a standard undo tablespace name from a space_id.

Parameters
[in]space_idid of the undo tablespace.
Returns
tablespace name of the undo tablespace file

◆ next_space_id() [1/2]

space_id_t undo::next_space_id ( space_id_t  space_id,
space_id_t  space_num 
)

Given a valid undo space_id or SPACE_UNKNOWN, return the next space_id for the given space number.

Parameters
[in]space_idundo tablespace ID
[in]space_numundo tablespace number
Returns
the next tablespace ID to use

◆ next_space_id() [2/2]

space_id_t undo::next_space_id ( space_id_t  space_id)

Given a valid undo space_id, return the next space_id for that space number.

Parameters
[in]space_idundo tablespace ID
Returns
the next tablespace ID to use

◆ num2id() [1/2]

space_id_t undo::num2id ( space_id_t  space_num,
size_t  ndx 
)
inline

Convert an undo space number (from 1 to 127) into the undo space_id, given an index indicating which space_id from the pool assigned to that undo number.

Parameters
[in]space_numundo tablespace number
[in]ndxindex of the space_id within that undo number
Returns
space_id of the undo tablespace

◆ num2id() [2/2]

space_id_t undo::num2id ( space_id_t  space_num)
inline

Convert an undo space number (from 1 to 127) into an undo space_id.

Use the undo::space_id_bank to return the curent space_id assigned to that undo number.

Parameters
[in]space_numundo tablespace number
Returns
space_id of the undo tablespace

◆ set_active()

void undo::set_active ( space_id_t  space_id)

Set an undo tablespace active.

◆ start_logging()

dberr_t undo::start_logging ( Tablespace undo_space)

Create the truncate log file.

Needed to track the state of truncate during a crash. An auxiliary redo log file undo_<space_id>_trunc.log will be created while the truncate of the UNDO is in progress. This file is required during recovery to complete the truncate.

Parameters
[in]undo_spaceundo tablespace to truncate.
Returns
DB_SUCCESS or error code.

◆ unuse_space_id()

void undo::unuse_space_id ( space_id_t  space_id)

Mark an undo number associated with a given space_id as unused and available to be resused.

This happens when the fil_space_t is closed associated with a drop undo tablespace.

Parameters
[in]space_idUndo Tablespace ID

◆ use_next_space_id()

space_id_t undo::use_next_space_id ( space_id_t  space_num)

Mark that the given undo space number is being used and return the next available space_id for that space number.

Parameters
[in]space_numundo tablespace number
Returns
the next tablespace ID to use

◆ use_space_id()

void undo::use_space_id ( space_id_t  space_id)

Note that the undo space number for a space ID is being used.

Put that space_id into the space_id_bank.

Parameters
[in]space_idundo tablespace number

Variable Documentation

◆ ddl_mutex

ib_mutex_t undo::ddl_mutex

Mutext for serializing undo tablespace related DDL.

These have to do with creating and dropping undo tablespaces.

◆ s_log_ext

const char* const undo::s_log_ext = "trunc.log"

Truncate Log file Extension.

◆ s_log_prefix

const char* const undo::s_log_prefix = "undo_"

Truncate Log file Prefix.

◆ s_magic

const ib_uint32_t undo::s_magic = 76845412

Magic Number to indicate truncate action is complete.

◆ s_under_construction

Space_Ids undo::s_under_construction

list of undo tablespaces that need header pages and rollback segments written to them at startup.

This can be because they are newly initialized, were being truncated and the system crashed, or they were an old format at startup and were replaced when they were opened. Old format undo tablespaces do not have space_ids between dict_sys_t::s_min_undo_space_id and dict_sys_t::s_max_undo_space_id and they do not contain an RSEG_ARRAY page.

◆ space_id_bank

struct space_id_account * undo::space_id_bank

List of currently used undo space IDs for each undo space number along with a boolean showing whether the undo space number is in use.

◆ spaces

Tablespaces * undo::spaces

A global object that contains a vector of undo::Tablespace structs.

◆ TRUNCATE_FREQUENCY

constexpr ulint undo::TRUNCATE_FREQUENCY = 128