MySQL 8.0.39
Source Code Documentation
fsp0fsp.h File Reference

File space management. More...

#include "univ.i"
#include "fsp0space.h"
#include "fut0lst.h"
#include "mtr0mtr.h"
#include "mysql/components/services/bits/mysql_cond_bits.h"
#include "mysql/components/services/bits/mysql_mutex_bits.h"
#include "page0types.h"
#include "rem0types.h"
#include "ut0byte.h"
#include <random>
#include "fsp0types.h"
#include "fsp0fsp.ic"

Go to the source code of this file.

Classes

struct  xdes_mem_t
 
struct  fsp_header_mem_t
 In-memory representation of the fsp_header_t file structure. More...
 
class  File_segment_inode
 A wrapper class to operate on a file segment inode pointer (fseg_inode_t*) More...
 

Macros

#define FSEG_FRAG_ARR_N_SLOTS   (FSP_EXTENT_SIZE / 2)
 
#define FSEG_INODE_SIZE    (16 + 3 * FLST_BASE_NODE_SIZE + FSEG_FRAG_ARR_N_SLOTS * FSEG_FRAG_SLOT_SIZE)
 
#define FSEG_FRAG_LIMIT   FSEG_FRAG_ARR_N_SLOTS
 
#define XDES_SIZE    (XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE))
 File extent data structure size in bytes. More...
 
#define XDES_SIZE_MAX    (XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MAX * XDES_BITS_PER_PAGE))
 File extent data structure size in bytes for MAX page size. More...
 
#define XDES_SIZE_MIN    (XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MIN * XDES_BITS_PER_PAGE))
 File extent data structure size in bytes for MIN page size. More...
 

Typedefs

typedef byte fsp_header_t
 
typedef byte xdes_t
 
typedef byte fseg_inode_t
 

Enumerations

enum  xdes_state_t {
  XDES_NOT_INITED = 0 , XDES_FREE = 1 , XDES_FREE_FRAG = 2 , XDES_FULL_FRAG = 3 ,
  XDES_FSEG = 4 , XDES_FSEG_FRAG = 5
}
 States of a descriptor. More...
 

Functions

bool xdes_state_is_valid (ulint state)
 Check if the state of extent descriptor is valid. More...
 
std::ostream & operator<< (std::ostream &out, const xdes_mem_t &obj)
 
std::ostream & operator<< (std::ostream &out, const fsp_header_mem_t &obj)
 
static uint32_t FSP_SEG_INODES_PER_PAGE (page_size_t page_size)
 
void fsp_init (void)
 Initializes the file space system. More...
 
page_no_t fsp_header_get_tablespace_size (void)
 Gets the size of the system tablespace from the tablespace header. More...
 
page_no_t fsp_get_pages_to_extend_ibd (const page_size_t &page_size, page_no_t size)
 Calculate the number of pages to extend a datafile. More...
 
static page_no_t fsp_get_extent_size_in_pages (const page_size_t &page_size)
 Calculate the number of physical pages in an extent for this file. More...
 
space_id_t fsp_header_get_space_id (const page_t *page)
 Reads the space id from the first page of a tablespace. More...
 
bool fsp_header_dict_get_server_version (uint *version)
 Read the server version number from the DD tablespace header. More...
 
uint32_t fsp_header_get_field (const page_t *page, uint32_t field)
 Read a tablespace header field. More...
 
void fsp_header_set_field (page_t *page, uint32_t field, uint32_t val)
 Update a tablespace header field. More...
 
uint32_t fsp_header_get_flags (const page_t *page)
 Read the flags from the tablespace header page. More...
 
page_size_t fsp_header_get_page_size (const page_t *page)
 Reads the page size from the first page of a tablespace. More...
 
bool fsp_header_get_encryption_key (uint32_t fsp_flags, Encryption_key &e_key, page_t *page)
 Reads the encryption key from the first page of a tablespace. More...
 
Encryption::Progress fsp_header_encryption_op_type_in_progress (const page_t *page, page_size_t page_size)
 Get encryption operation type in progress from the first page of a tablespace. More...
 
bool fsp_check_tablespace_size (space_id_t space_id)
 Check if the tablespace size information is valid. More...
 
void fsp_header_init_fields (page_t *page, space_id_t space_id, uint32_t flags)
 Writes the space id and flags to a tablespace header. More...
 
ulint fsp_header_get_encryption_offset (const page_size_t &page_size)
 Get the offset of encryption information in page 0. More...
 
bool fsp_header_write_encryption (space_id_t space_id, uint32_t space_flags, byte *encrypt_info, bool update_fsp_flags, bool rotate_encryption, mtr_t *mtr)
 Write the encryption info into the space header. More...
 
bool fsp_header_write_encryption_progress (space_id_t space_id, ulint space_flags, ulint progress_info, byte operation_type, bool update_operation_type, mtr_t *mtr)
 Write the encryption progress info into the space header. More...
 
bool fsp_header_rotate_encryption (fil_space_t *space, byte *encrypt_info, mtr_t *mtr)
 Rotate the encryption info in the space header. More...
 
bool fsp_header_init (space_id_t space_id, page_no_t size, mtr_t *mtr)
 Initializes the space header of a new created space and creates also the insert buffer tree root if space == 0. More...
 
void fsp_header_inc_size (space_id_t space_id, page_no_t size_inc, mtr_t *mtr)
 Increases the space size field of a space. More...
 
buf_block_tfseg_create (space_id_t space, page_no_t page, ulint byte_offset, mtr_t *mtr)
 Creates a new segment. More...
 
buf_block_tfseg_create_general (space_id_t space_id, page_no_t page, ulint byte_offset, bool has_done_reservation, mtr_t *mtr)
 Creates a new segment. More...
 
