MySQL 8.3.0
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 "log0buf.h"
#include "srv0srv.h"
#include "clone0api.h"
#include "dict0mem.h"
#include "fsp0sysspace.h"
#include "srv0start.h"
#include "trx0purge.h"
#include "dd/types/tablespace.h"
#include "mysqld.h"
#include "sql/dd/dictionary.h"
#include "sql_backup_lock.h"
#include "sql_thd_internal_api.h"
#include "thd_raii.h"
#include "transaction.h"
#include "ut0stage.h"

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 page_no_t xdes_get_n_used (const xdes_t *descr, mtr_t *mtr)
 Returns the number of used pages in a descriptor. 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, bool 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_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...
 
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...
 
static bool 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...
 
static void xdes_set_bit (xdes_t *descr, ulint bit, page_no_t offset, bool val, mtr_t *mtr)
 Sets a descriptor bit of a page. More...
 
static page_no_t xdes_find_bit (xdes_t *descr, ulint bit, bool val, page_no_t hint, mtr_t *mtr)
 Looks for a descriptor bit having the desired value. More...
 
static bool xdes_is_full (const xdes_t *descr, mtr_t *mtr)
 Returns true if extent contains no free pages. More...
 
void xdes_mark_all_used (xdes_t *descr, mtr_t *mtr)
 Mark all the pages of the extent as used. More...
 
void xdes_mark_pages_free (xdes_t *descr, mtr_t *mtr, const page_no_t from)
 Mark all the pages of the extent from given page_no as free. More...
 
bool xdes_state_is_valid (ulint state)
 Check if the state of extent descriptor is valid. More...
 
static bool xdes_is_free (const xdes_t *descr, mtr_t *mtr)
 Returns true if extent contains no used pages. More...
 
static 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...
 
static void xdes_init (xdes_t *descr, mtr_t *mtr)
 Inits an extent descriptor to the free and clean state. More...
 
static 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...
 
static 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...
 
static page_no_t xdes_get_offset (const xdes_t *descr)
 Returns page offset of the first page in extent described by a descriptor. More...
 
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 encryption 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::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_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)
 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, Encryption_key &e_key, 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 void adjust_undo_extend (fil_space_t *space)
 
static UNIV_COLD bool 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 page_no_t fsp_alloc_page_no (space_id_t space, const page_size_t &page_size, page_no_t hint, mtr_t *mtr)
 
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...
 
static 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 bool 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 (const 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...
 
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)
 Returns the file segment inode, page x-latched. More...
 
static 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...
 
static 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, bool 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...
 
static 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...
 
page_no_t fseg_alloc_page_no (fil_space_t *space, const page_size_t &page_size, fseg_inode_t *seg_inode, page_no_t hint, byte direction, mtr_t *mtr, bool has_done_reservation)
 Allocate a page number. 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 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...
 
bool fsp_extend_by_default_size (space_id_t space_id, bool make_old, size_t &space_size)
 Extend space by default extension size. 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...
 
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...
 
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...
 
static uint32_t get_encryption_progress (fil_space_t *space, byte &operation)
 Get the encryption progress by reading header page. More...
 
static dberr_t encrypt_begin_persist (fil_space_t *space)
 Initialize space encrypt operation and persist in page-0. More...
 
static void encrypt_begin_memory (fil_space_t *space)
 Initialize space encrypt memory flags. More...
 
static void process_all_pages (THD *thd, fil_space_t *space, page_no_t from_page)
 Force all pages of a space to be loaded and flushed back to disk. More...
 
static void encrypt_end (fil_space_t *space)
 Finish space encrypt operation. More...
 
static Encryption::Resume_point encrypt_resume_point (fil_space_t *space, page_no_t &from_page)
 Find out the place to resume the operation. More...
 
static dberr_t encrypt_tablespace (THD *thd, space_id_t space_id, bool resume)
 Encrypt all pages of a tablespace. More...
 
static dberr_t decrypt_begin_persist (fil_space_t *space)
 Initialize space decrypt operation and persist in page-0. More...
 
static void decrypt_begin_memory (fil_space_t *space)
 Initialize space decrypt memory flags. More...
 
static dberr_t decrypt_end (fil_space_t *space)
 Finish space decrypt operation. More...
 
static Encryption::Resume_point decrypt_resume_point (fil_space_t *space, page_no_t &from_page)
 Find out the place to resume the operation. More...
 
static dberr_t decrypt_tablespace (THD *thd, space_id_t space_id, bool resume)
 Decrypt all pages of a tablespace. 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...
 
static void validate_tablespace_encryption (fil_space_t *space)
 Validate tablespace encryption settings. More...
 
static bool load_encryption_from_header (fil_space_t *space)
 Load encryption info from header page. More...
 
static const std::string enc ("ENCRYPTION")
 
static const std::string dec ("DECRYPTION")
 
static const std::string none ("NONE")
 
static const std::string & get_encryption_op_str (Encryption::Progress op)
 
static void resume_alter_encrypt_tablespace (THD *thd)
 Resume Encrypt/Decrypt for tablespace(s) post recovery. More...
 
void fsp_init_resume_alter_encrypt_tablespace ()
 Initiate roll-forward of alter encrypt in background thread. More...
 
dberr_t fseg_alloc_pages_of_extent (const Page_alloc_info &info, mtr_t *mtr, Page_range_t &page_range)
 Allocate pages in bulk. More...
 

Variables

double fseg_reserve_pct = FSEG_RESERVE_PCT_DFLT
 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...
 
std::vector< DDL_Record * > ts_encrypt_ddl_records
 DDL records for tablespace (un)encryption. More...
 
std::vector< space_id_tflag_mismatch_spaces
 
constexpr uint32_t PAGE_GROUP_SIZE = 1
 Group of pages to be marked dirty together during (un)encryption. More...
 

Detailed Description

File space management.

Created 11/29/1995 Heikki Tuuri

Function Documentation

◆ adjust_undo_extend()

static UNIV_COLD void adjust_undo_extend ( fil_space_t space)
static

◆ dec()

static const std::string dec ( "DECRYPTION"  )
static

◆ decrypt_begin_memory()

static void decrypt_begin_memory ( fil_space_t space)
static

Initialize space decrypt memory flags.

Parameters
[in,out]spaceinnodb tablespace

◆ decrypt_begin_persist()

static dberr_t decrypt_begin_persist ( fil_space_t space)
static

Initialize space decrypt operation and persist in page-0.

Parameters
[in,out]spaceinnodb tablespace
Returns
innodb error code

◆ decrypt_end()

static dberr_t decrypt_end ( fil_space_t space)
static

Finish space decrypt operation.

Parameters
[in,out]spaceinnodb tablespace
Returns
innodb error code

◆ decrypt_resume_point()

static Encryption::Resume_point decrypt_resume_point ( fil_space_t space,
page_no_t from_page 
)
static

Find out the place to resume the operation.

Parameters
[in,out]spaceinnodb tablespace
[out]from_pagepage number to resume from
Returns
state to resume from

◆ decrypt_tablespace()

static dberr_t decrypt_tablespace ( THD thd,
space_id_t  space_id,
bool  resume 
)
static

Decrypt all pages of a tablespace.

Parameters
[in,out]thdserver session THD
[in]space_idTablespace id
[in]resumetrue if resumed after server restart
Returns
innodb error code

◆ enc()

static const std::string enc ( "ENCRYPTION"  )
static

◆ encrypt_begin_memory()

static void encrypt_begin_memory ( fil_space_t space)
static

Initialize space encrypt memory flags.

Parameters
[in,out]spaceinnodb tablespace

◆ encrypt_begin_persist()

static dberr_t encrypt_begin_persist ( fil_space_t space)
static

Initialize space encrypt operation and persist in page-0.

Parameters
[in,out]spaceinnodb tablespace
Returns
innodb error code

◆ encrypt_end()

static void encrypt_end ( fil_space_t space)
static

Finish space encrypt operation.

Parameters
[in,out]spaceinnodb tablespace

◆ encrypt_resume_point()

static Encryption::Resume_point encrypt_resume_point ( fil_space_t space,
page_no_t from_page 
)
static

Find out the place to resume the operation.

Parameters
[in,out]spaceinnodb tablespace
[out]from_pagepage number to resume from
Returns
state to resume from

◆ encrypt_tablespace()

static dberr_t encrypt_tablespace ( THD thd,
space_id_t  space_id,
bool  resume 
)
static

Encrypt all pages of a tablespace.

Parameters
[in,out]thdserver session THD
[in]space_idTablespace id
[in]resumetrue if resumed after server restart
Returns
innodb error code

◆ 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), returned block is not allocated nor 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,
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_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,
bool  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), returned block is not allocated nor initialized otherwise

◆ fseg_alloc_page_no()

page_no_t fseg_alloc_page_no ( fil_space_t space,
const page_size_t page_size,
fseg_inode_t seg_inode,
page_no_t  hint,
byte  direction,
mtr_t mtr,
bool  has_done_reservation 
)

Allocate a page number.

Parameters
[in]spacetablespace object
[in]page_sizepage size in the given tablespace.
[in]seg_inodefile segment inode where page number is to be allocated.
[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]mtrmini-transaction context.
[in,out]has_done_reservationtrue if caller has done reservation.
Returns
the allocated page number.

< extent of the hinted page

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

< the extent of the allocated page

◆ fseg_alloc_pages_of_extent()

dberr_t fseg_alloc_pages_of_extent ( const Page_alloc_info info,
mtr_t mtr,
Page_range_t page_range 
)

Allocate pages in bulk.

