MySQL 8.4.2
Source Code Documentation
Arch_Page_Sys Class Reference

Dirty page archive system. More...

#include <arch0arch.h>

Classes

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

Public Member Functions

 Arch_Page_Sys ()
 Constructor: Initialize elements and create mutex. More...
 
 ~Arch_Page_Sys ()
 Destructor: Free memory buffer and mutexes. More...
 
int start (Arch_Group **group, lsn_t *start_lsn, Arch_Page_Pos *start_pos, bool is_durable, bool restart, bool recovery)
 Start dirty page ID archiving. More...
 
int stop (Arch_Group *group, lsn_t *stop_lsn, Arch_Page_Pos *stop_pos, bool is_durable)
 Stop dirty page ID archiving. More...
 
int recovery_load_and_start (const Arch_Recv_Group_Info &info)
 Start dirty page ID archiving during recovery. More...
 
void release (Arch_Group *group, bool is_durable, Arch_Page_Pos start_pos)
 Release the current group from client. More...
 
void track_page (buf_page_t *bpage, lsn_t track_lsn, lsn_t frame_lsn, bool force)
 Check and add page ID to archived data. More...
 
void flush_at_checkpoint (lsn_t checkpoint_lsn)
 Flush all the unflushed inactive blocks and flush the active block if required. More...
 
bool archive (bool *wait)
 Archive dirty page IDs in current group. More...
 
void arch_mutex_enter ()
 Acquire dirty page ID archiver mutex. More...
 
void arch_mutex_exit ()
 Release page ID archiver mutex. More...
 
void arch_oper_mutex_enter ()
 Acquire dirty page ID archive operation mutex. More...
 
void arch_oper_mutex_exit ()
 Release page ID archiver operatiion mutex. More...
 
bool save_reset_point (bool is_durable)
 
bool wait_for_reset_info_flush (uint64_t request_block)
 Wait for reset info to be flushed to disk. More...
 
int fetch_group_within_lsn_range (lsn_t &start_id, lsn_t &stop_id, Arch_Group **group)
 Get the group which has tracked pages between the start_id and stop_id. More...
 
uint purge (lsn_t *purge_lsn)
 Purge the archived files until the specified purge LSN. More...
 
void update_stop_info (Arch_Block *cur_blk)
 Update the stop point in all the required structures. More...
 
void get_status (std::vector< std::pair< lsn_t, bool > > &status)
 Fetch the status of the page tracking system. More...
 
bool get_num_pages (Arch_Page_Pos start_pos, Arch_Page_Pos stop_pos, uint64_t &num_pages)
 Given start and stop position find number of pages tracked between them. More...
 
int get_num_pages (lsn_t &start_id, lsn_t &stop_id, uint64_t *num_pages)
 Get approximate number of tracked pages between two given LSN values. More...
 
bool get_pages (Arch_Group *group, Arch_Page_Pos *read_pos, uint read_len, byte *read_buff)
 Get page IDs from a specific position. More...
 
int get_pages (MYSQL_THD thd, Page_Track_Callback cbk_func, void *cbk_ctx, lsn_t &start_id, lsn_t &stop_id, byte *buf, uint buf_len)
 Get archived page Ids between two given LSN values. More...
 
void post_recovery_init ()
 Set the latest stop LSN to the checkpoint LSN at the time it's called. More...
 
dberr_t recover ()
 Recover the archiver system at the time of startup. More...
 
void print ()
 Print information related to the archiver for debugging purposes. More...
 
void set_read_only_mode ()
 Set the state of the archiver system to read only. More...
 
bool is_init () const
 Check if archiver system is in initial state. More...
 
bool is_active () const
 Check if archiver system is active. More...
 
bool is_abort () const
 
ib_mutex_t * get_mutex ()
 Get the mutex protecting concurrent start, stop operations required for initialising group during recovery. More...
 
ib_mutex_t * get_oper_mutex ()
 
Page_Arch_Client_Ctxget_sys_client () const
 Fetch the system client context. More...
 
lsn_t get_latest_stop_lsn () const
 
 Arch_Page_Sys (Arch_Page_Sys const &)=delete
 Disable copy construction. More...
 
Arch_Page_Sysoperator= (Arch_Page_Sys const &)=delete
 Disable assignment. More...
 

Private Member Functions

bool wait_idle ()
 Wait for archive system to come out of ARCH_STATE_PREPARE_IDLE. More...
 