ulint fseg_n_reserved_pages (fseg_header_t *header, ulint *used, mtr_t *mtr)
 Calculates the number of pages reserved by a segment, and how many pages are currently used. More...
 
buf_block_tfseg_alloc_free_page_general (fseg_header_t *seg_header, page_no_t hint, byte direction, bool has_done_reservation, mtr_t *mtr, mtr_t *init_mtr)
 Allocates a single free page from a segment. More...
 
static buf_block_tfseg_alloc_free_page (fseg_header_t *seg_header, page_no_t hint, byte direction, mtr_t *mtr)
 Allocates a single free page from a segment. More...
 
bool fsp_reserve_free_extents (ulint *n_reserved, space_id_t space_id, ulint n_ext, fsp_reserve_t alloc_type, mtr_t *mtr, page_no_t n_pages=2)
 Reserves free pages from a tablespace. More...
 
uintmax_t fsp_get_available_space_in_free_extents (space_id_t space_id)
 Calculate how many KiB of new data we will be able to insert to the tablespace without running out of space. More...
 
uintmax_t fsp_get_available_space_in_free_extents (const fil_space_t *space)
 Calculate how many KiB of new data we will be able to insert to the tablespace without running out of space. More...
 
void fseg_free_page (fseg_header_t *seg_header, space_id_t space_id, page_no_t page, bool ahi, mtr_t *mtr)
 Frees a single page of a segment. More...
 
bool fseg_page_is_free (fseg_header_t *seg_header, space_id_t space_id, page_no_t page)
 Checks if a single page of a segment is free. More...
 
bool fseg_free_step (fseg_header_t *header, bool ahi, mtr_t *mtr)
 Frees part of a segment. More...
 
bool fseg_free_step_not_header (fseg_header_t *header, bool ahi, mtr_t *mtr)
 Frees part of a segment. More...
 
static bool fsp_descr_page (const page_id_t &page_id, const page_size_t &page_size)
 Checks if a page address is an extent descriptor page address. More...
 
bytefsp_parse_init_file_page (byte *ptr, byte *end_ptr, buf_block_t *block)
 Parses a redo log record of a file page init. More...
 
bool fsp_is_undo_tablespace (space_id_t space_id)
 Check whether a space id is an undo tablespace ID Undo tablespaces have space_id's starting 1 less than the redo logs. More...
 
static bool fsp_is_system_tablespace (space_id_t space_id)
 
static bool fsp_is_system_or_temp_tablespace (space_id_t space_id)
 Check if the space_id is for a system-tablespace (shared + temp). More...
 
static bool fsp_is_ibd_tablespace (space_id_t space_id)
 Determine if the space ID is an IBD tablespace, either file_per_table or a general shared tablespace, where user tables exist. More...
 
static bool fsp_is_file_per_table (space_id_t space_id, uint32_t fsp_flags)
 Check if tablespace is file-per-table. More...
 
bool fsp_is_dd_tablespace (space_id_t space_id)
 Check if tablespace is dd tablespace. More...
 
static bool fsp_flags_is_compressed (uint32_t flags)
 Determine if the tablespace is compressed from tablespace flags. More...
 
static bool fsp_flags_are_equal (uint32_t flags1, uint32_t flags2)
 Determine if two tablespaces are equivalent or compatible. More...
 
static uint32_t fsp_flags_init (const page_size_t &page_size, bool atomic_blobs, bool has_data_dir, bool is_shared, bool is_temporary, bool is_encrypted=false)
 Initialize an FSP flags integer. More...
 
uint32_t fsp_flags_to_dict_tf (uint32_t fsp_flags, bool compact)
 Convert a 32 bit integer tablespace flags to the 32 bit table flags. More...
 
static ulint xdes_calc_descriptor_index (const page_size_t &page_size, ulint offset)
 Calculates the descriptor index within a descriptor page. More...
 
static bool xdes_get_bit (const xdes_t *descr, ulint bit, page_no_t offset)
 Gets a descriptor bit of a page. More...
 
static page_no_t xdes_calc_descriptor_page (const page_size_t &page_size, page_no_t offset)
 Calculates the page where the descriptor of a page resides. More...
 
fsp_header_tfsp_get_space_header_block (space_id_t id, const page_size_t &page_size, mtr_t *mtr, buf_block_t **block)
 Gets a pointer to the space header and acquires a SX lock on the page. More...
 
fsp_header_tfsp_get_space_header (space_id_t id, const page_size_t &page_size, mtr_t *mtr)
 Gets a pointer to the space header and acquires a SX lock on the page. More...
 
page_no_t fsp_sdi_get_root_page_num (space_id_t space, const page_size_t &page_size, mtr_t *mtr)
 Retrieve tablespace dictionary index root page number stored in the page 0. More...
 
void fsp_sdi_write_root_to_page (page_t *page, const page_size_t &page_size, page_no_t root_page_num, mtr_t *mtr)
 Write SDI Index root page num to page 0 of tablespace. More...
 
uint32_t fsp_header_get_server_version (const page_t *page)
 Reads the server version from the first page of a tablespace. More...
 
uint32_t fsp_header_get_space_version (const page_t *page)
 Reads the server space version from the first page of a tablespace. More...
 
xdes_state_t xdes_get_state (const xdes_t *descr, mtr_t *mtr)
 Get the state of an xdes. More...
 
std::ostream & xdes_page_print (std::ostream &out, const page_t *xdes, page_no_t page_no, mtr_t *mtr)
 Print the extent descriptor page in user-friendly format. More...
 
void fsp_header_size_update (fsp_header_t *header, ulint size, mtr_t *mtr)
 Update the tablespace size information and generate redo log for it. More...
 
bool fsp_is_inode_page (page_no_t page)
 Check if a specified page is inode page or not. More...
 
ulint fsp_header_get_sdi_offset (const page_size_t &page_size)
 Get the offset of SDI root page number in page 0. More...
 
