MySQL 8.0.39
Source Code Documentation
|
Data file control information. More...
#include <fsp0file.h>
Public Member Functions | |
Datafile () | |
Datafile (const char *name, uint32_t flags, page_no_t size, ulint order) | |
Datafile (const Datafile &file) | |
~Datafile () | |
Datafile & | operator= (const Datafile &file) |
void | init (const char *name, uint32_t flags) |
Initialize the name and flags of this datafile. More... | |
void | shutdown () |
Release the resources. More... | |
dberr_t | open_read_only (bool strict) |
Open a data file in read-only mode to check if it exists so that it can be validated. More... | |
dberr_t | open_read_write (bool read_only_mode) |
Open a data file in read-write mode during start-up so that doublewrite pages can be restored and then it can be validated. More... | |
void | init_file_info () |
Initialize OS specific file info. More... | |
dberr_t | close () |
Close a data file. More... | |
bool | is_raw_type () |
Returns if the Datafile is created in raw partition. More... | |
void | make_filepath (const char *dirpath, const char *filename, ib_file_suffix ext) |
Make a full filepath from a directory path and a filename. More... | |
void | set_filepath (const char *filepath) |
Set the filepath by duplicating the filepath sent in. More... | |
void | set_name (const char *name) |
Allocate and set the datafile or tablespace name in m_name. More... | |
dberr_t | validate_to_dd (space_id_t space_id, uint32_t flags, bool for_import) |
Validates the datafile and checks that it conforms with the expected space ID and flags. More... | |
dberr_t | validate_for_recovery (space_id_t space_id) |
Validates this datafile for the purpose of recovery. More... | |
dberr_t | validate_first_page (space_id_t space_id, lsn_t *flush_lsn, bool for_import) |
Checks the consistency of the first page of a datafile when the tablespace is opened. More... | |
lsn_t | get_flush_lsn () |
Get LSN of first page. More... | |
const char * | name () const |
Get Datafile::m_name. More... | |
const char * | filepath () const |
Get Datafile::m_filepath. More... | |
pfs_os_file_t | handle () const |
Get Datafile::m_handle. More... | |
ulint | order () const |
Get Datafile::m_order. More... | |
ulint | server_version () const |
Get Datafile::m_server_version. More... | |
ulint | space_version () const |
Get Datafile::m_space_version. More... | |
space_id_t | space_id () const |
Get Datafile::m_space_id. More... | |
uint32_t | flags () const |
Get Datafile::m_flags. More... | |
bool | is_open () const |
bool | is_valid () const |
Get Datafile::m_is_valid. More... | |
ulint | last_os_error () const |
Get the last OS error reported. More... | |
bool | same_filepath_as (const char *other) const |
Do a quick test if the filepath provided looks the same as this filepath byte by byte. More... | |
bool | same_as (const Datafile &other) const |
Test if another opened datafile is the same file as this object. More... | |
dberr_t | find_space_id () |
Determine the space id of the given file descriptor by reading a few pages from the beginning of the .ibd file. More... | |
page_no_t | size () const |
Public Attributes | |
struct stat | m_file_info |
Use the following to determine the uniqueness of this datafile. More... | |
byte * | m_encryption_key |
Encryption key read from first page. More... | |
byte * | m_encryption_iv |
Encryption iv read from first page. More... | |
Encryption::Progress | m_encryption_op_in_progress |
Encryption operation in progress. More... | |
uint32_t | m_encryption_master_key_id |
Master key id read from first page. More... | |
Protected Attributes | |
char * | m_filepath |
Physical file path with base name and extension. More... | |
ulint | m_last_os_error |
Last OS error received so it can be reported if needed. More... | |
Private Member Functions | |
void | free_filepath () |
Free the filepath buffer. More... | |
void | set_filename () |
Set the filename pointer to the start of the file name in the filepath. More... | |
dberr_t | open_or_create (bool read_only_mode) |
Create/open a data file. More... | |
dberr_t | read_first_page () |
Reads a few significant fields from the first page of the datafile, which must already be open. More... | |
void | free_first_page () |
Free the first page from memory when it is no longer needed. More... | |
void | set_open_flags (os_file_create_t open_flags) |
Set the Datafile::m_open_flags. More... | |
dberr_t | restore_from_doublewrite (page_no_t restore_page_no) |
Finds a given page of the given space id from the double write buffer and copies it to the corresponding .ibd file. More... | |
Private Attributes | |
char * | m_name |
Datafile name at the tablespace location. More... | |
char * | m_filename |
Points into m_filepath to the file name with extension. More... | |
pfs_os_file_t | m_handle |
Open file handle. More... | |
os_file_create_t | m_open_flags |
Flags to use for opening the data file. More... | |
page_no_t | m_size |
size in pages More... | |
ulint | m_order |
ordinal position of this datafile in the tablespace More... | |
device_t | m_type |
The type of the data file. More... | |
space_id_t | m_space_id |
Tablespace ID. More... | |
uint32_t | m_server_version |
Server version. More... | |
uint32_t | m_space_version |
Space version. More... | |
uint32_t | m_flags |
Tablespace flags. More... | |
bool | m_exists |
true if file already existed on startup More... | |
bool | m_is_valid |
byte * | m_first_page |
Buffer to hold first page. More... | |
bool | m_atomic_write |
true if atomic writes enabled for this file More... | |
Friends | |
class | Tablespace |
class | SysTablespace |
Data file control information.
|
inline |
|
inline |
|
inline |
dberr_t Datafile::close | ( | void | ) |
Close a data file.
|
inline |
Get Datafile::m_filepath.
dberr_t Datafile::find_space_id | ( | ) |
Determine the space id of the given file descriptor by reading a few pages from the beginning of the .ibd file.
|
inline |
Get Datafile::m_flags.
|
private |
Free the filepath buffer.
|
private |
Free the first page from memory when it is no longer needed.
|
inline |
Get LSN of first page.
|
inline |
Get Datafile::m_handle.
void Datafile::init | ( | const char * | name, |
uint32_t | flags | ||
) |
Initialize the name and flags of this datafile.
[in] | name | tablespace name, will be copied |
[in] | flags | tablespace flags |
void Datafile::init_file_info | ( | ) |
Initialize OS specific file info.
|
inline |
|
inline |
Returns if the Datafile is created in raw partition.
|
inline |
Get Datafile::m_is_valid.
|
inline |
Get the last OS error reported.
void Datafile::make_filepath | ( | const char * | dirpath, |
const char * | filename, | ||
ib_file_suffix | ext | ||
) |
Make a full filepath from a directory path and a filename.
Prepend the dirpath to filename using the extension given. If dirpath is nullptr, prepend the default datadir to filepath. Store the result in m_filepath.
[in] | dirpath | directory path |
[in] | filename | filename or filepath |
[in] | ext | filename extension |
|
inline |
Get Datafile::m_name.
|
private |
Create/open a data file.
[in] | read_only_mode | if true, then readonly mode checks are enforced. |
dberr_t Datafile::open_read_only | ( | bool | strict | ) |
Open a data file in read-only mode to check if it exists so that it can be validated.
[in] | strict | whether to issue error messages |
dberr_t Datafile::open_read_write | ( | bool | read_only_mode | ) |
Open a data file in read-write mode during start-up so that doublewrite pages can be restored and then it can be validated.
[in] | read_only_mode | if true, then readonly mode checks are enforced. |
|
inline |
Get Datafile::m_order.
|
private |
Reads a few significant fields from the first page of the datafile, which must already be open.
Finds a given page of the given space id from the double write buffer and copies it to the corresponding .ibd file.
[in] | restore_page_no | Page number to restore |
bool Datafile::same_as | ( | const Datafile & | other | ) | const |
Test if another opened datafile is the same file as this object.
[in] | other | Datafile to compare with |
bool Datafile::same_filepath_as | ( | const char * | other | ) | const |
Do a quick test if the filepath provided looks the same as this filepath byte by byte.
If they are two different looking paths to the same file, same_as() will be used to show that after the files are opened.
[in] | other | filepath to compare with |
true | if it is the same filename by byte comparison |
false | if it looks different |
|
inline |
Get Datafile::m_server_version.
|
inlineprivate |
Set the filename pointer to the start of the file name in the filepath.
void Datafile::set_filepath | ( | const char * | filepath | ) |
Set the filepath by duplicating the filepath sent in.
This is the name of the file with its extension and absolute or relative path.
[in] | filepath | filepath to set |
void Datafile::set_name | ( | const char * | name | ) |
Allocate and set the datafile or tablespace name in m_name.
If a name is provided, use it; else if the datafile is file-per-table, extract a file-per-table tablespace name from m_filepath; else it is a general tablespace, so just call it that for now. The value of m_name will be freed in the destructor.
[in] | name | Tablespace Name if known, nullptr if not |
|
inlineprivate |
Set the Datafile::m_open_flags.
open_flags | The Open flags to set. |
void Datafile::shutdown | ( | ) |
Release the resources.
|
inline |
|
inline |
Get Datafile::m_space_id.
|
inline |
Get Datafile::m_space_version.
dberr_t Datafile::validate_first_page | ( | space_id_t | space_id, |
lsn_t * | flush_lsn, | ||
bool | for_import | ||
) |
Checks the consistency of the first page of a datafile when the tablespace is opened.
This occurs before the fil_space_t is created so the Space ID found here must not already be open. m_is_valid is set true on success, else false. The datafile is always closed when returning from this method.
[in] | space_id | Expected space ID |
[out] | flush_lsn | contents of FIL_PAGE_FILE_FLUSH_LSN |
[in] | for_import | if it is for importing (only valid for the first file of the system tablespace) |
DB_WRONG_FILE_NAME | tablespace in file header doesn't match expected value |
DB_SUCCESS | on if the datafile is valid |
DB_CORRUPTION | if the datafile is not readable |
DB_INVALID_ENCRYPTION_META | if the encryption meta data is not readable |
DB_TABLESPACE_EXISTS | if there is a duplicate space_id |
TODO: Enable following after WL#11063: Update server version information in InnoDB tablespaces:
else if (!for_import && (fsp_header_get_server_version(m_first_page) != DD_SPACE_CURRENT_SRV_VERSION)) { error_txt = "Wrong server version"; } else if (!for_import && (fsp_header_get_space_version(m_first_page) != DD_SPACE_CURRENT_SPACE_VERSION)) { error_txt = "Wrong tablespace version"; }
dberr_t Datafile::validate_for_recovery | ( | space_id_t | space_id | ) |
Validates this datafile for the purpose of recovery.
The file should exist and be successfully opened. We initially open it in read-only mode because we just want to read the SpaceID. However, if the first page is corrupt and needs to be restored from the doublewrite buffer, we will reopen it in write mode and try to restore that page. The file will be closed when returning from this method.
[in] | space_id | Expected space ID |
DB_SUCCESS | on success m_is_valid is also set true on success, else false. |
dberr_t Datafile::validate_to_dd | ( | space_id_t | space_id, |
uint32_t | flags, | ||
bool | for_import | ||
) |
Validates the datafile and checks that it conforms with the expected space ID and flags.
The file should exist and be successfully opened in order for this function to validate it.
[in] | space_id | The expected tablespace ID. |
[in] | flags | The expected tablespace flags. |
[in] | for_import | if it is for importing |
DB_SUCCESS | if tablespace is valid, DB_ERROR if not. m_is_valid is also set true on success, else false. |
|
friend |
|
friend |
|
private |
true if atomic writes enabled for this file
byte* Datafile::m_encryption_iv |
Encryption iv read from first page.
byte* Datafile::m_encryption_key |
Encryption key read from first page.
uint32_t Datafile::m_encryption_master_key_id |
Master key id read from first page.
Encryption::Progress Datafile::m_encryption_op_in_progress |
Encryption operation in progress.
|
private |
true if file already existed on startup
struct stat Datafile::m_file_info |
Use the following to determine the uniqueness of this datafile.
Use field st_ino.
|
private |
Points into m_filepath to the file name with extension.
|
protected |
Physical file path with base name and extension.
|
private |
Buffer to hold first page.
|
private |
Tablespace flags.
Contained in the datafile header. If this is a system tablespace, FSP_SPACE_FLAGS are only valid in the first datafile.
|
private |
Open file handle.
|
private |
|
protected |
Last OS error received so it can be reported if needed.
|
private |
Datafile name at the tablespace location.
This is either the basename of the file if an absolute path was entered, or it is the relative path to the datadir or Tablespace::m_path.
|
private |
Flags to use for opening the data file.
|
private |
ordinal position of this datafile in the tablespace
|
private |
Server version.
|
private |
size in pages
|
private |
Tablespace ID.
Contained in the datafile header. If this is a system tablespace, FSP_SPACE_ID is only valid in the first datafile.
|
private |
Space version.
|
private |
The type of the data file.