bool is_gap_small ()
 Check if the gap from last reset is short. More...
 
void set_tracking_buf_pool (lsn_t tracking_lsn)
 Enable tracking pages in all buffer pools. More...
 
void track_initial_pages ()
 Track pages for which IO is already started. More...
 
dberr_t flush_blocks (bool *wait)
 Flush the blocks to disk. More...
 
dberr_t flush_inactive_blocks (Arch_Page_Pos &cur_pos, Arch_Page_Pos end_pos)
 Flush all the blocks which are ready to be flushed but not flushed. More...
 
dberr_t flush_active_block (Arch_Page_Pos cur_pos, bool partial_reset_block_flush)
 Do a partial flush of the current active block. More...
 

Private Attributes

ib_mutex_t m_mutex
 Mutex protecting concurrent start, stop operations. More...
 
Arch_State m_state {ARCH_STATE_INIT}
 Archiver system state. More...
 
Arch_Grp_List m_group_list {}
 List of log archive groups. More...
 
Arch_Page_Pos m_last_pos {}
 Position where last client started archiving. More...
 
lsn_t m_last_lsn {LSN_MAX}
 LSN when last client started archiving. More...
 
lsn_t m_latest_stop_lsn {LSN_MAX}
 Latest LSN until where the tracked pages have been flushed. More...
 
lsn_t m_latest_purged_lsn {LSN_MAX}
 LSN until where the groups are purged. More...
 
ib_mutex_t m_oper_mutex
 Mutex protecting concurrent operation on data. More...
 
Arch_Groupm_current_group {nullptr}
 Current archive group. More...
 
ArchPageData m_data {}
 In memory data buffer. More...
 
Arch_Page_Pos m_write_pos {}
 Position to add new page ID. More...
 
Arch_Page_Pos m_reset_pos {}
 Position to add new reset element. More...
 
Arch_Page_Pos m_request_flush_pos {}
 Position set to explicitly request the flush archiver to flush until this position. More...
 
uint64_t m_request_blk_num_with_lsn {std::numeric_limits<uint64_t>::max()}
 Block number set to explicitly request the flush archiver to partially flush the current active block with reset LSN. More...
 
uint64_t m_flush_blk_num_with_lsn {std::numeric_limits<uint64_t>::max()}
 Block number set once the flush archiver partially flushes the current active block with reset LSN. More...
 
Arch_Page_Pos m_flush_pos {}
 Position for start flushing. More...
 
uint m_last_reset_file_index {0}
 The index of the file the last reset belonged to. More...
 
Page_Arch_Client_Ctxm_ctx
 System client. More...
 

Detailed Description

Dirty page archive system.

Constructor & Destructor Documentation

◆ Arch_Page_Sys() [1/2]

Arch_Page_Sys::Arch_Page_Sys ( )

Constructor: Initialize elements and create mutex.

◆ ~Arch_Page_Sys()

Arch_Page_Sys::~Arch_Page_Sys ( )

Destructor: Free memory buffer and mutexes.

◆ Arch_Page_Sys() [2/2]

Arch_Page_Sys::Arch_Page_Sys ( Arch_Page_Sys const &  )
delete

Disable copy construction.

Member Function Documentation

◆ arch_mutex_enter()

void Arch_Page_Sys::arch_mutex_enter ( )
inline

Acquire dirty page ID archiver mutex.

It synchronizes concurrent start and stop operations by multiple clients.

◆ arch_mutex_exit()

void Arch_Page_Sys::arch_mutex_exit ( )
inline

Release page ID archiver mutex.

◆ arch_oper_mutex_enter()

void Arch_Page_Sys::arch_oper_mutex_enter ( )
inline

Acquire dirty page ID archive operation mutex.

It synchronizes concurrent page ID write to memory buffer.

◆ arch_oper_mutex_exit()

void Arch_Page_Sys::arch_oper_mutex_exit ( )
inline

Release page ID archiver operatiion mutex.

◆ archive()

bool Arch_Page_Sys::archive ( bool *  wait)

Archive dirty page IDs in current group.

This interface is for archiver background task to flush page archive data to disk by calling it repeatedly over time.

Parameters
[out]waittrue, if no more data to archive
Returns
true, if archiving is aborted

◆ fetch_group_within_lsn_range()

int Arch_Page_Sys::fetch_group_within_lsn_range ( lsn_t start_id,
lsn_t stop_id,
Arch_Group **  group 
)