ulint fsp_header_get_encryption_progress_offset (const page_size_t &page_size)
 Get the offset of encryption progress information in page 0. More...
 
dberr_t fsp_has_sdi (space_id_t space_id)
 Determine if the tablespace has SDI. More...
 
dberr_t fsp_alter_encrypt_tablespace (THD *thd, space_id_t space_id, bool to_encrypt, void *dd_space_in)
 Encrypt/Unencrypt a tablespace. More...
 
void fsp_init_resume_alter_encrypt_tablespace ()
 Initiate roll-forward of alter encrypt in background thread. More...
 
std::ostream & operator<< (std::ostream &out, const File_segment_inode &obj)
 The global output stream operator is overloaded to work with an object of type File_segment_inode. More...
 
fseg_inode_tfseg_inode_get (const fseg_header_t *header, space_id_t space, const page_size_t &page_size, mtr_t *mtr, buf_block_t **block=nullptr)
 Returns the file segment inode, page x-latched. More...
 

Variables

std::vector< DDL_Record * > ts_encrypt_ddl_records
 DDL records for tablespace (un)encryption. More...
 
mysql_cond_t resume_encryption_cond
 
mysql_mutex_t resume_encryption_cond_m
 
std::vector< space_id_tflag_mismatch_spaces
 
constexpr uint32_t FSP_HEADER_OFFSET = FIL_PAGE_DATA
 Offset of the space header within a file page. More...
 
constexpr uint32_t FSP_SDI_HEADER_LEN = 8
 The number of bytes required to store SDI root page number(4) and SDI version(4) at Page 0. More...
 
constexpr uint32_t FSP_SPACE_ID = 0
 space id More...
 
constexpr uint32_t FSP_NOT_USED = 4
 this field contained a value up to which we know that the modifications in the database have been flushed to the file space; not used now More...
 
constexpr uint32_t FSP_SIZE = 8
 Current size of the space in pages. More...
 
constexpr uint32_t FSP_FREE_LIMIT = 12
 Minimum page number for which the free list has not been initialized: the pages >= this limit are, bydefinition, free; note that in a single-table tablespace where size < 64 pages, this number is 64, i.e.,we have initialized the space about the first extent, but have not physically allocated those pages to thefile. More...
 
constexpr uint32_t FSP_SPACE_FLAGS = 16
 fsp_space_t.flags, similar to dict_table_t::flags More...
 
constexpr uint32_t FSP_FRAG_N_USED = 20
 number of used pages in the FSP_FREE_FRAG list More...
 
constexpr uint32_t FSP_FREE = 24
 list of free extents More...
 
constexpr uint32_t FSP_FREE_FRAG = 24 + FLST_BASE_NODE_SIZE
 list of partially free extents not belonging to any segment More...
 
constexpr uint32_t FSP_FULL_FRAG = 24 + 2 * FLST_BASE_NODE_SIZE
 list of full extents not belonging to any segment More...
 
constexpr uint32_t FSP_SEG_ID = 24 + 3 * FLST_BASE_NODE_SIZE
 8 bytes which give the first unused segment id More...
 
constexpr uint32_t FSP_SEG_INODES_FULL = 32 + 3 * FLST_BASE_NODE_SIZE
 list of pages containing segment headers, where all the segment inode slots are reserved More...
 
constexpr uint32_t FSP_SEG_INODES_FREE = 32 + 4 * FLST_BASE_NODE_SIZE
 list of pages containing segment headers, where not all the segment header slots are reserved More...
 
constexpr uint32_t FSP_HEADER_SIZE = 32 + 5 * FLST_BASE_NODE_SIZE
 
constexpr uint32_t FSP_FREE_ADD = 4
 This many free extents are added to the free list from above FSP_FREE_LIMIT at a time. More...
 
constexpr uint64_t FSP_MAX_AUTOEXTEND_SIZE = 4 * 1024 * 1024 * 1024ULL
 
constexpr uint32_t FSEG_INODE_PAGE_NODE = FSEG_PAGE_DATA
 
constexpr uint32_t FSEG_ARR_OFFSET = FSEG_PAGE_DATA + FLST_NODE_SIZE
 
constexpr uint32_t FSEG_ID = 0
 
constexpr uint32_t FSEG_NOT_FULL_N_USED = 8
 number of used segment pages in the FSEG_NOT_FULL list More...
 
constexpr uint32_t FSEG_FREE = 12
 list of free extents of this segment More...
 
constexpr uint32_t FSEG_NOT_FULL = 12 + FLST_BASE_NODE_SIZE
 list of partially free extents More...
 
constexpr uint32_t FSEG_FULL = 12 + 2 * FLST_BASE_NODE_SIZE
 list of full extents More...
 
constexpr uint32_t FSEG_MAGIC_N = 12 + 3 * FLST_BASE_NODE_SIZE
 magic number used in debugging More...
 
constexpr uint32_t FSEG_FRAG_ARR = 16 + 3 * FLST_BASE_NODE_SIZE
 array of individual pages belonging to this segment in fsp fragment extent lists More...
 
constexpr uint32_t FSEG_FRAG_SLOT_SIZE = 4
 a fragment page slot contains its page number within space, FIL_NULL means that the slot is not in use More...
 
constexpr uint32_t FSEG_MAGIC_N_VALUE = 97937874
 
double fseg_reserve_pct
 The segment_reserve_factor is the ratio x/y expressed in percentage, where x is the number of free pages in the segment, and y is the total number of pages in the segment. More...
 
constexpr double FSEG_RESERVE_PCT_DFLT = 12.50
 
constexpr double FSEG_RESERVE_PCT_MIN = 0.03
 
constexpr double FSEG_RESERVE_PCT_MAX = 40.00
 
constexpr uint32_t FSEG_FREE_LIST_LIMIT = 40
 If the reserved size of a segment is at least this many extents, we allow extents to be put to the free list of the extent: at most FSEG_FREE_LIST_MAX_LEN many. More...
 
constexpr uint32_t FSEG_FREE_LIST_MAX_LEN = 4
 
constexpr uint32_t XDES_ID = 0
 The identifier of the segment to which this extent belongs. More...
 
constexpr uint32_t XDES_FLST_NODE = 8
 The list node data structure for the descriptors. More...
 
constexpr uint32_t XDES_STATE = FLST_NODE_SIZE + 8
 contains state information of the extent More...
 
constexpr uint32_t XDES_BITMAP = FLST_NODE_SIZE + 12
 Descriptor bitmap of the pages in the extent. More...
 
constexpr uint32_t XDES_BITS_PER_PAGE = 2
 How many bits are there per page. More...
 
constexpr uint32_t XDES_FREE_BIT = 0
 Index of the bit which tells if the page is free. More...
 
constexpr uint32_t XDES_CLEAN_BIT = 1
 NOTE: currently not used! Index of the bit which tells if there are old versions of tuples on the page. More...
 
constexpr uint32_t XDES_ARR_OFFSET = FSP_HEADER_OFFSET + FSP_HEADER_SIZE
 Offset of the descriptor array on a descriptor page. More...
 
const ulint XDES_FRAG_N_USED = 2
 The number of reserved pages in a fragment extent. More...
 

Detailed Description

File space management.

Created 12/18/1995 Heikki Tuuri

Function Documentation

◆ fseg_alloc_free_page()

static buf_block_t * fseg_alloc_free_page ( fseg_header_t seg_header,
page_no_t  hint,
byte  direction,
mtr_t mtr 
)
inlinestatic

Allocates a single free page from a segment.

This function implements the intelligent allocation strategy which tries to minimize file space fragmentation.

Parameters
[in,out]seg_headerSegment header
[in]hintHint of which page would be desirable
[in]directionIf the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: FSP_DOWN, FSP_UP, FSP_NO_DIR
[in,out]mtrMini-transaction
Returns
X-latched block, or NULL if no page could be allocated

◆ fseg_alloc_free_page_general()

buf_block_t * fseg_alloc_free_page_general ( fseg_header_t seg_header,
page_no_t  hint,
byte  direction,
bool  has_done_reservation,
mtr_t mtr,
mtr_t init_mtr 
)

Allocates a single free page from a segment.

This function implements the intelligent allocation strategy which tries to minimize file space fragmentation.

Parameters
[in,out]seg_headerSegment header
[in]hintHint of which page would be desirable
[in,out]directionIf the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: fsp_down, fsp_up, fsp_no_dir
[in]has_done_reservationTrue if the caller has already done the reservation for the page with fsp_reserve_free_extents, then there is no need to do the check for this individual page
[in,out]mtrMini-transaction
[in,out]init_mtrmtr or another mini-transaction in which the page should be initialized. if init_mtr!=mtr, but the page is already latched in mtr, do not initialize the page.
Return values
NULLif no page could be allocated
block,rw_lock_x_lock_count(&block->lock)== 1 if allocation succeeded (init_mtr == mtr, or the page was not previously freed in mtr), returned block is not allocated nor initialized otherwise

◆ fseg_create()

buf_block_t * fseg_create ( space_id_t  space,
page_no_t  page,
ulint  byte_offset,
mtr_t mtr 
)

Creates a new segment.

Returns
the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space in/out: mini-transaction
the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space
Parameters
spacein: space id
pagein: page where the segment header is placed: if this is != 0, the page must belong to another segment, if this is 0, a new page will be allocated and it will belong to the created segment
byte_offsetin: byte offset of the created segment header on the page
mtrin/out: mini-transaction

◆ fseg_create_general()

buf_block_t * fseg_create_general ( space_id_t  space_id,
page_no_t  page,
ulint  byte_offset,
bool  has_done_reservation,
mtr_t mtr 
)

Creates a new segment.

Parameters
[in]space_idSpace id
[in,out]pagePage where the segment header is placed: if this is != 0, the page must belong to another segment, if this is 0, a new page will be allocated and it will belong to the created segment
[in]byte_offsetByte offset of the created segment header on the page
[in,out]has_done_reservationTrue if the caller has already done the reservation for the pages with fsp_reserve_free_extents (at least 2 extents: one for the inode and the other for the segment) then there is no need to do the check for this individual operation
[in,out]mtrMini-transaction
Returns
the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space
the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space
Parameters
space_idin: space id
pagein: page where the segment header is placed: if this is != 0, the page must belong to another segment, if this is 0, a new page will be allocated and it will belong to the created segment
byte_offsetin: byte offset of the created segment header on the page
has_done_reservationin: true if the caller has already done the reservation for the pages with fsp_reserve_free_extents (at least 2 extents: one for the inode and the other for the segment) then there is no need to do the check for this individual operation
mtrin/out: mini-transaction

◆ fseg_free_page()

void fseg_free_page ( fseg_header_t seg_header,
space_id_t  space_id,
page_no_t  page,
bool  ahi,
mtr_t mtr 
)

Frees a single page of a segment.

Parameters
[in]seg_headerSegment header
[in]space_idSpace id
[in]pagePage offset
[in]ahiWhether we may need to drop the adaptive hash index
[in,out]mtrMini-transaction

◆ fseg_free_step()

bool fseg_free_step ( fseg_header_t header,
bool  ahi,
mtr_t mtr 
)

Frees part of a segment.

This function can be used to free a segment by repeatedly calling this function in different mini-transactions. Doing the freeing in a single mini-transaction might result in too big a mini-transaction.

Returns
true if freeing completed in/out: mini-transaction

This function can be used to free a segment by repeatedly calling this function in different mini-transactions. Doing the freeing in a single mini-transaction might result in too big a mini-transaction.

