MySQL 8.0.39
Source Code Documentation
log0buf.h File Reference

Redo log functions related to the log buffer. More...

#include "log0sys.h"
#include "log0types.h"

Go to the source code of this file.

Classes

struct  Log_handle
 Handle which is used for writes to the log buffer. More...
 

Functions

Log - writing to the log buffer.
Remarks
These functions are designed for mtr_commit(), and used only there (except log0log-t.cc).
void log_buffer_x_lock_enter (log_t &log)
 Acquires the log buffer x-lock. More...
 
void log_buffer_x_lock_exit (log_t &log)
 Releases the log buffer x-lock. More...
 
Log_handle log_buffer_reserve (log_t &log, size_t len)
 Reserves space in the redo log for following write operations. More...
 
lsn_t log_buffer_write (log_t &log, const byte *str, size_t str_len, lsn_t start_lsn)
 Writes data to the log buffer. More...
 
void log_buffer_write_completed (log_t &log, lsn_t start_lsn, lsn_t end_lsn)
 Adds a link start_lsn -> end_lsn to the log recent written buffer. More...
 
void log_buffer_set_first_record_group (log_t &log, lsn_t rec_group_end_lsn)
 Modifies header of log block in the log buffer, which contains a given lsn value, and sets offset to the first group of log records within the block. More...
 
void log_buffer_close (log_t &log, const Log_handle &handle)
 Adds a link start_lsn -> end_lsn to the log recent closed buffer. More...
 
Log - management of the log buffer.
void log_update_buf_limit (log_t &log)
 Updates limit used when writing to log buffer. More...
 
void log_update_buf_limit (log_t &log, lsn_t write_lsn)
 Updates limit used when writing to log buffer, according to provided write_lsn. More...
 
void log_buffer_flush_to_disk (log_t &log, bool sync=true)
 Write to the log file up to the last log entry. More...
 
void log_buffer_flush_to_disk (bool sync=true)
 Requests flush of the log buffer. More...
 
void log_buffer_sync_in_background ()
 Writes the log buffer to the log file. More...
 
void log_buffer_get_last_block (log_t &log, lsn_t &last_lsn, byte *last_block, uint32_t &block_len)
 Get last redo block from redo buffer and end LSN. More...
 
bool log_buffer_resize (log_t &log, size_t new_size)
 Changes size of the log buffer. More...
 
bool log_buffer_resize_low (log_t &log, size_t new_size, lsn_t end_lsn)
 Changes size of the log buffer. More...
 

Log - the recent written, the recent closed buffers.

#define log_closer_mutex_enter(log)   mutex_enter(&((log).closer_mutex))
 
#define log_closer_mutex_enter_nowait(log)    mutex_enter_nowait(&((log).closer_mutex))
 
#define log_closer_mutex_exit(log)   mutex_exit(&((log).closer_mutex))
 
lsn_t log_buffer_ready_for_write_lsn (const log_t &log)
 
lsn_t log_buffer_dirty_pages_added_up_to_lsn (const log_t &log)
 
lsn_t log_buffer_flush_order_lag (const log_t &log)
 
void log_advance_ready_for_write_lsn (log_t &log)
 Advances log.buf_ready_for_write_lsn using links in the recent written buffer. More...
 
void log_recent_written_empty_validate (const log_t &log, lsn_t begin, lsn_t end)
 Validates that all slots in log recent written buffer for lsn values in range between begin and end, are empty. More...
 
void log_recent_closed_empty_validate (const log_t &log, lsn_t begin, lsn_t end)
 Validates that all slots in log recent closed buffer for lsn values in range between begin and end, are empty. More...
 
void log_wait_for_space_in_log_recent_closed (log_t &log, lsn_t lsn)
 Waits until there is free space in the log recent closed buffer for any links start_lsn -> end_lsn, which start at provided start_lsn. More...
 

Detailed Description

Redo log functions related to the log buffer.

Macro Definition Documentation

◆ log_closer_mutex_enter

#define log_closer_mutex_enter (   log)    mutex_enter(&((log).closer_mutex))

◆ log_closer_mutex_enter_nowait

#define log_closer_mutex_enter_nowait (   log)     mutex_enter_nowait(&((log).closer_mutex))

◆ log_closer_mutex_exit

