MySQL  8.0.21
Source Code Documentation
fsp0fsp.cc File Reference

File space management. More...

#include "fsp0fsp.h"
#include "buf0buf.h"
#include "fil0fil.h"
#include "ha_prototypes.h"
#include "mtr0log.h"
#include "my_dbug.h"
#include "page0page.h"
#include "page0zip.h"
#include "ut0byte.h"
#include <my_aes.h>
#include <debug_sync.h>
#include "btr0btr.h"
#include "btr0sea.h"
#include "dict0boot.h"
#include "dict0dd.h"
#include "fut0fut.h"
#include "ibuf0ibuf.h"
#include "log0log.h"
#include "srv0srv.h"
#include "dict0mem.h"
#include "fsp0sysspace.h"
#include "srv0start.h"
#include "trx0purge.h"
#include "dd/types/tablespace.h"
#include "sql_backup_lock.h"
#include "sql_thd_internal_api.h"
#include "thd_raii.h"
#include "transaction.h"
#include "ut0stage.h"

Macros

#define PAGE_GROUP_SIZE   1
 Group of pages to be marked dirty together during (un)encryption. More...
 

Functions

static void fsp_free_extent (const page_id_t &page_id, const page_size_t &page_size, mtr_t *mtr)
 Returns an extent to the free list of a space. More...
 
static bool xdes_in_segment (const xdes_t *descr, ib_id_t seg_id, mtr_t *mtr)
 Determine if extent belongs to a given segment. More...
 
static void fseg_mark_page_used (space_id_t space_id, const page_size_t &page_size, fseg_inode_t *seg_inode, page_no_t page, xdes_t *descr, mtr_t *mtr)
 Marks a page used. More...
 
static xdes_tfseg_get_first_extent (fseg_inode_t *inode, space_id_t space_id, const page_size_t &page_size, mtr_t *mtr)
 Returns the first extent descriptor for a segment. More...
 
static UNIV_COLD void fsp_fill_free_list (bool init_space, fil_space_t *space, fsp_header_t *header, mtr_t *mtr)
 Put new extents to the free list if there are free extents above the free limit. More...
 
static buf_block_tfseg_alloc_free_page_low (fil_space_t *space, const page_size_t &page_size, fseg_inode_t *seg_inode, page_no_t hint, byte direction, rw_lock_type_t rw_latch, mtr_t *mtr, mtr_t *init_mtr, ibool has_done_reservation)
 Allocates a single free page from a segment. More...
 
ib_id_t xdes_get_segment_id (const xdes_t *descr)
 Get the segment identifier to which the extent belongs to. More...
 
ib_id_t xdes_get_segment_id (const xdes_t *descr, mtr_t *mtr)
 Get the segment identifier to which the extent belongs to. 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 x-locks its page. 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...
 
bool fsp_is_dd_tablespace (space_id_t space_id)
 Check if tablespace is dd tablespace. 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...
 
bool fsp_is_global_temporary (space_id_t space_id)
 Check if tablespace is global temporary. More...
 
bool fsp_is_session_temporary (space_id_t space_id)
 Check if the tablespace is session temporary. More...
 
bool fsp_is_system_temporary (space_id_t space_id)
 Check if tablespace is system temporary. More...
 
bool fsp_is_checksum_disabled (space_id_t space_id)
 Check if checksum is disabled for the given space. More...
 
bool fsp_skip_sanity_check (space_id_t space_id)
 Skip some of the sanity checks that are time consuming even in debug mode and can affect frequent verification runs that are done to ensure stability of the product. More...
 
UNIV_INLINE ibool xdes_mtr_get_bit (const xdes_t *descr, ulint bit, page_no_t offset, mtr_t *mtr)
 Gets a descriptor bit of a page. More...
 
UNIV_INLINE void xdes_set_bit (xdes_t *descr, ulint bit, page_no_t offset, ibool val, mtr_t *mtr)
 Sets a descriptor bit of a page. More...
 
UNIV_INLINE page_no_t xdes_find_bit (xdes_t *descr, ulint bit, ibool val, page_no_t hint, mtr_t *mtr)
 Looks for a descriptor bit having the desired value. More...
 
UNIV_INLINE page_no_t xdes_get_n_used (const xdes_t *descr, mtr_t *mtr)
 Returns the number of used pages in a descriptor. More...
 
bool xdes_state_is_valid (ulint state)
 Check if the state of extent descriptor is valid. More...
 
UNIV_INLINE ibool xdes_is_free (const xdes_t *descr, mtr_t *mtr)
 Returns true if extent contains no used pages. More...
 
UNIV_INLINE ibool xdes_is_full (const xdes_t *descr, mtr_t *mtr)
 Returns true if extent contains no free pages. More...
 
UNIV_INLINE void xdes_set_state (xdes_t *descr, xdes_state_t state, mtr_t *mtr)
 Sets the state of an xdes. More...
 
void xdes_set_segment_id (xdes_t *descr, const ib_id_t seg_id, xdes_state_t state, mtr_t *mtr)
 Update the segment identifier to which the extent belongs to. More...
 
UNIV_INLINE void xdes_init (xdes_t *descr, mtr_t *mtr)
 Inits an extent descriptor to the free and clean state. More...
 
UNIV_INLINE xdes_txdes_get_descriptor_with_space_hdr (fsp_header_t *sp_header, space_id_t space, page_no_t offset, mtr_t *mtr, bool init_space=false, buf_block_t **desc_block=nullptr)
 Get pointer to a the extent descriptor of a page. More...
 
static xdes_txdes_get_descriptor (space_id_t space_id, page_no_t offset, const page_size_t &page_size, mtr_t *mtr)
 Gets pointer to a the extent descriptor of a page. More...
 
UNIV_INLINE xdes_txdes_lst_get_descriptor (space_id_t space, const page_size_t &page_size, fil_addr_t lst_node, mtr_t *mtr)
 Gets pointer to a the extent descriptor if the file address of the descriptor list node is known. More...
 
UNIV_INLINE page_no_t xdes_get_offset (const xdes_t *descr)
 Returns page offset of the first page in extent described by a descriptor. More...
 
static void fsp_init_file_page_low (buf_block_t *block)
 Inits a file page whose prior contents should be ignored. More...
 
static void fsp_space_modify_check (space_id_t id, const mtr_t *mtr)
 Assert that the mini-transaction is compatible with updating an allocation bitmap page. More...
 
static void fsp_init_file_page (buf_block_t *block, mtr_t *mtr)
 Initialize a file page. 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...
 
void fsp_init ()
 Initializes the fsp system. 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 encrytion information in page 0. More...
 
bool fsp_header_write_encryption_progress (space_id_t space_id, uint32_t space_flags, ulint progress_info, byte operation_type, bool update_operation_type, mtr_t *mtr)
 Write the (un)encryption progress info into the space header. More...
 
encryption_op_type 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_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_rotate_encryption (fil_space_t *space, byte *encrypt_info, mtr_t *mtr)
 Rotate the encryption info in the space header. More...
 
bool fsp_header_dict_get_server_version (uint *version)
 Read the server version number from the DD tablespace header. More...
 
bool fsp_header_init (space_id_t space_id, page_no_t size, mtr_t *mtr, bool is_boot)
 Initializes the space header of a new created space and creates also the insert buffer tree root if space == 0. 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...
 
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, byte *key, byte *iv, page_t *page)
 Reads the encryption key from the first page of a tablespace. 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...
 
page_no_t fsp_header_get_tablespace_size (void)
 Gets the size of the system tablespace from the tablespace header. More...
 
static UNIV_COLD bool fsp_try_extend_data_file_with_pages (fil_space_t *space, page_no_t page_no, fsp_header_t *header, mtr_t *mtr)
 Try to extend a single-table tablespace so that a page would fit in the data file. More...
 
static UNIV_COLD ulint fsp_try_extend_data_file (fil_space_t *space, fsp_header_t *header, mtr_t *mtr)
 Try to extend the last data file of a tablespace if it is auto-extending. 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 void fsp_init_xdes_free_frag (fsp_header_t *header, xdes_t *descr, mtr_t *mtr)
 Initialize a fragment extent and puts it into the free fragment list. More...
 
static xdes_tfsp_alloc_free_extent (space_id_t space_id, const page_size_t &page_size, page_no_t hint, mtr_t *mtr)
 Allocates a new free extent. More...
 
static void fsp_alloc_from_free_frag (fsp_header_t *header, xdes_t *descr, page_no_t bit, mtr_t *mtr)
 Allocates a single free page from a space. More...
 
static buf_block_tfsp_page_create (const page_id_t &page_id, const page_size_t &page_size, rw_lock_type_t rw_latch, mtr_t *mtr, mtr_t *init_mtr)
 Gets a buffer block for an allocated page. More...
 
static buf_block_tfsp_alloc_free_page (space_id_t space, const page_size_t &page_size, page_no_t hint, rw_lock_type_t rw_latch, mtr_t *mtr, mtr_t *init_mtr)
 Allocates a single free page from a space. More...
 
static void fsp_free_page (const page_id_t &page_id, const page_size_t &page_size, mtr_t *mtr)
 Frees a single page of a space. More...
 
UNIV_INLINE fseg_inode_tfsp_seg_inode_page_get_nth_inode (page_t *page, page_no_t i, const page_size_t &page_size, mtr_t *mtr)
 Returns the nth inode slot on an inode page. More...
 
static page_no_t fsp_seg_inode_page_find_used (page_t *page, const page_size_t &page_size, mtr_t *mtr)
 Looks for a used segment inode on a segment inode page. More...
 
static page_no_t fsp_seg_inode_page_find_free (page_t *page, page_no_t i, const page_size_t &page_size, mtr_t *mtr)
 Looks for an unused segment inode on a segment inode page. More...
 
static ibool fsp_alloc_seg_inode_page (fsp_header_t *space_header, mtr_t *mtr)
 Allocates a new file segment inode page. More...
 
static fseg_inode_tfsp_alloc_seg_inode (fsp_header_t *space_header, mtr_t *mtr)
 Allocates a new file segment inode. More...
 
static void fsp_free_seg_inode (space_id_t space, const page_size_t &page_size, fseg_inode_t *inode, mtr_t *mtr)
 Frees a file segment inode. More...
 
static fseg_inode_tfseg_inode_try_get (fseg_header_t *header, space_id_t space, const page_size_t &page_size, mtr_t *mtr, buf_block_t **block)
 Returns the file segment inode, page x-latched. More...
 
