InnoDB Plugin  1.0
Data Structures | Macros | Typedefs | Functions | Variables
log0log.h File Reference
#include "univ.i"
#include "ut0byte.h"
#include "ut0lst.h"
#include "sync0sync.h"
#include "sync0rw.h"
#include "log0log.ic"
Include dependency graph for log0log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  log_group_t
struct  log_t

Macros

#define LSN_MAX   IB_UINT64_MAX
#define LSN_PF   UINT64PF
#define LOG_MAX_N_GROUPS   32
#define LOG_FLUSH   7652559
#define LOG_CHECKPOINT   78656949
#define LOG_RECOVER   98887331
#define LOG_START_LSN   ((lsn_t) (16 * OS_FILE_LOG_BLOCK_SIZE))
#define LOG_BUFFER_SIZE   (srv_log_buffer_size * UNIV_PAGE_SIZE)
#define LOG_ARCHIVE_BUF_SIZE   (srv_log_buffer_size * UNIV_PAGE_SIZE / 4)
#define LOG_BLOCK_HDR_NO
#define LOG_BLOCK_FLUSH_BIT_MASK   0x80000000UL
#define LOG_BLOCK_HDR_DATA_LEN
#define LOG_BLOCK_FIRST_REC_GROUP
#define LOG_BLOCK_CHECKPOINT_NO
#define LOG_BLOCK_HDR_SIZE
#define LOG_BLOCK_CHECKSUM
#define LOG_BLOCK_TRL_SIZE   4 /* trailer size in bytes */
#define LOG_CHECKPOINT_NO   0
#define LOG_CHECKPOINT_LSN   8
#define LOG_CHECKPOINT_OFFSET_LOW32   16
#define LOG_CHECKPOINT_LOG_BUF_SIZE   20
#define LOG_CHECKPOINT_ARCHIVED_LSN   24
#define LOG_CHECKPOINT_GROUP_ARRAY   32
#define LOG_CHECKPOINT_ARCHIVED_FILE_NO   0
#define LOG_CHECKPOINT_ARCHIVED_OFFSET   4
#define LOG_CHECKPOINT_ARRAY_END
#define LOG_CHECKPOINT_CHECKSUM_1   LOG_CHECKPOINT_ARRAY_END
#define LOG_CHECKPOINT_CHECKSUM_2   (4 + LOG_CHECKPOINT_ARRAY_END)
#define LOG_CHECKPOINT_OFFSET_HIGH32   (16 + LOG_CHECKPOINT_ARRAY_END)
#define LOG_CHECKPOINT_SIZE   (20 + LOG_CHECKPOINT_ARRAY_END)
#define LOG_GROUP_ID   0 /* log group number */
#define LOG_FILE_START_LSN
#define LOG_FILE_NO
#define LOG_FILE_WAS_CREATED_BY_HOT_BACKUP   16
#define LOG_FILE_ARCH_COMPLETED   OS_FILE_LOG_BLOCK_SIZE
#define LOG_FILE_END_LSN   (OS_FILE_LOG_BLOCK_SIZE + 4)
#define LOG_CHECKPOINT_1   OS_FILE_LOG_BLOCK_SIZE
#define LOG_CHECKPOINT_2   (3 * OS_FILE_LOG_BLOCK_SIZE)
#define LOG_FILE_HDR_SIZE   (4 * OS_FILE_LOG_BLOCK_SIZE)
#define LOG_GROUP_OK   301
#define LOG_GROUP_CORRUPTED   302
#define log_flush_order_mutex_own()   mutex_own(&log_sys->log_flush_order_mutex)
#define log_flush_order_mutex_enter()
#define log_flush_order_mutex_exit()
#define LOG_NO_WAIT   91
#define LOG_WAIT_ONE_GROUP   92
#define LOG_WAIT_ALL_GROUPS   93

Typedefs

typedef ib_uint64_t lsn_t

