MySQL 9.1.0
Source Code Documentation
Binlog_index_monitor Class Reference

Binlog_index_monitor synchronizes access to Binlog_index object. More...

#include <binlog_index.h>

Public Member Functions

 Binlog_index_monitor (bool relay_log)
 
void set_psi_keys (PSI_mutex_key key_LOCK_index, PSI_file_key key_file_log_index, PSI_file_key key_file_log_index_cache)
 
void init_pthread_objects ()
 
void cleanup ()
 
bool open_index_file (const char *index_file_name_arg, const char *log_name, PSI_file_key key_file_log, bool need_lock_index)
 
int close_index_file (bool need_lock_index)
 
bool is_inited_index_file ()
 
int open_purge_index_file (bool destroy)
 
int close_purge_index_file ()
 
int end_close_purge_index_file ()
 
int set_purge_index_file_name (const char *base_file_name)
 
bool is_inited_purge_index_file ()
 
int reinit_purge_index_file ()
 
int sync_purge_index_file ()
 
int gets_purge_index_file (char *to, size_t max_length)
 
int error_purge_index_file ()
 
int register_purge_index_entry (const char *entry)
 
int register_create_index_entry (const char *entry)
 
int purge_index_entry (THD *thd, ulonglong *decrease_log_space, PSI_file_key key_file_log, bool need_lock_index)
 
int find_log_pos (Log_info *linfo, const char *log_name, bool need_lock_index)
 Find the position in the log-index-file for the given log name. More...
 
int find_next_log (Log_info *linfo, bool need_lock_index)
 Find the position in the log-index-file for the given log name. More...
 
int add_log_to_index (uchar *log_name, size_t log_name_len, bool need_lock_index)
 Append log file name to index file. More...
 
int move_crash_safe_index_file_to_index_file (bool need_lock_index)
 Move crash safe index file to index file. More...
 
int remove_logs_outside_range_from_index (Log_info *start_log_info, bool need_update_threads, Log_info *last_log_info=nullptr)
 
int remove_logs_outside_range_from_index (const std::string &first, bool need_update_threads, const std::string &last)
 Remove logs from index file except logs between first and last. More...
 
void register_log_info (Log_info *log_info)
 
void unregister_log_info (Log_info *log_info)
 
int log_in_use (const char *log_name)
 Check if any threads use log name. More...
 
void adjust_linfo_offsets (my_off_t purge_offset)
 
const char * get_index_fname () const
 
IO_CACHEget_index_file ()
 
std::pair< int, std::list< std::string > > get_log_index (bool need_lock_index=true)
 Retrieves the contents of the index file associated with this log object into an std::list<std::string> object. More...
 
std::pair< std::list< std::string >, mysql::utils::Errorget_filename_list ()
 Obtains the list of logs from the index file. More...
 
int find_next_relay_log (char log_name[FN_REFLEN+1])
 Find the relay log name following the given name from relay log index file. More...
 
Binlog_indexget_index ()
 
mysql_mutex_tget_index_lock ()
 
void lock ()
 
void unlock ()
 
void assert_owner ()
 

Private Attributes

PSI_mutex_key m_key_LOCK_index
 The instrumentation key to use for @ LOCK_index. More...
 
mysql_mutex_t m_LOCK_index
 POSIX thread objects are inited by init_pthread_objects() More...
 
Binlog_index m_binlog_index
 
const bool m_is_relay_log
 

Detailed Description

Binlog_index_monitor synchronizes access to Binlog_index object.

Methods defined by Binlog_index are exposed through Binlog_index_monitor class.

Please keep in mind that LOCK_index is exposed and its lock and unlock methods need to be called with caution.

Constructor & Destructor Documentation

◆ Binlog_index_monitor()

Binlog_index_monitor::Binlog_index_monitor ( bool  relay_log)

Member Function Documentation

◆ add_log_to_index()

int Binlog_index_monitor::add_log_to_index ( uchar log_name,
size_t  log_name_len,
bool  need_lock_index 
)

Append log file name to index file.

  • To make crash safe, we copy all the content of index file to crash safe index file firstly and then append the log file name to the crash safe index file. Finally move the crash safe index file to index file.
Parameters
log_nameLog file name
log_name_lenLength of log file name
need_lock_indexIf true, LOCK_index will be acquired; otherwise it should already be held by the caller.
Return values
0ok
-1error
See also
Binlog_index::add_log_to_index

◆ adjust_linfo_offsets()

void Binlog_index_monitor::adjust_linfo_offsets ( my_off_t  purge_offset)
See also
Binlog_index::adjust_linfo_offsets

◆ assert_owner()

void Binlog_index_monitor::assert_owner ( )
inline

◆ cleanup()

void Binlog_index_monitor::cleanup ( )

◆ close_index_file()

int Binlog_index_monitor::close_index_file ( bool  need_lock_index)
See also
Binlog_index::close_index_file

◆ close_purge_index_file()

int Binlog_index_monitor::close_purge_index_file ( )

◆ end_close_purge_index_file()

int Binlog_index_monitor::end_close_purge_index_file ( )

◆ error_purge_index_file()

int Binlog_index_monitor::error_purge_index_file ( )

◆ find_log_pos()

int Binlog_index_monitor::find_log_pos ( Log_info linfo,
const char *  log_name,
bool  need_lock_index 
)

Find the position in the log-index-file for the given log name.

Parameters
[out]linfoThe found log file name will be stored here, along with the byte offset of the next log file name in the index file.
log_nameFilename to find in the index file, or NULL if we want to read the first entry.
need_lock_indexIf false, this function acquires LOCK_index; otherwise the lock should already be held by the caller.
Note
On systems without the truncate function the file will end with one or more empty lines. These will be ignored when reading the file.
Return values
0ok
LOG_INFO_EOFEnd of log-index-file found
LOG_INFO_IOGot IO error while reading file
See also
Binlog_index::find_log_pos

◆ find_next_log()

int Binlog_index_monitor::find_next_log ( Log_info linfo,
bool  need_lock_index 
)

Find the position in the log-index-file for the given log name.

Parameters
[out]linfoThe filename will be stored here, along with the byte offset of the next filename in the index file.
need_lock_indexIf true, LOCK_index will be acquired; otherwise it should already be held by the caller.
Note
  • Before calling this function, one has to call find_log_pos() to set up 'linfo'
  • Mutex needed because we need to make sure the file pointer does not move from under our feet
Return values
0ok
LOG_INFO_EOFEnd of log-index-file found
LOG_INFO_IOGot IO error while reading file
See also
Binlog_index::find_next_log

◆ find_next_relay_log()

int Binlog_index_monitor::find_next_relay_log ( char  log_name[FN_REFLEN+1])

Find the relay log name following the given name from relay log index file.

Parameters
[in,out]log_nameThe name is full path name.
Returns
return 0 if it finds next relay log. Otherwise return the error code.

◆ get_filename_list()

std::pair< std::list< std::string >, mysql::utils::Error > Binlog_index_monitor::get_filename_list ( )

Obtains the list of logs from the index file.

Returns
List of log filenames

◆ get_index()

Binlog_index & Binlog_index_monitor::get_index ( )
inline

◆ get_index_file()

IO_CACHE * Binlog_index_monitor::get_index_file ( )
inline

◆ get_index_fname()

const char * Binlog_index_monitor::get_index_fname ( ) const

◆ get_index_lock()

mysql_mutex_t * Binlog_index_monitor::get_index_lock ( )
inline

◆ get_log_index()

std::pair< int, std::list< std::string > > Binlog_index_monitor::get_log_index ( bool  need_lock_index = true)

Retrieves the contents of the index file associated with this log object into an std::list<std::string> object.

The order held by the index file is kept.

Parameters
need_lock_indexwhether or not the lock over the index file should be acquired inside the function.
Returns
a pair: a function status code; a list of std::string objects with the content of the log index file.

◆ gets_purge_index_file()

int Binlog_index_monitor::gets_purge_index_file ( char *  to,
size_t  max_length 
)
See also
Binlog_index::gets_purge_index_file

◆ init_pthread_objects()

void Binlog_index_monitor::init_pthread_objects ( )

◆ is_inited_index_file()

bool Binlog_index_monitor::is_inited_index_file ( )
See also
Binlog_index::is_inited_index_file

◆ is_inited_purge_index_file()

bool Binlog_index_monitor::is_inited_purge_index_file ( )

◆ lock()

void Binlog_index_monitor::lock ( )
inline

◆ log_in_use()

int Binlog_index_monitor::log_in_use ( const char *  log_name)

Check if any threads use log name.

Note
This method expects the LOCK_index to be taken so there are no concurrent edits against linfo objects being iterated
Parameters
log_namename of a log which is checked for usage

◆ move_crash_safe_index_file_to_index_file()

int Binlog_index_monitor::move_crash_safe_index_file_to_index_file ( bool  need_lock_index)

Move crash safe index file to index file.

Parameters
need_lock_indexIf true, LOCK_index will be acquired; otherwise it should already be held.
Return values
0ok
-1error
See also
Binlog_index::move_crash_safe_index_file_to_index_file

◆ open_index_file()

bool Binlog_index_monitor::open_index_file ( const char *  index_file_name_arg,
const char *  log_name,
PSI_file_key  key_file_log,
bool  need_lock_index 
)
See also
Binlog_index::open_index_file

◆ open_purge_index_file()

int Binlog_index_monitor::open_purge_index_file ( bool  destroy)
See also
Binlog_index::open_purge_index_file

◆ purge_index_entry()

int Binlog_index_monitor::purge_index_entry ( THD thd,
ulonglong decrease_log_space,
PSI_file_key  key_file_log,
bool  need_lock_index 
)

◆ register_create_index_entry()

int Binlog_index_monitor::register_create_index_entry ( const char *  entry)

◆ register_log_info()

void Binlog_index_monitor::register_log_info ( Log_info log_info)
See also
Binlog_index::register_log_info

◆ register_purge_index_entry()

int Binlog_index_monitor::register_purge_index_entry ( const char *  entry)

◆ reinit_purge_index_file()

int Binlog_index_monitor::reinit_purge_index_file ( )

◆ remove_logs_outside_range_from_index() [1/2]

int Binlog_index_monitor::remove_logs_outside_range_from_index ( const std::string &  first,
bool  need_update_threads,
const std::string &  last 
)

Remove logs from index file except logs between first and last.

Parameters
firstFilename of the first relay log to be kept in index file
need_update_threadsIf we want to update the log coordinates of all threads. False for relay logs, true otherwise
lastFilename of the last relay log to be kept in index file
Return values
0OK
LOG_INFO_IOGot IO error while reading/writing file
LOG_INFO_EOFCould not find requested log file (first or last)

◆ remove_logs_outside_range_from_index() [2/2]

int Binlog_index_monitor::remove_logs_outside_range_from_index ( Log_info start_log_info,
bool  need_update_threads,
Log_info last_log_info = nullptr 
)
See also
Binlog_index::remove_logs_outside_range_from_index

◆ set_psi_keys()

void Binlog_index_monitor::set_psi_keys ( PSI_mutex_key  key_LOCK_index,
PSI_file_key  key_file_log_index,
PSI_file_key  key_file_log_index_cache 
)

◆ set_purge_index_file_name()

int Binlog_index_monitor::set_purge_index_file_name ( const char *  base_file_name)

◆ sync_purge_index_file()

int Binlog_index_monitor::sync_purge_index_file ( )

◆ unlock()

void Binlog_index_monitor::unlock ( )
inline

◆ unregister_log_info()

void Binlog_index_monitor::unregister_log_info ( Log_info log_info)
See also
Binlog_index::unregister_log_info

Member Data Documentation

◆ m_binlog_index

Binlog_index Binlog_index_monitor::m_binlog_index
private

◆ m_is_relay_log

const bool Binlog_index_monitor::m_is_relay_log
private

◆ m_key_LOCK_index

PSI_mutex_key Binlog_index_monitor::m_key_LOCK_index
private

The instrumentation key to use for @ LOCK_index.

◆ m_LOCK_index

mysql_mutex_t Binlog_index_monitor::m_LOCK_index
private

POSIX thread objects are inited by init_pthread_objects()


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