MySQL 8.0.40
Source Code Documentation
Arch_File_Ctx Class Reference

Archiver file context. More...

#include <arch0arch.h>

Classes

class  Recovery
 Recovery system data structure for the archiver. More...
 

Public Member Functions

 Arch_File_Ctx ()
 Constructor: Initialize members. More...
 
 ~Arch_File_Ctx ()
 Destructor: Close open file and free resources. More...
 
dberr_t init (const char *path, const char *base_dir, const char *base_file, uint num_files)
 Initializes archiver file context. More...
 
dberr_t open (bool read_only, lsn_t start_lsn, uint file_index, uint64_t file_offset, uint64_t file_size)
 Open a file at specific index. More...
 
dberr_t open_new (lsn_t start_lsn, uint64_t new_file_size, uint64_t initial_file_size)
 Add a new file and open. More...
 
dberr_t open_next (lsn_t start_lsn, uint64_t file_offset, uint64_t file_size)
 Open next file for read. More...
 
dberr_t read (byte *to_buffer, const uint64_t offset, uint size)
 Read data from the current file that is open. More...
 
dberr_t resize_and_overwrite_with_zeros (uint64_t file_size)
 Resize file to provided size and overwrite the whole file with 0x00. More...
 
dberr_t write (Arch_File_Ctx *from_file, byte *from_buffer, uint offset, uint size)
 Write data to this file context from the given file offset. More...
 
dberr_t write (Arch_File_Ctx *from_file, byte *from_buffer, uint size)
 Write data to this file context from the current offset. More...
 
void flush ()
 Flush file. More...
 
void close ()
 Close file, if open. More...
 
bool is_closed () const
 Check if file is closed. More...
 
uint64_t bytes_left () const
 Check how much is left in current file. More...
 
void build_name (uint idx, lsn_t dir_lsn, char *buffer, uint length)
 Construct file name at specific index. More...
 
void build_dir_name (lsn_t dir_lsn, char *buffer, uint length)
 Construct group directory name. More...
 
uint64_t get_size () const
 Get the logical size of a file. More...
 
uint64_t get_offset () const
 
uint get_index () const
 Get current file index. More...
 
uint get_count () const
 Get number of files. More...
 
uint64_t get_phy_size () const
 Get the physical size of a file that is open in this context. More...
 
void update_stop_point (uint file_index, lsn_t stop_lsn)
 Update stop lsn of a file in the group. More...
 
bool validate (Arch_Group *group, uint file_index, lsn_t start_lsn, uint &reset_count)
 Check if the information maintained in the memory is the same as the information maintained in the files. More...
 
void save_reset_point_in_mem (lsn_t lsn, Arch_Page_Pos pos)
 Update the reset information in the in-memory structure that we maintain for faster access. More...
 
bool find_reset_point (lsn_t check_lsn, Arch_Point &reset_point)
 Find the appropriate reset LSN that is less than or equal to the given lsn and fetch the reset point. More...
 
bool find_stop_point (Arch_Group *group, lsn_t check_lsn, Arch_Point &stop_point, Arch_Page_Pos last_pos)
 Find the first stop LSN that is greater than the given LSN and fetch the stop point. More...
 
bool delete_file (uint file_index, lsn_t begin_lsn)
 Delete a single file belonging to the specified file index. More...
 
void delete_files (lsn_t begin_lsn)
 Delete all files for this archive group. More...
 
lsn_t purge (lsn_t begin_lsn, lsn_t end_lsn, lsn_t purge_lsn)
 Purge archived files until the specified purge LSN. More...
 
void get_status (std::vector< std::pair< lsn_t, bool > > &status)
 Fetch the status of the page tracking system. More...
 

Private Member Functions

bool validate_reset_block_in_file (pfs_os_file_t file, uint file_index, uint &reset_count)
 Check if the reset information maintained in the memory is the same as the information maintained in the given file. More...
 
bool validate_stop_point_in_file (Arch_Group *group, pfs_os_file_t file, uint file_index)
 Check if the stop LSN maintained in the memory is the same as the information maintained in the files. More...
 
lsn_t fetch_reset_lsn (uint64_t block_num)
 Fetch reset lsn of a particular reset point pertaining to a file. More...
 

Private Attributes

char * m_name_buf {nullptr}
 File name buffer. More...
 
uint m_name_len {}
 File name buffer length. More...
 
