MySQL  8.0.21
Source Code Documentation
fil0fil.cc File Reference

The tablespace memory cache. More...

#include "my_config.h"
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include "arch0page.h"
#include "btr0btr.h"
#include "buf0buf.h"
#include "buf0flu.h"
#include "dict0boot.h"
#include "dict0dd.h"
#include "dict0dict.h"
#include "fsp0file.h"
#include "fsp0fsp.h"
#include "fsp0space.h"
#include "fsp0sysspace.h"
#include "ha_prototypes.h"
#include "hash0hash.h"
#include "log0recv.h"
#include "mach0data.h"
#include "mem0mem.h"
#include "mtr0log.h"
#include "my_dbug.h"
#include "clone0api.h"
#include "os0file.h"
#include "page0zip.h"
#include "sql/mysqld.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "buf0lru.h"
#include "ibuf0ibuf.h"
#include "os0event.h"
#include "row0mysql.h"
#include "sql_backup_lock.h"
#include "sql_class.h"
#include "sync0sync.h"
#include "trx0purge.h"
#include "os0thread-create.h"
#include "current_thd.h"
#include <array>
#include <fstream>
#include <functional>
#include <list>
#include <mutex>
#include <thread>
#include <tuple>
#include <unordered_map>

Classes

struct  Char_Ptr_Hash
 Hash a NUL terminated 'string'. More...
 
struct  Char_Ptr_Compare
 Compare two 'strings'. More...
 
class  Tablespace_files
 Tablespace files disovered during startup. More...
 
class  Tablespace_dirs
 Directories scanned during startup and the files discovered. More...
 
class  Fil_shard
 
class  Fil_system
 The tablespace memory cache; also the totality of logs (the log data space) is stored here; below we talk about tablespaces, but also the ib_logfiles form a 'space' and it is handled here. More...
 
struct  Fil_page_iterator
 

Namespaces

 dd_fil
 Used for collecting the data in boot_tablespaces()
 

Macros

#define mutex_acquire()   acquire(__LINE__)
 We want to store the line number from where it was called. More...
 
#define fil_buffering_disabled(s)
 Determine if user has explicitly disabled fsync(). More...
 
#define fil_report_invalid_page_access(b, s, n, o, l, t)   fil_report_invalid_page_access_low((b), (s), (n), (o), (l), (t), __LINE__)
 

Typedefs

using Dirs = std::vector< std::string >
 
using Space_id_set = std::set< space_id_t >
 
using dd_fil::Moved = std::tuple< dd::Object_id, space_id_t, std::string, std::string, std::string >
 
using dd_fil::Tablespaces = std::vector< Moved >
 
using Scanned_files = std::vector< std::pair< uint16_t, std::string > >
 

Enumerations

enum  {
  dd_fil::OBJECT_ID, dd_fil::SPACE_ID, dd_fil::SPACE_NAME, dd_fil::OLD_PATH,
  dd_fil::NEW_PATH
}
 
enum  fil_load_status {
  FIL_LOAD_OK, FIL_LOAD_ID_CHANGED, FIL_LOAD_NOT_FOUND, FIL_LOAD_INVALID,
  FIL_LOAD_MISMATCH
}
 
enum  fil_operation_t { FIL_OPERATION_DELETE, FIL_OPERATION_CLOSE }
 File operations for tablespace. More...
 

Functions

dberr_t dict_stats_rename_table (const char *old_name, const char *new_name, char *errstr, size_t errstr_sz)
 Renames a table in InnoDB persistent stats storage. More...
 
size_t fil_get_scan_threads (size_t num_files)
 Calculate the number of threads that can be spawned to scan the given number of files taking into the consideration, number of cores available on the machine. More...
 
static bool fil_op_replay_rename (const page_id_t &page_id, const std::string &old_name, const std::string &new_name)
 Replay a file rename operation if possible. More...
 
static void fil_rename_partition_file (const std::string &old_path, ib_file_suffix extn, bool revert, bool import)
 Rename partition file. More...
 
static bool fil_get_partition_file (const std::string &old_path, ib_file_suffix extn, std::string &new_path)
 Get modified name for partition file. More...
 
static bool fil_validate_skip ()
 Checks the consistency of the tablespace cache some of the time. More...
 
bool fil_validate ()
 Checks the consistency of the tablespace cache. More...
 
static dberr_t fil_read (const page_id_t &page_id, const page_size_t &page_size, ulint byte_offset, ulint len, void *buf)
 Reads data from a space to a buffer. More...
 
static dberr_t fil_write (const page_id_t &page_id, const page_size_t &page_size, ulint byte_offset, ulint len, void *buf)
 Writes data to a space from a buffer. More...
 
fil_space_tfil_space_get (space_id_t space_id)
 Look up a tablespace. More...
 
rw_lock_tfil_space_get_latch (space_id_t space_id)
 Returns the latch of a file space. More...
 
fil_type_t fil_space_get_type (space_id_t space_id)
 Gets the type of a file space. More...
 
void fil_space_set_imported (space_id_t space_id)
 Note that a tablespace has been imported. More...
 
char * fil_node_create (const char *name, page_no_t size, fil_space_t *space, bool is_raw, bool atomic_write, page_no_t max_pages)
 Attach a file to a tablespace. More...
 
static bool fil_space_free (space_id_t space_id, bool x_latched)
 Frees a space object from the tablespace memory cache. More...
 
fil_space_tfil_space_create (const char *name, space_id_t space_id, uint32_t flags, fil_type_t purpose)
 Create a space memory object and put it to the fil_system hash table. More...
 
bool fil_assign_new_space_id (space_id_t *space_id)
 Assigns a new space id for a new single-table tablespace. More...
 
char * fil_space_get_first_path (space_id_t space_id)
 Returns the path from the first fil_node_t found with this space ID. More...
 
page_no_t fil_space_get_size (space_id_t space_id)
 Returns the size of the space in pages. More...
 
uint32_t fil_space_get_flags (space_id_t space_id)
 Returns the flags of the space. More...
 
bool fil_space_open (space_id_t space_id)
 Open each file of a tablespace if not already open. More...
 
void fil_space_close (space_id_t space_id)
 Close each file of a tablespace if open. More...
 
const page_size_t fil_space_get_page_size (space_id_t space_id, bool *found)
 Returns the page size of the space and whether it is compressed or not. More...
 
void fil_init (ulint max_n_open)
 Initializes the tablespace memory cache. More...
 
void fil_open_log_and_system_tablespace_files ()
 Opens all log files and system tablespace data files. More...
 
void fil_close_all_files ()
 Closes all open files. More...
 
void fil_close_log_files (bool free_all)
 Closes the redo log files. More...
 
void fil_set_max_space_id_if_bigger (space_id_t max_id)
 Sets the max tablespace id counter if the given number is bigger than the previous value. More...
 
dberr_t fil_write_flushed_lsn (lsn_t lsn)
 Write the flushed LSN to the page header of the first page in the system tablespace. More...
 
fil_space_tfil_space_acquire_low (space_id_t space_id, bool silent)
 Acquire a tablespace when it could be dropped concurrently. More...
 
fil_space_tfil_space_acquire (space_id_t space_id)
 Acquire a tablespace when it could be dropped concurrently. More...
 
fil_space_tfil_space_acquire_silent (space_id_t space_id)
 Acquire a tablespace that may not exist. More...
 
void fil_space_release (fil_space_t *space)
 Release a tablespace acquired with fil_space_acquire(). More...
 
dberr_t fil_close_tablespace (trx_t *trx, space_id_t space_id)
 Closes a single-table tablespace. More...
 
static void fil_op_write_log (mlog_id_t type, space_id_t space_id, const char *path, const char *new_path, uint32_t flags, mtr_t *mtr)
 Write a log record about an operation on a tablespace file. More...
 
std::string fil_system_open_fetch (space_id_t space_id)
 Fetch the file name opened for a space_id during recovery from the file map. More...
 
dberr_t fil_delete_tablespace (space_id_t space_id, buf_remove_t buf_remove)
 Deletes an IBD or IBU tablespace. More...
 
bool fil_truncate_tablespace (space_id_t space_id, page_no_t size_in_pages)
 Truncate the tablespace to needed size. More...
 
void fil_space_inc_redo_skipped_count (space_id_t space_id)
 Increase redo skipped count for a tablespace. More...
 
void fil_space_dec_redo_skipped_count (space_id_t space_id)
 Decrease redo skipped count for a tablespace. More...
 
bool fil_space_is_redo_skipped (space_id_t space_id)
 Check whether a single-table tablespace is redo skipped. More...
 
dberr_t fil_discard_tablespace (space_id_t space_id)
 Discards a single-table tablespace. More...
 
static void fil_name_write_rename (space_id_t space_id, const char *old_name, const char *new_name, mtr_t *mtr)
 Write redo log for renaming a file. More...
 
dberr_t fil_rename_tablespace_check (space_id_t space_id, const char *old_path, const char *new_path, bool is_discarded)
 Test if a tablespace file can be renamed to a new filepath by checking if that the old filepath exists and the new filepath does not exist. More...
 
dberr_t fil_rename_tablespace (space_id_t space_id, const char *old_path, const char *new_name, const char *new_path_in)
 Rename a single-table tablespace. More...
 
dberr_t fil_rename_tablespace_by_id (space_id_t space_id, const char *old_name, const char *new_name)
 Rename a tablespace. More...
 
static dberr_t fil_create_tablespace (space_id_t space_id, const char *name, const char *path, uint32_t flags, page_no_t size, fil_type_t type)
 Create a tablespace (an IBD or IBT) file. More...
 
dberr_t fil_ibd_create (space_id_t space_id, const char *name, const char *path, uint32_t flags, page_no_t size)
 Create a IBD tablespace file. More...
 
dberr_t fil_ibt_create (space_id_t space_id, const char *name, const char *path, uint32_t flags, page_no_t size)
 Create a session temporary tablespace (IBT) file. More...
 
bool fil_replace_tablespace (space_id_t old_space_id, space_id_t new_space_id, page_no_t size_in_pages)
 Drop and create an UNDO tablespace. More...
 
dberr_t fil_ibd_open (bool validate, fil_type_t purpose, space_id_t space_id, uint32_t flags, const char *space_name, const char *table_name, const char *path_in, bool strict, bool old_space)
 Open a single-table tablespace and optionally check the space id is right in it. More...
 
bool fil_space_read_name_and_filepath (space_id_t space_id, char **name, char **filepath)
 Looks for a pre-existing fil_space_t with the given tablespace ID and, if found, returns the name and filepath in newly allocated buffers that the caller must free. More...
 
char * fil_path_to_space_name (const char *filename)
 Convert a file name to a tablespace name. More...
 
static void fil_report_missing_tablespace (const char *name, space_id_t space_id)
 Report that a tablespace for a table was not found. More...
 
bool fil_space_exists_in_mem (space_id_t space_id, const char *name, bool print_err, bool adjust_space, mem_heap_t *heap, table_id_t table_id)
 Returns true if a matching tablespace exists in the InnoDB tablespace memory cache. More...
 
space_id_t fil_space_get_id_by_name (const char *name)
 Return the space ID based on the tablespace name. More...
 
static dberr_t fil_write_zeros (const fil_node_t *file, ulint page_size, os_offset_t start, ulint len, bool read_only_mode)
 Fill the pages with NULs. More...
 
bool fil_space_extend (fil_space_t *space, page_no_t size)
 Try to extend a tablespace if it is smaller than the specified size. More...
 
bool fil_space_reserve_free_extents (space_id_t space_id, ulint n_free_now, ulint n_to_reserve)
 Tries to reserve free extents in a file space. More...
 
void fil_space_release_free_extents (space_id_t space_id, ulint n_reserved)
 Releases free extents in a file space. More...
 
ulint fil_space_get_n_reserved_extents (space_id_t space_id)
 Gets the number of reserved extents. More...
 
static void fil_report_invalid_page_access_low (page_no_t block_offset, space_id_t space_id, const char *space_name, ulint byte_offset, ulint len, bool is_read, int line)
 Report information about an invalid page access. More...
 
void fil_io_set_encryption (IORequest &req_type, const page_id_t &page_id, fil_space_t *space)
 Set encryption information for IORequest. More...
 
dberr_t fil_redo_io (const IORequest &type, const page_id_t &page_id, const page_size_t &page_size, ulint byte_offset, ulint len, void *buf)
 Read or write redo log data (synchronous buffered IO). More...
 
void fil_aio_wait (ulint segment)
 Waits for an AIO operation to complete. More...
 
dberr_t fil_io (const IORequest &type, bool sync, const page_id_t &page_id, const page_size_t &page_size, ulint byte_offset, ulint len, void *buf, void *message)
 Read or write data from a file. More...
 
void fil_flush (space_id_t space_id)
 Flushes to disk possible writes cached by the OS. More...
 
void fil_flush_file_spaces (uint8_t purpose)
 Flush to disk the writes in file spaces of the given type possibly cached by the OS. More...
 
void fil_flush_file_redo ()
 Flush to disk the writes in file spaces of the given type possibly cached by the OS. More...
 
bool fil_addr_is_null (const fil_addr_t &addr)
 Returns true if file address is undefined. More...
 
page_no_t fil_page_get_prev (const byte *page)
 Get the predecessor of a file page. More...
 
page_no_t fil_page_get_next (const byte *page)
 Get the successor of a file page. More...
 
void fil_page_set_type (byte *page, ulint type)
 Sets the file page type. More...
 
void fil_page_reset_type (const page_id_t &page_id, byte *page, ulint type, mtr_t *mtr)
 Reset the page type. More...
 
void fil_close ()
 Closes the tablespace memory cache. More...
 
static void fil_buf_block_init (buf_block_t *block, byte *frame)
 Initializes a buffer control block when the buf_pool is created. More...
 
static dberr_t fil_iterate (const Fil_page_iterator &iter, buf_block_t *block, PageCallback &callback)
 TODO: This can be made parallel trivially by chunking up the file and creating a callback per thread. More...
 
void fil_adjust_name_import (dict_table_t *table, const char *path, ib_file_suffix extn)
 Adjust file name for import for partition files in different letter case. More...
 
dberr_t fil_tablespace_iterate (dict_table_t *table, ulint n_io_buffers, PageCallback &callback)
 Iterate over all the pages in the tablespace. More...
 
bool fil_delete_file (const char *path)
 Delete the tablespace file and any related files like .cfg. More...
 
dberr_t fil_rename_precheck (const dict_table_t *old_table, const dict_table_t *new_table, const char *tmp_name)
 Check if swapping two .ibd files can be done without failure. More...
 
void fil_no_punch_hole (fil_node_t *file)
 Note that the file system where the file resides doesn't support PUNCH HOLE. More...
 
dberr_t fil_set_compression (dict_table_t *table, const char *algorithm)
 Set the compression type for the tablespace of a table. More...
 
Compression::Type fil_get_compression (space_id_t space_id)
 Get the compression algorithm for a tablespace. More...
 
dberr_t fil_set_encryption (space_id_t space_id, Encryption::Type algorithm, byte *key, byte *iv)
 Set the encryption type for the tablespace. More...
 
dberr_t fil_reset_encryption (space_id_t space_id)
 Reset the encryption type for the tablespace. More...
 
bool fil_encryption_rotate ()
 Rotate the tablespace keys by new master key. More...
 
void fil_space_set_flags (fil_space_t *space, uint32_t flags)
 Sets the flags of the tablespace. More...
 
static void fil_tablespace_encryption_init (const fil_space_t *space)
 Initialize the table space encryption. More...
 
static void fil_adjust_partition_stat (const std::string &old_path, const std::string &new_path)
 Modify table name in Innodb persistent stat tables, if needed. More...
 
dberr_t fil_open_for_business (bool read_only_mode)
 Free the Tablespace_files instance. More...
 
bool fil_op_replay_rename_for_ddl (const page_id_t &page_id, const char *old_name, const char *new_name)
 Replay a file rename operation for ddl replay. More...
 
bool fil_tablespace_lookup_for_recovery (space_id_t space_id)
 Lookup the tablespace ID. More...
 
bool fil_tablespace_open_for_recovery (space_id_t space_id)
 Open a tablespace that has a redo log record to apply. More...
 
Fil_state fil_tablespace_path_equals (dd::Object_id dd_object_id, space_id_t space_id, const char *space_name, ulint fsp_flags, std::string old_path, std::string *new_path)
 Lookup the tablespace ID and return the path to the file. More...
 
