MySQL 9.1.0
Source Code Documentation
Datafile Class Reference

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 ()
 
Datafileoperator= (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...
 
bytem_encryption_key
 Encryption key read from first page. More...
 
bytem_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
 
bytem_first_page
 Buffer to hold first page. More...
 

Friends

class Tablespace
 
class SysTablespace
 

Detailed Description

Data file control information.

Constructor & Destructor Documentation

◆ Datafile() [1/3]

Datafile::Datafile ( )
inline

◆ Datafile() [2/3]

Datafile::Datafile ( const char *  name,
uint32_t  flags,
page_no_t  size,
ulint  order 
)
inline

◆ Datafile() [3/3]

Datafile::Datafile ( const Datafile file)
inline

◆ ~Datafile()

Datafile::~Datafile ( )
inline

Member Function Documentation

◆ close()

dberr_t Datafile::close ( void  )

Close a data file.

Returns
DB_SUCCESS or error code

◆ filepath()

const char * Datafile::filepath ( ) const
inline

Get Datafile::m_filepath.

Returns
m_filepath

◆ find_space_id()

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.

Returns
DB_SUCCESS if space id was successfully identified, else DB_ERROR.

◆ flags()

uint32_t Datafile::flags ( ) const
inline

Get Datafile::m_flags.

Returns
m_flags

◆ free_filepath()

void Datafile::free_filepath ( )
private

Free the filepath buffer.

◆ free_first_page()

void Datafile::free_first_page ( )
private

Free the first page from memory when it is no longer needed.

◆ get_flush_lsn()

lsn_t Datafile::get_flush_lsn ( )
inline

Get LSN of first page.

◆ handle()

pfs_os_file_t Datafile::handle ( ) const
inline

Get Datafile::m_handle.

Returns
m_handle

◆ init()

void Datafile::init ( const char *  name,
uint32_t  flags 
)

Initialize the name and flags of this datafile.

Parameters
[in]nametablespace name, will be copied
[in]flagstablespace flags

◆ init_file_info()

void Datafile::init_file_info ( )

Initialize OS specific file info.

◆ is_open()

bool Datafile::is_open ( ) const
inline
Returns
true if m_handle is open, false if not

◆ is_raw_type()

bool Datafile::is_raw_type ( )
inline

Returns if the Datafile is created in raw partition.

Returns
true if partition used is raw , false otherwise

◆ is_valid()

bool Datafile::is_valid ( void  ) const
inline

Get Datafile::m_is_valid.

Returns
m_is_valid

◆ last_os_error()

ulint Datafile::last_os_error ( ) const
inline

Get the last OS error reported.

Returns
m_last_os_error

◆ make_filepath()

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.

Parameters
[in]dirpathdirectory path
[in]filenamefilename or filepath
[in]extfilename extension

◆ name()

const char * Datafile::name ( ) const
inline

Get Datafile::m_name.

Returns
m_name

◆ open_or_create()

dberr_t Datafile::open_or_create ( bool  read_only_mode)
private

Create/open a data file.

Parameters
[in]read_only_modeif true, then readonly mode checks are enforced.
Returns
DB_SUCCESS or error code

◆ open_read_only()

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.

Parameters
[in]strictwhether to issue error messages
Returns
DB_SUCCESS or error code

◆ open_read_write()

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.

Parameters
[in]read_only_modeif true, then readonly mode checks are enforced.
Returns
DB_SUCCESS or error code

◆ operator=()

Datafile & Datafile::operator= ( const Datafile file)
inline

◆ order()

ulint Datafile::order ( ) const
inline

Get Datafile::m_order.

Returns
m_order

◆ read_first_page()

dberr_t Datafile::read_first_page ( )
private

Reads a few significant fields from the first page of the datafile, which must already be open.

Returns
DB_SUCCESS or DB_IO_ERROR if page cannot be read

◆ restore_from_doublewrite()

dberr_t Datafile::restore_from_doublewrite ( page_no_t  restore_page_no)
private

Finds a given page of the given space id from the double write buffer and copies it to the corresponding .ibd file.

Parameters
[in]restore_page_noPage number to restore
Returns
DB_SUCCESS if page was restored from doublewrite, else DB_ERROR

◆ same_as()

bool Datafile::same_as ( const Datafile other) const

Test if another opened datafile is the same file as this object.

Parameters
[in]otherDatafile to compare with
Returns
true if it is the same file, else false

◆ same_filepath_as()

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.

Parameters
[in]otherfilepath to compare with
Return values
trueif it is the same filename by byte comparison
falseif it looks different

◆ server_version()

ulint Datafile::server_version ( ) const
inline

Get Datafile::m_server_version.

Returns
m_server_version

◆ set_filename()

void Datafile::set_filename ( )
inlineprivate

Set the filename pointer to the start of the file name in the filepath.

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

Parameters
[in]filepathfilepath to set

◆ set_name()

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.

Parameters
[in]nameTablespace Name if known, nullptr if not

◆ set_open_flags()

void Datafile::set_open_flags ( os_file_create_t  open_flags)
inlineprivate

Set the Datafile::m_open_flags.

Parameters
open_flagsThe Open flags to set.

◆ shutdown()

void Datafile::shutdown ( )

Release the resources.

◆ size()

page_no_t Datafile::size ( ) const
inline
Returns
file size in number of pages

◆ space_id()

space_id_t Datafile::space_id ( ) const
inline

Get Datafile::m_space_id.

Returns
m_space_id

◆ space_version()

ulint Datafile::space_version ( ) const
inline

Get Datafile::m_space_version.

Returns
m_space_version

◆ validate_first_page()

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.

Parameters
[in]space_idExpected space ID
[out]flush_lsncontents of FIL_PAGE_FILE_FLUSH_LSN
[in]for_importif it is for importing (only valid for the first file of the system tablespace)
Return values
DB_WRONG_FILE_NAMEtablespace in file header doesn't match expected value
DB_SUCCESSon if the datafile is valid
DB_CORRUPTIONif the datafile is not readable
DB_INVALID_ENCRYPTION_METAif the encryption meta data is not readable
DB_TABLESPACE_EXISTSif 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"; }

◆ validate_for_recovery()

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.

Parameters
[in]space_idExpected space ID
Return values
DB_SUCCESSon success m_is_valid is also set true on success, else false.

◆ validate_to_dd()

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.

Parameters
[in]space_idThe expected tablespace ID.
[in]flagsThe expected tablespace flags.
[in]for_importif it is for importing
Return values
DB_SUCCESSif tablespace is valid, DB_ERROR if not. m_is_valid is also set true on success, else false.

Friends And Related Function Documentation

◆ SysTablespace

friend class SysTablespace
friend

◆ Tablespace

friend class Tablespace
friend

Member Data Documentation

◆ m_encryption_iv

byte* Datafile::m_encryption_iv

Encryption iv read from first page.

◆ m_encryption_key

byte* Datafile::m_encryption_key

Encryption key read from first page.

◆ m_encryption_master_key_id

uint32_t Datafile::m_encryption_master_key_id

Master key id read from first page.

◆ m_encryption_op_in_progress

Encryption::Progress Datafile::m_encryption_op_in_progress

Encryption operation in progress.

◆ m_exists

bool Datafile::m_exists
private

true if file already existed on startup

◆ m_file_info

struct stat Datafile::m_file_info

Use the following to determine the uniqueness of this datafile.

Use field st_ino.

◆ m_filename

char* Datafile::m_filename
private

Points into m_filepath to the file name with extension.

◆ m_filepath

char* Datafile::m_filepath
protected

Physical file path with base name and extension.

◆ m_first_page

byte* Datafile::m_first_page
private

Buffer to hold first page.

◆ m_flags

uint32_t Datafile::m_flags
private

Tablespace flags.

Contained in the datafile header. If this is a system tablespace, FSP_SPACE_FLAGS are only valid in the first datafile.

◆ m_handle

pfs_os_file_t Datafile::m_handle
private

Open file handle.

◆ m_is_valid

bool Datafile::m_is_valid
private

◆ m_last_os_error

ulint Datafile::m_last_os_error
protected

Last OS error received so it can be reported if needed.

◆ m_name

char* Datafile::m_name
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.

◆ m_open_flags

os_file_create_t Datafile::m_open_flags
private

Flags to use for opening the data file.

◆ m_order

ulint Datafile::m_order
private

ordinal position of this datafile in the tablespace

◆ m_server_version

uint32_t Datafile::m_server_version
private

Server version.

◆ m_size

page_no_t Datafile::m_size
private

size in pages

◆ m_space_id

space_id_t Datafile::m_space_id
private

Tablespace ID.

Contained in the datafile header. If this is a system tablespace, FSP_SPACE_ID is only valid in the first datafile.

◆ m_space_version

uint32_t Datafile::m_space_version
private

Space version.

◆ m_type

device_t Datafile::m_type
private

The type of the data file.


The documentation for this class was generated from the following files: