MySQL 9.0.0
Source Code Documentation
Arch_Group Class Reference

Contiguous archived data for redo log or page tracking. More...

#include <arch0arch.h>

Classes

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

Public Types

typedef std::function< dberr_t(uint64_t start_offset, byte *header)> Get_file_header_callback
 Function responsible to format the header of a new file which is created, when the stream of data is written to a sequence of new files. More...
 

Public Member Functions

 Arch_Group (lsn_t start_lsn, uint header_len, ib_mutex_t *mutex)
 Constructor: Initialize members. More...
 
 ~Arch_Group ()
 Destructor: Delete all files for non-durable archiving. More...
 
dberr_t init_file_ctx (const char *path, const char *base_dir, const char *base_file, uint num_files, uint64_t file_size, Arch_group_uuid uuid)
 Initialize the file context for the archive group. More...
 
void close_file_ctxs ()
 
void disable (lsn_t end_lsn)
 Mark archive group inactive. More...
 
void attach (bool is_durable)
 Attach a client to the archive group. More...
 
uint detach (lsn_t stop_lsn, Arch_Page_Pos *stop_pos)
 Detach a client when archiving is stopped by the client. More...
 
void release (bool is_durable)
 Release the archive group from a client. More...
 
dberr_t build_active_file_name ()
 Construct file name for the active file which indicates whether a group is active or not. More...
 
dberr_t build_durable_file_name ()
 Construct file name for the durable file which indicates whether a group was made durable or not. More...
 
int mark_active ()
 Mark the group active by creating a file in the respective group directory. More...
 
int mark_durable ()
 Mark the group durable by creating a file in the respective group directory. More...
 
int mark_inactive ()
 Mark the group inactive by deleting the 'active' file. More...
 
bool is_active () const
 Check if archiving is going on for this group. More...
 
dberr_t write_file_header (byte *from_buffer, uint length)
 Write the header (RESET page) to an archived file. More...
 
dberr_t write_to_file (Arch_File_Ctx *from_file, byte *from_buffer, uint length, bool partial_write, bool do_persist, Get_file_header_callback new_file)
 Archive data to one or more files. 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 (lsn_t check_lsn, Arch_Point &stop_point, Arch_Page_Pos write_pos)
 Find the first stop LSN that is greater than the given LSN and fetch the stop point. More...
 
void adjust_end_lsn (lsn_t &stop_lsn, uint32_t &blk_len)
 Adjust end LSN to end of file. More...
 
void adjust_copy_length (lsn_t arch_lsn, uint32_t &copy_len)
 Adjust redo copy length to end of file. More...
 
bool validate_info_in_files ()
 Check if the information maintained in the memory is the same as the information maintained in the files. More...
 
uint get_file_count () const
 Get the total number of archived files belonging to this group. More...
 
bool is_referenced () const
 Check if any client (durable or not) is attached to the archiver. More...
 
bool is_durable_client_active () const
 Check if any client requiring durable archiving is active. More...
 
bool is_durable () const
 Check if any client requires durable archiving. More...
 
uint purge (lsn_t purge_lsn, lsn_t &purged_lsn)
 Purge archived files until the specified purge LSN. 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...
 
void update_stop_point (Arch_Page_Pos pos, lsn_t stop_lsn)
 Update stop lsn of a file in the group. More...
 
dberr_t recover (Arch_Recv_Group_Info &group_info, Arch_Dblwr_Ctx *dblwr_ctx)
 Recover the information belonging to this group from the archived files. More...
 
int read_data (Arch_Page_Pos cur_pos, byte *buff, uint buff_len)
 Parse block for block info (header/data). More...
 
void get_file_name (uint idx, char *name_buf, uint buf_len)
 Get archived file name at specific index in this group. More...
 
uint64_t get_file_size () const
 Get the current file size for this group. More...
 
lsn_t get_begin_lsn () const
 Get start LSN for this group. More...
 
lsn_t get_end_lsn () const
 
Arch_Page_Pos get_stop_pos () const
 
Arch_group_uuid get_uuid () const
 
void get_status (std::vector< std::pair< lsn_t, bool > > &status)
 Fetch the status of the page tracking system. More...
 
dberr_t open_file (Arch_Page_Pos write_pos, bool create_new)
 Open the file which was open at the time of a crash, during crash recovery, and set the file offset to the last written offset. More...
 
 Arch_Group (Arch_Group const &)=delete
 Disable copy construction. More...
 