void fil_add_moved_space (dd::Object_id dd_object_id, space_id_t space_id, const char *space_name, const std::string &old_path, const std::string &new_path)
 Add tablespace to the set of tablespaces to be updated in DD. More...
 
bool fil_update_partition_name (space_id_t space_id, uint32_t fsp_flags, bool update_space, std::string &space_name, std::string &dd_path)
 Compare and update space name and dd path for partitioned table. More...
 
bool fil_check_missing_tablespaces ()
 This function should be called after recovery has completed. More...
 
bytefil_tablespace_redo_create (byte *ptr, const byte *end, const page_id_t &page_id, ulint parsed_bytes, bool parse_only)
 Redo a tablespace create. More...
 
bytefil_tablespace_redo_rename (byte *ptr, const byte *end, const page_id_t &page_id, ulint parsed_bytes, bool parse_only)
 Redo a tablespace rename. More...
 
bytefil_tablespace_redo_delete (byte *ptr, const byte *end, const page_id_t &page_id, ulint parsed_bytes, bool parse_only)
 Redo a tablespace delete. More...
 
bytefil_tablespace_redo_encryption (byte *ptr, const byte *end, space_id_t space_id)
 Parse and process an encryption redo record. More...
 
static dberr_t fil_rename_validate (fil_space_t *space, const std::string &name, Datafile &df)
 Check whether we can rename the file. More...
 
void fil_set_scan_dir (const std::string &directory, bool is_undo_dir)
 Normalize and save a directory to scan for datafiles. More...
 
void fil_set_scan_dirs (const std::string &directories)
 Normalize and save a list of directories to scan for datafiles. More...
 
dberr_t fil_scan_for_tablespaces ()
 Discover tablespaces by reading the header from .ibd files. More...
 
bool fil_path_is_known (const std::string &path)
 Check if a path is known to InnoDB meaning that it is in or under one of the four path settings scanned at startup for file discovery. More...
 
std::string fil_get_dirs ()
 Get the list of directories that datafiles can reside in. More...
 
void fil_free_scanned_files ()
 Free the data structures required for recovery. More...
 
void fil_space_update_name (fil_space_t *space, const char *name)
 Update the tablespace name. More...
 
void fil_checkpoint (lsn_t lwm)
 Set the low water mark for the buffer pool. More...
 
size_t fil_count_deleted (space_id_t undo_num)
 Count how many truncated undo space IDs are still tracked in the buffer pool and the file_system cache. More...
 
bool fil_is_deleted (space_id_t space_id)
 Check if a particular undo space_id for a page in the buffer pool has been deleted recently. More...
 

Variables

Fil_path MySQL_datadir_path
 Reference to the server data directory. More...
 
Fil_path MySQL_undo_path
 Reference to the server undo directory. More...
 
bool MySQL_undo_path_is_unique
 The undo path is different from any other known directory. More...
 
const char * dot_ext [] = {"", ".ibd", ".cfg", ".cfp", ".ibt", ".ibu", ".dblwr"}
 Common InnoDB file extentions. More...
 
ulint fil_n_log_flushes = 0
 The number of fsyncs done to the log. More...
 
ulint fil_n_pending_log_flushes = 0
 Number of pending redo log flushes. More...
 
ulint fil_n_pending_tablespace_flushes = 0
 Number of pending tablespace flushes. More...
 
ulint fil_n_file_opened = 0
 Number of files currently open. More...
 
fil_addr_t fil_addr_null = {FIL_NULL, 0}
 The null file address. More...
 
static const size_t MAX_PAGES_TO_READ = 1
 Maximum number of pages to read to determine the space ID. More...
 
static const size_t MAX_SHARDS = 64
 Maximum number of shards supported. More...
 
static const size_t REDO_SHARD = MAX_SHARDS - 1
 The redo log is in its own shard. More...
 
static const size_t UNDO_SHARDS = 4
 Number of undo shards to reserve. More...
 
static const size_t UNDO_SHARDS_START = REDO_SHARD - (UNDO_SHARDS + 1)
 The UNDO logs have their own shards (4). More...
 
static const size_t EMPTY_OPEN_SLOT = std::numeric_limits<size_t>::max()
 Sentinel for empty open slot. More...
 
static Fil_systemfil_system = nullptr
 The tablespace memory cache. More...
 
static const size_t FIL_VALIDATE_SKIP = 17
 Try fil_validate() every this many times. More...
 

Detailed Description

The tablespace memory cache.

Macro Definition Documentation

◆ fil_buffering_disabled

#define fil_buffering_disabled (   s)
Value:
((s)->purpose == FIL_TYPE_TABLESPACE && \
enum srv_unix_flush_t srv_unix_file_flush_method
Definition: srv0srv.cc:451
do not use fsync() when using direct IO i.e.
Definition: srv0srv.h:855
persistent tablespace (for system, undo log or tables)
Definition: fil0fil.h:108

Determine if user has explicitly disabled fsync().

◆ fil_report_invalid_page_access

#define fil_report_invalid_page_access (   b,
  s,
  n,
  o,
  l,
 
)    fil_report_invalid_page_access_low((b), (s), (n), (o), (l), (t), __LINE__)

◆ mutex_acquire

#define mutex_acquire ( )    acquire(__LINE__)

We want to store the line number from where it was called.

Typedef Documentation

◆ Dirs

using Dirs = std::vector<std::string>

◆ Scanned_files

using Scanned_files = std::vector<std::pair<uint16_t, std::string> >

◆ Space_id_set

Enumeration Type Documentation

◆ fil_load_status

Enumerator
FIL_LOAD_OK 

The tablespace file(s) were found and valid.

FIL_LOAD_ID_CHANGED 

The name no longer matches space_id.

FIL_LOAD_NOT_FOUND 

The file(s) were not found.

FIL_LOAD_INVALID 

The file(s) were not valid.

FIL_LOAD_MISMATCH 

The tablespace file ID in the first page doesn't match expected value.

◆ fil_operation_t

File operations for tablespace.

Enumerator
FIL_OPERATION_DELETE 

delete a single-table tablespace

FIL_OPERATION_CLOSE 

close a single-table tablespace

Function Documentation

◆ dict_stats_rename_table()

dberr_t dict_stats_rename_table ( const char *  old_name,
const char *  new_name,
char *  errstr,
size_t  errstr_sz 
)

Renames a table in InnoDB persistent stats storage.

This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
old_namein: old name, e.g. 'db/table'
new_namein: new name, e.g. 'db/table'
errstrout: error string if != DB_SUCCESS is returned
errstr_szin: errstr size

◆ fil_add_moved_space()

void fil_add_moved_space ( dd::Object_id  dd_object_id,
space_id_t  space_id,
const char *  space_name,
const std::string &  old_path,
const std::string &  new_path 
)

Add tablespace to the set of tablespaces to be updated in DD.

Parameters
[in]dd_object_idServer DD tablespace ID
[in]space_idInnodb tablespace ID
[in]space_nameNew tablespace name
[in]old_pathOld Path in the data dictionary
[in]new_pathNew path to be update in dictionary

◆ fil_addr_is_null()

bool fil_addr_is_null ( const fil_addr_t addr)

Returns true if file address is undefined.

Parameters
[in]addrAddress
Returns
true if undefined

◆ fil_adjust_name_import()

void fil_adjust_name_import ( dict_table_t table,
const char *  path,
ib_file_suffix  extn 
)

Adjust file name for import for partition files in different letter case.

Parameters
[in]tableInnodb dict table
[in]pathfile path to open
[in]extnfile extension

◆ fil_adjust_partition_stat()

static void fil_adjust_partition_stat ( const std::string &  old_path,
const std::string &  new_path 
)
static

Modify table name in Innodb persistent stat tables, if needed.

Required when partitioned table file names from old versions are modified to change the letter case.

Parameters
[in]old_pathpath to old file
[in]new_pathpath to new file

◆ fil_aio_wait()

void fil_aio_wait ( ulint  segment)

Waits for an AIO operation to complete.

Waits for an aio operation to complete.

This function is used to write the handler for completed requests. The aio array of pending requests is divided into segments (see os0file.cc for more info). The thread specifies which segment it wants to wait for.

Parameters
[in]segmentThe number of the segment in the AIO array to wait for