Get the group which has tracked pages between the start_id and stop_id.

Parameters
[in,out]start_idstart LSN from which tracked pages are required; updated to the actual start LSN used for the search
[in,out]stop_idstop_lsn until when tracked pages are required; updated to the actual stop LSN used for the search
[out]groupgroup which has the required tracked pages, else nullptr.
Returns
error

◆ flush_active_block()

dberr_t Arch_Page_Sys::flush_active_block ( Arch_Page_Pos  cur_pos,
bool  partial_reset_block_flush 
)
private

Do a partial flush of the current active block.

Parameters
[in]cur_posposition of block which needs to be flushed
[in]partial_reset_block_flushtrue if reset block needs to be flushed
Returns
error code

◆ flush_at_checkpoint()

void Arch_Page_Sys::flush_at_checkpoint ( lsn_t  checkpoint_lsn)

Flush all the unflushed inactive blocks and flush the active block if required.

Note
Used only during the checkpointing process.
Parameters
[in]checkpoint_lsnnext checkpoint LSN

◆ flush_blocks()

dberr_t Arch_Page_Sys::flush_blocks ( bool *  wait)
private

Flush the blocks to disk.

Parameters
[out]waittrue, if no more data to archive
Returns
error code

◆ flush_inactive_blocks()

dberr_t Arch_Page_Sys::flush_inactive_blocks ( Arch_Page_Pos cur_pos,
Arch_Page_Pos  end_pos 
)
private

Flush all the blocks which are ready to be flushed but not flushed.

Parameters
[out]cur_posposition of block which needs to be flushed
[in]end_posposition of block until which the blocks need to be flushed
Returns
error code

◆ get_latest_stop_lsn()

lsn_t Arch_Page_Sys::get_latest_stop_lsn ( ) const
inline
Returns
the latest stop LSN

◆ get_mutex()

ib_mutex_t * Arch_Page_Sys::get_mutex ( )
inline

Get the mutex protecting concurrent start, stop operations required for initialising group during recovery.

Returns
mutex

◆ get_num_pages() [1/2]

bool Arch_Page_Sys::get_num_pages ( Arch_Page_Pos  start_pos,
Arch_Page_Pos  stop_pos,
uint64_t &  num_pages 
)

Given start and stop position find number of pages tracked between them.

Parameters
[in]start_posstart position
[in]stop_posstop position
[out]num_pagesnumber of pages tracked between start and stop position
Returns
false if start_pos and stop_pos are invalid else true

◆ get_num_pages() [2/2]

int Arch_Page_Sys::get_num_pages ( lsn_t start_id,
lsn_t stop_id,
uint64_t *  num_pages 
)

Get approximate number of tracked pages between two given LSN values.

Parameters
[in,out]start_idfetch archived page Ids from this LSN
[in,out]stop_idfetch archived page Ids until this LSN
[out]num_pagesnumber of pages tracked between specified LSN range
Returns
error code
  1. Get appropriate LSN range.
  2. Get block position from where to start.
  3. Get block position where to stop
  4. Fetch number of pages tracked.

◆ get_oper_mutex()

ib_mutex_t * Arch_Page_Sys::get_oper_mutex ( )
inline
Returns
operation mutex

◆ get_pages() [1/2]

bool Arch_Page_Sys::get_pages ( Arch_Group group,
Arch_Page_Pos read_pos,
uint  read_len,
byte read_buff 
)

Get page IDs from a specific position.

Caller must ensure that read_len doesn't exceed the block.

Parameters
[in]groupgroup whose pages we're interested in
[in]read_posposition in archived data
[in]read_lenamount of data to read
[out]read_buffbuffer to return the page IDs.
Note
Caller must allocate the buffer.
Returns
true if we could successfully read the block.

◆ get_pages() [2/2]

int Arch_Page_Sys::get_pages ( MYSQL_THD  thd,
Page_Track_Callback  cbk_func,
void *  cbk_ctx,
lsn_t start_id,
lsn_t stop_id,
byte buf,
uint  buf_len 
)

Get archived page Ids between two given LSN values.

Attempt to read blocks directly from in memory buffer. If overwritten, copy from archived files.

Parameters
[in]thdthread handle
[in]cbk_funccalled repeatedly with page ID buffer
[in]cbk_ctxcallback function context
[in,out]start_idfetch archived page Ids from this LSN
[in,out]stop_idfetch archived page Ids until this LSN
[in]bufbuffer to fill page IDs
[in]buf_lenbuffer length in bytes
Returns
error code
  1. Get appropriate LSN range.
  2. Get block position from where to start.

◆ get_status()

void Arch_Page_Sys::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_sys_client()

Page_Arch_Client_Ctx * Arch_Page_Sys::get_sys_client ( ) const
inline

Fetch the system client context.

Returns
system client context.

◆ is_abort()

bool Arch_Page_Sys::is_abort ( ) const
inline
Returns
true if in abort state

◆ is_active()

bool Arch_Page_Sys::is_active ( ) const
inline

Check if archiver system is active.

Returns
true, if page ID archiver state is ARCH_STATE_ACTIVE or ARCH_STATE_PREPARE_IDLE.

◆ is_gap_small()

bool Arch_Page_Sys::is_gap_small ( )
private

Check if the gap from last reset is short.

If not many page IDs are added till last reset, we avoid taking a new reset point

Returns
true, if the gap is small.

◆ is_init()

bool Arch_Page_Sys::is_init ( ) const
inline

Check if archiver system is in initial state.

Returns
true, if page ID archiver state is ARCH_STATE_INIT

◆ operator=()

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

Disable assignment.

◆ post_recovery_init()

void Arch_Page_Sys::post_recovery_init ( )

Set the latest stop LSN to the checkpoint LSN at the time it's called.

◆ print()

void Arch_Page_Sys::print ( )

Print information related to the archiver for debugging purposes.

◆ purge()

uint Arch_Page_Sys::purge ( lsn_t purge_lsn)

Purge the archived files until the specified purge LSN.

Parameters
[in]purge_lsnpurge lsn until where files needs to be purged
Returns
error code
Return values
0if purge was successful

◆ recover()

dberr_t Arch_Page_Sys::recover ( )

Recover the archiver system at the time of startup.

Recover information related to all the durable groups and start archiving if any group was active at the time of crash/shutdown.

Returns
error code

◆ recovery_load_and_start()

int Arch_Page_Sys::recovery_load_and_start ( const Arch_Recv_Group_Info info)

Start dirty page ID archiving during recovery.

Parameters
[in,out]infoinformation related to a group required for recovery
Returns
error code

◆ release()

void Arch_Page_Sys::release ( Arch_Group group,
bool  is_durable,
Arch_Page_Pos  start_pos 
)

Release the current group from client.

Parameters
[in]groupgroup the client is attached to
[in]is_durableif client needs durable archiving
[in]start_posstart position when the client calling the release was started

◆ save_reset_point()

bool Arch_Page_Sys::save_reset_point ( bool  is_durable)

◆ set_read_only_mode()

void Arch_Page_Sys::set_read_only_mode ( )
inline

Set the state of the archiver system to read only.

◆ set_tracking_buf_pool()

void Arch_Page_Sys::set_tracking_buf_pool ( lsn_t  tracking_lsn)
private

Enable tracking pages in all buffer pools.

Parameters
[in]tracking_lsntrack pages from this LSN

◆ start()

int Arch_Page_Sys::start ( Arch_Group **  group,
lsn_t start_lsn,
Arch_Page_Pos start_pos,
bool  is_durable,
bool  restart,
bool  recovery 
)

Start dirty page ID archiving.

If archiving is already in progress, the client is attached to current group.

Parameters
[out]grouppage archive group the client gets attached to
[out]start_lsnstart lsn for client in archived data
[out]start_posstart position for client in archived data
[in]is_durabletrue if client needs durable archiving
[in]restarttrue if client is already attached to current group
[in]recoverytrue if archiving is being started during recovery
Returns
error code

◆ stop()

int Arch_Page_Sys::stop ( Arch_Group group,
lsn_t stop_lsn,
Arch_Page_Pos stop_pos,
bool  is_durable 
)

Stop dirty page ID archiving.

If other clients are there, the client is detached from the current group.

Parameters
[in]grouppage archive group the client is attached to
[out]stop_lsnstop lsn for client
[out]stop_posstop position in archived data
[in]is_durabletrue if client needs durable archiving
Returns
error code

◆ track_initial_pages()

void Arch_Page_Sys::track_initial_pages ( )
private

Track pages for which IO is already started.

We read the io_fix flag without holding buf_page_get_mutex(bpage), but we hold flush_state_mutex which is also taken when transitioning:

  • from BUF_IO_NONE to BUF_IO_WRITE in buf_flush_page()
  • from BUF_IO_WRITE to BUF_IO_NONE in buf_flush_write_complete() which are the only transitions to and from BUF_IO_WRITE state that we care about.

