MySQL 8.3.0
Source Code Documentation
log0write.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2023, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/**************************************************/ /**
28 @file include/log0write.h
29
30 *******************************************************/
31
32#ifndef log0write_h
33#define log0write_h
34
35#ifndef UNIV_HOTBACKUP
36
37/* std::memory_order_X */
38#include <atomic>
39
40/* log.write_to_file_requests_interval */
41#include "log0sys.h"
42
43/* log_t&, lsn_t */
44#include "log0types.h"
45
46/* srv_threads */
47#include "srv0srv.h"
48
49/**************************************************/ /**
50
51 @name Log - waiting for redo written to disk.
52
53 *******************************************************/
54
55/** @{ */
56
57/** Waits until the redo log is written up to a provided lsn.
58@param[in] log redo log
59@param[in] lsn lsn to wait for
60@param[in] flush_to_disk true: wait until it is flushed
61@return statistics about waiting inside */
62Wait_stats log_write_up_to(log_t &log, lsn_t lsn, bool flush_to_disk);
63
64/** Total number of redo log flushes (fsyncs) that have been started since
65the redo log system (log_sys) became initialized (@see log_sys_init).
66@return total number of fsyncs or 0 if the redo log system is uninitialized */
67uint64_t log_total_flushes();
68
69/** Number of currently pending redo log flushes (fsyncs in-progress).
70@return number of pending fsyncs or 0 if the redo log system is uninitialized */
71uint64_t log_pending_flushes();
72
73/** Checks if the redo log writer exited extra margin. To minimize flipping
74of log.m_writer_inside_extra_margin, the check assumes the very pessimistic
75scenario in which a next write of the log_writer thread, would be executed
76up to the current lsn.
77
78Requirement: log.writer_mutex acquired and log.m_writer_inside_extra_margin
79is true, before calling this function.
80
81@remarks
82This method is supposed to be used by the log_checkpointer thread to detect
83situation in which the redo log writer has actually exited the extra_margin,
84because of advanced log.last_checkpoint_lsn, but the log_writer thread didn't
85notice it because it has not been active since then (e.g. because there is
86nothing more to write, ie. log.write_lsn == current lsn).
87
88@param[in,out] log redo log */
90
91/** @} */
92
93/**************************************************/ /**
94
95 @name Log - the log write threads.
96
97 *******************************************************/
98
99/** @{ */
100
101/** Pause / resume the log writer, the log flusher, the log write notifier
102and the log flush notifier threads based on innodb_log_writer_threads value.
103@note Calls to this function should be protected externally by some mutex.
104The caller innodb_log_writer_threads_update() is protected
105by LOCK_global_system_variables in mysqld. */
107
108/** The log writer thread routine.
109@param[in,out] log_ptr pointer to redo log */
110void log_writer(log_t *log_ptr);
111
112/** The log flusher thread routine.
113@param[in,out] log_ptr pointer to redo log */
114void log_flusher(log_t *log_ptr);
115
116/** The log flush notifier thread routine.
117@param[in,out] log_ptr pointer to redo log */
118void log_flush_notifier(log_t *log_ptr);
119
120/** The log write notifier thread routine.
121@param[in,out] log_ptr pointer to redo log */
122void log_write_notifier(log_t *log_ptr);
123
124/** Validates that the log writer thread is active.
125Used only to assert, that the state is correct. */
127
128/** Validates that the log writer, flusher threads are active.
129Used only to assert, that the state is correct.
130@param[in] log redo log */
132
133#define log_flusher_mutex_enter(log) mutex_enter(&((log).flusher_mutex))
134
135#define log_flusher_mutex_enter_nowait(log) \
136 mutex_enter_nowait(&((log).flusher_mutex))
137
138#define log_flusher_mutex_exit(log) mutex_exit(&((log).flusher_mutex))
139
140#define log_flusher_mutex_own(log) \
141 (mutex_own(&((log).flusher_mutex)) || !log_flusher_is_active())
142
143#define log_flush_notifier_mutex_enter(log) \
144 mutex_enter(&((log).flush_notifier_mutex))
145
146#define log_flush_notifier_mutex_exit(log) \
147 mutex_exit(&((log).flush_notifier_mutex))
148
149#define log_flush_notifier_mutex_own(log) \
150 (mutex_own(&((log).flush_notifier_mutex)) || !log_flush_notifier_is_active())
151
152#define log_writer_mutex_enter(log) mutex_enter(&((log).writer_mutex))
153
154#define log_writer_mutex_enter_nowait(log) \
155 mutex_enter_nowait(&((log).writer_mutex))
156
157#define log_writer_mutex_exit(log) mutex_exit(&((log).writer_mutex))
158
159#define log_writer_mutex_own(log) \
160 (mutex_own(&((log).writer_mutex)) || !log_writer_is_active())
161
162#define log_write_notifier_mutex_enter(log) \
163 mutex_enter(&((log).write_notifier_mutex))
164
165#define log_write_notifier_mutex_exit(log) \
166 mutex_exit(&((log).write_notifier_mutex))
167
168#define log_write_notifier_mutex_own(log) \
169 (mutex_own(&((log).write_notifier_mutex)) || !log_write_notifier_is_active())
170
171/** Checks if log writer thread is active.
172@return true if and only if the log writer thread is active */
173inline bool log_writer_is_active() {
175}
176
177/** Checks if log write notifier thread is active.
178@return true if and only if the log write notifier thread is active */
181}
182
183/** Checks if log flusher thread is active.
184@return true if and only if the log flusher thread is active */
187}
188
189/** Checks if log flush notifier thread is active.
190@return true if and only if the log flush notifier thread is active */
193}
194
195/** Checks if requests to write redo log buffer to disk are frequent
196(which means that there is at least one request per 1ms in average).
197@param[in] interval how often in average requests happen
198@return true iff requests are considered frequent */
200 std::chrono::microseconds interval) {
201 return interval < std::chrono::milliseconds{1};
202}
203
204/** Checks if requests to write redo log buffer to disk are frequent
205(which means that there is at least one request per 1ms in average).
206@param[in] log redo log
207@return true iff requests are considered frequent */
210 log.write_to_file_requests_interval.load(std::memory_order_relaxed));
211}
212
213/** @} */
214
215#else
216
217#define log_writer_mutex_own(log) true
218
219#endif /* UNIV_HOTBACKUP */
220
221#endif /* !log0write_h */
Redo log - the log_sys.
Redo log basic types.
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:62
bool log_writer_is_active()
Checks if log writer thread is active.
Definition: log0write.h:173
void log_flusher(log_t *log_ptr)
The log flusher thread routine.
Definition: log0write.cc:2488
bool log_flush_notifier_is_active()
Checks if log flush notifier thread is active.
Definition: log0write.h:191
void log_control_writer_threads(log_t &log)
Pause / resume the log writer, the log flusher, the log write notifier and the log flush notifier thr...
Definition: log0log.cc:1102
void log_write_notifier(log_t *log_ptr)
The log write notifier thread routine.
Definition: log0write.cc:2625
bool log_flusher_is_active()
Checks if log flusher thread is active.
Definition: log0write.h:185
void log_writer_thread_active_validate()
Validates that the log writer thread is active.
Definition: log0log.cc:872
uint64_t log_total_flushes()
Total number of redo log flushes (fsyncs) that have been started since the redo log system (log_sys) ...
Definition: log0write.cc:2410
bool log_write_notifier_is_active()
Checks if log write notifier thread is active.
Definition: log0write.h:179
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.
Definition: log0write.cc:1084
void log_background_write_threads_active_validate(const log_t &log)
Validates that the log writer, flusher threads are active.
Definition: log0log.cc:874
void log_writer_check_if_exited_extra_margin(log_t &log)
Checks if the redo log writer exited extra margin.
Definition: log0write.cc:1875
void log_writer(log_t *log_ptr)
The log writer thread routine.
Definition: log0write.cc:2223
void log_flush_notifier(log_t *log_ptr)
The log flush notifier thread routine.
Definition: log0write.cc:2747
uint64_t log_pending_flushes()
Number of currently pending redo log flushes (fsyncs in-progress).
Definition: log0write.cc:2412
bool log_write_to_file_requests_are_frequent(std::chrono::microseconds interval)
Checks if requests to write redo log buffer to disk are frequent (which means that there is at least ...
Definition: log0write.h:199
static int interval
Definition: mysqladmin.cc:69
The server main program.
bool srv_thread_is_active(const IB_thread &thread)
Check if given thread is still active.
Definition: srv0srv.cc:3254
Srv_threads srv_threads
Structure with state of srv background threads.
Definition: srv0srv.cc:102
IB_thread m_log_flush_notifier
Redo flush notifier thread.
Definition: srv0srv.h:186
IB_thread m_log_flusher
Redo flusher thread.
Definition: srv0srv.h:180
IB_thread m_log_write_notifier
Redo write notifier thread.
Definition: srv0srv.h:183
IB_thread m_log_writer
Redo writer thread.
Definition: srv0srv.h:177
Definition: ut0ut.h:346
Redo log - single data structure with state of the redo log system.
Definition: log0sys.h:76
std::atomic< std::chrono::microseconds > write_to_file_requests_interval
How often redo write/flush is requested in average.
Definition: log0sys.h:200
static uint64_t lsn
Definition: xcom_base.cc:445