MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
log0log.cc File Reference
#include "log0log.h"
#include "mem0mem.h"
#include "buf0buf.h"
#include "buf0flu.h"
#include "srv0srv.h"
#include "log0recv.h"
#include "fil0fil.h"
#include "dict0boot.h"
#include "srv0start.h"
#include "trx0sys.h"
#include "trx0trx.h"
#include "srv0mon.h"
Include dependency graph for log0log.cc:

Go to the source code of this file.

Macros

#define LOG_BUF_WRITE_MARGIN   (4 * OS_FILE_LOG_BLOCK_SIZE)
#define LOG_BUF_FLUSH_RATIO   2
#define LOG_BUF_FLUSH_MARGIN   (LOG_BUF_WRITE_MARGIN + 4 * UNIV_PAGE_SIZE)
#define LOG_CHECKPOINT_FREE_PER_THREAD   (4 * UNIV_PAGE_SIZE)
#define LOG_CHECKPOINT_EXTRA_FREE   (8 * UNIV_PAGE_SIZE)
#define LOG_POOL_CHECKPOINT_RATIO_ASYNC   32
#define LOG_POOL_PREFLUSH_RATIO_SYNC   16
#define LOG_POOL_PREFLUSH_RATIO_ASYNC   8
#define LOG_ARCHIVE_EXTRA_MARGIN   (4 * UNIV_PAGE_SIZE)
#define LOG_ARCHIVE_RATIO_ASYNC   16
#define LOG_UNLOCK_NONE_FLUSHED_LOCK   1
#define LOG_UNLOCK_FLUSH_LOCK   2
#define LOG_ARCHIVE_READ   1
#define LOG_ARCHIVE_WRITE   2

Functions

UNIV_INTERN lsn_t log_reserve_and_open (ulint len)
UNIV_INTERN void log_write_low (byte *str, ulint str_len)
UNIV_INTERN lsn_t log_close (void)
UNIV_INTERN lsn_t log_group_get_capacity (const log_group_t *group)
UNIV_INLINE lsn_t log_group_calc_size_offset (lsn_t offset, const log_group_t *group)
UNIV_INLINE lsn_t log_group_calc_real_offset (lsn_t offset, const log_group_t *group)
UNIV_INTERN ulint log_calc_where_lsn_is (ib_int64_t *log_file_offset, ib_uint64_t first_header_lsn, ib_uint64_t lsn, ulint n_log_files, ib_int64_t log_file_size)
UNIV_INTERN void log_group_set_fields (log_group_t *group, lsn_t lsn)
UNIV_INTERN void log_init (void)
UNIV_INTERN void log_group_init (ulint id, ulint n_files, lsn_t file_size, ulint space_id, ulint archive_space_id __attribute__((unused)))
UNIV_INLINE void log_flush_do_unlocks (ulint code)
UNIV_INLINE ulint log_group_check_flush_completion (log_group_t *group)
UNIV_INTERN void log_io_complete (log_group_t *group)
UNIV_INTERN void log_group_write_buf (log_group_t *group, byte *buf, ulint len, lsn_t start_lsn, ulint new_data_offset)
UNIV_INTERN void log_write_up_to (lsn_t lsn, ulint wait, ibool flush_to_disk)
UNIV_INTERN void log_buffer_flush_to_disk (void)
UNIV_INTERN void log_buffer_sync_in_background (ibool flush)
UNIV_INTERN void log_checkpoint_get_nth_group_info (const byte *buf, ulint n, ulint *file_no, ulint *offset)
UNIV_INTERN void log_group_read_checkpoint_info (log_group_t *group, ulint field)
UNIV_INTERN void log_groups_write_checkpoint_info (void)
UNIV_INTERN ibool log_checkpoint (ibool sync, ibool write_always)
UNIV_INTERN void log_make_checkpoint_at (lsn_t lsn, ibool write_always)
UNIV_INTERN void log_group_read_log_seg (ulint type, byte *buf, log_group_t *group, lsn_t start_lsn, lsn_t end_lsn)
UNIV_INTERN void log_check_margins (void)
UNIV_INTERN void logs_empty_and_mark_files_at_shutdown (void)
UNIV_INTERN ibool log_peek_lsn (lsn_t *lsn)
UNIV_INTERN void log_print (FILE *file)
UNIV_INTERN void log_refresh_stats (void)
UNIV_INTERN void log_group_close_all (void)
UNIV_INTERN void log_shutdown (void)
UNIV_INTERN void log_mem_free (void)

Variables

UNIV_INTERN log_tlog_sys = NULL
UNIV_INTERN ibool log_has_printed_chkp_warning = FALSE
UNIV_INTERN time_t log_last_warning_time

Detailed Description

Database log

Created 12/9/1995 Heikki Tuuri

Definition in file log0log.cc.

Function Documentation

UNIV_INTERN void log_buffer_flush_to_disk ( void  )

Does a syncronous flush of the log buffer to disk.

Definition at line 1549 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void log_buffer_sync_in_background ( ibool  flush)