static fseg_inode_tfseg_inode_get (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...
 
UNIV_INLINE page_no_t fseg_get_nth_frag_page_no (fseg_inode_t *inode, ulint n, mtr_t *mtr)
 Gets the page number from the nth fragment page slot. More...
 
UNIV_INLINE void fseg_set_nth_frag_page_no (fseg_inode_t *inode, ulint n, page_no_t page_no, mtr_t *mtr)
 Sets the page number in the nth fragment page slot. More...
 
static ulint fseg_find_free_frag_page_slot (fseg_inode_t *inode, mtr_t *mtr)
 Finds a fragment page slot which is free. More...
 
static ulint fseg_find_last_used_frag_page_slot (fseg_inode_t *inode, mtr_t *mtr)
 Finds a fragment page slot which is used and last in the array. More...
 
static ulint fseg_get_n_frag_pages (fseg_inode_t *inode, mtr_t *mtr)
 Calculates reserved fragment page slots. More...
 
buf_block_tfseg_create_general (space_id_t space_id, page_no_t page, ulint byte_offset, ibool has_done_reservation, mtr_t *mtr)
 Creates a new segment. More...
 
buf_block_tfseg_create (space_id_t space, page_no_t page, ulint byte_offset, mtr_t *mtr)
 Creates a new segment. More...
 
static ulint fseg_n_reserved_pages_low (space_id_t space_id, const page_size_t &page_size, fseg_inode_t *inode, ulint *used, mtr_t *mtr)
 Calculates the number of pages reserved by a segment, and how many pages are currently used. 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...
 
static void fseg_fill_free_list (fseg_inode_t *inode, space_id_t space, const page_size_t &page_size, page_no_t hint, mtr_t *mtr)
 Tries to fill the free list of a segment with consecutive free extents. More...
 
UNIV_INLINE bool xdes_is_leasable (const xdes_t *descr, const page_size_t &page_size, mtr_t *mtr)
 A fragment extent can be leased if it is the special kind that has a descriptor page and no other pages are being used except the descriptor and ibuf bitmap pages. More...
 
static xdes_tfsp_get_last_free_frag_extent (fsp_header_t *header, const page_size_t &page_size, mtr_t *mtr)
 Get the extent descriptor of the last fragmented extent from the free_frag list. More...
 
static xdes_tfsp_alloc_xdes_free_frag (space_id_t space, fseg_inode_t *inode, const page_size_t &page_size, mtr_t *mtr)
 Allocate an extent from free fragment extent to a segment. More...
 
static xdes_tfseg_alloc_free_extent (fseg_inode_t *inode, space_id_t space, const page_size_t &page_size, mtr_t *mtr)
 Allocates a free extent for the segment: looks first in the free list of the segment, then tries to allocate from the space free list. More...
 
buf_block_tfseg_alloc_free_page_general (fseg_header_t *seg_header, page_no_t hint, byte direction, ibool has_done_reservation, mtr_t *mtr, mtr_t *init_mtr)
 Allocates a single free page from a segment. More...
 
static bool fsp_reserve_free_pages (fil_space_t *space, fsp_header_t *space_header, page_no_t size, mtr_t *mtr, page_no_t n_pages)
 Check that we have at least n_pages frag pages free in the first extent of a single-table tablespace, and they are also physically initialized to the data file. 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)
 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...
 
static void fseg_free_page_low (fseg_inode_t *seg_inode, const page_id_t &page_id, const page_size_t &page_size, bool ahi, mtr_t *mtr)
 Frees a single page of a segment. 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...
 
static void fseg_free_extent (fseg_inode_t *seg_inode, space_id_t space, const page_size_t &page_size, page_no_t page, bool ahi, mtr_t *mtr)
 Frees an extent of a segment to the space free list. More...
 
ibool fseg_free_step (fseg_header_t *header, bool ahi, mtr_t *mtr)
 Frees part of a segment. More...
 
ibool fseg_free_step_not_header (fseg_header_t *header, bool ahi, mtr_t *mtr)
 Frees part of a segment. 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...
 
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...
 
bool fsp_check_tablespace_size (space_id_t space_id)
 Check if the tablespace size information is valid. More...
 
dberr_t fsp_has_sdi (space_id_t space_id)
 Determine if the tablespace has SDI. More...
 
static void mark_all_page_dirty_in_tablespace (THD *thd, space_id_t space_id, uint32_t space_flags, page_no_t total_pages, page_no_t from_page)
 Mark all pages in tablespace dirty. More...
 
dberr_t fsp_alter_encrypt_tablespace (THD *thd, space_id_t space_id, page_no_t from_page, bool to_encrypt, bool in_recovery, void *dd_space_in)
 Encrypt/Unencrypt a tablespace. More...
 
static void validate_tablespace_encryption (fil_space_t *space)
 Validate tablespace encryption settings. More...
 
static void resume_alter_encrypt_tablespace (THD *thd)
 Resume Encrypt/Unencrypt for tablespace(s) post recovery. More...
 
void fsp_init_resume_alter_encrypt_tablespace ()
 Initiate roll-forward of alter encrypt in background thread. More...
 

Variables

std::vector< DDL_Record * > ts_encrypt_ddl_records
 DDL records for tablespace (un)encryption. More...
 

Detailed Description

File space management.

Created 11/29/1995 Heikki Tuuri

Macro Definition Documentation

◆ PAGE_GROUP_SIZE

#define PAGE_GROUP_SIZE   1

Group of pages to be marked dirty together during (un)encryption.

Function Documentation

◆ fseg_alloc_free_extent()

static xdes_t* fseg_alloc_free_extent ( fseg_inode_t inode,
space_id_t  space,
const page_size_t page_size,
mtr_t mtr 
)
static

Allocates a free extent for the segment: looks first in the free list of the segment, then tries to allocate from the space free list.

NOTE that the extent returned still resides in the segment free list, it is not yet taken off it!

Parameters
[in]inodesegment inode
[in]spacespace id
[in]page_sizepage size
[in,out]mtrmini-transaction
Return values
NULLif no page could be allocated
blockrw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded (init_mtr == mtr, or the page was not previously freed in mtr)
block(not allocated or initialized) otherwise

◆ fseg_alloc_free_page_general()

buf_block_t* fseg_alloc_free_page_general ( fseg_header_t seg_header,
page_no_t  hint,
byte  direction,
ibool  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.

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)
block(not allocated or initialized) otherwise
Parameters
seg_headerin/out: segment header
hintin: hint of which page would be desirable
directionin: if 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
has_done_reservationin: TRUE 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
mtrin/out: mini-transaction
init_mtrin/out: mtr 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.

◆ fseg_alloc_free_page_low()

static buf_block_t * fseg_alloc_free_page_low ( fil_space_t space,
const page_size_t page_size,
fseg_inode_t seg_inode,
page_no_t  hint,
byte  direction,
rw_lock_type_t  rw_latch,
mtr_t mtr,
mtr_t init_mtr,
ibool  has_done_reservation 
)
static

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]spacetablespace
[in]page_sizepage size
[in,out]seg_inodesegment inode
[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]rw_latchRW_SX_LATCH, RW_X_LATCH
[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
[in]has_done_reservationTRUE if the space has already been reserved, in this case we will never return NULL
Return values
NULLif no page could be allocated
blockrw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded (init_mtr == mtr, or the page was not previously freed in mtr)
block(not allocated or initialized) otherwise

< extent of the hinted page

< the allocated page offset, FIL_NULL if could not be allocated

< the extent of the allocated page

◆ 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
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,
ibool  has_done_reservation,
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
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_fill_free_list()

static void fseg_fill_free_list ( fseg_inode_t inode,
space_id_t  space,
const page_size_t page_size,
page_no_t  hint,
mtr_t mtr 
)
static

Tries to fill the free list of a segment with consecutive free extents.

This happens if the segment is big enough to allow extents in the free list, the free list is empty, and the extents can be allocated consecutively from the hint onward.

Parameters
[in]inodesegment inode
[in]spacespace id
[in]page_sizepage size
[in]hinthint which extent would be good as the first extent
[in,out]mtrmini-transaction

◆ fseg_find_free_frag_page_slot()

static ulint fseg_find_free_frag_page_slot ( fseg_inode_t inode,
mtr_t mtr 
)
static

Finds a fragment page slot which is free.

Returns
slot index; ULINT_UNDEFINED if none found
Parameters
inodein: segment inode
mtrin/out: mini-transaction

◆ fseg_find_last_used_frag_page_slot()

static ulint fseg_find_last_used_frag_page_slot ( fseg_inode_t inode,
mtr_t mtr 
)
static

Finds a fragment page slot which is used and last in the array.

Returns
slot index; ULINT_UNDEFINED if none found
Parameters
inodein: segment inode
mtrin/out: mini-transaction

◆ fseg_free_extent()

static void fseg_free_extent ( fseg_inode_t seg_inode,
space_id_t  space,
const page_size_t page_size,
page_no_t  page,
bool  ahi,
mtr_t mtr 
)
static

Frees an extent of a segment to the space free list.

Parameters
[in]seg_inodesegment inode
[in]spacespace id
[in]pagea page in the extent
[in]page_sizepage size
[in]ahiwhether we may need to drop the adaptive hash index
[in,out]mtrmini-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
seg_headerin: segment header
space_idin: space id
pagein: page offset
ahiin: whether we may need to drop the adaptive hash index
mtrin/out: mini-transaction

◆ fseg_free_page_low()

static void fseg_free_page_low ( fseg_inode_t seg_inode,
const page_id_t page_id,
const page_size_t page_size,
bool  ahi,
mtr_t mtr 
)
static

Frees a single page of a segment.

Parameters
[in]seg_inodesegment inode
[in]page_idpage id
[in]page_sizepage size
[in]ahiwhether we may need to drop the adaptive hash index
[in,out]mtrmini-transaction

◆ fseg_free_step()

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

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

static xdes_t * fseg_get_first_extent ( fseg_inode_t inode,
space_id_t  space_id,
const page_size_t page_size,
mtr_t mtr 
)
static

Returns the first extent descriptor for a segment.

We think of the extent lists of the segment catenated in the order FSEG_FULL -> FSEG_NOT_FULL -> FSEG_FREE.

Parameters
[in]inodesegment inode
[in]space_idspace id
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
the first extent descriptor, or NULL if none

◆ fseg_get_n_frag_pages()

static ulint fseg_get_n_frag_pages ( fseg_inode_t inode,
mtr_t mtr 
)
static

Calculates reserved fragment page slots.

Returns
number of fragment pages
Parameters
inodein: segment inode
mtrin/out: mini-transaction

◆ fseg_get_nth_frag_page_no()

UNIV_INLINE page_no_t fseg_get_nth_frag_page_no ( fseg_inode_t inode,
ulint  n,
mtr_t mtr 
)

Gets the page number from the nth fragment page slot.

Returns
page number, FIL_NULL if not in use
Parameters
inodein: segment inode
nin: slot index
mtrin/out: mini-transaction

◆ fseg_inode_get()

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

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

static fseg_inode_t* fseg_inode_try_get ( fseg_header_t header,
space_id_t  space,
const page_size_t page_size,
mtr_t mtr,
buf_block_t **  block 
)
static

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, or NULL to ignore
Returns
segment inode, page x-latched; NULL if the inode is free

◆ fseg_mark_page_used()

static void fseg_mark_page_used ( space_id_t  space_id,
const page_size_t page_size,
fseg_inode_t seg_inode,
page_no_t  page,
xdes_t descr,
mtr_t mtr 
)
static

Marks a page used.

The page must reside within the extents of the given segment.

Parameters
[in]space_idtablespace identifier
[in]page_sizeSize of each page in the tablespace.
[in]seg_inodethe file segment inode pointer
[in]pagethe page number to be marked as used.
[in]descrextent descriptor containing information about page.
[in]mtrmini transaction context for modification.

◆ 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
Parameters
headerin: segment header
usedout: number of pages used (<= reserved)
mtrin/out: mini-transaction

◆ fseg_n_reserved_pages_low()

static ulint fseg_n_reserved_pages_low ( space_id_t  space_id,
const page_size_t page_size,
fseg_inode_t inode,
ulint *  used,
mtr_t mtr 
)
static

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

Parameters
[in]space_idunique tablespace identifier
[in]page_sizeSize of each page in the tablespace.
[in]inodefile segment inode pointer
[out]usednumber of pages used (not more than reserved)
[in,out]mtrthe mini transaction
Returns
number of reserved pages

◆ 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
Parameters
seg_headerin: segment header
space_idin: space id
pagein: page offset

◆ fseg_set_nth_frag_page_no()

UNIV_INLINE void fseg_set_nth_frag_page_no ( fseg_inode_t inode,
ulint  n,
page_no_t  page_no,
mtr_t mtr 
)

Sets the page number in the nth fragment page slot.

Parameters
inodein: segment inode
nin: slot index
page_noin: page number to set
mtrin/out: mini-transaction

◆ fsp_alloc_free_extent()

static xdes_t* fsp_alloc_free_extent ( space_id_t  space_id,
const page_size_t page_size,
page_no_t  hint,
mtr_t mtr 
)
static

Allocates a new free extent.

Parameters
[in]space_idtablespace identifier
[in]page_sizepage size
[in]hinthint of which extent would be desirable: any page offset in the extent goes; the hint must not be > FSP_FREE_LIMIT
[in,out]mtrmini-transaction
Returns
extent descriptor, NULL if cannot be allocated

◆ fsp_alloc_free_page()

static buf_block_t* fsp_alloc_free_page ( space_id_t  space,
const page_size_t page_size,
page_no_t  hint,
rw_lock_type_t  rw_latch,
mtr_t mtr,
mtr_t init_mtr 
)
static

Allocates a single free page from a space.

The page is marked as used.

Parameters
[in]spacespace id
[in]page_sizepage size
[in]hinthint of which page would be desirable
[in]rw_latchRW_SX_LATCH, RW_X_LATCH
[in,out]mtrmini-transaction
[in,out]init_mtrmini-transaction in which the page should be initialized (may be the same as mtr)
Return values
NULLif no page could be allocated
blockrw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded (init_mtr == mtr, or the page was not previously freed in mtr)
block(not allocated or initialized) otherwise

◆ fsp_alloc_from_free_frag()

static void fsp_alloc_from_free_frag ( fsp_header_t header,
xdes_t descr,
page_no_t  bit,
mtr_t mtr 
)
static

Allocates a single free page from a space.

Parameters
headerin/out: tablespace header
descrin/out: extent descriptor
bitin: slot to allocate in the extent
mtrin/out: mini-transaction

◆ fsp_alloc_seg_inode()

static fseg_inode_t* fsp_alloc_seg_inode ( fsp_header_t space_header,
mtr_t mtr 
)
static

Allocates a new file segment inode.

Returns
segment inode, or NULL if not enough space
Parameters
space_headerin: space header
mtrin/out: mini-transaction

◆ fsp_alloc_seg_inode_page()

static ibool fsp_alloc_seg_inode_page ( fsp_header_t space_header,
mtr_t mtr 
)
static

Allocates a new file segment inode page.

Returns
true if could be allocated
Parameters
space_headerin: space header
mtrin/out: mini-transaction

◆ fsp_alloc_xdes_free_frag()

static xdes_t* fsp_alloc_xdes_free_frag ( space_id_t  space,
fseg_inode_t inode,
const page_size_t page_size,
mtr_t mtr 
)
static

Allocate an extent from free fragment extent to a segment.

Parameters
[in]spacespace id
[in,out]inodesegment to which extent is leased
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
extent descriptor or NULL

◆ fsp_alter_encrypt_tablespace()

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

Encrypt/Unencrypt a tablespace.

Parameters
[in]thdcurrent thread
[in]space_idTablespace id
[in]from_pagepage id from where operation to be done
[in]to_encrypttrue if to encrypt, false if to unencrypt
[in]in_recoverytrue if its called after recovery
[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_fill_free_list()

static void fsp_fill_free_list ( bool  init_space,
fil_space_t space,
fsp_header_t header,
mtr_t mtr 
)
static

Put new extents to the free list if there are free extents above the free limit.

If an extent happens to contain an extent descriptor page, the extent is put to the FSP_FREE_FRAG list with the page marked as used.

Parameters
[in]init_spacetrue if this is a single-table tablespace and we are only initializing the first extent and the first bitmap pages; then we will not allocate more extents
[in,out]spacetablespace
[in,out]headertablespace header
[in,out]mtrmini-transaction

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

static void fsp_free_extent ( const page_id_t page_id,
const page_size_t page_size,
mtr_t mtr 
)
static

Returns an extent to the free list of a space.

Parameters
[in]page_idpage id in the extent
[in]page_sizepage size
[in,out]mtrmini-transaction

◆ fsp_free_page()

static void fsp_free_page ( const page_id_t page_id,
const page_size_t page_size,
mtr_t mtr 
)
static

Frees a single page of a space.

The page is marked as free and clean.

Parameters
[in]page_idpage id
[in]page_sizepage size
[in,out]mtrmini-transaction

◆ fsp_free_seg_inode()

static void fsp_free_seg_inode ( space_id_t  space,
const page_size_t page_size,
fseg_inode_t inode,
mtr_t mtr 
)
static

Frees a file segment inode.

Parameters
[in]spacespace id
[in]page_sizepage size
[in,out]inodesegment inode
[in,out]mtrmini-transaction

◆ fsp_get_available_space_in_free_extents() [1/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_available_space_in_free_extents() [2/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_last_free_frag_extent()

static xdes_t* fsp_get_last_free_frag_extent ( fsp_header_t header,
const page_size_t page_size,
mtr_t mtr 
)
static

Get the extent descriptor of the last fragmented extent from the free_frag list.

Parameters
[in]headertablespace header
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
the extent descriptor, or NULL if none

◆ 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 x-locks its page.

Parameters
[in]idspace id
[in]page_sizepage size
[in,out]mtrmini-transaction
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_op_type 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
encryption operation

◆ fsp_header_get_encryption_key()

bool fsp_header_get_encryption_key ( uint32_t  fsp_flags,
byte key,
byte iv,
page_t page 
)

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

Parameters
[in]fsp_flagstablespace flags
[in,out]keytablespace key
[in,out]ivtablespace 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 encrytion information in page 0.

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

◆ 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_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
Parameters
pagein: first page of a tablespace

◆ 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
space_idin: space id
size_incin: size increment in pages
mtrin/out: mini-transaction

◆ fsp_header_init()

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

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]mtrmin-transaction
[in]is_bootif it's for bootstrap
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.

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_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,
uint32_t  space_flags,
ulint  progress_info,
byte  operation_type,
bool  update_operation_type,
mtr_t mtr 
)

Write the (un)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 fsp system.

Initializes the file space system.

◆ fsp_init_file_page()

static void fsp_init_file_page ( buf_block_t block,
mtr_t mtr 
)
static

Initialize a file page.

Parameters
[in,out]blockfile page
[in,out]mtrmini-transaction

◆ fsp_init_file_page_low()

static void fsp_init_file_page_low ( buf_block_t block)
static

Inits a file page whose prior contents should be ignored.

Parameters
blockin: pointer to a page

◆ fsp_init_resume_alter_encrypt_tablespace()

void fsp_init_resume_alter_encrypt_tablespace ( )

Initiate roll-forward of alter encrypt in background thread.

◆ fsp_init_xdes_free_frag()

static void fsp_init_xdes_free_frag ( fsp_header_t header,
xdes_t descr,
mtr_t mtr 
)
static

Initialize a fragment extent and puts it into the free fragment list.

Parameters
[in,out]headertablespace header
[in,out]descrextent descriptor
[in,out]mtrmini-transaction

◆ fsp_is_checksum_disabled()

bool fsp_is_checksum_disabled ( space_id_t  space_id)

Check if checksum is disabled for the given space.

Parameters
[in]space_idtablespace ID
Returns
true if checksum is disabled for given space.

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

bool fsp_is_global_temporary ( space_id_t  space_id)

Check if tablespace is global temporary.

Check if a space_id is the system temporary space ID.

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

◆ fsp_is_session_temporary()

bool fsp_is_session_temporary ( space_id_t  space_id)

Check if the tablespace is session temporary.

Check if a space_id is the system temporary space ID.

Parameters
[in]space_idtablespace ID
Returns
true if tablespace is a session temporary tablespace.

◆ fsp_is_system_temporary()

bool fsp_is_system_temporary ( space_id_t  space_id)

Check if tablespace is system temporary.

Check if a space_id is the system temporary space ID.

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

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

Check whether a space id is an undo tablespace ID.

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

static buf_block_t* fsp_page_create ( const page_id_t page_id,
const page_size_t page_size,
rw_lock_type_t  rw_latch,
mtr_t mtr,
mtr_t init_mtr 
)
static

Gets a buffer block for an allocated page.

NOTE: If init_mtr != mtr, the block will only be initialized if it was not previously x-latched. It is assumed that the block has been x-latched only by mtr, and freed in mtr in that case.

Parameters
[in]page_idpage id of the allocated page
[in]page_sizepage size of the allocated page
[in]rw_latchRW_SX_LATCH, RW_X_LATCH
[in,out]mtrmini-transaction of the allocation
[in,out]init_mtrmini-transaction for initializing the page
Returns
block, initialized if init_mtr==mtr or rw_lock_x_lock_count(&block->lock) == 1

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

Returns
end of log record or NULL
Parameters
ptrin: buffer
end_ptrin: buffer end
blockin: block or NULL

◆ 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]mtrthe mini 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_reserve_free_pages()

static bool fsp_reserve_free_pages ( fil_space_t space,
fsp_header_t space_header,
page_no_t  size,
mtr_t mtr,
page_no_t  n_pages 
)
static

Check that we have at least n_pages frag pages free in the first extent of a single-table tablespace, and they are also physically initialized to the data file.

That is we have already extended the data file so that those pages are inside the data file. If not, this function extends the tablespace with pages.

Parameters
[in,out]spacetablespace
[in,out]space_headertablespace header, x-latched
[in]sizesize of the tablespace in pages, must be less than FSP_EXTENT_SIZE
[in,out]mtrmini-transaction
[in]n_pagesnumber of pages to reserve
Returns
true if there were at least n_pages free pages, or we were able to extend

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

◆ fsp_seg_inode_page_find_free()

static page_no_t fsp_seg_inode_page_find_free ( page_t page,
page_no_t  i,
const page_size_t page_size,
mtr_t mtr 
)
static

Looks for an unused segment inode on a segment inode page.

Parameters
[in]pagesegment inode page
[in]isearch forward starting from this index
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
segment inode index, or FIL_NULL if not found

◆ fsp_seg_inode_page_find_used()

static page_no_t fsp_seg_inode_page_find_used ( page_t page,
const page_size_t page_size,
mtr_t mtr 
)
static

Looks for a used segment inode on a segment inode page.

Parameters
[in]pagesegment inode page
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
segment inode index, or FIL_NULL if not found

◆ fsp_seg_inode_page_get_nth_inode()

UNIV_INLINE fseg_inode_t* fsp_seg_inode_page_get_nth_inode ( page_t page,
page_no_t  i,
const page_size_t page_size,
mtr_t mtr 
)

Returns the nth inode slot on an inode page.

Parameters
[in]pagesegment inode page
[in]iinode index on page
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
segment inode

◆ fsp_skip_sanity_check()

bool fsp_skip_sanity_check ( space_id_t  space_id)

Skip some of the sanity checks that are time consuming even in debug mode and can affect frequent verification runs that are done to ensure stability of the product.

Returns
true if check should be skipped for given space.

◆ fsp_space_modify_check()

static void fsp_space_modify_check ( space_id_t  id,
const mtr_t mtr 
)
static

Assert that the mini-transaction is compatible with updating an allocation bitmap page.

Parameters
[in]idtablespace identifier
[in]mtrmini-transaction

◆ fsp_try_extend_data_file()

static UNIV_COLD ulint fsp_try_extend_data_file ( fil_space_t space,
fsp_header_t header,
mtr_t mtr 
)
static

Try to extend the last data file of a tablespace if it is auto-extending.

Parameters
[in,out]spacetablespace
[in,out]headertablespace header
[in,out]mtrmini-transaction
Returns
whether the tablespace was extended

◆ fsp_try_extend_data_file_with_pages()

static UNIV_COLD bool fsp_try_extend_data_file_with_pages ( fil_space_t space,
page_no_t  page_no,
fsp_header_t header,
mtr_t mtr 
)
static

Try to extend a single-table tablespace so that a page would fit in the data file.

Parameters
[in,out]spacetablespace
[in]page_nopage number
[in,out]headertablespace header
[in,out]mtrmini-transaction
Returns
true if success

◆ mark_all_page_dirty_in_tablespace()

static void mark_all_page_dirty_in_tablespace ( THD thd,
space_id_t  space_id,
uint32_t  space_flags,
page_no_t  total_pages,
page_no_t  from_page 
)
static

Mark all pages in tablespace dirty.

Parameters
[in]thdcurrent thread
[in]space_idtablespace id
[in]space_flagstablespace flags
[in]total_pagestotal pages in tablespace
[in]from_pagepage number from where to start the operation

◆ resume_alter_encrypt_tablespace()

static void resume_alter_encrypt_tablespace ( THD thd)
static

Resume Encrypt/Unencrypt for tablespace(s) post recovery.

If an error occurs while processing any tablespace needing encryption, post an error for that space and keep going.

Parameters
[in]thdbackground thread

◆ validate_tablespace_encryption()

static void validate_tablespace_encryption ( fil_space_t space)
static

Validate tablespace encryption settings.

◆ xdes_find_bit()

UNIV_INLINE page_no_t xdes_find_bit ( xdes_t descr,
ulint  bit,
ibool  val,
page_no_t  hint,
mtr_t mtr 
)

Looks for a descriptor bit having the desired value.

Starts from hint and scans upward; at the end of the extent the search is wrapped to the start of the extent.

Returns
bit index of the bit, ULINT_UNDEFINED if not found
Parameters
descrin: descriptor
bitin: XDES_FREE_BIT or XDES_CLEAN_BIT
valin: desired bit value
hintin: hint of which bit position would be desirable
mtrin/out: mini-transaction

◆ xdes_get_descriptor()

static xdes_t* xdes_get_descriptor ( space_id_t  space_id,
page_no_t  offset,
const page_size_t page_size,
mtr_t mtr 
)
static

Gets pointer to a the extent descriptor of a page.

The page where the extent descriptor resides is x-locked. If the page offset is equal to the free limit of the space, adds new extents from above the free limit to the space free list, if not free limit == space size. This adding is necessary to make the descriptor defined, as they are uninitialized above the free limit.

Parameters
[in]space_idspace id
[in]offsetpage offset; if equal to the free limit, we try to add new extents to the space free list
[in]page_sizepage size
[in,out]mtrmini-transaction
Returns
pointer to the extent descriptor, NULL if the page does not exist in the space or if the offset exceeds the free limit

◆ xdes_get_descriptor_with_space_hdr()

UNIV_INLINE xdes_t* xdes_get_descriptor_with_space_hdr ( fsp_header_t sp_header,
space_id_t  space,
page_no_t  offset,
mtr_t mtr,
bool  init_space = false,
buf_block_t **  desc_block = nullptr 
)

Get pointer to a the extent descriptor of a page.

Parameters
[in,out]sp_headertablespace header page, x-latched
[in]spacetablespace identifier
[in]offsetpage offset
[in,out]mtrmini-transaction
[in]init_spacewhether the tablespace is being initialized
[out]desc_blockdescriptor block, or NULL if it is the same as the tablespace header
Returns
pointer to the extent descriptor, NULL if the page does not exist in the space or if the offset exceeds free limit

◆ xdes_get_n_used()

UNIV_INLINE page_no_t xdes_get_n_used ( const xdes_t descr,
mtr_t mtr 
)

Returns the number of used pages in a descriptor.

Returns
number of pages used
Parameters
descrin: descriptor
mtrin/out: mini-transaction

◆ xdes_get_offset()

UNIV_INLINE page_no_t xdes_get_offset ( const xdes_t descr)

Returns page offset of the first page in extent described by a descriptor.

Returns
offset of the first page in extent
Parameters
descrin: extent descriptor

◆ xdes_get_segment_id() [1/2]

ib_id_t xdes_get_segment_id ( const xdes_t descr)
inline

Get the segment identifier to which the extent belongs to.

Parameters
[in]descrextent descriptor
Returns
the segment identifier

◆ xdes_get_segment_id() [2/2]

ib_id_t xdes_get_segment_id ( const xdes_t descr,
mtr_t mtr 
)
inline

Get the segment identifier to which the extent belongs to.

Parameters
[in]descrextent descriptor
[in]mtrmini-transaction
Returns
the segment identifier

◆ xdes_in_segment()

static bool xdes_in_segment ( const xdes_t descr,
ib_id_t  seg_id,
mtr_t mtr 
)
static

Determine if extent belongs to a given segment.

Parameters
[in]descrextent descriptor
[in]seg_idsegment identifier
[in]mtrmini-transaction
Returns
true if extent is part of the segment, false otherwise

◆ xdes_init()

UNIV_INLINE void xdes_init ( xdes_t descr,
mtr_t mtr 
)

Inits an extent descriptor to the free and clean state.

Parameters
descrin: descriptor
mtrin/out: mini-transaction

◆ xdes_is_free()

UNIV_INLINE ibool xdes_is_free ( const xdes_t descr,
mtr_t mtr 
)

Returns true if extent contains no used pages.

Returns
true if totally free
Parameters
descrin: descriptor
mtrin/out: mini-transaction

◆ xdes_is_full()

UNIV_INLINE ibool xdes_is_full ( const xdes_t descr,
mtr_t mtr 
)

Returns true if extent contains no free pages.

Returns
true if full
Parameters
descrin: descriptor
mtrin/out: mini-transaction

◆ xdes_is_leasable()

UNIV_INLINE bool xdes_is_leasable ( const xdes_t descr,
const page_size_t page_size,
mtr_t mtr 
)

A fragment extent can be leased if it is the special kind that has a descriptor page and no other pages are being used except the descriptor and ibuf bitmap pages.

The number of used pages will be equal to XDES_FRAG_N_USED.

Parameters
[in]descrextent descriptor
[in]page_sizethe page size
[in,out]mtrmini transaction
Returns
true if the extent is leasable, false otherwise.

◆ xdes_lst_get_descriptor()

UNIV_INLINE xdes_t* xdes_lst_get_descriptor ( space_id_t  space,
const page_size_t page_size,
fil_addr_t  lst_node,
mtr_t mtr 
)

Gets pointer to a the extent descriptor if the file address of the descriptor list node is known.

The page where the extent descriptor resides is x-locked.

Parameters
[in]spacespace id
[in]page_sizepage size
[in]lst_nodefile address of the list node contained in the descriptor
[in,out]mtrmini-transaction
Returns
pointer to the extent descriptor

◆ xdes_mtr_get_bit()

UNIV_INLINE ibool xdes_mtr_get_bit ( const xdes_t descr,
ulint  bit,
page_no_t  offset,
mtr_t mtr 
)

Gets a descriptor bit of a page.

Returns
true if free
Parameters
descrin: descriptor
bitin: XDES_FREE_BIT or XDES_CLEAN_BIT
offsetin: page offset within extent: 0 ... FSP_EXTENT_SIZE - 1
mtrin: mini-transaction

◆ 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]mtrthe mini transaction.
Returns
None.

◆ xdes_set_bit()

UNIV_INLINE void xdes_set_bit ( xdes_t descr,
ulint  bit,
page_no_t  offset,
ibool  val,
mtr_t mtr 
)

Sets a descriptor bit of a page.

Parameters
descrin: descriptor
bitin: XDES_FREE_BIT or XDES_CLEAN_BIT
offsetin: page offset within extent: 0 ... FSP_EXTENT_SIZE - 1
valin: bit value
mtrin/out: mini-transaction

◆ xdes_set_segment_id()

void xdes_set_segment_id ( xdes_t descr,
const ib_id_t  seg_id,
xdes_state_t  state,
mtr_t mtr 
)
inline

Update the segment identifier to which the extent belongs to.

Parameters
[in,out]descrextent descriptor
[in,out]seg_idsegment identifier
[in]statestate of the extent.
[in,out]mtrmini-transaction.

◆ xdes_set_state()

UNIV_INLINE void xdes_set_state ( xdes_t descr,
xdes_state_t  state,
mtr_t mtr 
)

Sets the state of an xdes.

Parameters
descrin/out: descriptor
statein: state to set
mtrin/out: mini-transaction

◆ xdes_state_is_valid()

bool xdes_state_is_valid ( ulint  state)

Check if the state of extent descriptor is valid.

Parameters
[in]statethe extent descriptor state
Returns
true if state is valid, false otherwise

Variable Documentation

◆ ts_encrypt_ddl_records

std::vector<DDL_Record *> ts_encrypt_ddl_records

DDL records for tablespace (un)encryption.