MySQL 26.7.0
Source Code Documentation
Datafile Class Reference

Data file control information. More...

#include <fsp0file.h>

Classes

struct  first_page_fields_cache_t
 Cache of fields extracted from the first page. More...
 

Public Member Functions

 Datafile ()
 
 Datafile (const Datafile &file)=delete
 
 ~Datafile ()
 
Datafileoperator= (const Datafile &file)=delete
 
void shutdown ()
 Release the resources. More...
 
dberr_t open_read_only ()
 Open a data file in read-only mode to check if it exists so that it can be validated. More...
 
dberr_t close ()
 Close a data file. More...
 
void extract_fields_from_first_page (const byte *page)
 Extracts basic space fields from the first page header. 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...
 
dberr_t validate_to_dd (const byte *page, space_id_t space_id, uint32_t flags, const std::string &filepath, bool for_import)
 Validates the first page of tablespace supplied and checks that it conforms with the expected space ID and flags. More...
 
dberr_t validate_for_recovery (space_id_t space_id, uint32_t expected_physical_page_size)
 Validates this datafile for the purpose of recovery. More...
 
void reset_first_page_fields_cache ()
 
const char * filepath () const
 Get Datafile::m_filepath. More...
 
pfs_os_file_t handle () const
 Get Datafile::m_handle. More...
 
uint32_t get_cached_server_version () const
 Returns cached server version read from the first page during validation. More...
 
uint32_t get_cached_space_version () const
 Returns cached space version read from the first page during validation. More...
 
space_id_t get_cached_space_id () const
 Returns cached space ID read from the first page during validation. More...
 
uint32_t get_cached_space_flags () const
 Returns cached space FSP flags read from the first page during validation. More...
 
uint32_t get_cached_space_flush_lsn () const
 Returns cached space flush LSN read from the first page during validation. More...
 
size_t physical_page_size () const
 Get the physical page size used by the tablespace. More...
 
bool is_open () const
 
bool is_valid () const
 Get Datafile::m_is_valid. More...
 
page_no_t size () const
 

Public Attributes

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::Progress::NONE}
 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...
 

Private Member Functions

dberr_t validate_first_page (const byte *page, space_id_t space_id, const std::string &filepath, bool for_import)
 Checks the consistency of the first page supplied when the tablespace is opened, and verifies the space is not already added to the fil mappings with a different datafile path. More...
 
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...
 
ut::Expected< ut::unique_ptr_aligned< byte[]> > read_first_page (space_id_t space_id, uint32_t physical_page_size)
 Reads the first page of the datafile. More...
 

Private Attributes

char * m_filename {}
 Points into m_filepath to the file name with extension. More...
 
pfs_os_file_t m_handle
 Open file handle. More...
 
page_no_t m_size {}
 size in pages More...
 
node_device_type_t m_type {node_device_type_t::REGULAR_FILE}
 The type of the data file. More...
 
first_page_fields_cache_t m_first_page_fields_cache
 Cache of fields extracted from the first page. More...
 
bool m_exists {}
 true if file already existed on startup More...
 
bool m_is_valid {}
 

Friends

class SysTablespace
 

Detailed Description

Data file control information.

Constructor & Destructor Documentation

◆ Datafile() [1/2]

Datafile::Datafile ( )
inline

◆ Datafile() [2/2]

Datafile::Datafile ( const Datafile file)
delete

◆ ~Datafile()

Datafile::~Datafile ( )
inline

Member Function Documentation

◆ close()

dberr_t Datafile::close ( void  )

Close a data file.

Returns
DB_SUCCESS or error code

◆ extract_fields_from_first_page()

void Datafile::extract_fields_from_first_page ( const byte page)

Extracts basic space fields from the first page header.

Parameters
[in]pageThe content of the first page of the tablespace.

◆ filepath()

const char * Datafile::filepath ( ) const
inline

Get Datafile::m_filepath.

Returns
m_filepath

◆ free_filepath()

void Datafile::free_filepath ( )
private

Free the filepath buffer.