Arch_Groupoperator= (Arch_Group const &)=delete
 Disable assignment. More...
 

Static Public Member Functions

static dberr_t init_dblwr_file_ctx (const char *path, const char *base_file, uint num_files, uint64_t file_size)
 Initialize the doublewrite buffer file context for the archive group. More...
 
static dberr_t write_to_doublewrite_file (Arch_File_Ctx *from_file, byte *from_buffer, uint write_size, Arch_Page_Dblwr_Offset offset)
 Write to the doublewrite buffer before writing archived data to a file. More...
 
static void shutdown ()
 Operations to be done at the time of shutdown. More...
 

Private Member Functions

int read_from_file (Arch_Page_Pos *read_pos, uint read_len, byte *read_buff)
 Get page IDs from archived file. More...
 
void get_dir_name (char *name_buf, uint buf_len)
 Get the directory name for this archive group. More...
 
dberr_t prepare_file_with_header (uint64_t start_offset, Get_file_header_callback &get_header)
 Create a new file and write the header. More...
 

Private Attributes

bool m_is_active {true}
 If the group is active. More...
 
char * m_active_file_name {nullptr}
 To know which group was active at the time of a crash/shutdown during recovery we create an empty file in the group directory. More...
 
pfs_os_file_t m_active_file
 File descriptor for a file required to indicate that the group was active at the time of crash during recovery . More...
 
char * m_durable_file_name {nullptr}
 File name for the durable file which indicates whether a group was made durable or not. More...
 
pfs_os_file_t m_durable_file
 File descriptor for a file to indicate that the group was made durable or not. More...
 
uint m_ref_count {}
 Number of clients referencing the group. More...
 
uint m_dur_ref_count {}
 Number of clients referencing for durable archiving. More...
 
uint m_num_active {}
 Number of clients for which archiving is in progress. More...
 
lsn_t m_begin_lsn {LSN_MAX}
 Start LSN for the archive group. More...
 
lsn_t m_end_lsn {LSN_MAX}
 End lsn for this archive group. More...
 
Arch_Page_Pos m_stop_pos {}
 Stop position of the group, if it's not active. More...
 
uint m_header_len {}
 Header length for the archived files. More...
 
uint64_t m_file_size
 Size of file used when a new file is being created. More...
 
Arch_group_uuid m_uuid {}
 UUID generated for this arch group. More...
 
Arch_File_Ctx m_file_ctx
 Archive file context. More...
 
ib_mutex_t * m_arch_mutex
 Mutex protecting concurrent operations by multiple clients. More...
 

Static Private Attributes

static Arch_File_Ctx s_dblwr_file_ctx
 Doublewrite buffer file context. More...
 

Detailed Description

Contiguous archived data for redo log or page tracking.

If there is a gap, that is if archiving is stopped and started, a new group is created.

Member Typedef Documentation

◆ Get_file_header_callback

typedef std::function<dberr_t(uint64_t start_offset, byte *header)> Arch_Group::Get_file_header_callback

Function responsible to format the header of a new file which is created, when the stream of data is written to a sequence of new files.

Parameters
[in]start_offsetoffset at which a new file starts, expressed in bytes from the beginning of the stream
[in]headerheader to format

Constructor & Destructor Documentation

◆ Arch_Group() [1/2]

Arch_Group::Arch_Group ( lsn_t  start_lsn,
uint  header_len,
ib_mutex_t *  mutex 
)
inline

Constructor: Initialize members.

Parameters
[in]start_lsnstart LSN for the group
[in]header_lenlength of header for archived files
[in]mutexarchive system mutex from caller

◆ ~Arch_Group()

Arch_Group::~Arch_Group ( )

Destructor: Delete all files for non-durable archiving.

◆ Arch_Group() [2/2]

Arch_Group::Arch_Group ( Arch_Group const &  )
delete

Disable copy construction.

Member Function Documentation

◆ adjust_copy_length()

void Arch_Group::adjust_copy_length ( lsn_t  arch_lsn,
uint32_t &  copy_len 
)

Adjust redo copy length to end of file.

This is used in debug mode to archive only till end of file.

Parameters
[in]arch_lsnLSN up to which data is already archived
[in,out]copy_lenlength of data to copy in bytes

◆ adjust_end_lsn()

void Arch_Group::adjust_end_lsn ( lsn_t stop_lsn,
uint32_t &  blk_len 
)

Adjust end LSN to end of file.

This is used in debug mode to test the case when LSN is at file boundary.

Parameters
[in,out]stop_lsnstop lsn for client
[out]blk_lenlast block length

◆ attach()

void Arch_Group::attach ( bool  is_durable)
inline

Attach a client to the archive group.

Parameters
[in]is_durabletrue, if durable tracking is requested

◆ build_active_file_name()

dberr_t Arch_Group::build_active_file_name ( )

Construct file name for the active file which indicates whether a group is active or not.

Note
Used only by the page archiver.
Returns
error code.

◆ build_durable_file_name()

dberr_t Arch_Group::build_durable_file_name ( )

Construct file name for the durable file which indicates whether a group was made durable or not.

Note
Used only by the page archiver.
Returns
error code.

◆ close_file_ctxs()

void Arch_Group::close_file_ctxs ( )
inline

◆ detach()

uint Arch_Group::detach ( lsn_t  stop_lsn,
Arch_Page_Pos stop_pos 
)
inline

Detach a client when archiving is stopped by the client.

The client still has reference to the group so that the group is not destroyed when it retrieves the archived data. The reference is removed later by Arch_Group::release.

Parameters
[in]stop_lsnarchive stop lsn for client
[in]stop_posarchive stop position for client. Used only by the page_archiver.
Returns
number of active clients

◆ disable()

void Arch_Group::disable ( lsn_t  end_lsn)
inline

Mark archive group inactive.

A group is marked inactive by archiver background before entering into idle state ARCH_STATE_IDLE.

Parameters
[in]end_lsnlsn where redo archiving is stopped

◆ find_reset_point()

bool Arch_Group::find_reset_point ( lsn_t  check_lsn,
Arch_Point reset_point 
)
inline

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_Group::find_stop_point ( lsn_t  check_lsn,
Arch_Point stop_point,
Arch_Page_Pos  write_pos 
)
inline

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

Parameters
[in]check_lsnLSN to be searched against
[out]stop_pointstop point
[in]write_poslatest write_pos
Returns
true if the search was successful.

◆ get_begin_lsn()

lsn_t Arch_Group::get_begin_lsn ( ) const
inline

Get start LSN for this group.

Returns
start LSN

◆ get_dir_name()

void Arch_Group::get_dir_name ( char *  name_buf,
uint  buf_len 
)
inlineprivate

Get the directory name for this archive group.

It is used for cleaning up the archive directory.

Parameters
[out]name_bufdirectory name and path. Caller must allocate the buffer.
[in]buf_lenbuffer length

◆ get_end_lsn()

lsn_t Arch_Group::get_end_lsn ( ) const
inline
Returns
stop LSN for this group

◆ get_file_count()

uint Arch_Group::get_file_count ( ) const
inline

Get the total number of archived files belonging to this group.

Returns
number of archived files

◆ get_file_name()

void Arch_Group::get_file_name ( uint  idx,
char *  name_buf,
uint  buf_len 
)
inline

Get archived file name at specific index in this group.

Caller would use it to open and copy data from archived files.

Parameters
[in]idxfile index in the group
[out]name_buffile name and path. Caller must allocate the buffer.
[in]buf_lenallocated buffer length

◆ get_file_size()

uint64_t Arch_Group::get_file_size ( ) const
inline

Get the current file size for this group.

Fixed size files are used for archiving data in a group.

Returns
file size in bytes

◆ get_status()

void Arch_Group::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

◆ get_stop_pos()

Arch_Page_Pos Arch_Group::get_stop_pos ( ) const
inline
Returns
stop block position of the group.

◆ get_uuid()

Arch_group_uuid Arch_Group::get_uuid ( ) const
inline
Returns
uuid for the arch group

◆ init_dblwr_file_ctx()

dberr_t Arch_Group::init_dblwr_file_ctx ( const char *  path,
const char *  base_file,
uint  num_files,
uint64_t  file_size 
)
static

Initialize the doublewrite buffer file context for the archive group.

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

◆ init_file_ctx()

dberr_t Arch_Group::init_file_ctx ( const char *  path,
const char *  base_dir,
const char *  base_file,
uint  num_files,
uint64_t  file_size,
Arch_group_uuid  uuid 
)
inline

Initialize the file context for the archive group.

File context keeps the archived data in files on disk. There is one file context for a archive group.

Parameters
[in]pathpath to the file
[in]base_dirdirectory name prefix
[in]base_filefile name prefix
[in]num_filesinitial number of files
[in]file_sizesize of file used when a new file is created
[in]uuiduuid of this arch group or 0 if unknown
Returns
error code.