This functions writes the log buffer to the log file and if 'flush' is set it forces a flush of the log file as well. This is meant to be called from background master thread only as it does not wait for the write (+ possible flush) to finish.

Parameters
flushin: flush the logs to disk

Definition at line 1571 of file log0log.cc.

Here is the call graph for this function:

UNIV_INTERN ulint log_calc_where_lsn_is ( ib_int64_t *  log_file_offset,
ib_uint64_t  first_header_lsn,
ib_uint64_t  lsn,
ulint  n_log_files,
ib_int64_t  log_file_size 
)

Calculates where in log files we find a specified lsn.

Returns
log file number
Parameters
log_file_offsetout: offset in that file (including the header)
first_header_lsnin: first log file start lsn
lsnin: lsn whose position to determine
n_log_filesin: total number of log files
log_file_sizein: log file size (including the header)

Definition at line 567 of file log0log.cc.

UNIV_INTERN void log_check_margins ( void  )

Checks that there is enough free space in the log to start a new query step. Flushes the log buffer or makes a new checkpoint if necessary. NOTE: this function may only be called if the calling thread owns no synchronization objects!

Definition at line 3054 of file log0log.cc.

UNIV_INTERN ibool log_checkpoint ( ibool  sync,
ibool  write_always 
)

Makes a checkpoint. Note that this function does not flush dirty blocks from the buffer pool: it only checks what is lsn of the oldest modification in the pool, and writes information about the lsn in log files. Use log_make_checkpoint_at to flush also the pool.

Returns
TRUE if success, FALSE if a checkpoint write was already running
Parameters
syncin: TRUE if synchronous operation is desired
write_alwaysin: the function normally checks if the the new checkpoint would have a greater lsn than the previous one: if not, then no physical write is done; by setting this parameter TRUE, a physical write will always be made to log files

Definition at line 1966 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void log_checkpoint_get_nth_group_info ( const byte *  buf,
ulint  n,
ulint *  file_no,
ulint *  offset 
)

Gets info from a checkpoint about a log group.

Parameters
bufin: buffer containing checkpoint info
nin: nth slot
file_noout: archived file number
offsetout: archived file offset

Definition at line 1726 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN lsn_t log_close ( void  )

Closes the log.

Returns
lsn

Definition at line 338 of file log0log.cc.

Here is the call graph for this function:

UNIV_INLINE void log_flush_do_unlocks ( ulint  code)

Does the unlockings needed in flush i/o completion.

Parameters
codein: any ORed combination of LOG_UNLOCK_FLUSH_LOCK and LOG_UNLOCK_NONE_FLUSHED_LOCK

Definition at line 946 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE lsn_t log_group_calc_real_offset ( lsn_t  offset,
const log_group_t group 
)

Calculates the offset within a log group, when the log file headers are included.

Returns
real offset (>= offset)
Parameters
offsetin: size offset within the log group
groupin: log group

Definition at line 499 of file log0log.cc.

UNIV_INLINE lsn_t log_group_calc_size_offset ( lsn_t  offset,
const log_group_t group 
)

Calculates the offset within a log group, when the log file headers are not included.

Returns
size offset (<= offset)
Parameters
offsetin: real offset within the log group
groupin: log group

Definition at line 482 of file log0log.cc.

UNIV_INLINE ulint log_group_check_flush_completion ( log_group_t group)

Checks if a flush is completed for a log group and does the completion routine if yes.

Returns
LOG_UNLOCK_NONE_FLUSHED_LOCK or 0
Parameters
groupin: log group

Definition at line 979 of file log0log.cc.

Here is the caller graph for this function:

UNIV_INTERN void log_group_close_all ( void  )

Closes all log groups.

Definition at line 3555 of file log0log.cc.

Here is the caller graph for this function:

UNIV_INTERN lsn_t log_group_get_capacity ( const log_group_t group)

Calculates the data capacity of a log group, when the log file headers are not included.

Returns
capacity in bytes
Parameters
groupin: log group

Definition at line 467 of file log0log.cc.

Here is the caller graph for this function:

UNIV_INTERN void log_group_init ( ulint  id,
ulint  n_files,
lsn_t  file_size,
ulint  space_id,
ulint archive_space_id   __attribute__(unused) 
)

Inits a log group to the log system.

Parameters
idin: group id
n_filesin: number of log files
file_sizein: log file size in bytes
space_idin: space id of the file space which contains the log files of this group
__attribute__in: space id of the file space which contains some archived log files for this group; currently, only for the first log group this is used

Definition at line 862 of file log0log.cc.

Here is the call graph for this function:

UNIV_INTERN void log_group_read_checkpoint_info ( log_group_t group,
ulint  field 
)

Reads a checkpoint info from a log group header to log_sys->checkpoint_buf.

Parameters
groupin: log group
fieldin: LOG_CHECKPOINT_1 or LOG_CHECKPOINT_2

Definition at line 1921 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void log_group_read_log_seg ( ulint  type,
byte *  buf,
log_group_t group,
lsn_t  start_lsn,
lsn_t  end_lsn 
)

Reads a specified log segment to a buffer.

Parameters
typein: LOG_ARCHIVE or LOG_RECOVER
bufin: buffer where to read
groupin: log group
start_lsnin: read area start
end_lsnin: read area end

Definition at line 2181 of file log0log.cc.

Here is the call graph for this function:

UNIV_INTERN void log_group_set_fields ( log_group_t group,
lsn_t  lsn 
)

Sets the field values in group to correspond to a given lsn. For this function to work, the values must already be correctly initialized to correspond to some lsn, for instance, a checkpoint lsn.

Parameters
groupin/out: group
lsnin: lsn for which the values should be set

Definition at line 609 of file log0log.cc.

Here is the caller graph for this function:

UNIV_INTERN void log_group_write_buf ( log_group_t group,
byte *  buf,
ulint  len,
lsn_t  start_lsn,
ulint  new_data_offset 
)

Writes a buffer to a log file group.

Parameters
groupin: log group
bufin: buffer
lenin: buffer len; must be divisible by OS_FILE_LOG_BLOCK_SIZE
start_lsnin: start lsn of the buffer; must be divisible by OS_FILE_LOG_BLOCK_SIZE
new_data_offsetin: start offset of new data in buf: this parameter is used to decide if we have to write a new log file header

Definition at line 1190 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void log_groups_write_checkpoint_info ( void  )

Writes checkpoint info to groups.

Definition at line 1941 of file log0log.cc.

Here is the caller graph for this function:

UNIV_INTERN void log_init ( void  )

Initializes the log.

Definition at line 732 of file log0log.cc.

Here is the call graph for this function:

UNIV_INTERN void log_io_complete ( log_group_t group)

Completes an i/o to a log file.

< We currently use synchronous writing of the logs and cannot end up here!

Parameters
groupin: log group or a dummy pointer

Definition at line 1054 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void log_make_checkpoint_at ( lsn_t  lsn,
ibool  write_always 
)

Makes a checkpoint at a given lsn or later.

Parameters
lsnin: make a checkpoint at this or a later lsn, if LSN_MAX, makes a checkpoint at the latest lsn
write_alwaysin: the function normally checks if the new checkpoint would have a greater lsn than the previous one: if not, then no physical write is done; by setting this parameter TRUE, a physical write will always be made to log files

Definition at line 2062 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void log_mem_free ( void  )

Free the log system data structures.

Definition at line 3611 of file log0log.cc.

Here is the call graph for this function:

UNIV_INTERN ibool log_peek_lsn ( lsn_t *  lsn)

Peeks the current lsn.

Returns
TRUE if success, FALSE if could not get the log system mutex
Parameters
lsnout: if returns TRUE, current lsn is here

Definition at line 3448 of file log0log.cc.

Here is the caller graph for this function:

UNIV_INTERN void log_print ( FILE *  file)

Prints info of the log.

Parameters
filein: file where to print

Definition at line 3467 of file log0log.cc.

Here is the caller graph for this function:

UNIV_INTERN void log_refresh_stats ( void  )

Refreshes the statistics used to print per-second averages.

Definition at line 3514 of file log0log.cc.

UNIV_INTERN lsn_t log_reserve_and_open ( ulint  len)

Opens the log for log_write_low. The log must be closed with log_close and released with log_release.

Returns
start lsn of the log record
Parameters
lenin: length of data to be catenated

Definition at line 192 of file log0log.cc.

Here is the call graph for this function:

UNIV_INTERN void log_shutdown ( void  )

Shutdown the log system but do not release all the memory.

Definition at line 3576 of file log0log.cc.

Here is the call graph for this function:

UNIV_INTERN void log_write_low ( byte *  str,
ulint  str_len 
)

Writes to the log the string given. It is assumed that the caller holds the log mutex.

Parameters
strin: string
str_lenin: string length

Definition at line 266 of file log0log.cc.

Here is the call graph for this function:

UNIV_INTERN void log_write_up_to ( lsn_t  lsn,
ulint  wait,
ibool  flush_to_disk 
)

This function is called, e.g., when a transaction wants to commit. It checks that the log has been written to the log file up to the last log entry written by the transaction. If there is a flush running, it waits and checks if the flush flushed enough. If not, starts a new flush.

< We assume here that we have only one log group!

Parameters
lsnin: log sequence number up to which the log should be written, LSN_MAX if not specified
waitin: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP, or LOG_WAIT_ALL_GROUPS
flush_to_diskin: TRUE if we want the written log also to be flushed to disk

Definition at line 1321 of file log0log.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void logs_empty_and_mark_files_at_shutdown ( void  )

Makes a checkpoint at the latest lsn and writes it to first page of each data file in the database, so that we know that the file spaces contain all modifications up to that lsn. This can only be called at database shutdown. This function also writes all log in log files to the log archive.

Definition at line 3086 of file log0log.cc.

Here is the call graph for this function: