MySQL 9.1.0
Source Code Documentation
Binlog_index Class Reference

Binlog_index defines methods which handle binlog index file and its entries. More...

#include <binlog_index.h>

Public Member Functions

 Binlog_index (bool relay_log)
 
void set_psi_keys (PSI_file_key key_file_log_index, PSI_file_key key_file_log_index_cache)
 
bool open_index_file (const char *index_file_name_arg, myf opt)
 Create an index file that will hold all file names used for logging. More...
 
int close_index_file ()
 Close index file. More...
 
bool is_inited_index_file ()
 Check if index file is initalized. More...
 
int open_purge_index_file (bool destroy)
 Functions to manage purge index file. More...
 
int close_purge_index_file ()
 
int end_close_purge_index_file ()
 simulate failure using fault_injection_registering_index debug symbol More...
 
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)
 Read purge index file name into to buffer of max_length. More...
 
int error_purge_index_file ()
 
int register_purge_index_entry (const char *entry)
 
int register_create_index_entry (const char *entry)
 
int find_log_pos (Log_info *linfo, const char *log_name)
 Find the position in the log-index-file for the given log name. More...
 
int find_next_log (Log_info *linfo)
 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)
 Append log file name to index file. More...
 
int move_crash_safe_index_file_to_index_file ()
 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)
 Remove logs from index file, except files between 'start' and 'last'. More...
 
void register_log_info (Log_info *log_info)
 Register log_info which is used by log_in_use and adjust_linfo_offsets functions. More...
 
void unregister_log_info (Log_info *log_info)
 Unregister log_info. More...
 
int log_in_use (const char *log_name)
 Return number of logs in use. More...
 
void adjust_linfo_offsets (my_off_t purge_offset)
 Adjust all registered log_infos by purge_offset. More...
 
const char * get_index_fname () const
 
IO_CACHEget_index_file ()
 

Private Member Functions

int open_crash_safe_index_file ()
 Open a (new) crash safe index file. More...
 
int close_crash_safe_index_file ()
 Close the crash safe index file. More...
 
int set_crash_safe_index_file_name (const char *base_file_name)
 Set the name of crash safe index file. More...
 
bool is_inited_crash_safe_index_file ()
 Check if crash safe index is initalized. More...
 

Private Attributes

PSI_file_key m_key_file_log_index
 The instrumentation key to use for opening the log index file. More...
 
PSI_file_key m_key_file_log_index_cache
 The instrumentation key to use for opening a log index cache file. More...
 
IO_CACHE index_file
 
char index_file_name [FN_REFLEN]
 
IO_CACHE crash_safe_index_file
 crash_safe_index_file is temp file used for guaranteeing index file crash safe when master server restarts. More...
 
char crash_safe_index_file_name [FN_REFLEN]
 
IO_CACHE purge_index_file
 purge_file is a temp file used in purge_logs so that the index file can be updated before deleting files from disk, yielding better crash recovery. More...
 
char purge_index_file_name [FN_REFLEN]
 
const bool is_relay_log
 
std::set< Log_info * > log_info_set
 Set of log info objects that are in usage and might prevent some other operations from executing. More...
 

Static Private Attributes

static const int MAX_RETRIES_FOR_DELETE_RENAME_FAILURE = 5
 

Detailed Description

Binlog_index defines methods which handle binlog index file and its entries.

See also
Binlog_index_monitor to synchronize access to Binlog_index object.

Constructor & Destructor Documentation

◆ Binlog_index()

Binlog_index::Binlog_index ( bool  relay_log)

Member Function Documentation

◆ add_log_to_index()

int Binlog_index::add_log_to_index ( uchar log_name,
size_t  log_name_len 
)

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
Return values
0ok
-1error

◆ adjust_linfo_offsets()

void Binlog_index::adjust_linfo_offsets ( my_off_t  purge_offset)

Adjust all registered log_infos by purge_offset.

Parameters
purge_offsetoffset by which log_info are offset

◆ close_crash_safe_index_file()

int Binlog_index::close_crash_safe_index_file ( )
private

Close the crash safe index file.

Note
The crash safe file is just closed, is not deleted. Because it is moved to index file later on.
Return values
0ok
1error

◆ close_index_file()

int Binlog_index::close_index_file ( )

Close index file.

Returns
0 - success, !0 - failure

◆ close_purge_index_file()

int Binlog_index::close_purge_index_file ( )

◆ end_close_purge_index_file()

int Binlog_index::end_close_purge_index_file ( )

simulate failure using fault_injection_registering_index debug symbol

◆ error_purge_index_file()

int Binlog_index::error_purge_index_file ( )

◆ find_log_pos()

int Binlog_index::find_log_pos ( Log_info linfo,
const char *  log_name 
)

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.
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

◆ find_next_log()

int Binlog_index::find_next_log ( Log_info linfo)

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.
Note
  • Before calling this function, one has to call find_log_pos() to set up 'linfo'
Return values
0ok
LOG_INFO_EOFEnd of log-index-file found
LOG_INFO_IOGot IO error while reading file

◆ get_index_file()

IO_CACHE * Binlog_index::get_index_file ( )
inline

◆ get_index_fname()

const char * Binlog_index::get_index_fname ( ) const
inline

◆ gets_purge_index_file()

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

Read purge index file name into to buffer of max_length.

Parameters
tobuffer where to store purge index file name
max_lengthlength of the to buffer
Returns
number of characters read, 0 on error

◆ is_inited_crash_safe_index_file()

bool Binlog_index::is_inited_crash_safe_index_file ( )
private

Check if crash safe index is initalized.

Returns
true - is initalized, false - otherwise

◆ is_inited_index_file()

bool Binlog_index::is_inited_index_file ( )

Check if index file is initalized.

Returns
true - initalized, false - otherwise

◆ is_inited_purge_index_file()

bool Binlog_index::is_inited_purge_index_file ( )

◆ log_in_use()

int Binlog_index::log_in_use ( const char *  log_name)

Return number of logs in use.

Parameters
log_namelog_name to be searched among files registered by register_log_info
Returns
number of logs in use

◆ move_crash_safe_index_file_to_index_file()

int Binlog_index::move_crash_safe_index_file_to_index_file ( )

Move crash safe index file to index file.

Return values
0ok
-1error

◆ open_crash_safe_index_file()

int Binlog_index::open_crash_safe_index_file ( )
private

Open a (new) crash safe index file.

Note
The crash safe index file is a special file used for guaranteeing index file crash safe.
Return values
0ok
1error

◆ open_index_file()

bool Binlog_index::open_index_file ( const char *  index_file_name_arg,
myf  opt 
)

Create an index file that will hold all file names used for logging.

Parameters
index_file_name_argname of the index file
optopening mode
Returns
false - success, true - failure

◆ open_purge_index_file()

int Binlog_index::open_purge_index_file ( bool  destroy)

Functions to manage purge index file.

See also
purge_index_file

◆ register_create_index_entry()

int Binlog_index::register_create_index_entry ( const char *  entry)

◆ register_log_info()

void Binlog_index::register_log_info ( Log_info log_info)

Register log_info which is used by log_in_use and adjust_linfo_offsets functions.

Parameters
log_info- log_info to be registered

◆ register_purge_index_entry()

int Binlog_index::register_purge_index_entry ( const char *  entry)

◆ reinit_purge_index_file()

int Binlog_index::reinit_purge_index_file ( )

◆ remove_logs_outside_range_from_index()

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

Remove logs from index file, except files between 'start' and 'last'.

To make it crash safe, we copy the content of the index file from index_file_start_offset recorded in log_info to a crash safe index file first and then move the crash safe index file to the index file.

Parameters
start_log_infoMetadata of the first log to be kept in the index file.
need_update_threadsIf we want to update the log coordinates of all threads. False for relay logs, true otherwise.
last_log_infoMetadata of the last log to be kept in the index file; nullptr means that all logs after start_log_info will be kept
Return values
0ok
LOG_INFO_IOGot IO error while reading/writing file

◆ set_crash_safe_index_file_name()

int Binlog_index::set_crash_safe_index_file_name ( const char *  base_file_name)
private

Set the name of crash safe index file.

Return values
0ok
1error

◆ set_psi_keys()

void Binlog_index::set_psi_keys ( PSI_file_key  key_file_log_index,
PSI_file_key  key_file_log_index_cache 
)

◆ set_purge_index_file_name()

int Binlog_index::set_purge_index_file_name ( const char *  base_file_name)

◆ sync_purge_index_file()

int Binlog_index::sync_purge_index_file ( )

◆ unregister_log_info()

void Binlog_index::unregister_log_info ( Log_info log_info)

Unregister log_info.

Parameters
log_info- log_info to be unregistered
See also
register_log_info

Member Data Documentation

◆ crash_safe_index_file

IO_CACHE Binlog_index::crash_safe_index_file
private

crash_safe_index_file is temp file used for guaranteeing index file crash safe when master server restarts.

◆ crash_safe_index_file_name

char Binlog_index::crash_safe_index_file_name[FN_REFLEN]
private

◆ index_file

IO_CACHE Binlog_index::index_file
private

◆ index_file_name

char Binlog_index::index_file_name[FN_REFLEN]
private

◆ is_relay_log

const bool Binlog_index::is_relay_log
private

◆ log_info_set

std::set<Log_info *> Binlog_index::log_info_set
private

Set of log info objects that are in usage and might prevent some other operations from executing.

◆ m_key_file_log_index

PSI_file_key Binlog_index::m_key_file_log_index
private

The instrumentation key to use for opening the log index file.

◆ m_key_file_log_index_cache

PSI_file_key Binlog_index::m_key_file_log_index_cache
private

The instrumentation key to use for opening a log index cache file.

◆ MAX_RETRIES_FOR_DELETE_RENAME_FAILURE

const int Binlog_index::MAX_RETRIES_FOR_DELETE_RENAME_FAILURE = 5
staticprivate

◆ purge_index_file

IO_CACHE Binlog_index::purge_index_file
private

purge_file is a temp file used in purge_logs so that the index file can be updated before deleting files from disk, yielding better crash recovery.

It is created on demand the first time purge_logs is called and then reused for subsequent calls. It is cleaned up in cleanup().

◆ purge_index_file_name

char Binlog_index::purge_index_file_name[FN_REFLEN]
private

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