My Project
Classes | Enumerations | Functions | Variables
Binary Log

Classes

class  Mutex_sentry
class  Thread_excursion
class  binlog_cache_data
class  binlog_stmt_cache_data
class  binlog_trx_cache_data
class  binlog_cache_mngr
class  Row_data_memory

Enumerations

enum  enum_read_gtids_from_binlog_status {
  GOT_GTIDS, GOT_PREVIOUS_GTIDS, NO_GTIDS, ERROR,
  TRUNCATED
}

Functions

void check_binlog_cache_size (THD *thd)
void check_binlog_stmt_cache_size (THD *thd)
bool binlog_enabled ()
int gtid_empty_group_log_and_cleanup (THD *thd)
int check_binlog_magic (IO_CACHE *log, const char **errmsg)
File open_binlog_file (IO_CACHE *log, const char *log_file_name, const char **errmsg)
bool trans_has_updated_trans_table (const THD *thd)
bool stmt_has_updated_trans_table (const THD *thd)
bool ending_trans (THD *thd, const bool all)
bool ending_single_stmt_trans (THD *thd, const bool all)
bool trans_cannot_safely_rollback (const THD *thd)
bool stmt_cannot_safely_rollback (const THD *thd)
bool purge_master_logs (THD *thd, const char *to_log)
bool purge_master_logs_before_date (THD *thd, time_t purge_time)
int query_error_code (THD *thd, bool not_killed)
int log_loaded_block (IO_CACHE *file)
bool show_binlog_events (THD *thd, MYSQL_BIN_LOG *binary_log)
bool mysql_show_binlog_events (THD *thd)
void register_binlog_handler (THD *thd, bool trx)
int binlog_stmt_cache_data::finalize (THD *thd)
int binlog_cache_data::write_event (THD *thd, Log_event *event)
int binlog_cache_data::finalize (THD *thd, Log_event *end_event)
int binlog_cache_data::flush (THD *thd, my_off_t *bytes, bool *wrote_xid)
int binlog_trx_cache_data::truncate (THD *thd, bool all)
bool Stage_manager::Mutex_queue::append (THD *first)
std::pair< bool, THD * > Stage_manager::Mutex_queue::pop_front ()
bool Stage_manager::enroll_for (StageID stage, THD *first, mysql_mutex_t *stage_mutex)
THD * Stage_manager::Mutex_queue::fetch_and_empty ()
void Stage_manager::clear_preempt_status (THD *head)
int MYSQL_BIN_LOG::rollback (THD *thd, bool all)
 MYSQL_BIN_LOG::MYSQL_BIN_LOG (uint *sync_period)
void MYSQL_BIN_LOG::cleanup ()
void MYSQL_BIN_LOG::init_pthread_objects ()
bool MYSQL_BIN_LOG::open_index_file (const char *index_file_name_arg, const char *log_name, bool need_lock_index)
bool MYSQL_BIN_LOG::find_first_log_not_in_gtid_set (char *binlog_file_name, const Gtid_set *gtid_set, Gtid *first_gtid, const char **errmsg)
bool MYSQL_BIN_LOG::init_gtid_sets (Gtid_set *gtid_set, Gtid_set *lost_groups, Gtid *last_gtid, bool verify_checksum, bool need_lock, bool is_server_starting=false)
bool MYSQL_BIN_LOG::open_binlog (const char *log_name, const char *new_name, enum cache_type io_cache_type_arg, ulong max_size, bool null_created, bool need_lock_index, bool need_sid_lock, Format_description_log_event *extra_description_event)
int MYSQL_BIN_LOG::move_crash_safe_index_file_to_index_file (bool need_lock_index)
int MYSQL_BIN_LOG::add_log_to_index (uchar *log_file_name, int name_len, bool need_lock_index)
int MYSQL_BIN_LOG::get_current_log (LOG_INFO *linfo)
int MYSQL_BIN_LOG::raw_get_current_log (LOG_INFO *linfo)
bool MYSQL_BIN_LOG::check_write_error (THD *thd)
void MYSQL_BIN_LOG::set_write_error (THD *thd, bool is_transactional)
int MYSQL_BIN_LOG::find_log_pos (LOG_INFO *linfo, const char *log_name, bool need_lock_index)
int MYSQL_BIN_LOG::find_next_log (LOG_INFO *linfo, bool need_lock_index)
bool MYSQL_BIN_LOG::reset_logs (THD *thd)
int MYSQL_BIN_LOG::set_crash_safe_index_file_name (const char *base_file_name)
int MYSQL_BIN_LOG::open_crash_safe_index_file ()
int MYSQL_BIN_LOG::close_crash_safe_index_file ()
int MYSQL_BIN_LOG::purge_first_log (Relay_log_info *rli, bool included)
int MYSQL_BIN_LOG::remove_logs_from_index (LOG_INFO *linfo, bool need_update_threads)
int MYSQL_BIN_LOG::purge_logs (const char *to_log, bool included, bool need_lock_index, bool need_update_threads, ulonglong *decrease_log_space, bool auto_purge)
int MYSQL_BIN_LOG::set_purge_index_file_name (const char *base_file_name)
int MYSQL_BIN_LOG::open_purge_index_file (bool destroy)
int MYSQL_BIN_LOG::close_purge_index_file ()
bool MYSQL_BIN_LOG::is_inited_purge_index_file ()
int MYSQL_BIN_LOG::sync_purge_index_file ()
int MYSQL_BIN_LOG::register_purge_index_entry (const char *entry)
int MYSQL_BIN_LOG::register_create_index_entry (const char *entry)
int MYSQL_BIN_LOG::purge_index_entry (THD *thd, ulonglong *decrease_log_space, bool need_lock_index)
int MYSQL_BIN_LOG::purge_logs_before_date (time_t purge_time, bool auto_purge)
void MYSQL_BIN_LOG::make_log_name (char *buf, const char *log_ident)
bool MYSQL_BIN_LOG::is_active (const char *log_file_name)
int MYSQL_BIN_LOG::new_file (Format_description_log_event *extra_description_event)
bool MYSQL_BIN_LOG::flush_and_sync (const bool force=false)
void MYSQL_BIN_LOG::start_union_events (THD *thd, query_id_t query_id_param)
void MYSQL_BIN_LOG::stop_union_events (THD *thd)
bool MYSQL_BIN_LOG::is_query_in_union (THD *thd, query_id_t query_id_param)
void MYSQL_BIN_LOG::update_thd_next_event_pos (THD *thd)
int MYSQL_BIN_LOG::flush_and_set_pending_rows_event (THD *thd, Rows_log_event *event, bool is_transactional)
bool MYSQL_BIN_LOG::write_event (Log_event *event_info)
int MYSQL_BIN_LOG::rotate (bool force_rotate, bool *check_purge)
void MYSQL_BIN_LOG::purge ()
int MYSQL_BIN_LOG::rotate_and_purge (THD *thd, bool force_rotate)
uint MYSQL_BIN_LOG::next_file_id ()
int MYSQL_BIN_LOG::do_write_cache (IO_CACHE *cache)
bool MYSQL_BIN_LOG::write_incident (Incident_log_event *ev, bool need_lock_log, bool do_flush_and_sync=true)
bool MYSQL_BIN_LOG::write_incident (THD *thd, bool need_lock_log, bool do_flush_and_sync=true)
bool MYSQL_BIN_LOG::write_cache (THD *thd, class binlog_cache_data *binlog_cache_data)
int MYSQL_BIN_LOG::wait_for_update_relay_log (THD *thd, const struct timespec *timeout)
int MYSQL_BIN_LOG::wait_for_update_bin_log (THD *thd, const struct timespec *timeout)
void MYSQL_BIN_LOG::close (uint exiting)
void MYSQL_BIN_LOG::set_max_size (ulong max_size_arg)
void MYSQL_BIN_LOG::signal_update ()
int MYSQL_BIN_LOG::open_binlog (const char *opt_name)
void MYSQL_BIN_LOG::close ()
int MYSQL_BIN_LOG::prepare (THD *thd, bool all)
enum_result MYSQL_BIN_LOG::commit (THD *thd, bool all)
int MYSQL_BIN_LOG::recover (IO_CACHE *log, Format_description_log_event *fdle, my_off_t *valid_pos)

