MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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

Macros

#define MY_OFF_T_UNDEF   (~(my_off_t)0UL)
#define LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT   50
#define LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT   50
#define MAX_SESSION_ATTACH_TRIES   10

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)
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, const char **errmsg)
bool MYSQL_BIN_LOG::init_gtid_sets (Gtid_set *gtid_set, Gtid_set *lost_groups, bool verify_checksum, bool need_lock)
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 ()
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 (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

Detailed Description

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

Definition at line 2555 of file binlog.cc.

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

Definition at line 3271 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Stage_manager::Mutex_queue::append ( THD *  first)

Append a linked list of threads to the queue

Definition at line 1353 of file binlog.cc.

Here is the caller graph for this function:

bool binlog_enabled ( )

Check whether binlog_hton has valid slot and enabled

Definition at line 836 of file binlog.cc.

Here is the caller graph for this function:

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.

Definition at line 785 of file binlog.cc.

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.

Definition at line 811 of file binlog.cc.

void Stage_manager::clear_preempt_status ( THD *  head)

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

Definition at line 1473 of file binlog.cc.

void MYSQL_BIN_LOG::close ( )

This is called on shutdown, after ha_panic.

Definition at line 6084 of file binlog.cc.

Here is the caller graph for this function:

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

Definition at line 5840 of file binlog.cc.

Here is the call graph for this function:

int MYSQL_BIN_LOG::close_crash_safe_index_file ( )

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

Definition at line 3790 of file binlog.cc.

Here is the caller graph for this function:

TC_LOG::enum_result MYSQL_BIN_LOG::commit ( THD *  thd,
bool  all 
)

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.
  1. Second part execute an ordered flush and commit. This will be done using the group commit functionality in ordered_commit.
  1. 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

Definition at line 6133 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Definition at line 1979 of file binlog.cc.

Here is the caller graph for this function:

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.

Definition at line 1963 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Definition at line 1413 of file binlog.cc.

Here is the call graph for this function:

THD * Stage_manager::Mutex_queue::fetch_and_empty ( )

Fetch the entire queue for a stage.

This will fetch the entire queue in one go.

Definition at line 1453 of file binlog.cc.

Here is the caller graph for this function:

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.

Definition at line 1143 of file binlog.cc.

Here is the call graph for this function:

bool MYSQL_BIN_LOG::find_first_log_not_in_gtid_set ( char *  binlog_file_name,
const Gtid_set gtid_set,
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]errmsg,theerror message outputted, which is left untouched if the function returns false
Returns
false on success, true on error.

Definition at line 2723 of file binlog.cc.

Here is the call graph for this function:

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

Definition at line 3410 of file binlog.cc.

Here is the caller graph for this function:

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

Definition at line 3509 of file binlog.cc.

Here is the caller graph for this function:

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

Definition at line 1178 of file binlog.cc.

Here is the call graph for this function:

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

Definition at line 4920 of file binlog.cc.

Here is the caller graph for this function:

int gtid_empty_group_log_and_cleanup ( THD *  thd)

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.

Definition at line 1098 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool MYSQL_BIN_LOG::init_gtid_sets ( Gtid_set gtid_set,
Gtid_set lost_groups,
bool  verify_checksum,
bool  need_lock 
)

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.
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.
Returns
false on success, true on error.

Definition at line 2831 of file binlog.cc.

Here is the call graph for this function:

bool MYSQL_BIN_LOG::is_active ( const char *  log_file_name_arg)

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

Definition at line 4614 of file binlog.cc.

void MYSQL_BIN_LOG::make_log_name ( char *  buf,
const char *  log_ident 
)

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

Definition at line 4600 of file binlog.cc.

Here is the caller graph for this function:

int MYSQL_BIN_LOG::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

Definition at line 3202 of file binlog.cc.

Here is the caller graph for this function:

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!

Definition at line 5940 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2969 of file binlog.cc.

Here is the call graph for this function:

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

Open a single binary log file for reading.

Definition at line 1880 of file binlog.cc.

Here is the caller graph for this function:

int MYSQL_BIN_LOG::open_crash_safe_index_file ( )

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

Definition at line 3756 of file binlog.cc.

Here is the caller graph for this function:

void MYSQL_BIN_LOG::purge ( )

The method executes logs purging routine.

Return values
nonzero- error in rotating routine.

Definition at line 5247 of file binlog.cc.

Here is the caller graph for this function:

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

Definition at line 2022 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2051 of file binlog.cc.

Here is the caller graph for this function:

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

Definition at line 6896 of file binlog.cc.

Here is the caller graph for this function:

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

Definition at line 3568 of file binlog.cc.

Here is the call graph for this function:

int MYSQL_BIN_LOG::rollback ( THD *  thd,
bool  all 
)

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

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

Definition at line 1520 of file binlog.cc.

Here is the call graph for this function:

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.

Definition at line 5200 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

int MYSQL_BIN_LOG::rotate_and_purge ( 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.

Definition at line 5278 of file binlog.cc.

Here is the call graph for this function:

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

Definition at line 3729 of file binlog.cc.

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.

Definition at line 2005 of file binlog.cc.

Here is the caller graph for this function:

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.

Definition at line 1940 of file binlog.cc.

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.

Definition at line 1991 of file binlog.cc.

Here is the caller graph for this function:

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.

Definition at line 1924 of file binlog.cc.

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.

Definition at line 1233 of file binlog.cc.

Here is the call graph for this function:

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.

Definition at line 5811 of file binlog.cc.

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.

Definition at line 5775 of file binlog.cc.

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.

Definition at line 5680 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool MYSQL_BIN_LOG::write_event ( Log_event event_info)

Write an event to the binary log.

Definition at line 5023 of file binlog.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 5646 of file binlog.cc.

Here is the caller graph for this function:

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

Definition at line 5599 of file binlog.cc.

Here is the call graph for this function:

Variable Documentation

struct st_mysql_storage_engine binlog_storage_engine
Initial value:
{ MYSQL_HANDLERTON_INTERFACE_VERSION }

Definition at line 8773 of file binlog.cc.