Returns
true if freeing completed
Parameters
headerin, own: segment header; NOTE: if the header resides on the first page of the frag list of the segment, this pointer becomes obsolete after the last freeing step
ahiin: whether we may need to drop the adaptive hash index
mtrin/out: mini-transaction

◆ fseg_free_step_not_header()

bool fseg_free_step_not_header ( fseg_header_t header,
bool  ahi,
mtr_t mtr 
)

Frees part of a segment.

Differs from fseg_free_step because this function leaves the header page unfreed.

Returns
true if freeing completed, except the header page in/out: mini-transaction

Differs from fseg_free_step because this function leaves the header page unfreed.

Returns
true if freeing completed, except the header page
Parameters
headerin: segment header which must reside on the first fragment page of the segment
ahiin: whether we may need to drop the adaptive hash index
mtrin/out: mini-transaction

◆ fseg_inode_get()

fseg_inode_t * fseg_inode_get ( const fseg_header_t header,
space_id_t  space,
const page_size_t page_size,
mtr_t mtr,
buf_block_t **  block = nullptr 
)

Returns the file segment inode, page x-latched.

Parameters
[in]headerSegment header
[in]spaceSpace id
[in]page_sizePage size
[in,out]mtrMini-transaction
[out]blockInode block
Returns
segment inode, page x-latched

◆ fseg_n_reserved_pages()

ulint fseg_n_reserved_pages ( fseg_header_t header,
ulint used,
mtr_t mtr 
)

Calculates the number of pages reserved by a segment, and how many pages are currently used.

Returns
number of reserved pages in/out: mini-transaction
number of reserved pages
Parameters
headerin: segment header
usedout: number of pages used (<= reserved)
mtrin/out: mini-transaction

◆ fseg_page_is_free()

bool fseg_page_is_free ( fseg_header_t seg_header,
space_id_t  space_id,
page_no_t  page 
)

Checks if a single page of a segment is free.

Returns
true if free in: page offset
true if free
Parameters
seg_headerin: segment header
space_idin: space id
pagein: page offset

◆ fsp_alter_encrypt_tablespace()

dberr_t fsp_alter_encrypt_tablespace ( THD thd,
space_id_t  space_id,
bool  to_encrypt,
void *  dd_space_in 
)

Encrypt/Unencrypt a tablespace.

Parameters
[in]thdcurrent thread
[in]space_idTablespace id
[in]to_encrypttrue if to encrypt, false if to decrypt
[in,out]dd_space_indd tablespace object
Returns
0 for success, otherwise error code

◆ fsp_check_tablespace_size()

bool fsp_check_tablespace_size ( space_id_t  space_id)

Check if the tablespace size information is valid.

Parameters
[in]space_idthe tablespace identifier
Returns
true if valid, false if invalid.

◆ fsp_descr_page()

static bool fsp_descr_page ( const page_id_t page_id,
const page_size_t page_size 
)
inlinestatic

Checks if a page address is an extent descriptor page address.

Parameters
[in]page_idpage id
[in]page_sizepage size
Returns
true if a descriptor page

◆ fsp_flags_are_equal()

static bool fsp_flags_are_equal ( uint32_t  flags1,
uint32_t  flags2 
)
inlinestatic

Determine if two tablespaces are equivalent or compatible.

Parameters
[in]flags1First tablespace flags
[in]flags2Second tablespace flags
Returns
true the flags are compatible, false if not

◆ fsp_flags_init()

static uint32_t fsp_flags_init ( const page_size_t page_size,
bool  atomic_blobs,
bool  has_data_dir,
bool  is_shared,
bool  is_temporary,
bool  is_encrypted = false 
)
inlinestatic

Initialize an FSP flags integer.

Parameters
[in]page_sizepage sizes in bytes and compression flag.
[in]atomic_blobsUsed by Dynamic and Compressed.
[in]has_data_dirThis tablespace is in a remote location.
[in]is_sharedThis tablespace can be shared by many tables.
[in]is_temporaryThis tablespace is temporary.
[in]is_encryptedThis tablespace is encrypted.
Returns
tablespace flags after initialization

◆ fsp_flags_is_compressed()

static bool fsp_flags_is_compressed ( uint32_t  flags)
inlinestatic

Determine if the tablespace is compressed from tablespace flags.

Parameters
[in]flagsTablespace flags
Returns
true if compressed, false if not compressed

◆ fsp_flags_to_dict_tf()

uint32_t fsp_flags_to_dict_tf ( uint32_t  fsp_flags,
bool  compact 
)

Convert a 32 bit integer tablespace flags to the 32 bit table flags.

This can only be done for a tablespace that was built as a file-per-table tablespace. Note that the fsp_flags cannot show the difference between a Compact and Redundant table, so an extra Compact boolean must be supplied. Low order bit | REDUNDANT | COMPACT | COMPRESSED | DYNAMIC fil_space_t::flags | 0 | 0 | 1 | 1 dict_table_t::flags | 0 | 1 | 1 | 1

Parameters
[in]fsp_flagsfil_space_t::flags
[in]compacttrue if not Redundant row format
Returns
tablespace flags (fil_space_t::flags)

◆ fsp_get_available_space_in_free_extents() [1/2]

uintmax_t fsp_get_available_space_in_free_extents ( const fil_space_t space)

Calculate how many KiB of new data we will be able to insert to the tablespace without running out of space.

Start with a space object that has been acquired by the caller who holds it for the calculation,

Parameters
[in]spacetablespace object from fil_space_acquire()
Returns
available space in KiB

◆ fsp_get_available_space_in_free_extents() [2/2]

uintmax_t fsp_get_available_space_in_free_extents ( space_id_t  space_id)

Calculate how many KiB of new data we will be able to insert to the tablespace without running out of space.

Parameters
[in]space_idtablespace ID
Returns
available space in KiB
Return values
UINTMAX_MAXif unknown

◆ fsp_get_extent_size_in_pages()

static page_no_t fsp_get_extent_size_in_pages ( const page_size_t page_size)
inlinestatic

Calculate the number of physical pages in an extent for this file.

Parameters
[in]page_sizepage_size of the datafile
Returns
number of pages in an extent for this file.

◆ fsp_get_pages_to_extend_ibd()

page_no_t fsp_get_pages_to_extend_ibd ( const page_size_t page_size,
page_no_t  size 
)

Calculate the number of pages to extend a datafile.

We extend single-table and general tablespaces first one extent at a time, but 4 at a time for bigger tablespaces. It is not enough to extend always by one extent, because we need to add at least one extent to FSP_FREE. A single extent descriptor page will track many extents. And the extent that uses its extent descriptor page is put onto the FSP_FREE_FRAG list. Extents that do not use their extent descriptor page are added to FSP_FREE. The physical page size is used to determine how many extents are tracked on one extent descriptor page. See xdes_calc_descriptor_page().

Parameters
[in]page_sizepage_size of the datafile
[in]sizecurrent number of pages in the datafile
Returns
number of pages to extend the file.

◆ fsp_get_space_header()

fsp_header_t * fsp_get_space_header ( space_id_t  id,
const page_size_t page_size,
mtr_t mtr 
)

Gets a pointer to the space header and acquires a SX lock on the page.

Parameters
[in]idSpace id
[in]page_sizePage size
[in,out]mtrMini-transaction
Returns
pointer to the space header, page x-locked

◆ fsp_get_space_header_block()

fsp_header_t * fsp_get_space_header_block ( space_id_t  id,
const page_size_t page_size,
mtr_t mtr,
buf_block_t **  block 
)

Gets a pointer to the space header and acquires a SX lock on the page.

Parameters
[in]idSpace id
[in]page_sizePage size
[in,out]mtrMini-transaction
[out]blockBlock
Returns
pointer to the space header, page x-locked

◆ fsp_has_sdi()

dberr_t fsp_has_sdi ( space_id_t  space_id)

Determine if the tablespace has SDI.

Parameters
[in]space_idTablespace id
Returns
DB_SUCCESS if SDI is present else DB_ERROR or DB_TABLESPACE_NOT_FOUND

◆ fsp_header_dict_get_server_version()

bool fsp_header_dict_get_server_version ( uint version)

Read the server version number from the DD tablespace header.

Parameters
[out]versionserver version from tablespace header
Returns
false if success.

◆ fsp_header_encryption_op_type_in_progress()

Encryption::Progress fsp_header_encryption_op_type_in_progress ( const page_t page,
page_size_t  page_size 
)

Get encryption operation type in progress from the first page of a tablespace.

Parameters
[in]pagefirst page of a tablespace
[in]page_sizetablespace page size
Returns
operation type

◆ fsp_header_get_encryption_key()

bool fsp_header_get_encryption_key ( uint32_t  fsp_flags,
Encryption_key e_key,
page_t page 
)

Reads the encryption key from the first page of a tablespace.

Parameters
[in]fsp_flagstablespace flags
[in,out]e_keytablespace key, iv
[in]pagefirst page of a tablespace
Returns
true if success

◆ fsp_header_get_encryption_offset()

ulint fsp_header_get_encryption_offset ( const page_size_t page_size)

Get the offset of encryption information in page 0.

Parameters
[in]page_sizepage size.
Returns
offset on success, otherwise 0.

◆ fsp_header_get_encryption_progress_offset()

ulint fsp_header_get_encryption_progress_offset ( const page_size_t page_size)
inline

Get the offset of encryption progress information in page 0.

Parameters
[in]page_sizepage size.
Returns
offset on success, otherwise 0.

◆ fsp_header_get_field()

uint32_t fsp_header_get_field ( const page_t page,
uint32_t  field 
)
inline

Read a tablespace header field.

Parameters
[in]pagefirst page of a tablespace
[in]fieldthe header field
Returns
the contents of the header field

◆ fsp_header_get_flags()

uint32_t fsp_header_get_flags ( const page_t page)
inline

Read the flags from the tablespace header page.

Parameters
[in]pagefirst page of a tablespace
Returns
the contents of FSP_SPACE_FLAGS

◆ fsp_header_get_page_size()

page_size_t fsp_header_get_page_size ( const page_t page)

Reads the page size from the first page of a tablespace.

Parameters
[in]pagefirst page of a tablespace
Returns
page size

◆ fsp_header_get_sdi_offset()

ulint fsp_header_get_sdi_offset ( const page_size_t page_size)
inline

Get the offset of SDI root page number in page 0.

Parameters
[in]page_sizePage size.
Returns
offset on success, else 0

◆ fsp_header_get_server_version()

uint32_t fsp_header_get_server_version ( const page_t page)
inline

Reads the server version from the first page of a tablespace.

Parameters
[in]pagefirst page of a tablespace
Returns
space server version

◆ fsp_header_get_space_id()

space_id_t fsp_header_get_space_id ( const page_t page)

Reads the space id from the first page of a tablespace.

Returns
space id, ULINT UNDEFINED if error in: first page of a tablespace
space id, ULINT UNDEFINED if error
Parameters
pagein: first page of a tablespace

◆ fsp_header_get_space_version()

uint32_t fsp_header_get_space_version ( const page_t page)
inline

Reads the server space version from the first page of a tablespace.

Parameters
[in]pagefirst page of a tablespace
Returns
space server version

◆ fsp_header_get_tablespace_size()

page_no_t fsp_header_get_tablespace_size ( void  )

Gets the size of the system tablespace from the tablespace header.

If we do not have an auto-extending data file, this should be equal to the size of the data files. If there is an auto-extending data file, this can be smaller.

Returns
size in pages

◆ fsp_header_inc_size()

void fsp_header_inc_size ( space_id_t  space_id,
page_no_t  size_inc,
mtr_t mtr 
)

Increases the space size field of a space.

Parameters
[in]space_idSpace id
[in]size_incSize increment in pages
[in,out]mtrMini-transaction

◆ fsp_header_init()

bool fsp_header_init ( space_id_t  space_id,
page_no_t  size,
mtr_t mtr 
)

Initializes the space header of a new created space and creates also the insert buffer tree root if space == 0.

Parameters
[in]space_idSpace id
[in]sizeCurrent size in blocks
[in,out]mtrMini-transaction
Returns
true on success, otherwise false.

◆ fsp_header_init_fields()

void fsp_header_init_fields ( page_t page,
space_id_t  space_id,
uint32_t  flags 
)

Writes the space id and flags to a tablespace header.

The flags contain row type, physical/compressed page size, and logical/uncompressed page size of the tablespace. in: tablespace flags (FSP_SPACE_FLAGS): 0, or table->flags if newer than COMPACT

The flags contain row type, physical/compressed page size, and logical/uncompressed page size of the tablespace.

Parameters
pagein/out: first page in the space
space_idin: space id
flagsin: tablespace flags (FSP_SPACE_FLAGS)

◆ fsp_header_rotate_encryption()

bool fsp_header_rotate_encryption ( fil_space_t space,
byte encrypt_info,
mtr_t mtr 
)

Rotate the encryption info in the space header.

Parameters
[in]spaceTablespace
[in]encrypt_infoBuffer for re-encrypt key.
[in,out]mtrMini-transaction
Returns
true if success.

◆ fsp_header_set_field()

void fsp_header_set_field ( page_t page,
uint32_t  field,
uint32_t  val 
)
inline

Update a tablespace header field.

Parameters
[in]pagefirst page of a tablespace
[in]fieldthe header field
[in]valfield value

◆ fsp_header_size_update()

void fsp_header_size_update ( fsp_header_t header,
ulint  size,
mtr_t mtr 
)
inline

Update the tablespace size information and generate redo log for it.

Parameters
[in]headerTablespace header.
[in]sizeNew tablespace size in pages.
[in]mtrMini-transaction context.

◆ fsp_header_write_encryption()

bool fsp_header_write_encryption ( space_id_t  space_id,
uint32_t  space_flags,
byte encrypt_info,
bool  update_fsp_flags,
bool  rotate_encryption,
mtr_t mtr 
)

Write the encryption info into the space header.

Parameters
[in]space_idTablespace id
[in]space_flagsTablespace flags
[in]encrypt_infoBuffer for re-encrypt key
[in]update_fsp_flagsIf it need to update the space flags
[in]rotate_encryptionIf it is called during key rotation
[in,out]mtrMini-transaction
Returns
true if success.

◆ fsp_header_write_encryption_progress()

bool fsp_header_write_encryption_progress ( space_id_t  space_id,
ulint  space_flags,
ulint  progress_info,
byte  operation_type,
bool  update_operation_type,
mtr_t mtr 
)

Write the encryption progress info into the space header.

Parameters
[in]space_idTablespace id
[in]space_flagsTablespace flags
[in]progress_infoMax pages (un)encrypted
[in]operation_typeType of operation
[in]update_operation_typeIs operation to be updated
[in,out]mtrMini-transaction
Returns
true if success.

◆ fsp_init()

void fsp_init ( void  )

Initializes the file space system.

Initializes the file space system.

◆ fsp_init_resume_alter_encrypt_tablespace()

void fsp_init_resume_alter_encrypt_tablespace ( )

Initiate roll-forward of alter encrypt in background thread.

◆ fsp_is_dd_tablespace()

bool fsp_is_dd_tablespace ( space_id_t  space_id)

Check if tablespace is dd tablespace.

Parameters
[in]space_idtablespace ID
Returns
true if tablespace is dd tablespace.

◆ fsp_is_file_per_table()

static bool fsp_is_file_per_table ( space_id_t  space_id,
uint32_t  fsp_flags 
)
inlinestatic

Check if tablespace is file-per-table.

Parameters
[in]space_idtablespace ID
[in]fsp_flagstablespace flags
Returns
true if tablespace is file-per-table.

◆ fsp_is_ibd_tablespace()

static bool fsp_is_ibd_tablespace ( space_id_t  space_id)
inlinestatic

Determine if the space ID is an IBD tablespace, either file_per_table or a general shared tablespace, where user tables exist.

Parameters
[in]space_idtablespace ID
Returns
true if it is a user tablespace ID

◆ fsp_is_inode_page()

bool fsp_is_inode_page ( page_no_t  page)
inline

Check if a specified page is inode page or not.

This is used for index root pages of hard-coded DD tables, we can safely assume that the passed in page number is in the range of pages which are only either index root page or inode page

Parameters
[in]pagePage number to check
Returns
true if it's inode page, otherwise false

◆ fsp_is_system_or_temp_tablespace()

static bool fsp_is_system_or_temp_tablespace ( space_id_t  space_id)
inlinestatic

Check if the space_id is for a system-tablespace (shared + temp).

Parameters
[in]space_idtablespace ID
Returns
true if id is a system tablespace, false if not.

◆ fsp_is_system_tablespace()

static bool fsp_is_system_tablespace ( space_id_t  space_id)
inlinestatic

◆ fsp_is_undo_tablespace()

bool fsp_is_undo_tablespace ( space_id_t  space_id)

Check whether a space id is an undo tablespace ID Undo tablespaces have space_id's starting 1 less than the redo logs.

They are numbered down from this. Since rseg_id=0 always refers to the system tablespace, undo_space_num values start at 1. The current limit is 127. The translation from an undo_space_num is: undo space_id = log_first_space_id - undo_space_num

Parameters
[in]space_idspace id to check
Returns
true if it is undo tablespace else false.

◆ fsp_parse_init_file_page()

byte * fsp_parse_init_file_page ( byte ptr,
byte end_ptr,
buf_block_t block 
)

Parses a redo log record of a file page init.

Parameters
[in]ptrBuffer.
[in]end_ptrBuffer end.
[in]blockBlock or nullptr.
Returns
end of log record or nullptr

◆ fsp_reserve_free_extents()

bool fsp_reserve_free_extents ( ulint n_reserved,
space_id_t  space_id,
ulint  n_ext,
fsp_reserve_t  alloc_type,
mtr_t mtr,
page_no_t  n_pages 
)

Reserves free pages from a tablespace.

All mini-transactions which may use several pages from the tablespace should call this function beforehand and reserve enough free extents so that they certainly will be able to do their operation, like a B-tree page split, fully. Reservations must be released with function fil_space_release_free_extents!

The alloc_type below has the following meaning: FSP_NORMAL means an operation which will probably result in more space usage, like an insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are deleting rows, then this allocation will in the long run result in less space usage (after a purge); FSP_CLEANING means allocation done in a physical record delete (like in a purge) or other cleaning operation which will result in less space usage in the long run. We prefer the latter two types of allocation: when space is scarce, FSP_NORMAL allocations will not succeed, but the latter two allocations will succeed, if possible. The purpose is to avoid dead end where the database is full but the user cannot free any space because these freeing operations temporarily reserve some space.

Single-table tablespaces whose size is < FSP_EXTENT_SIZE pages are a special case. In this function we would liberally reserve several extents for every page split or merge in a B-tree. But we do not want to waste disk space if the table only occupies < FSP_EXTENT_SIZE pages. That is why we apply different rules in that special case, just ensuring that there are n_pages free pages available.

Parameters
[out]n_reservedNumber of extents actually reserved; if we return true and the tablespace size is < FSP_EXTENT_SIZE pages, then this can be 0, otherwise it is n_ext
[in]space_idTablespace identifier
[in]n_extNumber of extents to reserve
[in]alloc_typePage reservation type (FSP_BLOB, etc)
[in,out]mtrMini-transaction
[in]n_pagesFor small tablespaces (tablespace size is less than FSP_EXTENT_SIZE), number of free pages to reserve.
Returns
true if we were able to make the reservation

◆ fsp_sdi_get_root_page_num()

page_no_t fsp_sdi_get_root_page_num ( space_id_t  space,
const page_size_t page_size,
mtr_t mtr 
)

Retrieve tablespace dictionary index root page number stored in the page 0.

Parameters
[in]spaceTablespace id
[in]page_sizePage size
[in,out]mtrMini-transaction
Returns
root page num of the tablespace dictionary index copy

◆ fsp_sdi_write_root_to_page()

void fsp_sdi_write_root_to_page ( page_t page,
const page_size_t page_size,
page_no_t  root_page_num,
mtr_t mtr 
)

Write SDI Index root page num to page 0 of tablespace.

Parameters
[in,out]pagePage 0 frame
[in]page_sizeSize of page
[in]root_page_numRoot page number of SDI
[in,out]mtrMini-transaction

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
const File_segment_inode obj 
)
inline

The global output stream operator is overloaded to work with an object of type File_segment_inode.

Parameters
[in]outthe output stream.
[in]objan object of type File_segment_inode.
Returns
the output stream.

◆ xdes_calc_descriptor_index()

static ulint xdes_calc_descriptor_index ( const page_size_t page_size,
ulint  offset 
)
inlinestatic

Calculates the descriptor index within a descriptor page.

Parameters
[in]page_sizepage size
[in]offsetpage offset
Returns
descriptor index

◆ xdes_calc_descriptor_page()

static page_no_t xdes_calc_descriptor_page ( const page_size_t page_size,
page_no_t  offset 
)
inlinestatic

Calculates the page where the descriptor of a page resides.

Parameters
[in]page_sizepage size
[in]offsetpage offset
Returns
descriptor page offset

◆ xdes_get_bit()

static bool xdes_get_bit ( const xdes_t descr,
ulint  bit,
page_no_t  offset 
)
inlinestatic

Gets a descriptor bit of a page.

Parameters
[in]descrdescriptor
[in]bitXDES_FREE_BIT or XDES_CLEAN_BIT
[in]offsetpage offset within extent: 0 ... FSP_EXTENT_SIZE - 1
Returns
true if free

◆ xdes_get_state()

xdes_state_t xdes_get_state ( const xdes_t descr,
mtr_t mtr 
)
inline

Get the state of an xdes.

Parameters
[in]descrextent descriptor
[in,out]mtrMini-transaction.
Returns
state

◆ xdes_page_print()

std::ostream & xdes_page_print ( std::ostream &  out,
const page_t xdes,
page_no_t  page_no,
mtr_t mtr 
)

Print the extent descriptor page in user-friendly format.

Parameters
[in]outThe output file stream
[in]xdesThe extent descriptor page
[in]page_noThe page number of xdes page
[in]mtrMini-transaction.
Returns
None.

Variable Documentation

◆ FSP_MAX_AUTOEXTEND_SIZE

constexpr uint64_t FSP_MAX_AUTOEXTEND_SIZE = 4 * 1024 * 1024 * 1024ULL
constexpr

◆ resume_encryption_cond

mysql_cond_t resume_encryption_cond
extern

◆ resume_encryption_cond_m

mysql_mutex_t resume_encryption_cond_m
extern

◆ ts_encrypt_ddl_records

std::vector<DDL_Record *> ts_encrypt_ddl_records
extern

DDL records for tablespace (un)encryption.