Variables

bool opt_binlog_order_commits = true
const char * log_bin_index = 0
const char * log_bin_basename = 0
MYSQL_BIN_LOG mysql_bin_log & sync_binlog_period
struct st_mysql_storage_engine binlog_storage_engine

Enumeration Type Documentation

Reads GTIDs from the given binlog file.

Parameters:
filenameFile to read from.
all_gtidsIf not NULL, then the GTIDs from the Previous_gtids_log_event and from all Gtid_log_events are stored in this object.
prev_gtidsIf not NULL, then the GTIDs from the Previous_gtids_log_events are stored in this object.
first_gtidIf not NULL, then the first GTID information from the file will be stored in this object.
last_gtidIf not NULL, then the last GTID information from the file will be stored in this object.
sid_mapThe sid_map object to use in the rpl_sidno generation of the Gtid_log_event. If lock is needed in the sid_map, the caller must hold it.
verify_checksumSet to true to verify event checksums.
Return values:
GOT_GTIDSThe file was successfully read and it contains both Gtid_log_events and Previous_gtids_log_events.
GOT_PREVIOUS_GTIDSThe file was successfully read and it contains Previous_gtids_log_events but no Gtid_log_events.
NO_GTIDSThe file was successfully read and it does not contain GTID events.
ERROROut of memory, or the file contains GTID events when GTID_MODE = OFF, or the file is malformed (e.g., contains Gtid_log_events but no Previous_gtids_log_event).
TRUNCATEDThe file was truncated before the end of the first Previous_gtids_log_event.

Function Documentation