uint m_base_len {}
 Fixed length part of the file. More...
 
const char * m_path_name {nullptr}
 Fixed part of the path to file. More...
 
const char * m_dir_name {nullptr}
 Directory name prefix. More...
 
const char * m_file_name {nullptr}
 File name prefix. More...
 
pfs_os_file_t m_file
 Current file descriptor. More...
 
uint m_index {}
 File index within the archive group. More...
 
uint m_count {}
 Current number of files in the archive group. More...
 
uint64_t m_offset {}
 Current file offset. More...
 
uint64_t m_size {}
 File size limit in bytes. More...
 
Arch_Reset m_reset
 Queue of file structure holding reset information pertaining to their respective files in a group. More...
 
std::vector< lsn_tm_stop_points
 Vector of stop points corresponding to a file. More...
 

Detailed Description

Archiver file context.

Represents a set of fixed size files within a group

Constructor & Destructor Documentation

◆ Arch_File_Ctx()

Arch_File_Ctx::Arch_File_Ctx ( )
inline

Constructor: Initialize members.

◆ ~Arch_File_Ctx()

Arch_File_Ctx::~Arch_File_Ctx ( )
inline

Destructor: Close open file and free resources.

Member Function Documentation

◆ build_dir_name()

void Arch_File_Ctx::build_dir_name ( lsn_t  dir_lsn,
char *  buffer,
uint  length 
)

Construct group directory name.

Parameters
[in]dir_lsnlsn of the group
[out]bufferdirectory name. The buffer is allocated by caller.
[in]lengthbuffer length

◆ build_name()

void Arch_File_Ctx::build_name ( uint  idx,
lsn_t  dir_lsn,
char *  buffer,
uint  length 
)

Construct file name at specific index.

Parameters
[in]idxfile index
[in]dir_lsnlsn of the group
[out]bufferfile name including path. The buffer is allocated by caller.
[in]lengthbuffer length

◆ bytes_left()

uint64_t Arch_File_Ctx::bytes_left ( ) const
inline

Check how much is left in current file.

Returns
length left in bytes

◆ close()

void Arch_File_Ctx::close ( void  )
inline

Close file, if open.

◆ delete_file()

bool Arch_File_Ctx::delete_file ( uint  file_index,
lsn_t  begin_lsn 
)

Delete a single file belonging to the specified file index.

Parameters
[in]file_indexfile index of the file which needs to be deleted
[in]begin_lsngroup's start lsn
Returns
true if successful, else false.

◆ delete_files()

void Arch_File_Ctx::delete_files ( lsn_t  begin_lsn)

Delete all files for this archive group.

Parameters
[in]begin_lsngroup's start lsn

◆ fetch_reset_lsn()

lsn_t Arch_File_Ctx::fetch_reset_lsn ( uint64_t  block_num)
private

Fetch reset lsn of a particular reset point pertaining to a file.

Parameters
[in]block_numblock number where the reset occurred.
Returns
reset lsn

◆ find_reset_point()

bool Arch_File_Ctx::find_reset_point ( lsn_t  check_lsn,
Arch_Point reset_point 
)

Find the appropriate reset LSN that is less than or equal to the given lsn and fetch the reset point.

Parameters
[in]check_lsnLSN to be searched against
[out]reset_pointreset position of the fetched reset point
Returns
true if the search was successful.

◆ find_stop_point()

bool Arch_File_Ctx::find_stop_point ( Arch_Group group,
lsn_t  check_lsn,
Arch_Point stop_point,
Arch_Page_Pos  last_pos 
)

Find the first stop LSN that is greater than the given LSN and fetch the stop point.

Parameters
[in]groupthe group whose stop_point we're interested in
[in]check_lsnLSN to be searched against
[out]stop_pointstop point
[in]last_posposition of the last block in the group; m_write_pos if group is active and m_stop_pos if not
Returns
true if the search was successful.

◆ flush()

void Arch_File_Ctx::flush ( )
inline

Flush file.

◆ get_count()

uint Arch_File_Ctx::get_count ( ) const
inline

Get number of files.

Returns
current file count

◆ get_index()

uint Arch_File_Ctx::get_index ( void  ) const
inline

Get current file index.

Returns
current file index

◆ get_offset()

uint64_t Arch_File_Ctx::get_offset ( ) const
inline

◆ get_phy_size()

uint64_t Arch_File_Ctx::get_phy_size ( ) const
inline

Get the physical size of a file that is open in this context.

Returns
physical file size

◆ get_size()

uint64_t Arch_File_Ctx::get_size ( ) const
inline

Get the logical size of a file.

Returns
logical file size.

◆ get_status()

void Arch_File_Ctx::get_status ( std::vector< std::pair< lsn_t, bool > > &  status)
inline

Fetch the status of the page tracking system.

Parameters
[out]statusvector of a pair of (ID, bool) where ID is the start/stop point and bool is true if the ID is a start point else false

◆ init()

dberr_t Arch_File_Ctx::init ( const char *  path,
const char *  base_dir,
const char *  base_file,
uint  num_files 
)

Initializes archiver file context.

Parameters
[in]pathpath to the file
[in]base_dirdirectory name prefix
[in]base_filefile name prefix
[in]num_filesinitial number of files
Returns
error code.

◆ is_closed()

bool Arch_File_Ctx::is_closed ( ) const
inline

Check if file is closed.

Returns
true, if file is closed

◆ open()

dberr_t Arch_File_Ctx::open ( bool  read_only,
lsn_t  start_lsn,
uint  file_index,
uint64_t  file_offset,
uint64_t  file_size 
)

Open a file at specific index.

Parameters
[in]read_onlyopen in read only mode
[in]start_lsnstart lsn for the group
[in]file_indexindex of the file within the group which needs to be opened
[in]file_offsetstart offset
[in]file_sizemaximum allowed file size or 0 to use its current real size on disk as the limitation (file is full)
Returns
error code.

◆ open_new()

dberr_t Arch_File_Ctx::open_new ( lsn_t  start_lsn,
uint64_t  new_file_size,
uint64_t  initial_file_size 
)

Add a new file and open.

Parameters
[in]start_lsnstart lsn for the group
[in]new_file_sizesize limit for the new file
[in]initial_file_sizeinitial size of file to create
Returns
error code.

◆ open_next()

dberr_t Arch_File_Ctx::open_next ( lsn_t  start_lsn,
uint64_t  file_offset,
uint64_t  file_size 
)

Open next file for read.

Parameters
[in]start_lsnstart lsn for the group
[in]file_offsetstart offset
[in]file_sizemaximum allowed file size or 0 to use its current real size on disk as the limitation (file is full)
Returns
error code.

◆ purge()

lsn_t Arch_File_Ctx::purge ( lsn_t  begin_lsn,
lsn_t  end_lsn,
lsn_t  purge_lsn 
)

Purge archived files until the specified purge LSN.

Parameters
[in]begin_lsnstart LSN of the group
[in]end_lsnend LSN of the group
[in]purge_lsnpurge LSN until which files needs to be purged
Returns
LSN until which purging was successful
Return values
LSN_MAXif there was no purging done.

Removes the deleted file from reset info, thereby incrementing the iterator.

Only files which have a reset would be purged in the above loop. We want to purge all the files preceding reset_file_it regardless of whether it has a reset or not.

◆ read()

dberr_t Arch_File_Ctx::read ( byte to_buffer,
const uint64_t  offset,
uint  size 
)

Read data from the current file that is open.

Caller must ensure that the size is within the limits of current file context.

Parameters
[in,out]to_bufferread data into this buffer
[in]offsetfile offset from where to read
[in]sizesize of data to read in bytes
Returns
error code

◆ resize_and_overwrite_with_zeros()

dberr_t Arch_File_Ctx::resize_and_overwrite_with_zeros ( uint64_t  file_size)

Resize file to provided size and overwrite the whole file with 0x00.

Parameters
[in]file_sizenew file size
Returns
error code

◆ save_reset_point_in_mem()

void Arch_File_Ctx::save_reset_point_in_mem ( lsn_t  lsn,
Arch_Page_Pos  pos 
)

Update the reset information in the in-memory structure that we maintain for faster access.

Parameters
[in]lsnlsn at the time of reset
[in]pospos at the time of reset

◆ update_stop_point()

void Arch_File_Ctx::update_stop_point ( uint  file_index,
lsn_t  stop_lsn 
)

Update stop lsn of a file in the group.

Parameters
[in]file_indexfile_index the current write_pos belongs to
[in]stop_lsnstop point

◆ validate()

bool Arch_File_Ctx::validate ( Arch_Group group,
uint  file_index,
lsn_t  start_lsn,
uint reset_count 
)

Check if the information maintained in the memory is the same as the information maintained in the files.

Returns
true if both sets of information are the same
Parameters
[in]groupgroup whose file is being validated
[in]file_indexindex of the file which is being validated
[in]start_lsn
[in,out]reset_countcount of files which has been validated
Returns
true if both the sets of information are the same.

◆ validate_reset_block_in_file()

bool Arch_File_Ctx::validate_reset_block_in_file ( pfs_os_file_t  file,
uint  file_index,
uint reset_count 
)
private

Check if the reset information maintained in the memory is the same as the information maintained in the given file.

Parameters
[in]filefile descriptor
[in]file_indexindex of the file
[in,out]reset_countnumber of files processed containing reset data
Returns
true if both sets of information are the same

◆ validate_stop_point_in_file()

bool Arch_File_Ctx::validate_stop_point_in_file ( Arch_Group group,
pfs_os_file_t  file,
uint  file_index 
)
private

Check if the stop LSN maintained in the memory is the same as the information maintained in the files.

Parameters
[in]groupgroup whose file is being validated
[in]filefile descriptor
[in]file_indexindex of the file for which the validation is happening
Returns
true if both the sets of information are the same.

◆ write() [1/2]

dberr_t Arch_File_Ctx::write ( Arch_File_Ctx from_file,
byte from_buffer,
uint  offset,
uint  size 
)

Write data to this file context from the given file offset.

Data source is another file context or buffer. If buffer is NULL, data is copied from input file context. Caller must ensure that the size is within the limits of current file for both source and destination file context.

Parameters
[in]from_filefile context to copy data from
[in]from_bufferbuffer to copy data or NULL
[in]offsetfile offset from where to write
[in]sizesize of data to copy in bytes
Returns
error code

◆ write() [2/2]

dberr_t Arch_File_Ctx::write ( Arch_File_Ctx from_file,
byte from_buffer,
uint  size 
)

Write data to this file context from the current offset.

Data source is another file context or buffer. If buffer is NULL, data is copied from input file context. Caller must ensure that the size is within the limits of current file for both source and destination file context.

Parameters
[in]from_filefile context to copy data from
[in]from_bufferbuffer to copy data or NULL
[in]sizesize of data to copy in bytes
Returns
error code

Member Data Documentation

◆ m_base_len

uint Arch_File_Ctx::m_base_len {}
private

Fixed length part of the file.

Path ended with directory separator.

◆ m_count

uint Arch_File_Ctx::m_count {}
private

Current number of files in the archive group.

◆ m_dir_name

const char* Arch_File_Ctx::m_dir_name {nullptr}
private

Directory name prefix.

◆ m_file

pfs_os_file_t Arch_File_Ctx::m_file
private

Current file descriptor.

◆ m_file_name

const char* Arch_File_Ctx::m_file_name {nullptr}
private

File name prefix.

◆ m_index

uint Arch_File_Ctx::m_index {}
private

File index within the archive group.

◆ m_name_buf

char* Arch_File_Ctx::m_name_buf {nullptr}
private

File name buffer.

Used if caller doesn't allocate buffer.

◆ m_name_len

uint Arch_File_Ctx::m_name_len {}
private

File name buffer length.

◆ m_offset

uint64_t Arch_File_Ctx::m_offset {}
private

Current file offset.

◆ m_path_name

const char* Arch_File_Ctx::m_path_name {nullptr}
private

Fixed part of the path to file.

◆ m_reset

Arch_Reset Arch_File_Ctx::m_reset
private

Queue of file structure holding reset information pertaining to their respective files in a group.

Protected by Arch_Page_Sys::m_mutex and Arch_Page_Sys::m_oper_mutex.

Note
used only by the page archiver

◆ m_size

uint64_t Arch_File_Ctx::m_size {}
private

File size limit in bytes.

◆ m_stop_points

std::vector<lsn_t> Arch_File_Ctx::m_stop_points
private

Vector of stop points corresponding to a file.

Stop point refers to the stop lsn (checkpoint lsn) until which the pages are guaranteed to be tracked in a file. Each block in a file maintains this information. Protected by Arch_Page_Sys::m_oper_mutex.

Note
used only by the page archiver

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