![]() |
MySQL 9.0.0
Source Code Documentation
|
Redo log writing and flushing, including functions for: More...
#include <atomic>
#include <mysql/service_thd_wait.h>
#include <cstring>
#include "arch0arch.h"
#include "buf0types.h"
#include "log0buf.h"
#include "log0chkp.h"
#include "log0files_capacity.h"
#include "log0files_governor.h"
#include "log0log.h"
#include "log0meb.h"
#include "log0recv.h"
#include "log0sys.h"
#include "log0test.h"
#include "log0types.h"
#include "log0write.h"
#include "sql/sql_thd_internal_api.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "ut0byte.h"
Classes | |
struct | Log_thread_waiting |
Small utility which is used inside log threads when they have to wait for next interesting event to happen. More... | |
struct | Log_write_to_file_requests_monitor |
Namespaces | |
namespace | Log_files_write_impl |
Functions | |
static void | Log_files_write_impl::validate_buffer (const log_t &log, const byte *buffer, size_t buffer_size) |
static void | Log_files_write_impl::validate_start_lsn (const log_t &log, lsn_t start_lsn, size_t buffer_size) |
static bool | Log_files_write_impl::current_file_has_space (const log_t &log, os_offset_t offset, size_t size) |
static dberr_t | Log_files_write_impl::start_next_file (log_t &log, lsn_t start_lsn) |
static bool | Log_files_write_impl::write_ahead_enough (os_offset_t write_ahead_end, os_offset_t offset, size_t size) |
static bool | Log_files_write_impl::current_write_ahead_enough (const log_t &log, os_offset_t offset, size_t size) |
static os_offset_t | Log_files_write_impl::compute_next_write_ahead_end (os_offset_t real_offset) |
static size_t | Log_files_write_impl::compute_how_much_to_write (const log_t &log, os_offset_t real_offset, size_t buffer_size, bool &write_from_log_buffer) |
static void | Log_files_write_impl::prepare_full_blocks (const log_t &log, byte *buffer, size_t size, lsn_t start_lsn) |
static dberr_t | Log_files_write_impl::write_blocks (log_t &log, byte *write_buf, size_t write_size, os_offset_t real_offset) |
static void | Log_files_write_impl::notify_about_advanced_write_lsn (log_t &log, lsn_t old_write_lsn, lsn_t new_write_lsn) |
static void | Log_files_write_impl::copy_to_write_ahead_buffer (log_t &log, const byte *buffer, size_t &size, lsn_t start_lsn) |
static size_t | Log_files_write_impl::prepare_for_write_ahead (log_t &log, os_offset_t real_offset, size_t &write_size) |
static void | Log_files_write_impl::update_current_write_ahead (log_t &log, os_offset_t real_offset, size_t write_size) |
Log writer thread | |
static dberr_t | log_write_buffer (log_t &log, byte *buffer, size_t buffer_size, lsn_t start_lsn) |
Writes a given fragment of the log buffer to the current redo log file, unless the file is full, in which case a new file is produced and function exits (note, that the new log file's header is flushed in such case). More... | |
static void | log_writer_enter_extra_margin (log_t &log) |
Called when the redo log writer enters the extra_margin. More... | |
static void | log_writer_exit_extra_margin (log_t &log) |
Called when the redo log writer exits the extra_margin. More... | |
static lsn_t | log_writer_wait_on_checkpoint (log_t &log, lsn_t last_write_lsn, lsn_t next_write_lsn) |
static void | log_writer_wait_on_archiver (log_t &log, lsn_t next_write_lsn) |
static void | log_writer_write_failed (log_t &log, dberr_t err) |
Called after a write to the redo log file failed. More... | |
static void | log_writer_write_buffer (log_t &log, lsn_t next_write_lsn) |
Writes fragment of the log buffer, not further than up to provided lsn. More... | |
static bool | log_writer_extra_margin_check (log_t &log, lsn_t checkpoint_lsn, lsn_t next_write_lsn) |
void | log_writer_check_if_exited_extra_margin (log_t &log) |
Checks if the redo log writer exited extra margin. More... | |
static std::pair< lsn_t, bool > | log_writer_wait_on_checkpoint_optimistic (log_t &log, lsn_t last_write_lsn, lsn_t next_write_lsn) |
static lsn_t | log_writer_wait_on_checkpoint_pessimistic (log_t &log, lsn_t last_write_lsn, lsn_t next_write_lsn) |
static void | log_writer_wait_on_consumers (log_t &log, lsn_t next_write_lsn) |
static bool | log_writer_is_allowed_to_stop (log_t &log) |
void | log_writer (log_t *log_ptr) |
The log writer thread routine. More... | |
Log flusher thread | |
static void | log_flush_low (log_t &log) |
Executes a synchronous flush of the log files (doing fsyncs). More... | |
static void | log_flush_update_stats (log_t &log) |
uint64_t | log_total_flushes () |
Total number of redo log flushes (fsyncs) that have been started since the redo log system (log_sys) became initialized (. More... | |
uint64_t | log_pending_flushes () |
Number of currently pending redo log flushes (fsyncs in-progress). More... | |
void | log_flusher (log_t *log_ptr) |
The log flusher thread routine. More... | |
Waiting for redo log written or flushed up to lsn | |
static size_t | log_compute_wait_event_slot (lsn_t lsn, size_t events_n) |
Computes index of a slot (in array of "wait events"), which should be used when waiting until redo reached provided lsn. More... | |
static size_t | log_compute_write_event_slot (const log_t &log, lsn_t lsn) |
Computes index of a slot (in array of "wait events"), which should be used when waiting in log.write_events (for redo written up to lsn). More... | |
static size_t | log_compute_flush_event_slot (const log_t &log, lsn_t lsn) |
Computes index of a slot (in array of "wait events"), which should be used when waiting in log.flush_events (for redo flushed up to lsn). More... | |
static uint64_t | log_max_spins_when_waiting_in_user_thread (uint64_t min_non_zero_value) |
Computes maximum number of spin rounds which should be used when waiting in user thread (for written or flushed redo) or 0 if busy waiting should not be used at all. More... | |
static Wait_stats | log_wait_for_write (const log_t &log, lsn_t lsn, bool *interrupted) |
Waits until redo log is written up to provided lsn (or greater). More... | |
static Wait_stats | log_wait_for_flush (const log_t &log, lsn_t lsn, bool *interrupted) |
Waits until redo log is flushed up to provided lsn (or greater). More... | |
static Wait_stats | log_self_write_up_to (log_t &log, lsn_t end_lsn, bool flush_to_disk, bool *interrupted) |
Write the redo log up to a provided lsn by itself, if necessary. More... | |
Wait_stats | log_write_up_to (log_t &log, lsn_t end_lsn, bool flush_to_disk) |
Waits until the redo log is written up to a provided lsn. More... | |
Log write_notifier thread | |
void | log_write_notifier (log_t *log_ptr) |
The log write notifier thread routine. More... | |
Log flush_notifier thread | |
void | log_flush_notifier (log_t *log_ptr) |
The log flush notifier thread routine. More... | |
Redo log writing and flushing, including functions for:
Computes index of a slot (in array of "wait events"), which should be used when waiting in log.flush_events (for redo flushed up to lsn).
[in] | log | redo log |
[in] | lsn | lsn up to which waiting (for log.flushed_to_disk_lsn) |
|
inlinestatic |
Computes index of a slot (in array of "wait events"), which should be used when waiting until redo reached provided lsn.
[in] | lsn | lsn up to which waiting takes place |
[in] | events_n | size of the array (number of slots) |
Computes index of a slot (in array of "wait events"), which should be used when waiting in log.write_events (for redo written up to lsn).
[in] | log | redo log |
[in] | lsn | lsn up to which waiting (for log.write_lsn) |
|
static |
Executes a synchronous flush of the log files (doing fsyncs).
Advances log.flushed_to_disk_lsn and notifies log flush_notifier thread. Note: if only a single log block was flushed to disk, user threads waiting for lsns within the block are notified directly from here, and log flush_notifier thread is not notified! (optimization)
[in,out] | log | redo log |
void log_flush_notifier | ( | log_t * | log_ptr | ) |
The log flush notifier thread routine.
[in,out] | log_ptr | pointer to redo log |
|
static |
void log_flusher | ( | log_t * | log_ptr | ) |
The log flusher thread routine.
[in,out] | log_ptr | pointer to redo log |
|
inlinestatic |
Computes maximum number of spin rounds which should be used when waiting in user thread (for written or flushed redo) or 0 if busy waiting should not be used at all.
[in] | min_non_zero_value | minimum allowed value (unless 0 is returned) |
uint64_t log_pending_flushes | ( | ) |
Number of currently pending redo log flushes (fsyncs in-progress).
|
static |
Write the redo log up to a provided lsn by itself, if necessary.
[in] | log | redo log |
[in] | end_lsn | lsn to write for |
[in] | flush_to_disk | whether the written log should also be flushed |
[in,out] | interrupted | if true, was interrupted, needs retry |
uint64_t log_total_flushes | ( | ) |
Total number of redo log flushes (fsyncs) that have been started since the redo log system (log_sys) became initialized (.
|
static |
Waits until redo log is flushed up to provided lsn (or greater).
[in] | log | redo log |
[in] | lsn | wait until log.flushed_to_disk_lsn >= lsn |
[in,out] | interrupted | if true, was interrupted, needs retry. |
|
static |
Waits until redo log is written up to provided lsn (or greater).
We do not care if it's flushed or not.
[in] | log | redo log |
[in] | lsn | wait until log.write_lsn >= lsn |
[in,out] | interrupted | if true, was interrupted, needs retry. |
|
static |
Writes a given fragment of the log buffer to the current redo log file, unless the file is full, in which case a new file is produced and function exits (note, that the new log file's header is flushed in such case).
After data to the current log file has been written (log_data_blocks_write()), the log.write_lsn is advanced accordingly to the number of written bytes, which might be smaller than the requested number of bytes to write. That's because this function exits after doing a single write operation. That's because it might make sense to advance the lsn up to which data is ready in the log buffer (for writing), before making decision about next write (e.g. then the next write could be done for full blocks only).
[in] | log | redo log |
[in] | buffer | the beginning of first log block to write |
[in] | buffer_size | number of bytes to write since 'buffer' |
[in] | start_lsn | lsn corresponding to first block start |
void log_write_notifier | ( | log_t * | log_ptr | ) |
The log write notifier thread routine.
[in,out] | log_ptr | pointer to redo log |
Wait_stats log_write_up_to | ( | log_t & | log, |
lsn_t | lsn, | ||
bool | flush_to_disk | ||
) |
Waits until the redo log is written up to a provided lsn.
[in] | log | redo log |
[in] | lsn | lsn to wait for |
[in] | flush_to_disk | true: wait until it is flushed |
void log_writer | ( | log_t * | log_ptr | ) |
The log writer thread routine.
[in,out] | log_ptr | pointer to redo log |
void log_writer_check_if_exited_extra_margin | ( | log_t & | log | ) |
Checks if the redo log writer exited extra margin.
To minimize flipping of log.m_writer_inside_extra_margin, the check assumes the very pessimistic scenario in which a next write of the log_writer thread, would be executed up to the current lsn.
Requirement: log.writer_mutex acquired and log.m_writer_inside_extra_margin is true, before calling this function.
[in,out] | log | redo log |
|
static |
Called when the redo log writer enters the extra_margin.
Requirement: log.writer_mutex acquired and log.m_write_inside_extra_margin being false, before calling this function.
[in,out] | log | redo log |
|
static |
Called when the redo log writer exits the extra_margin.
Requirement: log.writer_mutex acquired and log.m_write_inside_extra_margin being true, before calling this function.
[in,out] | log | redo log |
|
inlinestatic |
|
static |
|
static |
|
inlinestatic |
|
static |
Writes fragment of the log buffer, not further than up to provided lsn.
Stops after the first call to log_data_blocks_write() or after producing a new log file or if it notices that some other thread has written to the redo log meanwhile. If some data was written, the log.write_lsn is advanced. For more details see
[in] | log | redo log |
[in] | next_write_lsn | write up to this lsn value |