◆ is_active()

bool Arch_Group::is_active ( ) const
inline

Check if archiving is going on for this group.

Returns
true, if the group is active

◆ is_durable()

bool Arch_Group::is_durable ( ) const
inline

Check if any client requires durable archiving.

Returns
true if there is at least 1 client that requires durable archiving

◆ is_durable_client_active()

bool Arch_Group::is_durable_client_active ( ) const
inline

Check if any client requiring durable archiving is active.

Returns
true if any durable client is still attached, else false

◆ is_referenced()

bool Arch_Group::is_referenced ( ) const
inline

Check if any client (durable or not) is attached to the archiver.

Returns
true if any client is attached, else false

◆ mark_active()

int Arch_Group::mark_active ( )

Mark the group active by creating a file in the respective group directory.

This is required at the time of recovery to know whether a group was active or not in case of a crash.

Note
Used only by the page archiver.
Returns
error code.

◆ mark_durable()

int Arch_Group::mark_durable ( )

Mark the group durable by creating a file in the respective group directory.

This is required at the time of recovery to differentiate durable group from group left over by crash during clone operation.

Note
Used only by the page archiver.
Returns
error code.

◆ mark_inactive()

int Arch_Group::mark_inactive ( )

Mark the group inactive by deleting the 'active' file.

This is required at the time of crash recovery to know whether a group was active or not in case of a crash.

Note
Used only by the page archiver.
Returns
error code

◆ open_file()

dberr_t Arch_Group::open_file ( Arch_Page_Pos  write_pos,
bool  create_new 
)

Open the file which was open at the time of a crash, during crash recovery, and set the file offset to the last written offset.

Parameters
[in]write_poslatest write position at the time of crash/shutdown
[in]create_newcreate new file if file not present
Returns
error code.

◆ operator=()

Arch_Group & Arch_Group::operator= ( Arch_Group const &  )
delete

Disable assignment.

◆ prepare_file_with_header()

dberr_t Arch_Group::prepare_file_with_header ( uint64_t  start_offset,
Get_file_header_callback get_header 
)
private

Create a new file and write the header.

Parameters
[in]start_offsetstart offste
[in]get_headercallback which prepares a header

◆ purge()

uint Arch_Group::purge ( lsn_t  purge_lsn,
lsn_t purged_lsn 
)

Purge archived files until the specified purge LSN.

Parameters
[in]purge_lsnLSN until which archived files needs to be purged
[out]purged_lsnLSN until which purging is successful; LSN_MAX if there was no purging done
Returns
error code

For a group (active or non-active) if there are any non-durable clients attached then we don't purge the group at all.

◆ read_data()

int Arch_Group::read_data ( Arch_Page_Pos  cur_pos,
byte buff,
uint  buff_len 
)

Parse block for block info (header/data).

Parameters
[in]cur_posposition to read
[in,out]buffbuffer into which to write the parsed data
[in]buff_lenlength of the buffer
Returns
error code

◆ read_from_file()

int Arch_Group::read_from_file ( Arch_Page_Pos read_pos,
uint  read_len,
byte read_buff 
)
private

Get page IDs from archived file.

Parameters
[in]read_posposition to read from
[in]read_lenlength of data to read
[in]read_buffbuffer to read page IDs
Returns
error code

◆ recover()

dberr_t Arch_Group::recover ( Arch_Recv_Group_Info group_info,
Arch_Dblwr_Ctx dblwr_ctx 
)

Recover the information belonging to this group from the archived files.

Parameters
[in,out]group_infostructure containing information of a group obtained during recovery by scanning files
[in]dblwr_ctxfile context related to doublewrite buffer
Returns
error code

◆ release()

void Arch_Group::release ( bool  is_durable)
inline

Release the archive group from a client.

Reduce the reference count. When all clients release the group, the reference count falls down to zero. The function would then return zero and the caller can remove the group.

Parameters
[in]is_durablethe client needs durable archiving

◆ save_reset_point_in_mem()

void Arch_Group::save_reset_point_in_mem ( lsn_t  lsn,
Arch_Page_Pos  pos 
)
inline

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

◆ shutdown()

static void Arch_Group::shutdown ( )
inlinestatic

Operations to be done at the time of shutdown.

◆ update_stop_point()

void Arch_Group::update_stop_point ( Arch_Page_Pos  pos,
lsn_t  stop_lsn 
)
inline

Update stop lsn of a file in the group.

Parameters
[in]posstop position
[in]stop_lsnstop point

◆ validate_info_in_files()

bool Arch_Group::validate_info_in_files ( )

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

◆ write_file_header()

dberr_t Arch_Group::write_file_header ( byte from_buffer,
uint  length 
)

Write the header (RESET page) to an archived file.

Note
Used only by the Page Archiver and not by the Redo Log Archiver.
Parameters
[in]from_bufferbuffer to copy data
[in]lengthsize of data to copy in bytes
Note
Used only by the Page Archiver.
Returns
error code

◆ write_to_doublewrite_file()

dberr_t Arch_Group::write_to_doublewrite_file ( Arch_File_Ctx from_file,
byte from_buffer,
uint  write_size,
Arch_Page_Dblwr_Offset  offset 
)
static

Write to the doublewrite buffer before writing archived data to a file.

The source is either a file context or buffer. Caller must ensure that data is in single file in source file context.

Parameters
[in]from_filefile context to copy data from
[in]from_bufferbuffer to copy data or NULL
[in]write_sizesize of data to write in bytes
[in]offsetoffset from where to write
Note
Used only by the Page Archiver.
Returns
error code

◆ write_to_file()

dberr_t Arch_Group::write_to_file ( Arch_File_Ctx from_file,
byte from_buffer,
uint  length,
bool  partial_write,
bool  do_persist,
Get_file_header_callback  new_file 
)

Archive data to one or more files.

The source is either a file context or buffer. Caller must ensure that data is in single file in source file context.

Parameters
[in]from_filefile context to copy data from
[in]from_bufferbuffer to copy data or NULL
[in]lengthsize of data to copy in bytes
[in]partial_writetrue if the operation is part of partial flush
[in]do_persistdoublewrite to ensure persistence
[in]new_filecallback called for each new file being created
Returns
error code

Member Data Documentation

◆ m_active_file

pfs_os_file_t Arch_Group::m_active_file
private

File descriptor for a file required to indicate that the group was active at the time of crash during recovery .

◆ m_active_file_name

char* Arch_Group::m_active_file_name {nullptr}
private

To know which group was active at the time of a crash/shutdown during recovery we create an empty file in the group directory.

This holds the name of the file.

◆ m_arch_mutex

ib_mutex_t* Arch_Group::m_arch_mutex
private

Mutex protecting concurrent operations by multiple clients.

This is either the redo log or page archive system mutex. Currently used for assert checks.

◆ m_begin_lsn

lsn_t Arch_Group::m_begin_lsn {LSN_MAX}
private

Start LSN for the archive group.

◆ m_dur_ref_count

uint Arch_Group::m_dur_ref_count {}
private

Number of clients referencing for durable archiving.

◆ m_durable_file

pfs_os_file_t Arch_Group::m_durable_file
private

File descriptor for a file to indicate that the group was made durable or not.

Required to differentiate durable group from group left over by crash during clone operation.

◆ m_durable_file_name

char* Arch_Group::m_durable_file_name {nullptr}
private

File name for the durable file which indicates whether a group was made durable or not.

Required to differentiate durable group from group left over by crash during clone operation.

◆ m_end_lsn

lsn_t Arch_Group::m_end_lsn {LSN_MAX}
private

End lsn for this archive group.

◆ m_file_ctx

Arch_File_Ctx Arch_Group::m_file_ctx
private

Archive file context.

◆ m_file_size

uint64_t Arch_Group::m_file_size
private

Size of file used when a new file is being created.

◆ m_header_len

uint Arch_Group::m_header_len {}
private

Header length for the archived files.

◆ m_is_active

bool Arch_Group::m_is_active {true}
private

If the group is active.

◆ m_num_active

uint Arch_Group::m_num_active {}
private

Number of clients for which archiving is in progress.

◆ m_ref_count

uint Arch_Group::m_ref_count {}
private

Number of clients referencing the group.

◆ m_stop_pos

Arch_Page_Pos Arch_Group::m_stop_pos {}
private

Stop position of the group, if it's not active.

◆ m_uuid

Arch_group_uuid Arch_Group::m_uuid {}
private

UUID generated for this arch group.

◆ s_dblwr_file_ctx

Arch_File_Ctx Arch_Group::s_dblwr_file_ctx
staticprivate

Doublewrite buffer file context.

Note - Used only in the case of page archiver.


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