◆ 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,
bool  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
[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_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()

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

static page_no_t fseg_get_nth_frag_page_no ( fseg_inode_t inode,
ulint  n,
mtr_t mtr 
)
inlinestatic

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

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

static fseg_inode_t * fseg_inode_try_get ( const 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]mtrMini-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()

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

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), returned block is not allocated nor 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_page_no()

static page_no_t fsp_alloc_page_no ( space_id_t  space,
const page_size_t page_size,
page_no_t  hint,
mtr_t mtr 
)
static

◆ 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 bool 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,
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_extend_by_default_size()

bool fsp_extend_by_default_size ( space_id_t  space_id,
bool  make_old,
size_t &  space_size 
)

Extend space by default extension size.

Parameters
[in]space_idspace ID
[in]make_oldadd the header to LRU tail to flush at the earliest.
[out]space_sizesize after extending the space
Returns
true iff successful.

◆ 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 ( 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_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 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_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
[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.

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

void fsp_init_file_page_low ( buf_block_t block)

Inits a file page whose prior contents should be ignored.

Parameters
[in,out]blockbuffer block

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

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.

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.

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.

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.

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

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

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

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

◆ get_encryption_op_str()

static const std::string & get_encryption_op_str ( Encryption::Progress  op)
inlinestatic

◆ get_encryption_progress()

static uint32_t get_encryption_progress ( fil_space_t space,
byte operation 
)
static

Get the encryption progress by reading header page.

Parameters
[in]spacetablespace
[out]operationoperation which was being performed

◆ load_encryption_from_header()

static bool load_encryption_from_header ( fil_space_t space)
static

Load encryption info from header page.

Parameters
[in]spacetablespace
Returns
false if success, true otherwise.

◆ 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

◆ none()

static const std::string none ( "NONE"  )
static

◆ process_all_pages()

static void process_all_pages ( THD thd,
fil_space_t space,
page_no_t  from_page 
)
static

Force all pages of a space to be loaded and flushed back to disk.

Parameters
[in,out]thdserver session THD
[in,out]spaceinnodb tablespace
[in]from_pagepage number to resume from

◆ resume_alter_encrypt_tablespace()

static void resume_alter_encrypt_tablespace ( THD thd)
static

Resume Encrypt/Decrypt 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()

static page_no_t xdes_find_bit ( xdes_t descr,
ulint  bit,
bool  val,
page_no_t  hint,
mtr_t mtr 
)
inlinestatic

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

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

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

static page_no_t xdes_get_n_used ( const xdes_t descr,
mtr_t mtr 
)
inlinestatic

Returns the number of used pages in a descriptor.

Parameters
[in]descrExtent descriptor
[in]mtrMini-transaction
Returns
number of pages used

◆ xdes_get_offset()

static page_no_t xdes_get_offset ( const xdes_t descr)
inlinestatic

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

static void xdes_init ( xdes_t descr,
mtr_t mtr 
)
inlinestatic

Inits an extent descriptor to the free and clean state.

Parameters
descrin: descriptor
mtrin/out: mini-transaction

◆ xdes_is_free()

static bool xdes_is_free ( const xdes_t descr,
mtr_t mtr 
)
inlinestatic

Returns true if extent contains no used pages.

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

◆ xdes_is_full()

static bool xdes_is_full ( const xdes_t descr,
mtr_t mtr 
)
inlinestatic

Returns true if extent contains no free pages.

Parameters
[in]descrextent descriptor
[in]mtrmini transaction context.
Returns
true if full

◆ xdes_is_leasable()

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

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

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

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

void xdes_mark_all_used ( xdes_t descr,
mtr_t mtr 
)

Mark all the pages of the extent as used.

Parameters
[in]descrextent descriptor
[in]mtrmini transaction context.

◆ xdes_mark_pages_free()

void xdes_mark_pages_free ( xdes_t descr,
mtr_t mtr,
const page_no_t  from 
)

Mark all the pages of the extent from given page_no as free.

Parameters
[in]descrextent descriptor
[in]mtrmini transaction context.
[in]fromall pages from this page_no is marked as free.

◆ xdes_mtr_get_bit()

static bool xdes_mtr_get_bit ( const xdes_t descr,
ulint  bit,
page_no_t  offset,
mtr_t mtr 
)
inlinestatic

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]mtrMini-transaction.
Returns
None.

◆ xdes_set_bit()

static void xdes_set_bit ( xdes_t descr,
ulint  bit,
page_no_t  offset,
bool  val,
mtr_t mtr 
)
inlinestatic

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

static void xdes_set_state ( xdes_t descr,
xdes_state_t  state,
mtr_t mtr 
)
inlinestatic

Sets the state of an xdes.

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

Variable Documentation

◆ PAGE_GROUP_SIZE

constexpr uint32_t PAGE_GROUP_SIZE = 1
constexpr

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

◆ ts_encrypt_ddl_records

std::vector<DDL_Record *> ts_encrypt_ddl_records

DDL records for tablespace (un)encryption.