◆ track_page()

void Arch_Page_Sys::track_page ( buf_page_t bpage,
lsn_t  track_lsn,
lsn_t  frame_lsn,
bool  force 
)

Check and add page ID to archived data.

Check for duplicate page.

Parameters
[in]bpagepage to track
[in]track_lsnLSN when tracking started
[in]frame_lsncurrent LSN of the page
[in]forceif true, add page ID without check

◆ update_stop_info()

void Arch_Page_Sys::update_stop_info ( Arch_Block cur_blk)

Update the stop point in all the required structures.

Parameters
[in]cur_blkblock which needs to be updated with the stop info

◆ wait_for_reset_info_flush()

bool Arch_Page_Sys::wait_for_reset_info_flush ( uint64_t  request_block)

Wait for reset info to be flushed to disk.

Parameters
[in]request_blockblock number until which blocks need to be flushed
Returns
true if flushed, else false

◆ wait_idle()

bool Arch_Page_Sys::wait_idle ( )
private

Wait for archive system to come out of ARCH_STATE_PREPARE_IDLE.

If the system is preparing to idle, start needs to wait for it to come to idle state.

Returns
true, if successful false, if needs to abort

Member Data Documentation

◆ m_ctx

Page_Arch_Client_Ctx* Arch_Page_Sys::m_ctx
private

System client.

◆ m_current_group

Arch_Group* Arch_Page_Sys::m_current_group {nullptr}
private

Current archive group.

◆ m_data

ArchPageData Arch_Page_Sys::m_data {}
private

In memory data buffer.

◆ m_flush_blk_num_with_lsn

uint64_t Arch_Page_Sys::m_flush_blk_num_with_lsn {std::numeric_limits<uint64_t>::max()}
private

Block number set once the flush archiver partially flushes the current active block with reset LSN.

Note
this is always increasing and is only updated by the requester thread like checkpoint

◆ m_flush_pos

Arch_Page_Pos Arch_Page_Sys::m_flush_pos {}
private

Position for start flushing.

Note
this is always increasing and is only updated by the page archiver thread

◆ m_group_list

Arch_Grp_List Arch_Page_Sys::m_group_list {}
private

List of log archive groups.

◆ m_last_lsn

lsn_t Arch_Page_Sys::m_last_lsn {LSN_MAX}
private

LSN when last client started archiving.

◆ m_last_pos

Arch_Page_Pos Arch_Page_Sys::m_last_pos {}
private

Position where last client started archiving.

◆ m_last_reset_file_index

uint Arch_Page_Sys::m_last_reset_file_index {0}
private

The index of the file the last reset belonged to.


◆ m_latest_purged_lsn

lsn_t Arch_Page_Sys::m_latest_purged_lsn {LSN_MAX}
private

LSN until where the groups are purged.

◆ m_latest_stop_lsn

lsn_t Arch_Page_Sys::m_latest_stop_lsn {LSN_MAX}
private

Latest LSN until where the tracked pages have been flushed.

◆ m_mutex

ib_mutex_t Arch_Page_Sys::m_mutex
private

Mutex protecting concurrent start, stop operations.

◆ m_oper_mutex

ib_mutex_t Arch_Page_Sys::m_oper_mutex
private

Mutex protecting concurrent operation on data.

◆ m_request_blk_num_with_lsn

uint64_t Arch_Page_Sys::m_request_blk_num_with_lsn {std::numeric_limits<uint64_t>::max()}
private

Block number set to explicitly request the flush archiver to partially flush the current active block with reset LSN.

Note
this is always increasing and is only updated by the requester thread like checkpoint

◆ m_request_flush_pos

Arch_Page_Pos Arch_Page_Sys::m_request_flush_pos {}
private

Position set to explicitly request the flush archiver to flush until this position.

Note
this is always increasing and is only updated by the requester thread like checkpoint

◆ m_reset_pos

Arch_Page_Pos Arch_Page_Sys::m_reset_pos {}
private

Position to add new reset element.

◆ m_state

Arch_State Arch_Page_Sys::m_state {ARCH_STATE_INIT}
private

Archiver system state.

◆ m_write_pos

Arch_Page_Pos Arch_Page_Sys::m_write_pos {}
private

Position to add new page ID.


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