◆ fil_assign_new_space_id()

bool fil_assign_new_space_id ( space_id_t space_id)

Assigns a new space id for a new single-table tablespace.

This works simply by incrementing the global counter. If 4 billion id's is not enough, we may need to recycle id's.

Parameters
[out]space_idSet this to the new tablespace ID
Returns
true if assigned, false if not

◆ fil_buf_block_init()

static void fil_buf_block_init ( buf_block_t block,
byte frame 
)
static

Initializes a buffer control block when the buf_pool is created.

Parameters
[in]blockPointer to the control block
[in]framePointer to buffer frame

◆ fil_check_missing_tablespaces()

bool fil_check_missing_tablespaces ( )

This function should be called after recovery has completed.

Check for tablespace files for which we did not see any MLOG_FILE_DELETE or MLOG_FILE_RENAME record. These could not be recovered

Returns
true if there were some filenames missing for which we had to ignore redo log records during the apply phase

◆ fil_checkpoint()

void fil_checkpoint ( lsn_t  lwm)

Set the low water mark for the buffer pool.

This will remove all dirty pages lower than this LSN in the BP.

Parameters
[in]lwmLow water mark

◆ fil_close()

void fil_close ( )

Closes the tablespace memory cache.

Initializes the tablespace memory cache.

◆ fil_close_all_files()

void fil_close_all_files ( )

Closes all open files.

There must not be any pending i/o's or not flushed modifications in the files.

◆ fil_close_log_files()

void fil_close_log_files ( bool  free_all)

Closes the redo log files.

There must not be any pending i/o's or not flushed modifications in the files.

Parameters
[in]free_allIf set then free all instances

◆ fil_close_tablespace()

dberr_t fil_close_tablespace ( trx_t trx,
space_id_t  space_id 
)

Closes a single-table tablespace.

The tablespace must be cached in the memory cache. Free all pages used by the tablespace.

Parameters
[in,out]trxTransaction covering the close
[in]space_idTablespace ID
Returns
DB_SUCCESS or error

◆ fil_count_deleted()

size_t fil_count_deleted ( space_id_t  undo_num)

Count how many truncated undo space IDs are still tracked in the buffer pool and the file_system cache.

Parameters
[in]undo_numundo tablespace number.
Returns
number of undo tablespaces that are still in memory.

◆ fil_create_tablespace()

static dberr_t fil_create_tablespace ( space_id_t  space_id,
const char *  name,
const char *  path,
uint32_t  flags,
page_no_t  size,
fil_type_t  type 
)
static

Create a tablespace (an IBD or IBT) file.

Parameters
[in]space_idTablespace ID
[in]nameTablespace name in dbname/tablename format. For general tablespaces, the 'dbname/' part may be missing.
[in]pathPath and filename of the datafile to create.
[in]flagsTablespace flags
[in]sizeInitial size of the tablespace file in pages, must be >= FIL_IBD_FILE_INITIAL_SIZE
[in]typeFIL_TYPE_TABLESPACE or FIL_TYPE_TEMPORARY
Returns
DB_SUCCESS or error code

◆ fil_delete_file()

bool fil_delete_file ( const char *  path)

Delete the tablespace file and any related files like .cfg.

This should not be called for temporary tables.

Parameters
[in]pathFile path of the IBD tablespace
Returns
true on success

◆ fil_delete_tablespace()

dberr_t fil_delete_tablespace ( space_id_t  space_id,
buf_remove_t  buf_remove 
)

Deletes an IBD or IBU tablespace.

The tablespace must be cached in the memory cache. This will delete the datafile, fil_space_t & fil_node_t entries from the file_system_t cache.

Parameters
[in]space_idTablespace ID
[in]buf_removeSpecify the action to take on the pages for this table in the buffer pool.
Returns
DB_SUCCESS, DB_TABLESPCE_NOT_FOUND or DB_IO_ERROR

◆ fil_discard_tablespace()

dberr_t fil_discard_tablespace ( space_id_t  space_id)

Discards a single-table tablespace.

The tablespace must be cached in the memory cache. Discarding is like deleting a tablespace, but

  1. We do not drop the table from the data dictionary;
  2. We remove all insert buffer entries for the tablespace immediately; in DROP TABLE they are only removed gradually in the background;
  3. Free all the pages in use by the tablespace.
    Parameters
    [in]space_idTablespace ID
    Returns
    DB_SUCCESS or error

◆ fil_encryption_rotate()

bool fil_encryption_rotate ( )

Rotate the tablespace keys by new master key.

Returns
true if the re-encrypt succeeds

◆ fil_flush()

void fil_flush ( space_id_t  space_id)

Flushes to disk possible writes cached by the OS.

If the space does not exist or is being dropped, does not do anything.

Parameters
[in]space_idFile space ID (this can be a group of log files or a tablespace of the database)

◆ fil_flush_file_redo()

void fil_flush_file_redo ( )

Flush to disk the writes in file spaces of the given type possibly cached by the OS.

◆ fil_flush_file_spaces()

void fil_flush_file_spaces ( uint8_t  purpose)

Flush to disk the writes in file spaces of the given type possibly cached by the OS.

Parameters
[in]purposeFIL_TYPE_TABLESPACE or FIL_TYPE_LOG, can be ORred

◆ fil_free_scanned_files()

void fil_free_scanned_files ( )

Free the data structures required for recovery.

◆ fil_get_compression()

Compression::Type fil_get_compression ( space_id_t  space_id)

Get the compression algorithm for a tablespace.

Get the compression type for the tablespace.

Parameters
[in]space_idSpace ID to check
Returns
the compression algorithm

◆ fil_get_dirs()

std::string fil_get_dirs ( )

Get the list of directories that datafiles can reside in.

Returns
the list of directories 'dir1;dir2;....;dirN'

◆ fil_get_partition_file()

static bool fil_get_partition_file ( const std::string &  old_path,
ib_file_suffix  extn,
std::string &  new_path 
)
static

Get modified name for partition file.

During upgrade we change all partition files to have lower case separator and partition name.

Parameters
[in]old_pathold file name and path
[in]extnfile extension suffix
[out]new_pathmodified new name for partitioned file
Returns
true, iff name needs modification.

◆ fil_get_scan_threads()

size_t fil_get_scan_threads ( size_t  num_files)

Calculate the number of threads that can be spawned to scan the given number of files taking into the consideration, number of cores available on the machine.

Parameters
[in]num_filesNumber of files to be scanned
Returns
number of threads to be spawned for scanning the files

◆ fil_ibd_create()

dberr_t fil_ibd_create ( space_id_t  space_id,
const char *  name,
const char *  path,
uint32_t  flags,
page_no_t  size 
)

Create a IBD tablespace file.

Create a tablespace file.

Parameters
[in]space_idTablespace ID
[in]nameTablespace name in dbname/tablename format. For general tablespaces, the 'dbname/' part may be missing.
[in]pathPath and filename of the datafile to create.
[in]flagsTablespace flags
[in]sizeInitial size of the tablespace file in pages, must be >= FIL_IBD_FILE_INITIAL_SIZE
Returns
DB_SUCCESS or error code

◆ fil_ibd_open()

dberr_t fil_ibd_open ( bool  validate,
fil_type_t  purpose,
space_id_t  space_id,
uint32_t  flags,
const char *  space_name,
const char *  table_name,
const char *  path_in,
bool  strict,
bool  old_space 
)

Open a single-table tablespace and optionally check the space id is right in it.

If not successful, print an error message to the error log. This function is used to open a tablespace when we start up mysqld, and also in IMPORT TABLESPACE. NOTE that we assume this operation is used either at the database startup or under the protection of the dictionary mutex, so that two users cannot race here.

The fil_node_t::handle will not be left open.

Parameters
[in]validatewhether we should validate the tablespace (read the first page of the file and check that the space id in it matches id)
[in]purposeFIL_TYPE_TABLESPACE or FIL_TYPE_TEMPORARY
[in]space_idTablespace ID
[in]flagstablespace flags
[in]space_nametablespace name of the datafile If file-per-table, it is the table name in the databasename/tablename format
[in]table_nametable name in case if need to construct file path
[in]path_inexpected filepath, usually read from dictionary
[in]strictwhether to report error when open ibd failed
[in]old_spacewhether it is a 5.7 tablespace opening by upgrade
Returns
DB_SUCCESS or error code

◆ fil_ibt_create()

dberr_t fil_ibt_create ( space_id_t  space_id,
const char *  name,
const char *  path,
uint32_t  flags,
page_no_t  size 
)

Create a session temporary tablespace (IBT) file.

Parameters
[in]space_idTablespace ID
[in]nameTablespace name
[in]pathPath and filename of the datafile to create.
[in]flagsTablespace flags
[in]sizeInitial size of the tablespace file in pages, must be >= FIL_IBT_FILE_INITIAL_SIZE
Returns
DB_SUCCESS or error code

◆ fil_init()

void fil_init ( ulint  max_n_open)

Initializes the tablespace memory cache.

Parameters
[in]max_n_openMaximum number of open files

◆ fil_io()

dberr_t fil_io ( const IORequest type,
bool  sync,
const page_id_t page_id,
const page_size_t page_size,
ulint  byte_offset,
ulint  len,
void *  buf,
void *  message 
)

Read or write data from a file.

Read or write data.

Parameters
[in]typeIO context
[in]syncIf true then do synchronous IO
[in]page_idpage id
[in]page_sizepage size
[in]byte_offsetremainder of offset in bytes; in aio this must be divisible by the OS block size
[in]lenhow many bytes to read or write; this must not cross a file boundary; in AIO this must be a block size multiple
[in,out]bufbuffer where to store read data or from where to write; in AIO this must be appropriately aligned
[in]messagemessage for AIO handler if !sync, else ignored
Returns
error code
Return values
DB_SUCCESSon success
DB_TABLESPACE_DELETEDif the tablespace does not exist

◆ fil_io_set_encryption()

void fil_io_set_encryption ( IORequest req_type,
const page_id_t page_id,
fil_space_t space 
)

Set encryption information for IORequest.

Set encryption.

Parameters
[in,out]req_typeIO request
[in]page_idpage id
[in]spacetable space

◆ fil_is_deleted()

bool fil_is_deleted ( space_id_t  space_id)

Check if a particular undo space_id for a page in the buffer pool has been deleted recently.

Its space_id will be found in m_deleted until Fil:shard::checkpoint removes all its pages from the buffer pool and the fil_space_t from Fil_system.

Returns
true if this space_id is in the list of recently deleted undo spaces.

◆ fil_iterate()

static dberr_t fil_iterate ( const Fil_page_iterator iter,
buf_block_t block,
PageCallback callback 
)
static

TODO: This can be made parallel trivially by chunking up the file and creating a callback per thread.

Main benefit will be to use multiple CPUs for checksums and compressed tables. We have to do compressed tables block by block right now. Secondly we need to decompress/compress and copy too much of data. These are CPU intensive.

Iterate over all the pages in the tablespace.

Parameters
[in]iterTablespace iterator
[in,out]blockBlock to use for IO
[in]callbackCallback to inspect and update page contents
Return values
DB_SUCCESSor error code

◆ fil_name_write_rename()

static void fil_name_write_rename ( space_id_t  space_id,
const char *  old_name,
const char *  new_name,
mtr_t mtr 
)
static

Write redo log for renaming a file.

Parameters
[in]space_idtablespace id
[in]old_nametablespace file name
[in]new_nametablespace file name after renaming
[in,out]mtrmini-transaction

◆ fil_no_punch_hole()

void fil_no_punch_hole ( fil_node_t file)

Note that the file system where the file resides doesn't support PUNCH HOLE.

Called from AIO handlers when IO returns DB_IO_NO_PUNCH_HOLE

Parameters
[in,out]filefile to set

◆ fil_node_create()

char* fil_node_create ( const char *  name,
page_no_t  size,
fil_space_t space,
bool  is_raw,
bool  atomic_write,
page_no_t  max_pages 
)

Attach a file to a tablespace.

Append a file to the chain of files of a space.

File must be closed.

Parameters
[in]namefile name (file must be closed)
[in]sizefile size in database blocks, rounded downwards to an integer
[in,out]spacespace where to append
[in]is_rawtrue if a raw device or a raw disk partition
[in]atomic_writetrue if the file has atomic write enabled
[in]max_pagesmaximum number of pages in file
Returns
pointer to the file name
Return values
nullptrif error

◆ fil_op_replay_rename()

static bool fil_op_replay_rename ( const page_id_t page_id,
const std::string &  old_name,
const std::string &  new_name 
)
static

Replay a file rename operation if possible.

Parameters
[in]page_idSpace ID and first page number in the file
[in]old_nameold file name
[in]new_namenew file name
Returns
whether the operation was successfully applied (the name did not exist, or new_name did not exist and name was successfully renamed to new_name)

◆ fil_op_replay_rename_for_ddl()

bool fil_op_replay_rename_for_ddl ( const page_id_t page_id,
const char *  old_name,
const char *  new_name 
)

Replay a file rename operation for ddl replay.

Parameters
[in]page_idSpace ID and first page number in the file
[in]old_nameold file name
[in]new_namenew file name
Returns
whether the operation was successfully applied (the name did not exist, or new_name did not exist and name was successfully renamed to new_name)

◆ fil_op_write_log()

static void fil_op_write_log ( mlog_id_t  type,
space_id_t  space_id,
const char *  path,
const char *  new_path,
uint32_t  flags,
mtr_t mtr 
)
static

Write a log record about an operation on a tablespace file.

Parameters
[in]typeMLOG_FILE_OPEN or MLOG_FILE_DELETE or MLOG_FILE_CREATE or MLOG_FILE_RENAME
[in]space_idtablespace identifier
[in]pathfile path
[in]new_pathif type is MLOG_FILE_RENAME, the new name
[in]flagsif type is MLOG_FILE_CREATE, the space flags
[in,out]mtrmini-transaction

◆ fil_open_for_business()

dberr_t fil_open_for_business ( bool  read_only_mode)

Free the Tablespace_files instance.

Parameters
[in]read_only_modetrue if InnoDB is started in read only mode.
Returns
DB_SUCCESS if all OK

◆ fil_open_log_and_system_tablespace_files()

void fil_open_log_and_system_tablespace_files ( )

Opens all log files and system tablespace data files.

They stay open until the database server shutdown. This should be called at a server startup after the space objects for the log and the system tablespace have been created. The purpose of this operation is to make sure we never run out of file descriptors if we need to read from the insert buffer or to write to the log.

◆ fil_page_get_next()

page_no_t fil_page_get_next ( const byte page)

Get the successor of a file page.

Parameters
[in]pageFile page
Returns
FIL_PAGE_NEXT

◆ fil_page_get_prev()

page_no_t fil_page_get_prev ( const byte page)

Get the predecessor of a file page.

Parameters
[in]pageFile page
Returns
FIL_PAGE_PREV

◆ fil_page_reset_type()

void fil_page_reset_type ( const page_id_t page_id,
byte page,
ulint  type,
mtr_t mtr 
)

Reset the page type.

Data files created before MySQL 5.1 may contain garbage in FIL_PAGE_TYPE. In MySQL 3.23.53, only undo log pages and index pages were tagged. Any other pages were written with uninitialized bytes in FIL_PAGE_TYPE.

Parameters
[in]page_idpage number
[in,out]pagepage with invalid FIL_PAGE_TYPE
[in]typeexpected page type
[in,out]mtrmini-transaction

◆ fil_page_set_type()

void fil_page_set_type ( byte page,
ulint  type 
)

Sets the file page type.

Parameters
[in,out]pageFile page
[in]typePage type

◆ fil_path_is_known()

bool fil_path_is_known ( const std::string &  path)

Check if a path is known to InnoDB meaning that it is in or under one of the four path settings scanned at startup for file discovery.

Parameters
[in]pathPath to check
Returns
true if path is known to InnoDB

◆ fil_path_to_space_name()

char* fil_path_to_space_name ( const char *  filename)

Convert a file name to a tablespace name.

Strip the file name prefix and suffix, leaving only databasename/tablename.

Parameters
[in]filenamedirectory/databasename/tablename.ibd
Returns
database/tablename string, to be freed with ut_free()

◆ fil_read()

static dberr_t fil_read ( const page_id_t page_id,
const page_size_t page_size,
ulint  byte_offset,
ulint  len,
void *  buf 
)
static

Reads data from a space to a buffer.

Remember that the possible incomplete blocks at the end of file are ignored: they are not taken into account when calculating the byte offset within a space.

Parameters
[in]page_idpage id
[in]page_sizepage size
[in]byte_offsetremainder of offset in bytes; in aio this must be divisible by the OS block size
[in]lenhow many bytes to read; this must not cross a file boundary; in aio this must be a block size multiple
[in,out]bufbuffer where to store data read; in aio this must be appropriately aligned
Returns
DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do i/o on a tablespace which does not exist

◆ fil_redo_io()

dberr_t fil_redo_io ( const IORequest type,
const page_id_t page_id,
const page_size_t page_size,
ulint  byte_offset,
ulint  len,
void *  buf 
)

Read or write redo log data (synchronous buffered IO).

Parameters
[in]typeIO context
[in]page_idwhere to read or write
[in]page_sizepage size
[in]byte_offsetremainder of offset in bytes
[in]lenthis must not cross a file boundary;
[in,out]bufbuffer where to store read data or from where to write
Return values
DB_SUCCESSif all OK

◆ fil_rename_partition_file()

static void fil_rename_partition_file ( const std::string &  old_path,
ib_file_suffix  extn,
bool  revert,
bool  import 
)
static

Rename partition file.

Parameters
[in]old_pathold file path
[in]extnfile extension suffix
[in]revertif true, rename from new to old file
[in]importif called during import

◆ fil_rename_precheck()

dberr_t fil_rename_precheck ( const dict_table_t old_table,
const dict_table_t new_table,
const char *  tmp_name 
)

Check if swapping two .ibd files can be done without failure.

Parameters
[in]old_tableold table
[in]new_tablenew table
[in]tmp_nametemporary table name
Returns
innodb error code

◆ fil_rename_tablespace()

dberr_t fil_rename_tablespace ( space_id_t  space_id,
const char *  old_path,
const char *  new_name,
const char *  new_path_in 
)

Rename a single-table tablespace.

The tablespace must exist in the memory cache.

Parameters
[in]space_idTablespace ID
[in]old_pathOld file name
[in]new_nameNew tablespace name in the schema/name format
[in]new_path_inNew file name, or nullptr if it is located in the normal data directory
Returns
InnoDB error code

◆ fil_rename_tablespace_by_id()

dberr_t fil_rename_tablespace_by_id ( space_id_t  space_id,
const char *  old_name,
const char *  new_name 
)

Rename a tablespace.

Use the space_id to find the shard.

Parameters
[in]space_idtablespace ID
[in]old_nameold tablespace name
[in]new_namenew tablespace name
Returns
DB_SUCCESS on success

◆ fil_rename_tablespace_check()

dberr_t fil_rename_tablespace_check ( space_id_t  space_id,
const char *  old_path,
const char *  new_path,
bool  is_discarded 
)

Test if a tablespace file can be renamed to a new filepath by checking if that the old filepath exists and the new filepath does not exist.

Parameters
[in]space_idtablespace id
[in]old_pathold filepath
[in]new_pathnew filepath
[in]is_discardedwhether the tablespace is discarded
Returns
innodb error code

◆ fil_rename_validate()

static dberr_t fil_rename_validate ( fil_space_t space,
const std::string &  name,
Datafile df 
)
static

Check whether we can rename the file.

Parameters
[in]spaceTablespace for which to rename
[in]nameSource file name
[in]dfTarget file that exists on disk
Returns
DB_SUCCESS if all OK

◆ fil_replace_tablespace()

bool fil_replace_tablespace ( space_id_t  old_space_id,
space_id_t  new_space_id,
page_no_t  size_in_pages 
)

Drop and create an UNDO tablespace.

Parameters
[in]old_space_idTablespace ID to truncate
[in]new_space_idTablespace ID to for the new file
[in]size_in_pagesTruncate size.
Returns
true if truncate was successful.

◆ fil_report_invalid_page_access_low()

static void fil_report_invalid_page_access_low ( page_no_t  block_offset,
space_id_t  space_id,
const char *  space_name,
ulint  byte_offset,
ulint  len,
bool  is_read,
int  line 
)
static

Report information about an invalid page access.

Parameters
[in]block_offsetBlock offset
[in]space_idTablespace ID
[in]space_nameTablespace name
[in]byte_offsetByte offset
[in]lenI/O length
[in]is_readI/O type
[in]lineLine called from

◆ fil_report_missing_tablespace()

static void fil_report_missing_tablespace ( const char *  name,
space_id_t  space_id 
)
static

Report that a tablespace for a table was not found.

Parameters
[in]nameTable name
[in]space_idTable's space ID

◆ fil_reset_encryption()

dberr_t fil_reset_encryption ( space_id_t  space_id)

Reset the encryption type for the tablespace.

Parameters
[in]space_idSpace ID of tablespace for which to set
Returns
DB_SUCCESS or error code

◆ fil_scan_for_tablespaces()

dberr_t fil_scan_for_tablespaces ( )

Discover tablespaces by reading the header from .ibd files.

Returns
DB_SUCCESS if all goes well

◆ fil_set_compression()

dberr_t fil_set_compression ( dict_table_t table,
const char *  algorithm 
)

Set the compression type for the tablespace of a table.

Parameters
[in]tableThe table that should be compressed
[in]algorithmText representation of the algorithm
Returns
DB_SUCCESS or error code

◆ fil_set_encryption()

dberr_t fil_set_encryption ( space_id_t  space_id,
Encryption::Type  algorithm,
byte key,
byte iv 
)

Set the encryption type for the tablespace.

Parameters
[in]space_idSpace ID of tablespace for which to set
[in]algorithmEncryption algorithm
[in]keyEncryption key
[in]ivEncryption iv
Returns
DB_SUCCESS or error code

◆ fil_set_max_space_id_if_bigger()

void fil_set_max_space_id_if_bigger ( space_id_t  max_id)

Sets the max tablespace id counter if the given number is bigger than the previous value.

Parameters
[in]max_idMaximum known tablespace ID

◆ fil_set_scan_dir()

void fil_set_scan_dir ( const std::string &  directory,
bool  is_undo_dir = false 
)

Normalize and save a directory to scan for datafiles.

Parameters
[in]directorydirectory to scan for ibd and ibu files
[in]is_undo_dirtrue for an undo directory

◆ fil_set_scan_dirs()

void fil_set_scan_dirs ( const std::string &  directories)

Normalize and save a list of directories to scan for datafiles.

Parameters
[in]directoriesDirectories to scan for ibd and ibu files in the form: "dir1;dir2; ... dirN"

◆ fil_space_acquire()

fil_space_t* fil_space_acquire ( space_id_t  space_id)

Acquire a tablespace when it could be dropped concurrently.

Used by background threads that do not necessarily hold proper locks for concurrency control.

Parameters
[in]space_idTablespace ID
Returns
the tablespace, or nullptr if missing or being deleted

◆ fil_space_acquire_low()

fil_space_t* fil_space_acquire_low ( space_id_t  space_id,
bool  silent 
)
inline

Acquire a tablespace when it could be dropped concurrently.

Used by background threads that do not necessarily hold proper locks for concurrency control.

Parameters
[in]space_idTablespace ID
[in]silentWhether to silently ignore missing tablespaces
Returns
the tablespace, or nullptr if missing or being deleted

◆ fil_space_acquire_silent()

fil_space_t* fil_space_acquire_silent ( space_id_t  space_id)

Acquire a tablespace that may not exist.

Used by background threads that do not necessarily hold proper locks for concurrency control.

Parameters
[in]space_idTablespace ID
Returns
the tablespace, or nullptr if missing or being deleted

◆ fil_space_close()

void fil_space_close ( space_id_t  space_id)

Close each file of a tablespace if open.

Parameters
[in]space_idtablespace identifier

◆ fil_space_create()

fil_space_t* fil_space_create ( const char *  name,
space_id_t  space_id,
uint32_t  flags,
fil_type_t  purpose 
)

Create a space memory object and put it to the fil_system hash table.

The tablespace name is independent from the tablespace file-name. Error messages are issued to the server log.

Parameters
[in]nameTablespace name
[in]space_idTablespace ID
[in]flagsTablespace flags
[in]purposeTablespace purpose
Returns
pointer to created tablespace, to be filled in with fil_node_create()
Return values
nullptron failure (such as when the same tablespace exists)