int MYSQL_BIN_LOG::add_log_to_index ( uchar *  log_name,
int  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.
Return values:
0ok
-1error
bool Stage_manager::Mutex_queue::append ( THD *  first)

Append a linked list of threads to the queue

bool binlog_enabled ( )

Check whether binlog_hton has valid slot and enabled

void check_binlog_cache_size ( THD *  thd)

Checks if the BINLOG_CACHE_SIZE's value is greater than MAX_BINLOG_CACHE_SIZE. If this happens, the BINLOG_CACHE_SIZE is set to MAX_BINLOG_CACHE_SIZE.

void check_binlog_stmt_cache_size ( THD *  thd)

Checks if the BINLOG_STMT_CACHE_SIZE's value is greater than MAX_BINLOG_STMT_CACHE_SIZE. If this happens, the BINLOG_STMT_CACHE_SIZE is set to MAX_BINLOG_STMT_CACHE_SIZE.

This is called only once.

Reimplemented from MYSQL_LOG.

The method ensures the follower's execution path can be preempted by the leader's thread. Preempt status of head follower is checked to engange the leader into waiting when set.

Parameters:
headTHD* of a follower thread
void MYSQL_BIN_LOG::close ( ) [virtual]

This is called on shutdown, after ha_panic.

Implements TC_LOG.

void MYSQL_BIN_LOG::close ( uint  exiting)

Close the log file.

Parameters:
exitingBitmask for one or more of the following bits:
  • LOG_CLOSE_INDEX : if we should close the index file
  • LOG_CLOSE_TO_BE_OPENED : if we intend to call open at once after close.
  • LOG_CLOSE_STOP_EVENT : write a 'stop' event to the log
Note:
One can do an open on the object at once after doing a close. The internal structures are not freed until cleanup() is called

Reimplemented from MYSQL_LOG.

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
TC_LOG::enum_result MYSQL_BIN_LOG::commit ( THD *  thd,
bool  all 
) [virtual]

Commit the transaction in the transaction coordinator.

This function will commit the sessions transaction in the binary log and in the storage engines (by calling ha_commit_low). If the transaction was successfully logged (or not successfully unlogged) but the commit in the engines did not succed, there is a risk of inconsistency between the engines and the binary log.

For binary log group commit, the commit is separated into three parts:

1. First part consists of filling the necessary caches and finalizing them (if they need to be finalized). After this, nothing is added to any of the caches.

2. Second part execute an ordered flush and commit. This will be done using the group commit functionality in ordered_commit.

3. Third part checks any errors resulting from the ordered commit and handles them appropriately.

Return values:
0success
1error, transaction was neither logged nor committed
2error, transaction was logged but not committed

Implements TC_LOG.

bool ending_single_stmt_trans ( THD *  thd,
const bool  all 
)

This function checks if a single statement transaction is about to commit or not.

Parameters:
thdThe client thread that executed the current statement.
allCommitting a transaction (i.e. TRUE) or a statement (i.e. FALSE).
Returns:
true if committing a single statement transaction, otherwise false.
bool ending_trans ( THD *  thd,
const bool  all 
)

This function checks if a transaction, either a multi-statement or a single statement transaction is about to commit or not.

Parameters:
thdThe client thread that executed the current statement.
allCommitting a transaction (i.e. TRUE) or a statement (i.e. FALSE).
Returns:
true if committing a transaction, otherwise false.
bool Stage_manager::enroll_for ( StageID  stage,
THD *  first,
mysql_mutex_t *  stage_mutex 
)

Enroll a set of sessions for a stage.

This will queue the session thread for writing and flushing.

If the thread being queued is assigned as stage leader, it will return immediately.

If wait_if_follower is true the thread is not the stage leader, the thread will be wait for the queue to be processed by the leader before it returns. In DBUG-ON version the follower marks is preempt status as ready.

Parameters:
stageStage identifier for the queue to append to.
firstQueue to append.
stage_mutexPointer to the currently held stage mutex, or NULL if we're not in a stage.
Return values:
trueThread is stage leader.
falseThread was not stage leader and processing has been done.

Fetch the entire queue for a stage.

This will fetch the entire queue in one go.

int binlog_cache_data::finalize ( THD *  thd,
Log_event end_event 
)

This function finalizes the cache preparing for commit or rollback.

The function just writes all the necessary events to the cache but does not flush the data to the binary log file. That is the role of the binlog_cache_data::flush function.

See also:
binlog_cache_data::flush
Parameters:
thdThe thread whose transaction should be flushed
cache_dataPointer to the cache
end_evThe end event either commit/rollback
Returns:
nonzero if an error pops up when flushing the cache.
bool MYSQL_BIN_LOG::find_first_log_not_in_gtid_set ( char *  binlog_file_name,
const Gtid_set gtid_set,
Gtid first_gtid,
const char **  errmsg 
)

Find the oldest binary log that contains any GTID that is not in the given gtid set.

Parameters:
[out]binlog_file_name,thefile name of oldest binary log found
[in]gtid_set,thegiven gtid set
[out]first_gtid,thefirst GTID information from the binary log file returned at binlog_file_name
[out]errmsg,theerror message outputted, which is left untouched if the function returns false
Returns:
false on success, true on error.
int MYSQL_BIN_LOG::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
int MYSQL_BIN_LOG::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
int binlog_cache_data::flush ( THD *  thd,
my_off_t *  bytes_written,
bool *  wrote_xid 
)

Flush caches to the binary log.

If the cache is finalized, the cache will be flushed to the binary log file. If the cache is not finalized, nothing will be done.

If flushing fails for any reason, an error will be reported and the cache will be reset. Flushing can fail in two circumstances:

  • It was not possible to write the cache to the file. In this case, it does not make sense to keep the cache.
  • The cache was successfully written to disk but post-flush actions (such as binary log rotation) failed. In this case, the cache is already written to disk and there is no reason to keep it.
See also:
binlog_cache_data::finalize
bool MYSQL_BIN_LOG::flush_and_sync ( const bool  force = false)

Flush binlog cache and synchronize to disk.

This function flushes events in binlog cache to binary log file, it will do synchronizing according to the setting of system variable 'sync_binlog'. If file is synchronized, synced will be set to 1, otherwise 0.

Parameters:
[out]syncedif not NULL, set to 1 if file is synchronized, otherwise 0
[in]forceif TRUE, ignores the 'sync_binlog' and synchronizes the file.
Return values:
0Success
otherFailure

The function logs an empty group with GTID and performs cleanup. Its logic wrt GTID is equivalent to one of binlog_commit(). It's called at the end of statement execution in case binlog_commit() was skipped. Such cases are due ineffective binlogging incl an empty group re-execution.

Parameters:
thdThe thread handle
Returns:
nonzero if an error pops up.
bool MYSQL_BIN_LOG::init_gtid_sets ( Gtid_set gtid_set,
Gtid_set lost_groups,
Gtid last_gtid,
bool  verify_checksum,
bool  need_lock,
bool  is_server_starting = false 
)

Reads the set of all GTIDs in the binary log, and the set of all lost GTIDs in the binary log, and stores each set in respective argument.

Parameters:
gtid_setWill be filled with all GTIDs in this binary log.
lost_groupsWill be filled with all GTIDs in the Previous_gtids_log_event of the first binary log that has a Previous_gtids_log_event.
last_gtidWill be filled with the last availble GTID information in the binary/relay log files.
verify_checksumIf true, checksums will be checked.
need_lockIf true, LOCK_log, LOCK_index, and global_sid_lock->wrlock are acquired; otherwise they are asserted to be taken already.
is_server_startingTrue if the server is starting.
Returns:
false on success, true on error.
bool MYSQL_BIN_LOG::is_active ( const char *  log_file_name_arg)

Check if we are writing/reading to the given log file.

int log_loaded_block ( IO_CACHE *  file)

Load data's io cache specific hook to be executed before a chunk of data is being read into the cache's buffer The fuction instantianates and writes into the binlog replication events along LOAD DATA processing.

Parameters:
filepointer to io-cache
Return values:
0success
1failure
void MYSQL_BIN_LOG::make_log_name ( char *  buf,
const char *  log_ident 
)

Create a new log file name.

Parameters:
bufbuf of at least FN_REFLEN where new name is stored
Note:
If file name will be longer then FN_REFLEN it will be truncated

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
bool mysql_show_binlog_events ( THD *  thd)

Execute a SHOW BINLOG EVENTS statement.

Parameters:
thdPointer to THD object for the client thread executing the statement.
Return values:
FALSEsuccess
TRUEfailure
int MYSQL_BIN_LOG::open_binlog ( const char *  opt_name)
Todo:
keep in-memory list of prepared transactions (add to list in log(), remove on unlog()) and copy it to the new binlog if rotated but let's check the behaviour of tc_log_page_waits first!
bool MYSQL_BIN_LOG::open_binlog ( const char *  log_name,
const char *  new_name,
enum cache_type  io_cache_type_arg,
ulong  max_size_arg,
bool  null_created_arg,
bool  need_lock_index,
bool  need_sid_lock,
Format_description_log_event extra_description_event 
)

Create a new binary log.

Parameters:
log_nameName of binlog
new_nameName of binlog, too. todo: what's the difference between new_name and log_name?
io_cache_type_argSpecifies how the IO cache is opened: read-only or read-write.
max_sizeThe size at which this binlog will be rotated.
null_createdIf false, and a Format_description_log_event is written, then the Format_description_log_event will have the timestamp 0. Otherwise, it the timestamp will be the time when the event was written to the log.
need_lock_indexIf true, LOCK_index is acquired; otherwise LOCK_index must be taken by the caller.
need_sid_lockIf true, the read lock on global_sid_lock will be acquired. Otherwise, the caller must hold the read lock on global_sid_lock.

Open a (new) binlog file.

  • Open the log file and the index file. Register the new file name in it
  • When calling this when the file is in use, you must have a locks on LOCK_log and LOCK_index.
Return values:
0ok
1error
Todo:
: although this was introduced to appease valgrind when injecting emulated faults using fault_injection_registering_index it may be good to consider what actually happens when open_purge_index_file succeeds but register or sync fails.

Perhaps we might need the code below in MYSQL_LOG_BIN::cleanup for "real life" purposes as well?

File open_binlog_file ( IO_CACHE *  log,
const char *  log_file_name,
const char **  errmsg 
)

Open a single binary log file for reading.

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
int MYSQL_BIN_LOG::prepare ( THD *  thd,
bool  all 
) [virtual]

Log a prepare record of the transaction to the storage engines.

Parameters:
thdSession to log transaction record for.
alltrue if an explicit commit or an implicit commit for a statement, false if an internal commit of the statement.
Returns:
Error code on failure, zero on success.

Implements TC_LOG.

The method executes logs purging routine.

Return values:
nonzero- error in rotating routine.
int MYSQL_BIN_LOG::purge_first_log ( Relay_log_info rli,
bool  included 
)

Delete relay log files prior to rli->group_relay_log_name (i.e. all logs which are not involved in a non-finished group (transaction)), remove them from the index file and start on next relay log.

IMPLEMENTATION

  • You must hold rli->data_lock before calling this function, since it writes group_relay_log_pos and similar fields of Relay_log_info.
  • Protects index file with LOCK_index
  • Delete relevant relay log files
  • Copy all file names after these ones to the front of the index file
  • If the OS has truncate, truncate the file, else fill it with
    '
  • Read the next file name from the index file and store in rli->linfo
Parameters:
rliRelay log information
includedIf false, all relay logs that are strictly before rli->group_relay_log_name are deleted ; if true, the latter is deleted too (i.e. all relay logs read by the SQL slave thread are deleted).
Note:
  • This is only called from the slave SQL thread when it has read all commands from a relay log and want to switch to a new relay log.
  • When this happens, we can be in an active transaction as a transaction can span over two relay logs (although it is always written as a single block to the master's binary log, hence cannot span over two master's binary logs).
Return values:
0ok
LOG_INFO_EOFEnd of log-index-file found
LOG_INFO_SEEKCould not allocate IO cache
LOG_INFO_IOGot IO error while reading file
int MYSQL_BIN_LOG::purge_logs ( const char *  to_log,
bool  included,
bool  need_lock_index,
bool  need_update_threads,
ulonglong *  decrease_log_space,
bool  auto_purge 
)

Remove all logs before the given log from disk and from the index file.

Parameters:
to_logDelete all log file name before this file.
includedIf true, to_log is deleted too.
need_lock_index
need_update_threadsIf we want to update the log coordinates of all threads. False for relay logs, true otherwise.
freed_log_spaceIf not null, decrement this variable of the amount of log space freed
auto_purgeTrue if this is an automatic purge.
Note:
If any of the logs before the deleted one is in use, only purge logs up to this one.
Return values:
0ok
LOG_INFO_EOFto_log not found LOG_INFO_EMFILE too many files opened LOG_INFO_FATAL if any other than ENOENT error from mysql_file_stat() or mysql_file_delete()
int MYSQL_BIN_LOG::purge_logs_before_date ( time_t  purge_time,
bool  auto_purge 
)

Remove all logs before the given file date from disk and from the index file.

Parameters:
thdThread pointer
purge_timeDelete all log files before given date.
auto_purgeTrue if this is an automatic purge.
Note:
If any of the logs before the deleted one is in use, only purge logs up to this one.
Return values:
0ok
LOG_INFO_PURGE_NO_ROTATEBinary file that can't be rotated LOG_INFO_FATAL if any other than ENOENT error from mysql_file_stat() or mysql_file_delete()
bool purge_master_logs ( THD *  thd,
const char *  to_log 
)

Execute a PURGE BINARY LOGS TO <log> command.

Parameters:
thdPointer to THD object for the client thread executing the statement.
to_logName of the last log to purge.
Return values:
FALSEsuccess
TRUEfailure
bool purge_master_logs_before_date ( THD *  thd,
time_t  purge_time 
)

Execute a PURGE BINARY LOGS BEFORE <date> command.

Parameters:
thdPointer to THD object for the client thread executing the statement.
purge_timeDate before which logs should be purged.
Return values:
FALSEsuccess
TRUEfailure
int MYSQL_BIN_LOG::recover ( IO_CACHE *  log,
Format_description_log_event fdle,
my_off_t *  valid_pos 
)

MYSQLD server recovers from last crashed binlog.

Parameters:
logIO_CACHE of the crashed binlog.
fdleFormat_description_log_event of the crashed binlog.
valid_posThe position of the last valid transaction or event(non-transaction) of the crashed binlog.
Return values:
0ok
1error
int MYSQL_BIN_LOG::remove_logs_from_index ( LOG_INFO log_info,
bool  need_update_threads 
)

Remove logs from index file.

  • To make crash safe, we copy the content of index file from index_file_start_offset recored in log_info to crash safe index file firstly and then move the crash safe index file to index file.
Parameters:
linfoStore here the found log file name and position to the NEXT log file name in the index file.
need_update_threadsIf we want to update the log coordinates of all threads. False for relay logs, true otherwise.
Return values:
0ok
LOG_INFO_IOGot IO error while reading/writing file
bool MYSQL_BIN_LOG::reset_logs ( THD *  thd)

Removes files, as part of a RESET MASTER or RESET SLAVE statement, by deleting all logs refered to in the index file. Then, it starts writing to a new log file.

The new index file will only contain this file.

Parameters:
thdThread
Note:
If not called from slave thread, write start event to new log
Return values:
0ok
1error
int MYSQL_BIN_LOG::rollback ( THD *  thd,
bool  all 
) [virtual]

Write a rollback record of the transaction to the binary log.

For binary log group commit, the rollback is separated into three parts:

1. First part consists of filling the necessary caches and finalizing them (if they need to be finalized). After a cache is finalized, nothing can be added to the cache.

2. Second part execute an ordered flush and commit. This will be done using the group commit functionality in ordered_commit.

Since we roll back the transaction early, we call ordered_commit with the skip_commit flag set. The ha_commit_low call inside ordered_commit will then not be called.

3. Third part checks any errors resulting from the flush and handles them appropriately.

See also:
MYSQL_BIN_LOG::ordered_commit
ha_commit_low
ha_rollback_low
Parameters:
thdSession to commit
allThis is true if this is a real transaction rollback, and otherwise.
Returns:
Error code, or zero if there were no error.

Implements TC_LOG.

int MYSQL_BIN_LOG::rotate ( bool  force_rotate,
bool *  check_purge 
)

The method executes rotation when LOCK_log is already acquired by the caller.

Parameters:
force_rotatecaller can request the log rotation
check_purgeis set to true if rotation took place
Note:
If rotation fails, for instance the server was unable to create a new log file, we still try to write an incident event to the current log.
The caller must hold LOCK_log when invoking this function.
Return values:
nonzero- error in rotating routine.

Be conservative... There are possible lost events (eg, failing to log the Execute_load_query_log_event on a LOAD DATA while using a non-transactional table)!

We give it a shot and try to write an incident event anyway to the current log.

int MYSQL_BIN_LOG::rotate_and_purge ( THD *  thd,
bool  force_rotate 
)

The method is a shortcut of rotate() and purge(). LOCK_log is acquired prior to rotate and is released after it.

Parameters:
force_rotatecaller can request the log rotation
Return values:
nonzero- error in rotating routine.
int MYSQL_BIN_LOG::set_crash_safe_index_file_name ( const char *  base_file_name)

Set the name of crash safe index file.

Return values:
0ok
1error
bool stmt_cannot_safely_rollback ( const THD *  thd)

This function checks if current statement cannot be rollded back safely.

Parameters:
thdThe client thread that executed the current statement.
Returns:
true if cannot be safely rolled back, false otherwise.
bool stmt_has_updated_trans_table ( const THD *  thd)

This function checks if a transactional table was updated by the current statement.

Parameters:
thdThe client thread that executed the current statement.
Returns:
true if a transactional table was updated, false otherwise.
bool trans_cannot_safely_rollback ( const THD *  thd)

This function checks if a transaction cannot be rolled back safely.

Parameters:
thdThe client thread that executed the current statement.
Returns:
true if cannot be safely rolled back, false otherwise.
bool trans_has_updated_trans_table ( const THD *  thd)

This function checks if a transactional table was updated by the current transaction.

Parameters:
thdThe client thread that executed the current statement.
Returns:
true if a transactional table was updated, false otherwise.
int binlog_trx_cache_data::truncate ( THD *  thd,
bool  all 
)

This function truncates the transactional cache upon committing or rolling back either a transaction or a statement.

Parameters:
thdThe thread whose transaction should be flushed
cache_mngrPointer to the cache data to be flushed
alltrue means truncate the transaction, otherwise the statement must be truncated.
Returns:
nonzero if an error pops up when truncating the transactional cache.
int MYSQL_BIN_LOG::wait_for_update_bin_log ( THD *  thd,
const struct timespec *  timeout 
)

Wait until we get a signal that the binary log has been updated. Applies to master only.

NOTES

Parameters:
[in]thda THD struct
[in]timeouta pointer to a timespec; NULL means to wait w/o timeout.
Return values:
0if got signalled on update
non-0if wait timeout elapsed
Note:
LOCK_log must be taken before calling this function. LOCK_log is being released while the thread is waiting. LOCK_log is released by the caller.
int MYSQL_BIN_LOG::wait_for_update_relay_log ( THD *  thd,
const struct timespec *  timeout 
)

Wait until we get a signal that the relay log has been updated.

Parameters:
[in]thdThread variable
[in]timeouta pointer to a timespec; NULL means to wait w/o timeout.
Return values:
0if got signalled on update
non-0if wait timeout elapsed
Note:
One must have a lock on LOCK_log before calling this function.
bool MYSQL_BIN_LOG::write_cache ( THD *  thd,
class binlog_cache_data binlog_cache_data 
)

Write a cached log entry to the binary log.

Parameters:
thdThread variable
cacheThe cache to copy to the binlog
incidentDefines if an incident event should be created to notify that some non-transactional changes did not get into the binlog.
preparedDefines if a transaction is part of a 2-PC.
Note:
We only come here if there is something in the cache.
The thing in the cache is always a complete transaction.
'cache' needs to be reinitialized after this functions returns.
bool MYSQL_BIN_LOG::write_event ( Log_event event_info)

Write an event to the binary log.

bool MYSQL_BIN_LOG::write_incident ( THD *  thd,
bool  need_lock_log,
bool  do_flush_and_sync = true 
)

Creates an incident event and writes it to the binary log.

Parameters:
thdThread variable
evIncident event to be written
lockIf the binary lock should be locked or not
Return values:
0error
1success
bool MYSQL_BIN_LOG::write_incident ( Incident_log_event ev,
bool  need_lock_log,
bool  do_flush_and_sync = true 
)

Writes an incident event to the binary log.

Parameters:
evIncident event to be written
need_lock_logIf true, will acquire LOCK_log; otherwise the caller should already have acquired LOCK_log. If true, will call flush_and_sync(), rotate() and purge().
Return values:
falseerror
truesuccess

Variable Documentation

struct st_mysql_storage_engine binlog_storage_engine
Initial value:
{ MYSQL_HANDLERTON_INTERFACE_VERSION }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines