MySQL 8.0.40
Source Code Documentation
Rpl_applier_reader Class Reference

This class provides the feature to read events from relay log files. More...

#include <rpl_applier_reader.h>

Classes

class  Stage_controller
 It manages a stage and the related mutex and makes the process of locking and entering stage/unlock and exiting stage as monolithic operations. More...
 

Public Member Functions

 Rpl_applier_reader (Relay_log_info *rli)
 
 Rpl_applier_reader (const Rpl_applier_reader &)=delete
 
Rpl_applier_readeroperator= (const Rpl_applier_reader &)=delete
 
 ~Rpl_applier_reader ()
 
bool open (const char **errmsg)
 Open the first relay log file which will be read by applier and seek to correct position. More...
 
void close ()
 
Log_eventread_next_event ()
 Read next event from relay log. More...
 

Private Member Functions

bool move_to_next_log (bool force_purge)
 When reaching the end of current relay log file, close it and open next relay log. More...
 
bool read_active_log_end_pos ()
 It reads the coordinates up to which the receiver thread has written and check whether there is any event to be read. More...
 
Rotate_log_eventgenerate_rotate_event ()
 In the case receiver thread says master skipped some events, it will generate a Rotate_log_event for applier to advance executed master log position. More...
 
bool purge_applied_logs ()
 Purge relay log files prior to m_rli->group_relay_log_name. More...
 
bool wait_for_new_event ()
 Waits for new events coming. More...
 
bool reopen_log_reader_if_needed ()
 It checks if the relaylog file reader should be reopened and then reopens the reader if receiver thread truncated some data from active relay log. More...
 
void reset_seconds_behind_master ()
 
void debug_print_next_event_positions ()
 

Private Attributes

Relaylog_file_reader m_relaylog_file_reader
 
Relay_log_infom_rli = nullptr
 
const char * m_errmsg = nullptr
 Stores the error message which is used internally. More...
 
bool m_reading_active_log = true
 
my_off_t m_log_end_pos = 0
 Stores active log's end position. More...
 
LOG_INFO m_linfo
 
bool m_relay_log_purge = relay_log_purge
 

Detailed Description

This class provides the feature to read events from relay log files.

  • Open() function just opens the first relay log file (rli->get_group_relay_log_name()) which need to be applied by slave.
  • read_next_event() just returns the events one by one. It will close() current relay log and open next relay log file automatically when reaching the end of current relay log. Internally each relay log file is opened and read by using a Relaylog_file_reader.
  • It will purge the applied relay logs accordingly when moving to next relay log.
  • When reaching the end of active relay log file, it will wait for new events coming and make MTS checkpoints accordingly while waiting for events.

Constructor & Destructor Documentation

◆ Rpl_applier_reader() [1/2]

Rpl_applier_reader::Rpl_applier_reader ( Relay_log_info rli)
Parameters
[in]rlirelay log info is used in the function. So rli should be initialized before initializing Rpl_applier_reader object.

◆ Rpl_applier_reader() [2/2]

Rpl_applier_reader::Rpl_applier_reader ( const Rpl_applier_reader )
delete

◆ ~Rpl_applier_reader()

Rpl_applier_reader::~Rpl_applier_reader ( )

Member Function Documentation

◆ close()

void Rpl_applier_reader::close ( void  )

◆ debug_print_next_event_positions()

void Rpl_applier_reader::debug_print_next_event_positions ( )
private

◆ generate_rotate_event()

Rotate_log_event * Rpl_applier_reader::generate_rotate_event ( )
private

In the case receiver thread says master skipped some events, it will generate a Rotate_log_event for applier to advance executed master log position.

◆ move_to_next_log()

bool Rpl_applier_reader::move_to_next_log ( bool  force_purge)
private

When reaching the end of current relay log file, close it and open next relay log.

purge old relay logs if necessary.

Parameters
force_purgeThis function rarely purges the current log before moving to the next. Sometimes, we need to enforce this purge, e.g. when receiver is waiting for available relay log space. The 'force_purge' will enable an aggressive relay log purge. Beware that 'move_to_next_log' with force_purge enabled, will ignore that current group position is lower than required and will reset it. Therefore, make sure that workers finished executing ALL scheduled jobs.
Return values
falseSuccess
trueError

◆ open()

bool Rpl_applier_reader::open ( const char **  errmsg)

Open the first relay log file which will be read by applier and seek to correct position.

The file name and position are read from rli->get_group_master_log_name() and rli->get_group_relay_log_pos().

Parameters
[out]errmsgSet the error message to it if any error happens.
Return values
falseSuccess
trueError

group_relay_log_name may be different from the one in index file. For example group_relay_log_name includes a full path. But the one in index file has relative path. So set group_relay_log_name to the one in index file. It guarantees MYSQL_BIN_LOG::purge works well.

◆ operator=()

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

◆ purge_applied_logs()

bool Rpl_applier_reader::purge_applied_logs ( )
private

Purge relay log files prior to m_rli->group_relay_log_name.

It is used to be called MYSQL_BIN_LOG::purge_first_log

Return values
falseSuccess
trueError

◆ read_active_log_end_pos()

bool Rpl_applier_reader::read_active_log_end_pos ( )
private

It reads the coordinates up to which the receiver thread has written and check whether there is any event to be read.

Return values
falseThe applier has read all events.
trueThe applier is behind the receiver.

◆ read_next_event()

Log_event * Rpl_applier_reader::read_next_event ( )

Read next event from relay log.

  • It will wait until the receiver writes some events to relay log in case where there are no more events left to read from the active relay log.
  • The caller must hold m_rli->data_lock. The lock will be released temporarily while waiting and required after waking up.
  • The wait is protected by relay_log.lock_binlog_end_pos().
Return values
Log_event*A valid Log_event object.
nullptrError happened or sql thread was killed.

◆ reopen_log_reader_if_needed()

bool Rpl_applier_reader::reopen_log_reader_if_needed ( )
private

It checks if the relaylog file reader should be reopened and then reopens the reader if receiver thread truncated some data from active relay log.

The caller must hold m_rli->data_lock

Return values
falseSuccess
trueError

◆ reset_seconds_behind_master()

void Rpl_applier_reader::reset_seconds_behind_master ( )
private

◆ wait_for_new_event()

bool Rpl_applier_reader::wait_for_new_event ( )
private

Waits for new events coming.

Returning successfully just means it gets a signal. That doesn't guarantee that any new event came.

Return values
falseSuccess
trueError. The thread is killed or flush failed while executing mta_checkpoint_routine.
Note
the The caller must hold m_rli->data_lock and relaylog.lock_binlog_end_pos().

Member Data Documentation

◆ m_errmsg

const char* Rpl_applier_reader::m_errmsg = nullptr
private

Stores the error message which is used internally.

◆ m_linfo

LOG_INFO Rpl_applier_reader::m_linfo
private

◆ m_log_end_pos

my_off_t Rpl_applier_reader::m_log_end_pos = 0
private

Stores active log's end position.

Thus avoids to call relay_log.get_binlog_log_pos() for each event.

◆ m_reading_active_log

bool Rpl_applier_reader::m_reading_active_log = true
private

◆ m_relay_log_purge

bool Rpl_applier_reader::m_relay_log_purge = relay_log_purge
private

◆ m_relaylog_file_reader

Relaylog_file_reader Rpl_applier_reader::m_relaylog_file_reader
private

◆ m_rli

Relay_log_info* Rpl_applier_reader::m_rli = nullptr
private

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