#define log_closer_mutex_exit (   log)    mutex_exit(&((log).closer_mutex))

Function Documentation

◆ log_advance_ready_for_write_lsn()

void log_advance_ready_for_write_lsn ( log_t log)

Advances log.buf_ready_for_write_lsn using links in the recent written buffer.

It's used by the log writer thread only.

Parameters
[in]logredo log

◆ log_buffer_close()

void log_buffer_close ( log_t log,
const Log_handle handle 
)

Adds a link start_lsn -> end_lsn to the log recent closed buffer.

This is called after all dirty pages related to [start_lsn, end_lsn) have been added to corresponding flush lists. For detailed explanation -

See also
log0write.cc.
Parameters
[in,out]logredo log
[in]handlehandle for the reservation of space

◆ log_buffer_dirty_pages_added_up_to_lsn()

lsn_t log_buffer_dirty_pages_added_up_to_lsn ( const log_t log)
inline
Returns
lsn up to which all dirty pages have been added to flush list

◆ log_buffer_flush_order_lag()

lsn_t log_buffer_flush_order_lag ( const log_t log)
inline
Returns
capacity of the recent_closed, or 0 if !log_use_threads()

◆ log_buffer_flush_to_disk() [1/2]

void log_buffer_flush_to_disk ( bool  sync = true)

Requests flush of the log buffer.

Parameters
[in]synctrue: wait until the flush is done

◆ log_buffer_flush_to_disk() [2/2]

void log_buffer_flush_to_disk ( log_t log,
bool  sync = true 
)

Write to the log file up to the last log entry.

Parameters
[in,out]logredo log
[in]syncwhether we want the written log also to be flushed to disk.

◆ log_buffer_get_last_block()

void log_buffer_get_last_block ( log_t log,
lsn_t last_lsn,
byte last_block,
uint32_t &  block_len 
)

Get last redo block from redo buffer and end LSN.

Note that it takes x-lock on the log buffer for a short period. Out values are always set, even when provided last_block is nullptr.

Parameters
[in,out]logredo log
[out]last_lsnend lsn of last mtr
[out]last_blocklast redo block
[in,out]block_lenlength in bytes

◆ log_buffer_ready_for_write_lsn()

lsn_t log_buffer_ready_for_write_lsn ( const log_t log)
inline
Returns
lsn up to which all writes to log buffer have been finished

◆ log_buffer_reserve()

Log_handle log_buffer_reserve ( log_t log,
size_t  len 
)

Reserves space in the redo log for following write operations.

Space is reserved for a given number of data bytes. Additionally bytes for required headers and footers of log blocks are reserved.

After the space is reserved, range of lsn values from a start_lsn to an end_lsn is assigned. The log writer thread cannot proceed further than to the start_lsn, until a link start_lsn -> end_lsn has been added to the log recent written buffer.

NOTE that the link is added after data is written to the reserved space in the log buffer. It is very critical to do all these steps as fast as possible, because very likely the log writer thread is waiting for the link.

Parameters
[in,out]logredo log
[in]lennumber of data bytes to reserve for write
Returns
handle that represents the reservation

◆ log_buffer_resize()

bool log_buffer_resize ( log_t log,
size_t  new_size 
)

Changes size of the log buffer.

This is a thread-safe version. It is used by SET GLOBAL innodb_log_buffer_size = X.

Parameters
[in,out]logredo log
[in]new_sizerequested new size
Returns
true iff succeeded in resize

◆ log_buffer_resize_low()

bool log_buffer_resize_low ( log_t log,
size_t  new_size,
lsn_t  end_lsn 
)

Changes size of the log buffer.

This is a non-thread-safe version which might be invoked only when there are no concurrent possible writes to the log buffer. It is used in log_buffer_reserve() when a requested size to reserve is larger than size of the log buffer.

Parameters
[in,out]logredo log
[in]new_sizerequested new size
[in]end_lsnmaximum lsn written to log buffer
Returns
true iff succeeded in resize

◆ log_buffer_set_first_record_group()

void log_buffer_set_first_record_group ( log_t log,
lsn_t  rec_group_end_lsn 
)

Modifies header of log block in the log buffer, which contains a given lsn value, and sets offset to the first group of log records within the block.

This is used by mtr after writing a log record group which ends at lsn belonging to different log block than lsn at which the group was started. When write was finished at the last data byte of log block, it is considered ended in the next log block, because the next data byte belongs to that block.

During recovery, when recovery is started in the middle of some group of log records, it first looks for the beginning of the next group.

Parameters
[in,out]logredo log
[in]rec_group_end_lsnlsn at which the first log record group starts within the block containing this lsn value

◆ log_buffer_sync_in_background()

void log_buffer_sync_in_background ( )

Writes the log buffer to the log file.

It is intended to be called from background master thread periodically. If the log writer threads are active, this function writes nothing.

◆ log_buffer_write()

lsn_t log_buffer_write ( log_t log,
const byte str,
size_t  str_len,
lsn_t  start_lsn 
)

Writes data to the log buffer.

The space in the redo log has to be reserved before calling to this function and lsn pointing to inside the reserved range of lsn values has to be provided.

The write does not have to cover the whole reserved space, but may not overflow it. If it does not cover, then returned value should be used to start the next write operation. Note that finally we must use exactly all the reserved space.

Parameters
[in,out]logredo log
[in]strmemory to write data from
[in]str_lennumber of bytes to write
[in]start_lsnlsn to start writing at (the reserved space)
Returns
end_lsn after writing the data (in the reserved space), could be used to start the next write operation if there is still free space in the reserved space

◆ log_buffer_write_completed()

void log_buffer_write_completed ( log_t log,
lsn_t  start_lsn,
lsn_t  end_lsn 
)

Adds a link start_lsn -> end_lsn to the log recent written buffer.

This function must be called after the data has been written to the fragment of log buffer represented by range [start_lsn, end_lsn). After the link is added, the log writer may write the data to disk.

NOTE that still dirty pages for the [start_lsn, end_lsn) are not added to flush lists when this function is called.

Parameters
[in,out]logredo log
[in]start_lsnstart_lsn of the link to add
[in]end_lsnend_lsn of the link to add

◆ log_buffer_x_lock_enter()

void log_buffer_x_lock_enter ( log_t log)

Acquires the log buffer x-lock.

Parameters
[in,out]logredo log

◆ log_buffer_x_lock_exit()

void log_buffer_x_lock_exit ( log_t log)

Releases the log buffer x-lock.

Parameters
[in,out]logredo log

◆ log_recent_closed_empty_validate()

void log_recent_closed_empty_validate ( const log_t log,
lsn_t  begin,
lsn_t  end 
)

Validates that all slots in log recent closed buffer for lsn values in range between begin and end, are empty.

Used during tests, crashes the program if validation does not pass.

Parameters
[in]logredo log which buffer is validated
[in]beginvalidation start (inclusive)
[in]endvalidation end (exclusive)

◆ log_recent_written_empty_validate()

void log_recent_written_empty_validate ( const log_t log,
lsn_t  begin,
lsn_t  end 
)

Validates that all slots in log recent written buffer for lsn values in range between begin and end, are empty.

Used during tests, crashes the program if validation does not pass.

Parameters
[in]logredo log which buffer is validated
[in]beginvalidation start (inclusive)
[in]endvalidation end (exclusive)

◆ log_update_buf_limit() [1/2]

void log_update_buf_limit ( log_t log)

Updates limit used when writing to log buffer.

Note that the log buffer may have space for log records for which we still do not have space in log files (for larger lsn values).

Parameters
[in,out]logredo log

◆ log_update_buf_limit() [2/2]

void log_update_buf_limit ( log_t log,
lsn_t  write_lsn 
)

Updates limit used when writing to log buffer, according to provided write_lsn.

It must be <= log.write_lsn.load() to protect from log buffer overwrites.

Parameters
[in,out]logredo log
[in]write_lsnvalue <= log.write_lsn.load()

◆ log_wait_for_space_in_log_recent_closed()

void log_wait_for_space_in_log_recent_closed ( log_t log,
lsn_t  lsn 
)

Waits until there is free space in the log recent closed buffer for any links start_lsn -> end_lsn, which start at provided start_lsn.

It does not add any link.

This is called just before dirty pages for [start_lsn, end_lsn) are added to flush lists. That's because we need to guarantee, that the delay until dirty page is added to flush list is limited. For detailed explanation -

See also
log0write.cc.
Parameters
[in,out]logredo log
[in]lsnlsn on which we wait (for any link: lsn -> x)