◆ fil_space_dec_redo_skipped_count()

void fil_space_dec_redo_skipped_count ( space_id_t  space_id)

Decrease redo skipped count for a tablespace.

Decrease redo skipped of a tablespace.

Parameters
[in]space_idTablespace id

◆ fil_space_exists_in_mem()

bool fil_space_exists_in_mem ( space_id_t  space_id,
const char *  name,
bool  print_err,
bool  adjust_space,
mem_heap_t heap,
table_id_t  table_id 
)

Returns true if a matching tablespace exists in the InnoDB tablespace memory cache.

Parameters
[in]space_idTablespace ID
[in]nameTablespace name used in space_create().
[in]print_errPrint detailed error information to the error log if a matching tablespace is not found from memory.
[in]adjust_spaceWhether to adjust space id on mismatch
[in]heapHeap memory
[in]table_idtable ID
Returns
true if a matching tablespace exists in the memory cache

◆ fil_space_extend()

bool fil_space_extend ( fil_space_t space,
page_no_t  size 
)

Try to extend a tablespace if it is smaller than the specified size.

Parameters
[in,out]spacetablespace
[in]sizedesired size in pages
Returns
whether the tablespace is at least as big as requested

◆ fil_space_free()

static bool fil_space_free ( space_id_t  space_id,
bool  x_latched 
)
static

Frees a space object from the tablespace memory cache.

Closes a tablespaces' files but does not delete them. There must not be any pending i/o's or flushes on the files.

Parameters
[in]space_idTablespace ID
[in]x_latchedWhether the caller holds X-mode space->latch
Returns
true if success

◆ fil_space_get()

fil_space_t* fil_space_get ( space_id_t  space_id)

Look up a tablespace.

The caller should hold an InnoDB table lock or a MDL that prevents the tablespace from being dropped during the operation, or the caller should be in single-threaded crash recovery mode (no user connections that could drop tablespaces). If this is not the case, fil_space_acquire() and fil_space_release() should be used instead.

Parameters
[in]space_idTablespace ID
Returns
tablespace, or nullptr if not found

◆ fil_space_get_first_path()

char* fil_space_get_first_path ( space_id_t  space_id)

Returns the path from the first fil_node_t found with this space ID.

The caller is responsible for freeing the memory allocated here for the value returned.

Parameters
[in]space_idTablespace ID
Returns
own: A copy of fil_node_t::path, nullptr if space ID is zero or not found.

◆ fil_space_get_flags()

uint32_t fil_space_get_flags ( space_id_t  space_id)

Returns the flags of the space.

The tablespace must be cached in the memory cache.

Parameters
[in]space_idTablespace ID for which to get the flags
Returns
flags, ULINT_UNDEFINED if space not found

◆ fil_space_get_id_by_name()

space_id_t fil_space_get_id_by_name ( const char *  name)

Return the space ID based on the tablespace name.

Returns the space ID based on the tablespace name.

The tablespace must be found in the tablespace memory cache.

Parameters
[in]nameTablespace name
Returns
space ID if tablespace found, SPACE_UNKNOWN if space not.

◆ fil_space_get_latch()

rw_lock_t* fil_space_get_latch ( space_id_t  space_id)

Returns the latch of a file space.

Parameters
[in]space_idTablespace ID
Returns
latch protecting storage allocation

◆ fil_space_get_n_reserved_extents()

ulint fil_space_get_n_reserved_extents ( space_id_t  space_id)

Gets the number of reserved extents.

If the database is silent, this number should be zero.

Parameters
[in]space_idTablespace ID
Returns
the number of reserved extents

◆ fil_space_get_page_size()

const page_size_t fil_space_get_page_size ( space_id_t  space_id,
bool found 
)

Returns the page size of the space and whether it is compressed or not.

The tablespace must be cached in the memory cache.

Parameters
[in]space_idTablespace ID
[out]foundtrue if tablespace was found
Returns
page size

◆ fil_space_get_size()

page_no_t fil_space_get_size ( space_id_t  space_id)

Returns the size of the space in pages.

The tablespace must be cached in the memory cache.

Parameters
[in]space_idTablespace ID
Returns
space size, 0 if space not found

◆ fil_space_get_type()

fil_type_t fil_space_get_type ( space_id_t  space_id)

Gets the type of a file space.

Parameters
[in]space_idTablespace ID
Returns
file type

◆ fil_space_inc_redo_skipped_count()

void fil_space_inc_redo_skipped_count ( space_id_t  space_id)

Increase redo skipped count for a tablespace.

Increase redo skipped of a tablespace.

Parameters
[in]space_idTablespace ID

◆ fil_space_is_redo_skipped()

bool fil_space_is_redo_skipped ( space_id_t  space_id)

Check whether a single-table tablespace is redo skipped.

Parameters
[in]space_idTablespace id
Returns
true if redo skipped

◆ fil_space_open()

bool fil_space_open ( space_id_t  space_id)

Open each file of a tablespace if not already open.

Parameters
[in]space_idtablespace identifier
Return values
trueif all file nodes were opened
falseon failure

◆ fil_space_read_name_and_filepath()

bool fil_space_read_name_and_filepath ( space_id_t  space_id,
char **  name,
char **  filepath 
)

Looks for a pre-existing fil_space_t with the given tablespace ID and, if found, returns the name and filepath in newly allocated buffers that the caller must free.

Parameters
[in]space_idThe tablespace ID to search for.
[out]nameName of the tablespace found.
[out]filepathThe filepath of the first datafile for the tablespace.
Returns
true if tablespace is found, false if not.

◆ fil_space_release()

void fil_space_release ( fil_space_t space)

Release a tablespace acquired with fil_space_acquire().

Parameters
[in,out]spacetablespace to release

◆ fil_space_release_free_extents()

void fil_space_release_free_extents ( space_id_t  space_id,
ulint  n_reserved 
)

Releases free extents in a file space.

Parameters
[in]space_idTablespace ID
[in]n_reservedHow many were reserved

◆ fil_space_reserve_free_extents()

bool fil_space_reserve_free_extents ( space_id_t  space_id,
ulint  n_free_now,
ulint  n_to_reserve 
)

Tries to reserve free extents in a file space.

Parameters
[in]space_idTablespace ID
[in]n_free_nowNumber of free extents now
[in]n_to_reserveHow many one wants to reserve
Returns
true if succeed

◆ fil_space_set_flags()

void fil_space_set_flags ( fil_space_t space,
uint32_t  flags 
)

Sets the flags of the tablespace.

The tablespace must be locked in MDL_EXCLUSIVE MODE.

Parameters
[in]spacetablespace in-memory struct
[in]flagstablespace flags

◆ fil_space_set_imported()

void fil_space_set_imported ( space_id_t  space_id)

Note that a tablespace has been imported.

It is initially marked as FIL_TYPE_IMPORT so that no logging is done during the import process when the space ID is stamped to each page. Now we change it to FIL_SPACE_TABLESPACE to start redo and undo logging. NOTE: temporary tablespaces are never imported.

Parameters
[in]space_idTablespace ID

◆ fil_space_update_name()

void fil_space_update_name ( fil_space_t space,
const char *  name 
)

Update the tablespace name.

Incase, the new name and old name are same, no update done.

Parameters
[in,out]spacetablespace object on which name will be updated
[in]namenew name for tablespace

◆ fil_system_open_fetch()

std::string fil_system_open_fetch ( space_id_t  space_id)

Fetch the file name opened for a space_id during recovery from the file map.

Parameters
[in]space_idUndo tablespace ID
Returns
file name that was opened, empty string if space ID not found.

◆ fil_tablespace_encryption_init()

static void fil_tablespace_encryption_init ( const fil_space_t space)
static

Initialize the table space encryption.

Parameters
[in,out]spaceTablespace instance

◆ fil_tablespace_iterate()

dberr_t fil_tablespace_iterate ( dict_table_t table,
ulint  n_io_buffers,
PageCallback callback 
)

Iterate over all the pages in the tablespace.

Parameters
[in,out]tablethe table definiton in the server
[in]n_io_buffersnumber of blocks to read and write together
[in]callbackfunctor that will do the page updates
Returns
DB_SUCCESS or error code

Add an extra page for compressed page scratch area.

◆ fil_tablespace_lookup_for_recovery()

bool fil_tablespace_lookup_for_recovery ( space_id_t  space_id)

Lookup the tablespace ID.

Lookup the space ID.

Parameters
[in]space_idTablespace ID to lookup
Returns
true if the space ID is known.

◆ fil_tablespace_open_for_recovery()

bool fil_tablespace_open_for_recovery ( space_id_t  space_id)

Open a tablespace that has a redo log record to apply.

Open the tabelspace and also get the tablespace filenames, space_id must already be known.

Parameters
[in]space_idTablespace ID
Returns
true if the open was successful

◆ fil_tablespace_path_equals()

Fil_state fil_tablespace_path_equals ( dd::Object_id  dd_object_id,
space_id_t  space_id,
const char *  space_name,
ulint  fsp_flags,
std::string  old_path,
std::string *  new_path 
)

Lookup the tablespace ID and return the path to the file.

The filename is ignored when testing for equality. Only the path up to the file name is considered for matching: e.g. ./test/a.ibd == ./test/b.ibd.

Parameters
[in]dd_object_idserver DD tablespace ID
[in]space_idtablespace ID to lookup
[in]space_nametablespace name
[in]fsp_flagstablespace flags
[in]old_paththe path found in dd:Tablespace_files
[out]new_paththe scanned path for this space_id
Returns
status of the match.

◆ fil_tablespace_redo_create()

byte* fil_tablespace_redo_create ( byte ptr,
const byte end,
const page_id_t page_id,
ulint  parsed_bytes,
bool  parse_only 
)

Redo a tablespace create.

Parameters
[in]ptrredo log record
[in]endend of the redo log buffer
[in]page_idTablespace Id and first page in file
[in]parsed_bytesNumber of bytes parsed so far
[in]parse_onlyDon't apply, parse only
Returns
pointer to next redo log record
Return values
nullptrif this log record was truncated

◆ fil_tablespace_redo_delete()

byte* fil_tablespace_redo_delete ( byte ptr,
const byte end,
const page_id_t page_id,
ulint  parsed_bytes,
bool  parse_only 
)

Redo a tablespace delete.

Redo a tablespace drop.

Parameters
[in]ptrredo log record
[in]endend of the redo log buffer
[in]page_idTablespace Id and first page in file
[in]parsed_bytesNumber of bytes parsed so far
[in]parse_onlyDon't apply, parse only
Returns
pointer to next redo log record
Return values
nullptrif this log record was truncated

◆ fil_tablespace_redo_encryption()

byte* fil_tablespace_redo_encryption ( byte ptr,
const byte end,
space_id_t  space_id 
)

Parse and process an encryption redo record.

Parameters
[in]ptrredo log record
[in]endend of the redo log buffer
[in]space_idthe tablespace ID
Returns
log record end, nullptr if not a complete record

◆ fil_tablespace_redo_rename()

byte* fil_tablespace_redo_rename ( byte ptr,
const byte end,
const page_id_t page_id,
ulint  parsed_bytes,
bool  parse_only 
)

Redo a tablespace rename.

This function doesn't do anything, simply parses the redo log record.

Parameters
[in]ptrredo log record
[in]endend of the redo log buffer
[in]page_idTablespace Id and first page in file
[in]parsed_bytesNumber of bytes parsed so far
[in]parse_onlyDon't apply, parse only
Returns
pointer to next redo log record
Return values
nullptrif this log record was truncated

◆ fil_truncate_tablespace()

bool fil_truncate_tablespace ( space_id_t  space_id,
page_no_t  size_in_pages 
)

Truncate the tablespace to needed size.

Parameters
[in]space_idTablespace ID to truncate
[in]size_in_pagesTruncate size.
Returns
true if truncate was successful.

◆ fil_update_partition_name()

bool fil_update_partition_name ( space_id_t  space_id,
uint32_t  fsp_flags,
bool  update_space,
std::string &  space_name,
std::string &  dd_path 
)

Compare and update space name and dd path for partitioned table.

Uniformly converts partition separators and names to lower case.

Parameters
[in]space_idtablespace ID
[in]fsp_flagstablespace flags
[in]update_spaceupdate space name
[in,out]space_nametablespace name
[in,out]dd_pathfile name with complete path
Returns
true, if names are updated.

◆ fil_validate()

bool fil_validate ( )

Checks the consistency of the tablespace cache.

Returns
true if ok

◆ fil_validate_skip()

static bool fil_validate_skip ( )
static

Checks the consistency of the tablespace cache some of the time.

Returns
true if ok or the check was skipped

The fil_validate() call skip counter. Use a signed type because of the race condition below.

◆ fil_write()

static dberr_t fil_write ( const page_id_t page_id,
const page_size_t page_size,
ulint  byte_offset,
ulint  len,
void *  buf 
)
static

Writes data to a space from a buffer.

Remember that the possible incomplete blocks at the end of file are ignored: they are not taken into account when calculating the byte offset within a space.

Parameters
[in]page_idpage id
[in]page_sizepage size
[in]byte_offsetremainder of offset in bytes; in aio this must be divisible by the OS block size
[in]lenhow many bytes to write; this must not cross a file boundary; in aio this must be a block size multiple
[in]bufbuffer from which to write; in aio this must be appropriately aligned
Returns
DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do I/O on a tablespace which does not exist

◆ fil_write_flushed_lsn()

dberr_t fil_write_flushed_lsn ( lsn_t  lsn)

Write the flushed LSN to the page header of the first page in the system tablespace.

Parameters
[in]lsnflushed LSN
Returns
DB_SUCCESS or error number

◆ fil_write_zeros()

static dberr_t fil_write_zeros ( const fil_node_t file,
ulint  page_size,
os_offset_t  start,
ulint  len,
bool  read_only_mode 
)
static

Fill the pages with NULs.

Parameters
[in]fileTablespace file
[in]page_sizephysical page size
[in]startOffset from the start of the file in bytes
[in]lenLength in bytes
[in]read_only_modeif true, then read only mode checks are enforced.
Returns
DB_SUCCESS or error code

Variable Documentation

◆ dot_ext

const char* dot_ext[] = {"", ".ibd", ".cfg", ".cfp", ".ibt", ".ibu", ".dblwr"}

Common InnoDB file extentions.

◆ EMPTY_OPEN_SLOT

const size_t EMPTY_OPEN_SLOT = std::numeric_limits<size_t>::max()
static

Sentinel for empty open slot.

◆ fil_addr_null

fil_addr_t fil_addr_null = {FIL_NULL, 0}

The null file address.

◆ fil_n_file_opened

ulint fil_n_file_opened = 0

Number of files currently open.

◆ fil_n_log_flushes

ulint fil_n_log_flushes = 0

The number of fsyncs done to the log.

◆ fil_n_pending_log_flushes

ulint fil_n_pending_log_flushes = 0

Number of pending redo log flushes.

◆ fil_n_pending_tablespace_flushes

ulint fil_n_pending_tablespace_flushes = 0

Number of pending tablespace flushes.

◆ fil_system

Fil_system* fil_system = nullptr
static

The tablespace memory cache.

This variable is nullptr before the module is initialized.

◆ FIL_VALIDATE_SKIP

const size_t FIL_VALIDATE_SKIP = 17
static

Try fil_validate() every this many times.

◆ MAX_PAGES_TO_READ

const size_t MAX_PAGES_TO_READ = 1
static

Maximum number of pages to read to determine the space ID.

◆ MAX_SHARDS

const size_t MAX_SHARDS = 64
static

Maximum number of shards supported.

◆ MySQL_datadir_path

Fil_path MySQL_datadir_path

Reference to the server data directory.

The MySQL server –datadir value.

◆ MySQL_undo_path

Fil_path MySQL_undo_path

Reference to the server undo directory.

The MySQL server –innodb-undo-directory value.

◆ MySQL_undo_path_is_unique

bool MySQL_undo_path_is_unique

The undo path is different from any other known directory.

◆ REDO_SHARD

const size_t REDO_SHARD = MAX_SHARDS - 1
static

The redo log is in its own shard.

◆ UNDO_SHARDS

const size_t UNDO_SHARDS = 4
static

Number of undo shards to reserve.

◆ UNDO_SHARDS_START

const size_t UNDO_SHARDS_START = REDO_SHARD - (UNDO_SHARDS + 1)
static

The UNDO logs have their own shards (4).