Functions

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_INLINE lsn_t log_reserve_and_write_fast (const void *str, ulint len, lsn_t *start_lsn)
UNIV_INLINE void log_release (void)
UNIV_INLINE void log_free_check (void)
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_INLINE lsn_t log_get_lsn (void)
UNIV_INLINE lsn_t log_get_capacity (void)
UNIV_INLINE lsn_t log_get_max_modified_age_async (void)
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)
UNIV_INTERN void log_io_complete (log_group_t *group)
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 ibool log_checkpoint (ibool sync, ibool write_always)
UNIV_INTERN void log_make_checkpoint_at (lsn_t lsn, ibool write_always)
UNIV_INTERN void logs_empty_and_mark_files_at_shutdown (void)
UNIV_INTERN void log_group_read_checkpoint_info (log_group_t *group, ulint field)
UNIV_INTERN void log_checkpoint_get_nth_group_info (const byte *buf, ulint n, ulint *file_no, ulint *offset)
UNIV_INTERN void log_groups_write_checkpoint_info (void)
UNIV_INTERN ibool log_archive_do (ibool sync, ulint *n_bytes)
UNIV_INTERN ulint log_archive_stop (void)
UNIV_INTERN ulint log_archive_start (void)
UNIV_INTERN ulint log_archive_noarchivelog (void)
UNIV_INTERN ulint log_archive_archivelog (void)
UNIV_INTERN void log_archived_file_name_gen (char *buf, ulint id, ulint file_no)
UNIV_INTERN void log_check_margins (void)
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_group_write_buf (log_group_t *group, byte *buf, ulint len, lsn_t start_lsn, ulint new_data_offset)
UNIV_INTERN void log_group_set_fields (log_group_t *group, lsn_t lsn)
UNIV_INTERN lsn_t log_group_get_capacity (const log_group_t *group)
UNIV_INLINE ibool log_block_get_flush_bit (const byte *log_block)
UNIV_INLINE ulint log_block_get_hdr_no (const byte *log_block)
UNIV_INLINE ulint log_block_get_data_len (const byte *log_block)
UNIV_INLINE void log_block_set_data_len (byte *log_block, ulint len)
UNIV_INLINE ulint log_block_calc_checksum (const byte *block)
UNIV_INLINE ulint log_block_get_checksum (const byte *log_block)
UNIV_INLINE void log_block_set_checksum (byte *log_block, ulint checksum)
UNIV_INLINE ulint log_block_get_first_rec_group (const byte *log_block)
UNIV_INLINE void log_block_set_first_rec_group (byte *log_block, ulint offset)
UNIV_INLINE ulint log_block_get_checkpoint_no (const byte *log_block)
UNIV_INLINE void log_block_init (byte *log_block, lsn_t lsn)
UNIV_INLINE void log_block_init_in_old_format (byte *log_block, lsn_t lsn)
UNIV_INLINE ulint log_block_convert_lsn_to_no (lsn_t lsn)
UNIV_INTERN void log_print (FILE *file)
UNIV_INTERN ibool log_peek_lsn (lsn_t *lsn)
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

ibool log_do_write
ibool log_debug_writes
log_tlog_sys

Detailed Description

Database log

Created 12/9/1995 Heikki Tuuri

Macro Definition Documentation

#define LOG_BLOCK_CHECKPOINT_NO
Value:
8 /* 4 lower bytes of the value of
log_sys->next_checkpoint_no when the
log block was last written to: if the
block has not yet been written full,
this value is only updated before a
log buffer flush */
#define LOG_BLOCK_CHECKSUM
Value:
4 /* 4 byte checksum of the log block
contents; in InnoDB versions
< 3.23.52 this did not contain the
checksum but the same value as
.._HDR_NO */
#define LOG_BLOCK_FIRST_REC_GROUP
Value:
6 /* offset of the first start of an
mtr log record group in this log block,
0 if none; if the value is the same
as LOG_BLOCK_HDR_DATA_LEN, it means
that the first rec group has not yet
been catenated to this log block, but
if it will, it will start at this
offset; an archive recovery can
start parsing the log records starting
from this offset in this log block,
if value not 0 */
#define LOG_BLOCK_HDR_DATA_LEN
Value:
4 /* number of bytes of log written to
this block */
#define LOG_BLOCK_HDR_NO
Value:
0 /* block number which must be > 0 and
is allowed to wrap around at 2G; the
highest bit is set to 1 if this is the
first log block in a log flush write
segment */
#define LOG_BLOCK_HDR_SIZE
Value:
12 /* size of the log block header in
bytes */
#define LOG_CHECKPOINT_ARRAY_END
Value:
(LOG_CHECKPOINT_GROUP_ARRAY\
#define LOG_FILE_NO
Value:
12 /* 4-byte archived log file number;
this field is only defined in an
archived log file */
#define LOG_FILE_START_LSN
Value:
4 /* lsn of the start of data in this
log file */
#define log_flush_order_mutex_enter ( )
Value:
do { \
mutex_enter(&log_sys->log_flush_order_mutex); \
} while (0)

Acquire the flush order mutex.

#define log_flush_order_mutex_exit ( )
Value:
do { \
mutex_exit(&log_sys->log_flush_order_mutex); \
} while (0)

Release the flush order mutex.

#define log_flush_order_mutex_own ( )    mutex_own(&log_sys->log_flush_order_mutex)

Test if flush order mutex is owned.

#define LOG_MAX_N_GROUPS   32

Maximum number of log groups in log_group_t::checkpoint_buf

#define LOG_NO_WAIT   91

Wait modes for log_write_up_to

Function Documentation

UNIV_INTERN ulint log_archive_archivelog ( void  )

Start archiving the log so that a gap may occur in the archived log files.

Returns
DB_SUCCESS or DB_ERROR
UNIV_INTERN ibool log_archive_do ( ibool  sync,
ulint *  n_bytes 
)

Starts an archiving operation.

Returns
TRUE if succeed, FALSE if an archiving operation was already running out: archive log buffer size, 0 if nothing to archive
Parameters
syncin: TRUE if synchronous operation is desired
UNIV_INTERN ulint log_archive_noarchivelog ( void  )

Stop archiving the log so that a gap may occur in the archived log files.

Returns
DB_SUCCESS or DB_ERROR
UNIV_INTERN ulint log_archive_start ( void  )

Starts again archiving which has been stopped.

Returns
DB_SUCCESS or DB_ERROR
UNIV_INTERN ulint log_archive_stop ( void  )

Writes the log contents to the archive up to the lsn when this function was called, and stops the archiving. When archiving is started again, the archived log file numbers start from a number one higher, so that the archiving will not write again to the archived log files which exist when this function returns.

Returns
DB_SUCCESS or DB_ERROR
UNIV_INTERN void log_archived_file_name_gen ( char *  buf,
ulint  id,
ulint  file_no 
)

Generates an archived log file name. in: file number

Parameters
bufin: buffer where to write
idin: group id
UNIV_INLINE ulint log_block_calc_checksum ( const byte *  block)

Calculates the checksum for a log block.

Returns
checksum in: log block

Calculates the checksum for a log block.

Returns
checksum
Parameters
blockin: log block
UNIV_INLINE ulint log_block_convert_lsn_to_no ( lsn_t  lsn)

Converts a lsn to a log block number.

Returns
log block number, it is > 0 and <= 1G in: lsn of a byte within the block

Converts a lsn to a log block number.

Returns
log block number, it is > 0 and <= 1G
Parameters
lsnin: lsn of a byte within the block
UNIV_INLINE ulint log_block_get_checkpoint_no ( const byte *  log_block)

Gets a log block checkpoint number field (4 lowest bytes).

Returns
checkpoint no (4 lowest bytes) in: log block

Gets a log block checkpoint number field (4 lowest bytes).

Returns
checkpoint no (4 lowest bytes)
Parameters
log_blockin: log block
UNIV_INLINE ulint log_block_get_checksum ( const byte *  log_block)

Gets a log block checksum field value.

Returns
checksum in: log block

Gets a log block checksum field value.

Returns
checksum
Parameters
log_blockin: log block
UNIV_INLINE ulint log_block_get_data_len ( const byte *  log_block)

Gets a log block data length.

Returns
log block data length measured as a byte offset from the block start in: log block

Gets a log block data length.

Returns
log block data length measured as a byte offset from the block start
Parameters
log_blockin: log block
UNIV_INLINE ulint log_block_get_first_rec_group ( const byte *  log_block)

Gets a log block first mtr log record group offset.

Returns
first mtr log record group byte offset from the block start, 0 if none in: log block

Gets a log block first mtr log record group offset.

Returns
first mtr log record group byte offset from the block start, 0 if none
Parameters
log_blockin: log block
UNIV_INLINE ibool log_block_get_flush_bit ( const byte *  log_block)

Gets a log block flush bit.

Returns
TRUE if this block was the first to be written in a log flush in: log block

Gets a log block flush bit.

Returns
TRUE if this block was the first to be written in a log flush
Parameters
log_blockin: log block
UNIV_INLINE ulint log_block_get_hdr_no ( const byte *  log_block)

Gets a log block number stored in the header.

Returns
log block number stored in the block header in: log block

Gets a log block number stored in the header.

Returns
log block number stored in the block header
Parameters
log_blockin: log block
UNIV_INLINE void log_block_init ( byte *  log_block,
lsn_t  lsn 
)

Initializes a log block in the log buffer. in: lsn within the log block

Initializes a log block in the log buffer.

Parameters
log_blockin: pointer to the log buffer
lsnin: lsn within the log block
UNIV_INLINE void log_block_init_in_old_format ( byte *  log_block,
lsn_t  lsn 
)

Initializes a log block in the log buffer in the old, < 3.23.52 format, where there was no checksum yet. in: lsn within the log block

Initializes a log block in the log buffer in the old format, where there was no checksum yet.

Parameters
log_blockin: pointer to the log buffer
lsnin: lsn within the log block
UNIV_INLINE void log_block_set_checksum ( byte *  log_block,
ulint  checksum 
)

Sets a log block checksum field value. in: checksum

Sets a log block checksum field value.

Parameters
log_blockin/out: log block
checksumin: checksum
UNIV_INLINE void log_block_set_data_len ( byte *  log_block,
ulint  len 
)

Sets the log block data length. in: data length

Sets the log block data length.

Parameters
log_blockin/out: log block
lenin: data length
UNIV_INLINE void log_block_set_first_rec_group ( byte *  log_block,
ulint  offset 
)

Sets the log block first mtr log record group offset. in: offset, 0 if none

Sets the log block first mtr log record group offset.

Parameters
log_blockin/out: log block
offsetin: offset, 0 if none
UNIV_INTERN void log_buffer_flush_to_disk ( void  )

Does a syncronous flush of the log buffer to disk.

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.

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 in: log file size (including the header)
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
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!

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 in: 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
Parameters
syncin: TRUE if synchronous operation is desired
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. out: archived file offset

Parameters
bufin: buffer containing checkpoint info
nin: nth slot
file_noout: archived file number
UNIV_INTERN lsn_t log_close ( void  )

Closes the log.

Returns
lsn
UNIV_INLINE void log_free_check ( void  )

Checks if there is need for a log buffer flush or a new checkpoint, and does this if yes. Any database operation should call this when it has modified more than about 4 pages. NOTE that this function may only be called when the OS thread owns no synchronization objects except the dictionary mutex.

UNIV_INLINE lsn_t log_get_lsn ( void  )

Gets the current lsn.

Returns
current lsn
UNIV_INTERN void log_group_close_all ( void  )

Closes all log groups.

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 in: log group
UNIV_INTERN void log_group_init ( ulint  id,
ulint  n_files,
lsn_t  file_size,
ulint  space_id,
ulint  archive_space_id 
)

Inits a log group to the log system. 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

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
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. in: LOG_CHECKPOINT_1 or LOG_CHECKPOINT_2

Parameters
groupin: log group
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. in: read area end

Parameters
typein: LOG_ARCHIVE or LOG_RECOVER
bufin: buffer where to read
groupin: log group
start_lsnin: read area start
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. in: lsn for which the values should be set

Parameters
groupin/out: group
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. in: start offset of new data in buf: this parameter is used to decide if we have to write a new log file header

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
UNIV_INTERN void log_groups_write_checkpoint_info ( void  )

Writes checkpoint info to groups.

UNIV_INTERN void log_init ( void  )

Initializes the log.

UNIV_INTERN void log_io_complete ( log_group_t group)

Completes an i/o to a log file. in: log group

UNIV_INTERN void log_make_checkpoint_at ( lsn_t  lsn,
ibool  write_always 
)

Makes a checkpoint at a given lsn or later. in: 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

Parameters
lsnin: make a checkpoint at this or a later lsn, if LSN_MAX, makes a checkpoint at the latest lsn
UNIV_INTERN void log_mem_free ( void  )

Free the log system data structures.

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 out: if returns TRUE, current lsn is here
UNIV_INTERN void log_print ( FILE *  file)

Prints info of the log. in: file where to print

UNIV_INTERN void log_refresh_stats ( void  )

Refreshes the statistics used to print per-second averages.

UNIV_INLINE void log_release ( void  )

Releases the log mutex.

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 in: length of data to be catenated
UNIV_INLINE lsn_t log_reserve_and_write_fast ( const void *  str,
ulint  len,
lsn_t *  start_lsn 
)

Writes to the log the string given. The log must be released with log_release.

Returns
end lsn of the log record, zero if did not succeed out: start lsn of the log record

Writes to the log the string given. The log must be released with log_release.

Returns
end lsn of the log record, zero if did not succeed
Parameters
strin: string
lenin: string length
start_lsnout: start lsn of the log record
UNIV_INTERN void log_shutdown ( void  )

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

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. in: string length

Parameters
strin: string
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. in: TRUE if we want the written log also to be flushed to disk

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

Variable Documentation

ibool log_debug_writes

Flag: enable debug output when writing to the log?

ibool log_do_write

Flag: write to log file?