MySQL 8.4.2
Source Code Documentation
|
The tablespace memory cache. More...
Public Types | |
using | Fil_shards = std::vector< Fil_shard * > |
Public Member Functions | |
Fil_system (size_t n_shards, size_t max_open) | |
Constructor. More... | |
~Fil_system () | |
Destructor. More... | |
fil_space_t * | space_acquire (space_id_t space_id, bool silent) |
Acquire a tablespace when it could be dropped concurrently. More... | |
Tablespace_dirs::Result | get_scanned_filename_by_space_id (space_id_t space_id) |
Fetch the file names opened for a space_id during recovery. More... | |
Tablespace_dirs::Result | get_scanned_filename_by_space_num (space_id_t space_num, space_id_t &space_id) |
Fetch the file name opened for an undo space number. More... | |
bool | get_file_by_space_id (space_id_t space_id, std::string &name) |
Fetch the file name opened for a space_id from the file map. More... | |
bool | get_file_by_space_num (space_id_t space_num, space_id_t &space_id, std::string &name) |
Fetch the file name opened for an undo space number. More... | |
bool | erase_path (space_id_t space_id) |
Erase a tablespace ID and its mapping from the scanned files. More... | |
void | add_old_file (const std::string &file_path) |
Add file to old file list. More... | |
void | rename_partition_files (bool revert) |
Rename partition files during upgrade. More... | |
void | clear_old_files () |
Clear all accumulated old files. More... | |
const std::string & | get_root (const std::string &path) const |
Get the top level directory where this filename was found. More... | |
dberr_t | prepare_open_for_business (bool read_only_mode) |
Update the DD if any files were moved to a new location. More... | |
void | flush_file_spaces () |
Flush to disk the writes in file spaces possibly cached by the OS (note: spaces of type FIL_TYPE_TEMPORARY are skipped) More... | |
void | purge () |
Clean up the shards. More... | |
size_t | count_undo_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 | is_deleted (space_id_t space_id) noexcept |
Check if a particular undo space_id for a page in the buffer pool has been deleted recently. More... | |
fil_space_t * | get_space_by_name (const char *name) |
Fetch the fil_space_t instance that maps to the name. More... | |
bool | is_greater_than_max_id (space_id_t space_id) const |
Check a space ID against the maximum known tablespace ID. More... | |
void | set_maximum_space_id (const fil_space_t *space) |
Update the maximum known tablespace ID. More... | |
void | update_maximum_space_id (space_id_t space_id) |
Update the maximum known space ID if it's smaller than max_id. More... | |
bool | assign_new_space_id (space_id_t *space_id) |
Assigns a new space id for a new single-table tablespace. More... | |
void | wait_while_ios_in_progress () const |
Allows other threads to advance work while we wait for I/Os to complete. More... | |
bool | close_file_in_all_LRU () |
Tries to close a file in all the LRU lists. More... | |
void | open_all_system_tablespaces () |
Opens all system tablespace data files in all shards. More... | |
void | close_all_files () |
Close all open files. More... | |
size_t | get_minimum_limit_for_open_files (size_t n_files_not_belonging_in_lru) const |
Returns minimum open files limit to be set to allow the specified number of non-LRU files opened. More... | |
bool | set_open_files_limit (size_t &new_max_open_files) |
Changes the maximum opened files limit. More... | |
size_t | get_open_files_limit () const |
Returns maximum number of allowed opened files. More... | |
dberr_t | iterate (Fil_iterator::Function &f) |
Iterate through all persistent tablespace files (FIL_TYPE_TABLESPACE) returning the nodes via callback function cbk. More... | |
size_t | encryption_rotate () |
Rotate the tablespace keys by new master key. More... | |
void | encryption_reencrypt (std::vector< space_id_t > &sid_vector) |
Reencrypt tablespace keys by current master key. More... | |
void | space_detach (fil_space_t *space) |
Detach a space object from the tablespace memory cache. More... | |
space_id_t | get_max_space_id () const |
bool | lookup_for_recovery (space_id_t space_id) |
Lookup the tablespace ID. More... | |
dberr_t | open_for_recovery (space_id_t space_id) |
Open a tablespace that has a redo log record to apply. More... | |
bool | check_missing_tablespaces () |
This function should be called after recovery has completed. More... | |
void | moved (dd::Object_id object_id, space_id_t space_id, const char *space_name, const std::string &old_path, const std::string &new_path, bool moved_prev_or_has_datadir) |
Note that a file has been relocated. More... | |
bool | check_path (const std::string &path) const |
Check if a path is known to InnoDB. More... | |
std::string | get_dirs () const |
Get the list of directories that InnoDB knows about. More... | |
void | set_scan_dir (const std::string &directory, bool is_undo_dir) |
Normalize and save a directory to scan for IBD and IBU datafiles before recovery. More... | |
void | set_scan_dirs (const std::string &directories) |
Normalize and save a list of directories to scan for IBD and IBU datafiles before recovery. More... | |
dberr_t | scan () |
Scan the directories to build the tablespace ID to file name mapping table. More... | |
Fil_shard * | shard_by_id (space_id_t space_id) const |
Fil_shard by space ID. More... | |
void | mutex_acquire_all () const |
Acquire all the mutexes. More... | |
void | mutex_release_all () const |
Release all the mutexes. More... | |
bool | validate () const |
Checks the consistency of the tablespace cache. More... | |
bool | mutex_owned_all () const |
Check if all mutexes are owned. More... | |
dberr_t | rename_tablespace_name (space_id_t space_id, const char *old_name, const char *new_name) |
Rename a tablespace. More... | |
void | free_scanned_files () |
Free the data structures required for recovery. More... | |
Static Public Member Functions | |
static size_t | get_limit_for_non_lru_files (size_t open_files_limit) |
Returns maximum number of allowed non-LRU files opened for a specified open files limit. More... | |
static bool | space_belongs_in_LRU (const fil_space_t *space) |
Determines if a file belongs to the least-recently-used list. More... | |
static space_id_t | get_tablespace_id (const std::string &filename) |
Get the tablespace ID from an .ibd and/or an undo tablespace. More... | |
Private Member Functions | |
fil_load_status | ibd_open_for_recovery (space_id_t space_id, const std::string &path, fil_space_t *&space) |
Open an ibd tablespace and add it to the InnoDB data structures. More... | |
Fil_system (Fil_system &&)=delete | |
Fil_system (const Fil_system &)=delete | |
Fil_system & | operator= (const Fil_system &)=delete |
Private Attributes | |
Fil_shards | m_shards |
Fil_shards managed. More... | |
fil::detail::Open_files_limit | m_open_files_limit |
space_id_t | m_max_assigned_id |
Maximum space id in the existing tables, or assigned during the time mysqld has been up; at an InnoDB startup we scan the data dictionary and set here the maximum of the space id's of the tables there. More... | |
bool | m_space_id_reuse_warned |
true if fil_space_create() has issued a warning about potential space_id reuse More... | |
dd_fil::Tablespaces | m_moved |
List of tablespaces that have been relocated. More... | |
std::mutex | m_moved_mutex |
Mutex protecting the list of relocated tablespaces. More... | |
Tablespace_dirs | m_dirs |
Tablespace directories scanned at startup. More... | |
std::vector< std::string > | m_old_paths |
Old file paths during 5.7 upgrade. More... | |
std::atomic_size_t | m_next_shard_to_close_from_LRU {} |
Next index (modulo number of shards) to try to close a file from the LRU list to distribute closures evenly between the shards. More... | |
std::atomic_size_t | m_n_files_not_belonging_in_lru {} |
Current number of files that are not belonging in LRU. More... | |
ib::Throttler | m_MANY_NON_LRU_FILES_OPENED_throttler {} |
Throttles messages about high files not belonging in LRU count, the warning ER_IB_WARN_MANY_NON_LRU_FILES_OPENED. More... | |
ib::Throttler | m_TRYING_TO_OPEN_FILE_FOR_LONG_TIME_throttler {} |
Throttles messages about long waiting for opened files limit, the warning ER_IB_MSG_TRYING_TO_OPEN_FILE_FOR_LONG_TIME. More... | |
ib::Throttler | m_ACCESSING_NONEXISTINC_SPACE_throttler {} |
Throttles messages about accessing space that was already removed, the warning ACCESSING_NONEXISTINC_SPACE. More... | |
Friends | |
class | Fil_shard |
The tablespace memory cache.
using Fil_system::Fil_shards = std::vector<Fil_shard *> |
Fil_system::Fil_system | ( | size_t | n_shards, |
size_t | max_open | ||
) |
Constructor.
[in] | n_shards | Number of shards to create |
[in] | max_open | Maximum number of open files |
Fil_system::~Fil_system | ( | ) |
Destructor.
|
privatedelete |
|
privatedelete |
|
inline |
Add file to old file list.
The list is used during 5.7 upgrade failure to revert back the modified file names. We modify partitioned file names to lower case.
[in] | file_path | old file name with path |
bool Fil_system::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 ids is not enough, we may need to recycle ids.
[out] | space_id | Set this to the new tablespace ID |
bool Fil_system::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.
|
inline |
Check if a path is known to InnoDB.
[in] | path | Path to check |
|
inline |
Clear all accumulated old files.
void Fil_system::close_all_files | ( | ) |
Close all open files.
bool Fil_system::close_file_in_all_LRU | ( | ) |
Tries to close a file in all the LRU lists.
The caller must hold the mutex.
|
inline |
Count how many truncated undo space IDs are still tracked in the buffer pool and the file_system cache.
[in] | undo_num | undo tablespace number. |
void Fil_system::encryption_reencrypt | ( | std::vector< space_id_t > & | sid_vector | ) |
Reencrypt tablespace keys by current master key.
size_t Fil_system::encryption_rotate | ( | ) |
Rotate the tablespace keys by new master key.
|
inline |
Erase a tablespace ID and its mapping from the scanned files.
[in] | space_id | Tablespace ID to erase |
void Fil_system::flush_file_spaces | ( | ) |
Flush to disk the writes in file spaces possibly cached by the OS (note: spaces of type FIL_TYPE_TEMPORARY are skipped)
|
inline |
Free the data structures required for recovery.
|
inline |
Get the list of directories that InnoDB knows about.
|
inline |
Fetch the file name opened for a space_id from the file map.
[in] | space_id | tablespace ID |
[out] | name | the scanned filename |
|
inline |
Fetch the file name opened for an undo space number.
[in] | space_num | undo tablespace number |
[out] | space_id | tablespace ID |
[out] | name | the scanned filename |
|
static |
Returns maximum number of allowed non-LRU files opened for a specified open files limit.
|
inline |
size_t Fil_system::get_minimum_limit_for_open_files | ( | size_t | n_files_not_belonging_in_lru | ) | const |
Returns minimum open files limit to be set to allow the specified number of non-LRU files opened.
This is inverse function for the get_limit_for_non_lru_files.
|
inline |
Returns maximum number of allowed opened files.
const std::string & Fil_system::get_root | ( | const std::string & | path | ) | const |
Get the top level directory where this filename was found.
[in] | path | Path to look for. |
|
inline |
Fetch the file names opened for a space_id during recovery.
[in] | space_id | Tablespace ID to lookup |
|
inline |
Fetch the file name opened for an undo space number.
[in] | space_num | undo tablespace numb er to lookup |
[out] | space_id | Tablespace ID found |
|
inline |
Fetch the fil_space_t instance that maps to the name.
[in] | name | Tablespace name to lookup |
|
static |
Get the tablespace ID from an .ibd and/or an undo tablespace.
If the ID is 0 on the first page then try finding the ID with Datafile::find_space_id().
[in] | filename | File name to check |
|
private |
Open an ibd tablespace and add it to the InnoDB data structures.
This is similar to fil_ibd_open() except that it is used while processing the redo log, so the data dictionary is not available and very little validation is done. The tablespace name is extracted from the dbname/tablename.ibd portion of the filename, which assumes that the file is a file-per-table tablespace. Any name will do for now. General tablespace names will be read from the dictionary after it has been recovered. The tablespace flags are read at this time from the first page of the file in validate_for_recovery().
[in] | space_id | tablespace ID |
[in] | path | path/to/databasename/tablename.ibd |
[out] | space | the tablespace, or nullptr on error |
|
inlinenoexcept |
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 Fil_shard::m_deleted_spaces until Fil:shard::checkpoint removes the fil_space_t from Fil_system.
[in] | space_id | Tablespace ID to check. |
|
inline |
Check a space ID against the maximum known tablespace ID.
[in] | space_id | Tablespace ID to check |
dberr_t Fil_system::iterate | ( | Fil_iterator::Function & | f | ) |
Iterate through all persistent tablespace files (FIL_TYPE_TABLESPACE) returning the nodes via callback function cbk.
[in] | f | Callback |
bool Fil_system::lookup_for_recovery | ( | space_id_t | space_id | ) |
Lookup the tablespace ID.
Lookup the tablespace ID for recovery and DDL log apply.
[in] | space_id | Tablespace ID to lookup |
|
inline |
Note that a file has been relocated.
[in] | object_id | Server DD tablespace ID |
[in] | space_id | InnoDB tablespace ID |
[in] | space_name | Tablespace name |
[in] | old_path | Path to the old location |
[in] | new_path | Path scanned from disk |
[in] | moved_prev_or_has_datadir | The move has happened before 8.0.38/8.4.1/9.0.0 or table is created with data dir clause. |
|
inline |
Acquire all the mutexes.
|
inline |
Check if all mutexes are owned.
|
inline |
Release all the mutexes.
void Fil_system::open_all_system_tablespaces | ( | ) |
Opens all system tablespace data files in all shards.
dberr_t Fil_system::open_for_recovery | ( | space_id_t | space_id | ) |
Open a tablespace that has a redo log record to apply.
[in] | space_id | Tablespace ID |
|
privatedelete |
dberr_t Fil_system::prepare_open_for_business | ( | bool | read_only_mode | ) |
Update the DD if any files were moved to a new location.
Free the Tablespace_files instance.
[in] | read_only_mode | true if InnoDB is started in read only mode. |
|
inline |
Clean up the shards.
void Fil_system::rename_partition_files | ( | bool | revert | ) |
Rename partition files during upgrade.
[in] | revert | if true, revert to old names |
dberr_t Fil_system::rename_tablespace_name | ( | space_id_t | space_id, |
const char * | old_name, | ||
const char * | new_name | ||
) |
Rename a tablespace.
Use the space_id to find the shard.
[in] | space_id | tablespace ID |
[in] | old_name | old tablespace name |
[in] | new_name | new tablespace name |
|
inline |
Scan the directories to build the tablespace ID to file name mapping table.
|
inline |
Update the maximum known tablespace ID.
[in] | space | Tablespace instance |
bool Fil_system::set_open_files_limit | ( | size_t & | new_max_open_files | ) |
Changes the maximum opened files limit.
[in,out] | new_max_open_files | New value for the open files limit. If the limit cannot be changed, the value is changed to a minimum value recommended. If there are any concurrent calls to set_open_files_limit in progress, setting the limit will fail and the new_max_open_files will be set to 0. |
|
inline |
Normalize and save a directory to scan for IBD and IBU datafiles before recovery.
[in] | directory | Directory to scan |
[in] | is_undo_dir | true for an undo directory |
|
inline |
Normalize and save a list of directories to scan for IBD and IBU datafiles before recovery.
[in] | directories | Directories to scan |
|
inline |
Fil_shard by space ID.
[in] | space_id | Tablespace ID |
fil_space_t * Fil_system::space_acquire | ( | space_id_t | space_id, |
bool | silent | ||
) |
Acquire a tablespace when it could be dropped concurrently.
Used by background threads that do not necessarily hold proper locks for concurrency control.
[in] | space_id | Tablespace ID |
[in] | silent | Whether to silently ignore missing tablespaces |
|
static |
Determines if a file belongs to the least-recently-used list.
[in] | space | Tablespace to check |
void Fil_system::space_detach | ( | fil_space_t * | space | ) |
Detach a space object from the tablespace memory cache.
Closes the tablespace files but does not delete them. There must not be any pending I/O's or flushes on the files.
[in,out] | space | tablespace |
|
inline |
Update the maximum known space ID if it's smaller than max_id.
[in] | space_id | Value to set if it's greater |
bool Fil_system::validate | ( | ) | const |
Checks the consistency of the tablespace cache.
|
inline |
Allows other threads to advance work while we wait for I/Os to complete.
|
friend |
|
private |
Throttles messages about accessing space that was already removed, the warning ACCESSING_NONEXISTINC_SPACE.
|
private |
Tablespace directories scanned at startup.
|
private |
Throttles messages about high files not belonging in LRU count, the warning ER_IB_WARN_MANY_NON_LRU_FILES_OPENED.
|
private |
Maximum space id in the existing tables, or assigned during the time mysqld has been up; at an InnoDB startup we scan the data dictionary and set here the maximum of the space id's of the tables there.
|
private |
List of tablespaces that have been relocated.
We need to update the DD when it is safe to do so.
|
private |
Mutex protecting the list of relocated tablespaces.
|
private |
Current number of files that are not belonging in LRU.
This includes redo and temporary tablespaces, but not files that were temporarily removed from the LRU for I/O.
|
private |
Next index (modulo number of shards) to try to close a file from the LRU list to distribute closures evenly between the shards.
|
private |
Old file paths during 5.7 upgrade.
|
private |
|
private |
Fil_shards managed.
|
private |
true if fil_space_create() has issued a warning about potential space_id reuse
|
private |
Throttles messages about long waiting for opened files limit, the warning ER_IB_MSG_TRYING_TO_OPEN_FILE_FOR_LONG_TIME.