◆ get_cached_server_version()

uint32_t Datafile::get_cached_server_version ( ) const
inline

Returns cached server version read from the first page during validation.

◆ get_cached_space_flags()

uint32_t Datafile::get_cached_space_flags ( ) const
inline

Returns cached space FSP flags read from the first page during validation.

◆ get_cached_space_flush_lsn()

uint32_t Datafile::get_cached_space_flush_lsn ( ) const
inline

Returns cached space flush LSN read from the first page during validation.

◆ get_cached_space_id()

space_id_t Datafile::get_cached_space_id ( ) const
inline

Returns cached space ID read from the first page during validation.

◆ get_cached_space_version()

uint32_t Datafile::get_cached_space_version ( ) const
inline

Returns cached space version read from the first page during validation.

◆ handle()

pfs_os_file_t Datafile::handle ( ) const
inline

Get Datafile::m_handle.

Returns
m_handle

◆ 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

◆ 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

◆ open_read_only()

dberr_t Datafile::open_read_only ( )

Open a data file in read-only mode to check if it exists so that it can be validated.

Returns
DB_SUCCESS or error code

◆ operator=()

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

◆ physical_page_size()

size_t Datafile::physical_page_size ( ) const
inline

Get the physical page size used by the tablespace.

◆ read_first_page()

ut::Expected< ut::unique_ptr_aligned< byte[]> > Datafile::read_first_page ( space_id_t  space_id,
uint32_t  physical_page_size 
)
private

Reads the first page of the datafile.

The datafile must be already opened.

Parameters
[in]space_idExpected space ID
[in]physical_page_sizePhysical page size of the tablespace.
Returns
DB_SUCCESS or DB_IO_ERROR if page cannot be read

◆ reset_first_page_fields_cache()

void Datafile::reset_first_page_fields_cache ( )
inline

◆ 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

◆ shutdown()

void Datafile::shutdown ( )

Release the resources.

◆ size()

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

◆ validate_first_page()

dberr_t Datafile::validate_first_page ( const byte page,
space_id_t  space_id,
const std::string &  filepath,
bool  for_import 
)
private

Checks the consistency of the first page supplied when the tablespace is opened, and verifies the space is not already added to the fil mappings with a different datafile path.

m_is_valid is set true on success, else false. The datafile will not be attempted to be opened.

Parameters
[in]pageThe content of the first page of the tablespace.
[in]space_idExpected space ID
[in]filepathThe file path to the first node in the tablespace, used for error message printing.
[in]for_importif it is for importing
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

◆ validate_for_recovery()

dberr_t Datafile::validate_for_recovery ( space_id_t  space_id,
uint32_t  expected_physical_page_size 
)

Validates this datafile for the purpose of recovery.

The file must exist and be already opened. The datafile is always closed when returning from this method.

Parameters
[in]space_idExpected space ID
[in]expected_physical_page_sizePhysical page size of the 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 m_is_valid is also set true on success, else false.

◆ validate_to_dd()

dberr_t Datafile::validate_to_dd ( const byte page,
space_id_t  space_id,
uint32_t  flags,
const std::string &  filepath,
bool  for_import 
)

Validates the first page of tablespace supplied and checks that it conforms with the expected space ID and flags.

The datafile will not be attempted to be opened.

Parameters
[in]pageThe content of the first page of the tablespace.
[in]space_idThe expected tablespace ID.
[in]flagsThe expected tablespace flags.
[in]filepathThe file path to the first node in the tablespace, used for error message printing.
[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

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::Progress::NONE}

Encryption operation in progress.

◆ m_exists

bool Datafile::m_exists {}
private

true if file already existed on startup

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

first_page_fields_cache_t Datafile::m_first_page_fields_cache
private

Cache of fields extracted from the first page.

◆ m_handle

pfs_os_file_t Datafile::m_handle
private

Open file handle.

◆ m_is_valid

bool Datafile::m_is_valid {}
private

◆ m_size

page_no_t Datafile::m_size {}
private

size in pages

◆ m_type

The type of the data file.


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