MySQL  8.0.23
Source Code Documentation
log0log.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
4 Copyright (c) 2009, Google Inc.
5 
6 Portions of this file contain modifications contributed and copyrighted by
7 Google, Inc. Those modifications are gratefully acknowledged and are described
8 briefly in the InnoDB documentation. The contributions by Google are
9 incorporated with their permission, and subject to the conditions contained in
10 the file COPYING.Google.
11 
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License, version 2.0, as published by the
14 Free Software Foundation.
15 
16 This program is also distributed with certain software (including but not
17 limited to OpenSSL) that is licensed under separate terms, as designated in a
18 particular file or component or in included license documentation. The authors
19 of MySQL hereby grant you an additional permission to link the program and
20 your derivative works with the separately licensed software that they have
21 included with MySQL.
22 
23 This program is distributed in the hope that it will be useful, but WITHOUT
24 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
26 for more details.
27 
28 You should have received a copy of the GNU General Public License along with
29 this program; if not, write to the Free Software Foundation, Inc.,
30 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 
32 *****************************************************************************/
33 
34 /**************************************************/ /**
35  @file include/log0log.h
36 
37  Redo log constants and functions.
38 
39  Types are defined inside log0types.h.
40 
41  Created 12/9/1995 Heikki Tuuri
42  *******************************************************/
43 
44 #ifndef log0log_h
45 #define log0log_h
46 
47 #include "dyn0buf.h"
48 #include "univ.i"
49 #ifndef UNIV_HOTBACKUP
50 #include "sync0rw.h"
51 #endif /* !UNIV_HOTBACKUP */
52 
53 #include "log0test.h"
54 #include "log0types.h"
55 #include "my_compiler.h"
56 
57 /** Prefix for name of log file, e.g. "ib_logfile" */
58 constexpr const char *const ib_logfile_basename = "ib_logfile";
59 
60 /* base name length(10) + length for decimal digits(22) */
61 constexpr uint32_t MAX_LOG_FILE_NAME = 32;
62 
63 /** Magic value to use instead of log checksums when they are disabled. */
64 constexpr uint32_t LOG_NO_CHECKSUM_MAGIC = 0xDEADBEEFUL;
65 
66 /** Absolute margin for the free space in the log, before a new query step
67 which modifies the database, is started. Expressed in number of pages. */
68 constexpr uint32_t LOG_CHECKPOINT_EXTRA_FREE = 8;
69 
70 /** Per thread margin for the free space in the log, before a new query step
71 which modifies the database, is started. It's multiplied by maximum number
72 of threads, that can concurrently enter mini-transactions. Expressed in
73 number of pages. */
74 constexpr uint32_t LOG_CHECKPOINT_FREE_PER_THREAD = 4;
75 
76 /** Controls asynchronous making of a new checkpoint.
77 Should be bigger than LOG_POOL_PREFLUSH_RATIO_SYNC. */
78 constexpr uint32_t LOG_POOL_CHECKPOINT_RATIO_ASYNC = 32;
79 
80 /** Controls synchronous preflushing of modified buffer pages. */
81 constexpr uint32_t LOG_POOL_PREFLUSH_RATIO_SYNC = 16;
82 
83 /** Controls asynchronous preflushing of modified buffer pages.
84 Should be less than the LOG_POOL_PREFLUSH_RATIO_SYNC. */
85 constexpr uint32_t LOG_POOL_PREFLUSH_RATIO_ASYNC = 8;
86 
87 /** The counting of lsn's starts from this value: this must be non-zero. */
89 
90 /* Offsets used in a log block header. */
91 
92 /** Block number which must be > 0 and is allowed to wrap around at 1G.
93 The highest bit is set to 1, if this is the first block in a call to
94 fil_io (for possibly many consecutive blocks). */
95 constexpr uint32_t LOG_BLOCK_HDR_NO = 0;
96 
97 /** Mask used to get the highest bit in the hdr_no field. */
98 constexpr uint32_t LOG_BLOCK_FLUSH_BIT_MASK = 0x80000000UL;
99 
100 /** Maximum allowed block's number (stored in hdr_no). */
101 constexpr uint32_t LOG_BLOCK_MAX_NO = 0x3FFFFFFFUL + 1;
102 
103 /** Number of bytes written to this block (also header bytes). */
104 constexpr uint32_t LOG_BLOCK_HDR_DATA_LEN = 4;
105 
106 /** Mask used to get the highest bit in the data len field,
107 this bit is to indicate if this block is encrypted or not. */
108 constexpr uint32_t LOG_BLOCK_ENCRYPT_BIT_MASK = 0x8000UL;
109 
110 /** Offset of the first start of mtr log record group in this log block.
111 0 if none. If the value is the same as LOG_BLOCK_HDR_DATA_LEN, it means
112 that the first rec group has not yet been concatenated to this log block,
113 but if it will, it will start at this offset.
114 
115 An archive recovery can start parsing the log records starting from this
116 offset in this log block, if value is not 0. */
117 constexpr uint32_t LOG_BLOCK_FIRST_REC_GROUP = 6;
118 
119 /** 4 lower bytes of the value of log_sys->next_checkpoint_no when the log
120 block was last written to: if the block has not yet been written full,
121 this value is only updated before a log buffer flush. */
122 constexpr uint32_t LOG_BLOCK_CHECKPOINT_NO = 8;
123 
124 /** Size of the log block's header in bytes. */
125 constexpr uint32_t LOG_BLOCK_HDR_SIZE = 12;
126 
127 /* Offsets used in a log block's footer (refer to the end of the block). */
128 
129 /** 4 byte checksum of the log block contents. In InnoDB versions < 3.23.52
130 this did not contain the checksum, but the same value as .._HDR_NO. */
131 constexpr uint32_t LOG_BLOCK_CHECKSUM = 4;
132 
133 /** Size of the log block footer (trailer) in bytes. */
134 constexpr uint32_t LOG_BLOCK_TRL_SIZE = 4;
135 
137  "Header + footer cannot be larger than the whole log block.");
138 
139 /** Size of log block's data fragment (where actual data is stored). */
140 constexpr uint32_t LOG_BLOCK_DATA_SIZE =
142 
143 /** Ensure, that 64 bits are enough to represent lsn values, when 63 bits
144 are used to represent sn values. It is enough to ensure that lsn < 2*sn,
145 and that is guaranteed if the overhead enumerated in lsn sequence is not
146 bigger than number of actual data bytes. */
148  "Overhead in LSN sequence cannot be bigger than actual data.");
149 
150 /** Maximum possible sn value. */
151 constexpr sn_t SN_MAX = (1ULL << 62) - 1;
152 
153 /** The sn bit to express locked state. */
154 constexpr sn_t SN_LOCKED = 1ULL << 63;
155 
156 /** Maximum possible lsn value is slightly higher than the maximum sn value,
157 because lsn sequence enumerates also bytes used for headers and footers of
158 all log blocks. However, still 64-bits are enough to represent the maximum
159 lsn value, because only 63 bits are used to represent sn value. */
160 constexpr lsn_t LSN_MAX = (1ULL << 63) - 1;
161 
162 /* Offsets inside the checkpoint pages (redo log format version 1). */
163 
164 /** Checkpoint number. It's incremented by one for each consecutive checkpoint.
165 During recovery, all headers are scanned, and one with the maximum checkpoint
166 number is used for the recovery (checkpoint_lsn from the header is used). */
167 constexpr uint32_t LOG_CHECKPOINT_NO = 0;
168 
169 /** Checkpoint lsn. Recovery starts from this lsn and searches for the first
170 log record group that starts since then. In InnoDB < 8.0, it was exact value
171 at which the first log record group started. Because of the relaxed order in
172 flush lists, checkpoint lsn values are not precise anymore (the maximum delay
173 related to the relaxed order in flush lists, is subtracted from oldest_lsn,
174 when writing a checkpoint). */
175 constexpr uint32_t LOG_CHECKPOINT_LSN = 8;
176 
177 /** Offset within the log files, which corresponds to checkpoint lsn.
178 Used for calibration of lsn and offset calculations. */
179 constexpr uint32_t LOG_CHECKPOINT_OFFSET = 16;
180 
181 /** Size of the log buffer, when the checkpoint write was started.
182 It seems to be write-only field in InnoDB. Not used by recovery.
183 
184 @note
185 Note that when the log buffer is being resized, all the log background threads
186 are stopped, so there no is concurrent checkpoint write (the log_checkpointer
187 thread is stopped). */
188 constexpr uint32_t LOG_CHECKPOINT_LOG_BUF_SIZE = 24;
189 
190 /** Offsets used in a log file header */
191 
192 /** Log file header format identifier (32-bit unsigned big-endian integer).
193 This used to be called LOG_GROUP_ID and always written as 0,
194 because InnoDB never supported more than one copy of the redo log. */
195 constexpr uint32_t LOG_HEADER_FORMAT = 0;
196 
197 /** 4 unused (zero-initialized) bytes. */
198 constexpr uint32_t LOG_HEADER_PAD1 = 4;
199 
200 /** LSN of the start of data in this log file (with format version 1 and 2). */
201 constexpr uint32_t LOG_HEADER_START_LSN = 8;
202 
203 /** A null-terminated string which will contain either the string 'MEB'
204 and the MySQL version if the log file was created by mysqlbackup,
205 or 'MySQL' and the MySQL version that created the redo log file. */
206 constexpr uint32_t LOG_HEADER_CREATOR = 16;
207 
208 /** End of the log file creator field. */
209 constexpr uint32_t LOG_HEADER_CREATOR_END = LOG_HEADER_CREATOR + 32;
210 
211 /** 32 BITs flag */
213 
214 /** Flag at BIT-1 to indicate if redo logging is disabled or not. */
215 constexpr uint32_t LOG_HEADER_FLAG_NO_LOGGING = 1;
216 
217 /** Flag at BIT-2 to indicate if server is not recoverable on crash. This
218 is set only when redo logging is disabled and unset on slow shutdown after
219 all pages are flushed to disk. */
220 constexpr uint32_t LOG_HEADER_FLAG_CRASH_UNSAFE = 2;
221 
222 /** Maximum BIT position number. Should be set to the latest added. */
224 
225 /** Current total size of LOG header. */
226 constexpr uint32_t LOG_HEADER_SIZE = LOG_HEADER_FLAGS + 4;
227 
228 /** Set a specific bit in flag.
229 @param[in] flag bit flag
230 @param[in] bit set bit */
231 inline void LOG_HEADER_SET_FLAG(uint32_t &flag, uint32_t bit) {
232  ut_ad(bit > 0);
233  ut_ad(bit <= LOG_HEADER_FLAG_MAX);
234  flag |= static_cast<uint32_t>(1UL << (bit - 1));
235 }
236 
237 /** Check a specific bit in flag.
238 @param[in] flag bit flag
239 @param[in] bit check bit
240 @return true, iff bit is set in flag. */
241 inline bool LOG_HEADER_CHECK_FLAG(uint32_t flag, uint32_t bit) {
242  return ((flag & (1ULL << (bit - 1))) > 0);
243 }
244 
245 /** Contents of the LOG_HEADER_CREATOR field */
246 #define LOG_HEADER_CREATOR_CURRENT "MySQL " INNODB_VERSION_STR
247 
248 /** Header is created during DB clone */
249 #define LOG_HEADER_CREATOR_CLONE "MySQL Clone"
250 
251 /** First checkpoint field in the log header. We write alternately to
252 the checkpoint fields when we make new checkpoints. This field is only
253 defined in the first log file. */
255 
256 /** Log Encryption information in redo log header. */
257 constexpr uint32_t LOG_ENCRYPTION = 2 * OS_FILE_LOG_BLOCK_SIZE;
258 
259 /** Second checkpoint field in the header of the first log file. */
260 constexpr uint32_t LOG_CHECKPOINT_2 = 3 * OS_FILE_LOG_BLOCK_SIZE;
261 
262 /** Size of log file's header. */
263 constexpr uint32_t LOG_FILE_HDR_SIZE = 4 * OS_FILE_LOG_BLOCK_SIZE;
264 
265 /** Constants related to server variables (default, min and max values). */
266 
267 /** Default value of innodb_log_write_max_size (in bytes). */
268 constexpr ulint INNODB_LOG_WRITE_MAX_SIZE_DEFAULT = 4096;
269 
270 /** Default value of innodb_log_checkpointer_every (in milliseconds). */
271 constexpr ulong INNODB_LOG_CHECKPOINT_EVERY_DEFAULT = 1000; // 1000ms = 1s
272 
273 /** Default value of innodb_log_writer_spin_delay (in spin rounds).
274 We measured that 1000 spin round takes 4us. We decided to select 1ms
275 as the maximum time for busy waiting. Therefore it corresponds to 250k
276 spin rounds. Note that first wait on event takes 50us-100us (even if 10us
277 is passed), so it is 5%-10% of the total time that we have already spent
278 on busy waiting, when we fall back to wait on event. */
279 constexpr ulong INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT = 250000;
280 
281 /** Default value of innodb_log_writer_timeout (in microseconds).
282 Note that it will anyway take at least 50us. */
284 
285 /** Default value of innodb_log_spin_cpu_abs_lwm.
286 Expressed in percent (80 stands for 80%) of a single CPU core. */
288 
289 /** Default value of innodb_log_spin_cpu_pct_hwm.
290 Expressed in percent (50 stands for 50%) of all CPU cores. */
292 
293 /** Default value of innodb_log_wait_for_write_spin_delay (in spin rounds).
294 Read about INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT.
295 Number of spin rounds is calculated according to current usage of CPU cores.
296 If the usage is smaller than lwm percents of single core, then max rounds = 0.
297 If the usage is smaller than 50% of hwm percents of all cores, then max rounds
298 is decreasing linearly from 10x innodb_log_writer_spin_delay to 1x (for 50%).
299 Then in range from 50% of hwm to 100% of hwm, the max rounds stays equal to
300 the innodb_log_writer_spin_delay, because it doesn't make sense to use too
301 short waits. Hence this is minimum value for the max rounds when non-zero
302 value is being used. */
304 
305 /** Default value of innodb_log_wait_for_write_timeout (in microseconds). */
307 
308 /** Default value of innodb_log_wait_for_flush_spin_delay (in spin rounds).
309 Read about INNODB_LOG_WAIT_FOR_WRITE_SPIN_DELAY_DEFAULT. The same mechanism
310 applies here (to compute max rounds). */
312 
313 /** Default value of innodb_log_wait_for_flush_spin_hwm (in microseconds). */
315 
316 /** Default value of innodb_log_wait_for_flush_timeout (in microseconds). */
318 
319 /** Default value of innodb_log_flusher_spin_delay (in spin rounds).
320 Read about INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT. */
321 constexpr ulong INNODB_LOG_FLUSHER_SPIN_DELAY_DEFAULT = 250000;
322 
323 /** Default value of innodb_log_flusher_timeout (in microseconds).
324 Note that it will anyway take at least 50us. */
326 
327 /** Default value of innodb_log_write_notifier_spin_delay (in spin rounds). */
329 
330 /** Default value of innodb_log_write_notifier_timeout (in microseconds). */
332 
333 /** Default value of innodb_log_flush_notifier_spin_delay (in spin rounds). */
335 
336 /** Default value of innodb_log_flush_notifier_timeout (in microseconds). */
338 
339 /** Default value of innodb_log_buffer_size (in bytes). */
340 constexpr ulong INNODB_LOG_BUFFER_SIZE_DEFAULT = 16 * 1024 * 1024UL;
341 
342 /** Minimum allowed value of innodb_log_buffer_size. */
343 constexpr ulong INNODB_LOG_BUFFER_SIZE_MIN = 256 * 1024UL;
344 
345 /** Maximum allowed value of innodb_log_buffer_size. */
346 constexpr ulong INNODB_LOG_BUFFER_SIZE_MAX = ULONG_MAX;
347 
348 /** Default value of innodb_log_recent_written_size (in bytes). */
349 constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_DEFAULT = 1024 * 1024;
350 
351 /** Minimum allowed value of innodb_log_recent_written_size. */
353 
354 /** Maximum allowed value of innodb_log_recent_written_size. */
355 constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_MAX = 1024 * 1024 * 1024UL;
356 
357 /** Default value of innodb_log_recent_closed_size (in bytes). */
358 constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_DEFAULT = 2 * 1024 * 1024;
359 
360 /** Minimum allowed value of innodb_log_recent_closed_size. */
362 
363 /** Maximum allowed value of innodb_log_recent_closed_size. */
364 constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_MAX = 1024 * 1024 * 1024UL;
365 
366 /** Default value of innodb_log_events (number of events). */
367 constexpr ulong INNODB_LOG_EVENTS_DEFAULT = 2048;
368 
369 /** Minimum allowed value of innodb_log_events. */
370 constexpr ulong INNODB_LOG_EVENTS_MIN = 1;
371 
372 /** Maximum allowed value of innodb_log_events. */
373 constexpr ulong INNODB_LOG_EVENTS_MAX = 1024 * 1024 * 1024UL;
374 
375 /** Default value of innodb_log_write_ahead_size (in bytes). */
376 constexpr ulong INNODB_LOG_WRITE_AHEAD_SIZE_DEFAULT = 8192;
377 
378 /** Minimum allowed value of innodb_log_write_ahead_size. */
380 
381 /** Maximum allowed value of innodb_log_write_ahead_size. */
383  UNIV_PAGE_SIZE_DEF; // 16kB...
384 
385 /** Value to which MLOG_TEST records should sum up within a group. */
386 constexpr int64_t MLOG_TEST_VALUE = 10000;
387 
388 /** Maximum size of single MLOG_TEST record (in bytes). */
389 constexpr uint32_t MLOG_TEST_MAX_REC_LEN = 100;
390 
391 /** Maximum number of MLOG_TEST records in single group of log records. */
392 constexpr uint32_t MLOG_TEST_GROUP_MAX_REC_N = 100;
393 
394 /** Bytes consumed by MLOG_TEST record with an empty payload. */
395 constexpr uint32_t MLOG_TEST_REC_OVERHEAD = 37;
396 
397 /** Redo log system (singleton). */
398 extern log_t *log_sys;
399 
400 /** Pointer to the log checksum calculation function. Changes are protected
401 by log_mutex_enter_all, which also stops the log background threads. */
403 
404 #ifndef UNIV_HOTBACKUP
405 /** Represents currently running test of redo log, nullptr otherwise. */
406 extern std::unique_ptr<Log_test> log_test;
407 #endif /* !UNIV_HOTBACKUP */
408 
409 /* Declaration of inline functions (definition is available in log0log.ic). */
410 
411 /** Gets a log block flush bit. The flush bit is set, if and only if,
412 the block was the first block written in a call to fil_io().
413 
414 During recovery, when encountered the flush bit, recovery code can be
415 pretty sure, that all previous blocks belong to a completed fil_io(),
416 because the block with flush bit belongs to the next call to fil_io(),
417 which could only be started after the previous one has been finished.
418 
419 @param[in] log_block log block
420 @return true if this block was the first to be written in fil_io(). */
421 inline bool log_block_get_flush_bit(const byte *log_block);
422 
423 /** Sets the log block flush bit.
424 @param[in,out] log_block log block (must have hdr_no != 0)
425 @param[in] value value to set */
426 inline void log_block_set_flush_bit(byte *log_block, bool value);
427 
428 /** Gets a log block number stored in the header. The number corresponds
429 to lsn range for data stored in the block.
430 
431 During recovery, when a next block is being parsed, a next range of lsn
432 values is expected to be read. This corresponds to a log block number
433 increased by one. However, if a smaller number is read from the header,
434 it is then considered the end of the redo log and recovery is finished.
435 In such case, the next block is most likely an empty block or a block
436 from the past, because the redo log is written in circular manner.
437 
438 @param[in] log_block log block (may be invalid or empty block)
439 @return log block number stored in the block header */
440 inline uint32_t log_block_get_hdr_no(const byte *log_block);
441 
442 /** Sets the log block number stored in the header.
443 NOTE that this must be set before the flush bit!
444 
445 @param[in,out] log_block log block
446 @param[in] n log block number: must be in (0, 1G] */
447 inline void log_block_set_hdr_no(byte *log_block, uint32_t n);
448 
449 /** Gets a log block data length.
450 @param[in] log_block log block
451 @return log block data length measured as a byte offset from the block start */
452 inline uint32_t log_block_get_data_len(const byte *log_block);
453 
454 /** Sets the log block data length.
455 @param[in,out] log_block log block
456 @param[in] len data length (@see log_block_get_data_len) */
457 inline void log_block_set_data_len(byte *log_block, ulint len);
458 
459 /** Gets an offset to the beginning of the first group of log records
460 in a given log block.
461 @param[in] log_block log block
462 @return first mtr log record group byte offset from the block start,
463 0 if none. */
464 inline uint32_t log_block_get_first_rec_group(const byte *log_block);
465 
466 /** Sets an offset to the beginning of the first group of log records
467 in a given log block.
468 @param[in,out] log_block log block
469 @param[in] offset offset, 0 if none */
470 inline void log_block_set_first_rec_group(byte *log_block, uint32_t offset);
471 
472 /** Gets a log block checkpoint number field (4 lowest bytes).
473 @param[in] log_block log block
474 @return checkpoint no (4 lowest bytes) */
475 inline uint32_t log_block_get_checkpoint_no(const byte *log_block);
476 
477 /** Sets a log block checkpoint number field (4 lowest bytes).
478 @param[in,out] log_block log block
479 @param[in] no checkpoint no */
480 inline void log_block_set_checkpoint_no(byte *log_block, uint64_t no);
481 
482 /** Converts a lsn to a log block number. Consecutive log blocks have
483 consecutive numbers (unless the sequence wraps). It is guaranteed that
484 the calculated number is greater than zero.
485 
486 @param[in] lsn lsn of a byte within the block
487 @return log block number, it is > 0 and <= 1G */
489 
490 /** Calculates the checksum for a log block.
491 @param[in] log_block log block
492 @return checksum */
493 inline uint32_t log_block_calc_checksum(const byte *log_block);
494 
495 /** Calculates the checksum for a log block using the MySQL 5.7 algorithm.
496 @param[in] log_block log block
497 @return checksum */
498 inline uint32_t log_block_calc_checksum_crc32(const byte *log_block);
499 
500 /** Calculates the checksum for a log block using the "no-op" algorithm.
501 @param[in] log_block log block
502 @return checksum */
503 inline uint32_t log_block_calc_checksum_none(const byte *log_block);
504 
505 /** Gets value of a log block checksum field.
506 @param[in] log_block log block
507 @return checksum */
508 inline uint32_t log_block_get_checksum(const byte *log_block);
509 
510 /** Sets value of a log block checksum field.
511 @param[in,out] log_block log block
512 @param[in] checksum checksum */
513 inline void log_block_set_checksum(byte *log_block, uint32_t checksum);
514 
515 /** Stores a 4-byte checksum to the trailer checksum field of a log block.
516 This is used before writing the log block to disk. The checksum in a log
517 block is used in recovery to check the consistency of the log block.
518 @param[in] log_block log block (completely filled in!) */
519 inline void log_block_store_checksum(byte *log_block);
520 
521 /** Gets the current lsn value. This value points to the first non
522 reserved data byte in the redo log. When next user thread reserves
523 space in the redo log, it starts at this lsn.
524 
525 If the last reservation finished exactly before footer of log block,
526 this value points to the first byte after header of the next block.
527 
528 NOTE that it is possible that the current lsn value does not fit
529 free space in the log files or in the log buffer. In such case,
530 user threads need to wait until the space becomes available.
531 
532 @return current lsn */
533 inline lsn_t log_get_lsn(const log_t &log);
534 
535 /** Gets the last checkpoint lsn stored and flushed to disk.
536 @return last checkpoint lsn */
537 inline lsn_t log_get_checkpoint_lsn(const log_t &log);
538 
539 #ifndef UNIV_HOTBACKUP
540 
541 /** @return true iff log_free_check should be executed. */
542 inline bool log_needs_free_check();
543 
544 /** Any database operation should call this when it has modified more than
545 about 4 pages. NOTE that this function may only be called when the thread
546 owns no synchronization objects except the dictionary mutex.
547 
548 Checks if current log.sn exceeds log.free_check_limit_sn, in which case waits.
549 This is supposed to guarantee that we would not run out of space in the log
550 files when holding latches of some dirty pages (which could end up in
551 a deadlock, because flush of the latched dirty pages could be required
552 to reclaim the space and it is impossible to flush latched pages). */
553 inline void log_free_check();
554 
555 /** Calculates lsn value for given sn value. Sequence of sn values
556 enumerate all data bytes in the redo log. Sequence of lsn values
557 enumerate all data bytes and bytes used for headers and footers
558 of all log blocks in the redo log. For every LOG_BLOCK_DATA_SIZE
559 bytes of data we have OS_FILE_LOG_BLOCK_SIZE bytes in the redo log.
560 NOTE that LOG_BLOCK_DATA_SIZE + LOG_BLOCK_HDR_SIZE + LOG_BLOCK_TRL_SIZE
561 == OS_FILE_LOG_BLOCK_SIZE. The calculated lsn value will always point
562 to some data byte (will be % OS_FILE_LOG_BLOCK_SIZE >= LOG_BLOCK_HDR_SIZE,
563 and < OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE).
564 
565 @param[in] sn sn value
566 @return lsn value for the provided sn value */
567 constexpr inline lsn_t log_translate_sn_to_lsn(lsn_t sn);
568 
569 /** Calculates sn value for given lsn value.
570 @see log_translate_sn_to_lsn
571 @param[in] lsn lsn value
572 @return sn value for the provided lsn value */
574 
575 #endif /* !UNIV_HOTBACKUP */
576 
577 /** Validates a given lsn value. Checks if the lsn value points to data
578 bytes inside log block (not to some bytes in header/footer). It is used
579 by assertions.
580 @return true if lsn points to data bytes within log block */
582 
583 #ifndef UNIV_HOTBACKUP
584 
585 /** Calculates age of current checkpoint as number of bytes since
586 last checkpoint. This includes bytes for headers and footers of
587 all log blocks. The calculation is based on the latest written
588 checkpoint lsn, and the current lsn, which points to the first
589 non reserved data byte. Note that the current lsn could not fit
590 the free space in the log files. This means that the checkpoint
591 age could potentially be larger than capacity of the log files.
592 However we do the best effort to avoid such situations, and if
593 they happen, user threads wait until the space is reclaimed.
594 @param[in] log redo log
595 @return checkpoint age as number of bytes */
596 inline lsn_t log_get_checkpoint_age(const log_t &log);
597 
598 /* Declaration of log_buffer functions (definition in log0buf.cc). */
599 
600 /** Reserves space in the redo log for following write operations.
601 Space is reserved for a given number of data bytes. Additionally
602 bytes for required headers and footers of log blocks are reserved.
603 
604 After the space is reserved, range of lsn values from a start_lsn
605 to an end_lsn is assigned. The log writer thread cannot proceed
606 further than to the start_lsn, until a link start_lsn -> end_lsn
607 has been added to the log recent written buffer.
608 
609 NOTE that the link is added after data is written to the reserved
610 space in the log buffer. It is very critical to do all these steps
611 as fast as possible, because very likely the log writer thread is
612 waiting for the link.
613 */
616 /**
617 @see @ref sect_redo_log_buf_reserve
618 */
620 /**
621 @param[in,out] log redo log
622 @param[in] len number of data bytes to reserve for write
623 @return handle that represents the reservation */
624 Log_handle log_buffer_reserve(log_t &log, size_t len);
625 
626 /** Writes data to the log buffer. The space in the redo log has to be
627 reserved before calling to this function and lsn pointing to inside the
628 reserved range of lsn values has to be provided.
629 
630 The write does not have to cover the whole reserved space, but may not
631 overflow it. If it does not cover, then returned value should be used
632 to start the next write operation. Note that finally we must use exactly
633 all the reserved space.
634 
635 */
638 /**
639 @see @ref sect_redo_log_buf_write
640 */
642 /**
643 @param[in,out] log redo log
644 @param[in] handle handle for the reservation of space
645 @param[in] str memory to write data from
646 @param[in] str_len number of bytes to write
647 @param[in] start_lsn lsn to start writing at (the reserved space)
648 
649 @return end_lsn after writing the data (in the reserved space), could be
650 used to start the next write operation if there is still free space in
651 the reserved space */
652 lsn_t log_buffer_write(log_t &log, const Log_handle &handle, const byte *str,
653  size_t str_len, lsn_t start_lsn);
654 
655 /** Adds a link start_lsn -> end_lsn to the log recent written buffer.
656 
657 This function must be called after the data has been written to the
658 fragment of log buffer represented by range [start_lsn, end_lsn).
659 After the link is added, the log writer may write the data to disk.
660 
661 NOTE that still dirty pages for the [start_lsn, end_lsn) are not added
662 to flush lists when this function is called.
663 
664 */
667 /**
668 @see @ref sect_redo_log_buf_add_links_to_recent_written
669 */
671 /**
672 @param[in,out] log redo log
673 @param[in] handle handle for the reservation of space
674 @param[in] start_lsn start_lsn of the link to add
675 @param[in] end_lsn end_lsn of the link to add */
677  lsn_t start_lsn, lsn_t end_lsn);
678 
679 /** Modifies header of log block in the log buffer, which contains
680 a given lsn value, and sets offset to the first group of log records
681 within the block.
682 
683 This is used by mtr after writing a log record group which ends at
684 lsn belonging to different log block than lsn at which the group was
685 started. When write was finished at the last data byte of log block,
686 it is considered ended in the next log block, because the next data
687 byte belongs to that block.
688 
689 During recovery, when recovery is started in the middle of some group
690 of log records, it first looks for the beginning of the next group.
691 
692 @param[in,out] log redo log
693 @param[in] handle handle for the reservation of space
694 @param[in] rec_group_end_lsn lsn at which the first log record
695 group starts within the block containing this lsn value */
697  lsn_t rec_group_end_lsn);
698 
699 /** Adds a link start_lsn -> end_lsn to the log recent closed buffer.
700 
701 This is called after all dirty pages related to [start_lsn, end_lsn)
702 have been added to corresponding flush lists.
703 For detailed explanation - @see log0write.cc.
704 
705 */
708 /**
709 @see @ref sect_redo_log_add_link_to_recent_closed
710 */
712 /**
713 
714 @param[in,out] log redo log
715 @param[in] handle handle for the reservation of space */
716 void log_buffer_close(log_t &log, const Log_handle &handle);
717 
718 /** Write to the log file up to the last log entry.
719 @param[in,out] log redo log
720 @param[in] sync whether we want the written log
721 also to be flushed to disk. */
722 void log_buffer_flush_to_disk(log_t &log, bool sync = true);
723 
724 /** Writes the log buffer to the log file. It is intended to be called from
725 background master thread periodically. If the log writer threads are active,
726 this function writes nothing. */
728 
729 /** Requests flush of the log buffer.
730 @param[in] sync true: wait until the flush is done */
731 inline void log_buffer_flush_to_disk(bool sync = true);
732 
733 /** @return lsn up to which all writes to log buffer have been finished */
735 
736 /** @return lsn up to which all dirty pages have been added to flush list */
738 
739 /** @return capacity of the recent_closed, or 0 if !log_use_threads() */
741 
742 /** Get last redo block from redo buffer and end LSN. Note that it takes
743 x-lock on the log buffer for a short period. Out values are always set,
744 even when provided last_block is nullptr.
745 @param[in,out] log redo log
746 @param[out] last_lsn end lsn of last mtr
747 @param[out] last_block last redo block
748 @param[in,out] block_len length in bytes */
749 void log_buffer_get_last_block(log_t &log, lsn_t &last_lsn, byte *last_block,
750  uint32_t &block_len);
751 
752 /** Advances log.buf_ready_for_write_lsn using links in the recent written
753 buffer. It's used by the log writer thread only.
754 @param[in,out] log redo log */
756 
757 /** Validates that all slots in log recent written buffer for lsn values
758 in range between begin and end, are empty. Used during tests, crashes the
759 program if validation does not pass.
760 @param[in] log redo log which buffer is validated
761 @param[in] begin validation start (inclusive)
762 @param[in] end validation end (exclusive) */
764  lsn_t end);
765 
766 /** Validates that all slots in log recent closed buffer for lsn values
767 in range between begin and end, are empty. Used during tests, crashes the
768 program if validation does not pass.
769 @param[in] log redo log which buffer is validated
770 @param[in] begin validation start (inclusive)
771 @param[in] end validation end (exclusive) */
773 
774 /* Declaration of remaining functions. */
775 
776 /** Waits until there is free space in the log recent closed buffer
777 for any links start_lsn -> end_lsn, which start at provided start_lsn.
778 It does not add any link.
779 
780 This is called just before dirty pages for [start_lsn, end_lsn)
781 are added to flush lists. That's because we need to guarantee,
782 that the delay until dirty page is added to flush list is limited.
783 For detailed explanation - @see log0write.cc.
784 
785 */
788 /**
789 @see @ref sect_redo_log_add_dirty_pages
790 */
792 /**
793 @param[in,out] log redo log
794 @param[in] lsn lsn on which we wait (for any link: lsn -> x) */
796 
797 /** Waits until there is free space in the log buffer. The free space has to be
798 available for range of sn values ending at the provided sn.
799 */
802 /**
803 @see @ref sect_redo_log_waiting_for_writer
804 */
806 /**
807 @param[in] log redo log
808 @param[in] end_sn end of the range of sn values */
809 void log_wait_for_space_in_log_buf(log_t &log, sn_t end_sn);
810 
811 /** Waits until there is free space for range of sn values ending
812 at the provided sn, in both the log buffer and in the log files.
813 @param[in] log redo log
814 @param[in] end_sn end of the range of sn values */
815 void log_wait_for_space(log_t &log, sn_t end_sn);
816 
817 /** Computes capacity of redo log available until log_free_check()
818 reaches point where it needs to wait.
819 @param[in] log redo log
820 @return lsn capacity up to free_check_wait happens */
822 
823 /** When the oldest dirty page age exceeds this value, we start
824 an asynchronous preflush of dirty pages.
825 @param[in] log redo log
826 @return age of dirty page at which async preflush is started */
828 
829 /** Waits until there is free space in log files which includes
830 concurrency margin required for all threads. You should rather
831 use log_free_check().
832 */
835 /**
836 @see @ref sect_redo_log_reclaim_space
837 */
839 /**
840 @param[in] log redo log */
841 void log_free_check_wait(log_t &log);
842 
843 /** Updates limits related to free space in redo log files:
844 log.available_for_checkpoint_lsn and log.free_check_limit_sn.
845 @param[in,out] log redo log */
846 void log_update_limits(log_t &log);
847 
848 /** Updates limit used when writing to log buffer. Note that the
849 log buffer may have space for log records for which we still do
850 not have space in log files (for larger lsn values).
851 @param[in,out] log redo log */
852 void log_update_buf_limit(log_t &log);
853 
854 /** Updates limit used when writing to log buffer, according to provided
855 write_lsn. It must be <= log.write_lsn.load() to protect from log buffer
856 overwrites.
857 @param[in,out] log redo log
858 @param[in] write_lsn value <= log.write_lsn.load() */
859 void log_update_buf_limit(log_t &log, lsn_t write_lsn);
860 
861 /** Waits until the redo log is written up to a provided lsn.
862 @param[in] log redo log
863 @param[in] lsn lsn to wait for
864 @param[in] flush_to_disk true: wait until it is flushed
865 @return statistics about waiting inside */
866 Wait_stats log_write_up_to(log_t &log, lsn_t lsn, bool flush_to_disk);
867 
868 /* Read the first log file header to get the encryption
869 information if it exist.
870 @return true if success */
871 bool log_read_encryption();
872 
873 /** Write the encryption info into the log file header(the 3rd block).
874 It just need to flush the file header block with current master key.
875 @param[in] key encryption key
876 @param[in] iv encryption iv
877 @param[in] is_boot if it is for bootstrap
878 @return true if success. */
879 bool log_write_encryption(byte *key, byte *iv, bool is_boot);
880 
881 /** Rotate the redo log encryption
882 It will re-encrypt the redo log encryption metadata and write it to
883 redo log file header.
884 @return true if success. */
885 bool log_rotate_encryption();
886 
887 /** Rotate default master key for redo log encryption. */
889 
890 /** Computes lsn up to which sync flush should be done or returns 0
891 if there is no need to execute sync flush now.
892 @param[in,out] log redo log
893 @return lsn for which we want to have oldest_lsn >= lsn in each BP,
894  or 0 if there is no need for sync flush */
896 
897 /** Requests a sharp checkpoint write for provided or greater lsn.
898 @param[in,out] log redo log
899 @param[in] sync true -> wait until it is finished
900 @param[in] lsn lsn for which we need checkpoint (or greater chkp) */
901 void log_request_checkpoint(log_t &log, bool sync, lsn_t lsn);
902 
903 /** Requests a fuzzy checkpoint write (for lsn currently available
904 for checkpointing).
905 @param[in,out] log redo log
906 @param[in] sync true -> wait until it is finished */
907 void log_request_checkpoint(log_t &log, bool sync);
908 
909 /** Make a checkpoint at the current lsn. Reads current lsn and waits
910 until all dirty pages have been flushed up to that lsn. Afterwards
911 requests a checkpoint write and waits until it is finished.
912 @param[in,out] log redo log
913 @return true iff current lsn was greater than last checkpoint lsn */
915 
916 /** Make a checkpoint at the current lsn. Reads current lsn and waits
917 until all dirty pages have been flushed up to that lsn. Afterwards
918 requests a checkpoint write and waits until it is finished.
919 @return true iff current lsn was greater than last checkpoint lsn */
921 
922 /** Reads a log file header page to log.checkpoint_buf.
923 @param[in,out] log redo log
924 @param[in] header 0 or LOG_CHECKPOINT_1 or LOG_CHECKPOINT2 */
925 void log_files_header_read(log_t &log, uint32_t header);
926 
927 /** Fill redo log header.
928 @param[out] buf filled buffer
929 @param[in] start_lsn log start LSN
930 @param[in] creator creator of the header
931 @param[in] no_logging redo logging is disabled
932 @param[in] crash_unsafe it is not safe to crash */
933 void log_files_header_fill(byte *buf, lsn_t start_lsn, const char *creator,
934  bool no_logging, bool crash_unsafe);
935 
936 /** Writes a log file header to the log file space.
937 @param[in] log redo log
938 @param[in] nth_file header for the nth file in the log files
939 @param[in] start_lsn log file data starts at this lsn */
940 void log_files_header_flush(log_t &log, uint32_t nth_file, lsn_t start_lsn);
941 
942 /** Changes format of redo files to previous format version.
943 
944 @note Note this will work between the two formats 5_7_9 & current because
945 the only change is the version number */
946 void log_files_downgrade(log_t &log);
947 
948 /** Writes the next checkpoint info to header of the first log file.
949 Note that two pages of the header are used alternately for consecutive
950 checkpoints. If we crashed during the write, we would still have the
951 previous checkpoint info and recovery would work.
952 @param[in,out] log redo log
953 @param[in] next_checkpoint_lsn writes checkpoint at this lsn */
954 void log_files_write_checkpoint(log_t &log, lsn_t next_checkpoint_lsn);
955 
956 /** Updates current_file_lsn and current_file_real_offset to correspond
957 to a given lsn. For this function to work, the values must already be
958 initialized to correspond to some lsn, for instance, a checkpoint lsn.
959 @param[in,out] log redo log
960 @param[in] lsn log sequence number to set files_start_lsn at */
962 
963 /** Acquires the log buffer x-lock.
964 @param[in,out] log redo log */
965 void log_buffer_x_lock_enter(log_t &log);
966 
967 /** Releases the log buffer x-lock.
968 @param[in,out] log redo log */
969 void log_buffer_x_lock_exit(log_t &log);
970 #endif /* !UNIV_HOTBACKUP */
971 
972 /** Calculates offset within log files, excluding headers of log files.
973 @param[in] log redo log
974 @param[in] offset real offset (including log file headers)
975 @return size offset excluding log file headers (<= offset) */
976 uint64_t log_files_size_offset(const log_t &log, uint64_t offset);
977 
978 /** Calculates offset within log files, including headers of log files.
979 @param[in] log redo log
980 @param[in] offset size offset (excluding log file headers)
981 @return real offset including log file headers (>= offset) */
982 uint64_t log_files_real_offset(const log_t &log, uint64_t offset);
983 
984 /** Calculates offset within log files, including headers of log files,
985 for the provided lsn value.
986 @param[in] log redo log
987 @param[in] lsn log sequence number
988 @return real offset within the log files */
989 uint64_t log_files_real_offset_for_lsn(const log_t &log, lsn_t lsn);
990 #ifndef UNIV_HOTBACKUP
991 
992 /** Changes size of the log buffer. This is a thread-safe version.
993 It is used by SET GLOBAL innodb_log_buffer_size = X.
994 @param[in,out] log redo log
995 @param[in] new_size requested new size
996 @return true iff succeeded in resize */
997 bool log_buffer_resize(log_t &log, size_t new_size);
998 
999 /** Changes size of the log buffer. This is a non-thread-safe version
1000 which might be invoked only when there are no concurrent possible writes
1001 to the log buffer. It is used in log_buffer_reserve() when a requested
1002 size to reserve is larger than size of the log buffer.
1003 @param[in,out] log redo log
1004 @param[in] new_size requested new size
1005 @param[in] end_lsn maximum lsn written to log buffer
1006 @return true iff succeeded in resize */
1007 bool log_buffer_resize_low(log_t &log, size_t new_size, lsn_t end_lsn);
1008 
1009 /** Resizes the write ahead buffer in the redo log.
1010 @param[in,out] log redo log
1011 @param[in] new_size new size (in bytes) */
1012 void log_write_ahead_resize(log_t &log, size_t new_size);
1013 
1014 /** Updates the field log.dict_max_allowed_checkpoint_lsn.
1015 @param[in,out] log redo log
1016 @param[in] max_lsn new value for the field */
1018 
1019 /** Updates log.dict_persist_margin and recompute free check limit.
1020 @param[in,out] log redo log
1021 @param[in] margin new value for log.dict_persist_margin */
1022 void log_set_dict_persist_margin(log_t &log, sn_t margin);
1023 
1024 /** Increase concurrency_margin used inside log_free_check() calls. */
1026 
1027 /** Prints information about important lsn values used in the redo log,
1028 and some statistics about speed of writing and flushing of data.
1029 @param[in] log redo log for which print information
1030 @param[out] file file where to print */
1031 void log_print(const log_t &log, FILE *file);
1032 
1033 /** Refreshes the statistics used to print per-second averages in log_print().
1034 @param[in,out] log redo log */
1035 void log_refresh_stats(log_t &log);
1036 
1037 /** Creates the first checkpoint ever in the log files. Used during
1038 initialization of new log files. Flushes:
1039  - header of the first log file (including checkpoint headers),
1040  - log block with data addressed by the checkpoint lsn.
1041 @param[in,out] log redo log
1042 @param[in] lsn the first checkpoint lsn */
1044 
1045 /** Calculates limits for maximum age of checkpoint and maximum age of
1046 the oldest page.
1047 @param[in,out] log redo log */
1048 void log_calc_max_ages(log_t &log);
1049 
1050 /** Updates concurrency margin. Uses current value of srv_thread_concurrency.
1051 @param[in,out] log redo log
1052 @retval true if success
1053 @retval false if the redo log is too small to accommodate the number of
1054 OS threads in the database server */
1056 
1057 /** Initializes the log system. Note that the log system is not ready
1058 for user writes after this call is finished. It should be followed by
1059 a call to log_start. Also, log background threads need to be started
1060 manually using log_start_background_threads afterwards.
1061 
1062 Hence the proper order of calls looks like this:
1063  - log_sys_init(),
1064  - log_start(),
1065  - log_start_background_threads().
1066 
1067 @param[in] n_files number of log files
1068 @param[in] file_size size of each log file in bytes
1069 @param[in] space_id space id of the file space with log files */
1070 bool log_sys_init(uint32_t n_files, uint64_t file_size, space_id_t space_id);
1071 
1072 /** Starts the initialized redo log system using a provided
1073 checkpoint_lsn and current lsn. Block for current_lsn must
1074 be properly initialized in the log buffer prior to calling
1075 this function. Therefore a proper value of first_rec_group
1076 must be set for that block before log_start is called.
1077 @param[in,out] log redo log
1078 @param[in] checkpoint_no checkpoint no (sequential number)
1079 @param[in] checkpoint_lsn checkpoint lsn
1080 @param[in] start_lsn current lsn to start at */
1081 void log_start(log_t &log, checkpoint_no_t checkpoint_no, lsn_t checkpoint_lsn,
1082  lsn_t start_lsn);
1083 
1084 /** Validates that the log writer thread is active.
1085 Used only to assert, that the state is correct.
1086 @param[in] log redo log */
1087 void log_writer_thread_active_validate(const log_t &log);
1088 
1089 /** Validates that the log writer, flusher threads are active.
1090 Used only to assert, that the state is correct.
1091 @param[in] log redo log */
1093 
1094 /** Validates that all the log background threads are active.
1095 Used only to assert, that the state is correct.
1096 @param[in] log redo log */
1098 
1099 /** Validates that all the log background threads are inactive.
1100 Used only to assert, that the state is correct.
1101 @param[in] log redo log */
1103 
1104 /** Starts all the log background threads. This can be called only,
1105 when the threads are inactive. This should never be called concurrently.
1106 This may not be called during read-only mode.
1107 @param[in,out] log redo log */
1109 
1110 /** Stops all the log background threads. This can be called only,
1111 when the threads are active. This should never be called concurrently.
1112 This may not be called in read-only mode. Note that is is impossible
1113 to start log background threads in such case.
1114 @param[in,out] log redo log */
1116 
1117 /** Marks the flag which tells log threads to stop and wakes them.
1118 Does not wait until they are stopped. */
1120 
1121 /** Wakes up all log threads which are alive. */
1122 void log_wake_threads(log_t &log);
1123 
1124 /** Pause/Resume the log writer threads based on innodb_log_writer_threads
1125 value.
1126 NOTE: These pause/resume functions should be protected by mutex while serving.
1127 The caller innodb_log_writer_threads_update() is protected
1128 by LOCK_global_system_variables in mysqld. */
1130 
1131 /** Free the log system data structures. Deallocate all the related memory. */
1132 void log_sys_close();
1133 
1134 /** The log writer thread co-routine.
1135  */
1138 /**
1139 @see @ref sect_redo_log_writer
1140 */
1142 /**
1143 @param[in,out] log_ptr pointer to redo log */
1144 void log_writer(log_t *log_ptr);
1145 
1146 /** The log flusher thread co-routine.
1147  */
1150 /**
1151 @see @ref sect_redo_log_flusher
1152 */
1154 /**
1155 @param[in,out] log_ptr pointer to redo log */
1156 void log_flusher(log_t *log_ptr);
1157 
1158 /** The log flush notifier thread co-routine.
1159  */
1162 /**
1163 @see @ref sect_redo_log_flush_notifier
1164 */
1166 /**
1167 @param[in,out] log_ptr pointer to redo log */
1168 void log_flush_notifier(log_t *log_ptr);
1169 
1170 /** The log write notifier thread co-routine.
1171  */
1174 /**
1175 @see @ref sect_redo_log_write_notifier
1176 */
1178 /**
1179 @param[in,out] log_ptr pointer to redo log */
1180 void log_write_notifier(log_t *log_ptr);
1181 
1182 /** The log checkpointer thread co-routine.
1183  */
1186 /**
1187 @see @ref sect_redo_log_checkpointer
1188 */
1190 /**
1191 @param[in,out] log_ptr pointer to redo log */
1192 void log_checkpointer(log_t *log_ptr);
1193 
1194 #define log_checkpointer_mutex_enter(log) \
1195  mutex_enter(&((log).checkpointer_mutex))
1196 
1197 #define log_checkpointer_mutex_exit(log) mutex_exit(&((log).checkpointer_mutex))
1199 #define log_checkpointer_mutex_own(log) \
1200  (mutex_own(&((log).checkpointer_mutex)) || !log_checkpointer_is_active())
1201 
1202 #define log_closer_mutex_enter(log) mutex_enter(&((log).closer_mutex))
1204 #define log_closer_mutex_enter_nowait(log) \
1205  mutex_enter_nowait(&((log).closer_mutex))
1206 
1207 #define log_closer_mutex_exit(log) mutex_exit(&((log).closer_mutex))
1209 #define log_flusher_mutex_enter(log) mutex_enter(&((log).flusher_mutex))
1211 #define log_flusher_mutex_enter_nowait(log) \
1212  mutex_enter_nowait(&((log).flusher_mutex))
1213 
1214 #define log_flusher_mutex_exit(log) mutex_exit(&((log).flusher_mutex))
1216 #define log_flusher_mutex_own(log) \
1217  (mutex_own(&((log).flusher_mutex)) || !log_flusher_is_active())
1218 
1219 #define log_flush_notifier_mutex_enter(log) \
1220  mutex_enter(&((log).flush_notifier_mutex))
1221 
1222 #define log_flush_notifier_mutex_exit(log) \
1223  mutex_exit(&((log).flush_notifier_mutex))
1224 
1225 #define log_flush_notifier_mutex_own(log) \
1226  (mutex_own(&((log).flush_notifier_mutex)) || !log_flush_notifier_is_active())
1227 
1228 #define log_writer_mutex_enter(log) mutex_enter(&((log).writer_mutex))
1230 #define log_writer_mutex_enter_nowait(log) \
1231  mutex_enter_nowait(&((log).writer_mutex))
1232 
1233 #define log_writer_mutex_exit(log) mutex_exit(&((log).writer_mutex))
1235 #define log_writer_mutex_own(log) \
1236  (mutex_own(&((log).writer_mutex)) || !log_writer_is_active())
1237 
1238 #define log_write_notifier_mutex_enter(log) \
1239  mutex_enter(&((log).write_notifier_mutex))
1240 
1241 #define log_write_notifier_mutex_exit(log) \
1242  mutex_exit(&((log).write_notifier_mutex))
1243 
1244 #define log_write_notifier_mutex_own(log) \
1245  (mutex_own(&((log).write_notifier_mutex)) || !log_write_notifier_is_active())
1246 
1247 #define log_limits_mutex_enter(log) mutex_enter(&((log).limits_mutex))
1249 #define log_limits_mutex_exit(log) mutex_exit(&((log).limits_mutex))
1251 #define log_limits_mutex_own(log) mutex_own(&(log).limits_mutex)
1253 #define LOG_SYNC_POINT(a) \
1254  do { \
1255  DEBUG_SYNC_C(a); \
1256  DBUG_EXECUTE_IF(a, DBUG_SUICIDE();); \
1257  if (log_test != nullptr) { \
1258  log_test->sync_point(a); \
1259  } \
1260  } while (0)
1261 
1262 /** Lock redo log. Both current lsn and checkpoint lsn will not change
1263 until the redo log is unlocked.
1264 @param[in,out] log redo log to lock */
1265 void log_position_lock(log_t &log);
1266 
1267 /** Unlock the locked redo log.
1268 @param[in,out] log redo log to unlock */
1269 void log_position_unlock(log_t &log);
1270 
1271 /** Collect coordinates in the locked redo log.
1272 @param[in] log locked redo log
1273 @param[out] current_lsn stores current lsn there
1274 @param[out] checkpoint_lsn stores checkpoint lsn there */
1275 void log_position_collect_lsn_info(const log_t &log, lsn_t *current_lsn,
1276  lsn_t *checkpoint_lsn);
1277 
1278 /** Checks if log writer thread is active.
1279 @return true if and only if the log writer thread is active */
1280 inline bool log_writer_is_active();
1281 
1282 /** Checks if log write notifier thread is active.
1283 @return true if and only if the log write notifier thread is active */
1285 
1286 /** Checks if log flusher thread is active.
1287 @return true if and only if the log flusher thread is active */
1289 
1290 /** Checks if log flush notifier thread is active.
1291 @return true if and only if the log flush notifier thread is active */
1293 
1294 /** Checks if log checkpointer thread is active.
1295 @return true if and only if the log checkpointer thread is active */
1297 
1298 /** Writes encryption information to log header.
1299 @param[in,out] buf log file header
1300 @param[in] key encryption key
1301 @param[in] iv encryption iv
1302 @param[in] is_boot if it's for bootstrap
1303 @param[in] encrypt_key encrypt with master key */
1304 bool log_file_header_fill_encryption(byte *buf, byte *key, byte *iv,
1305  bool is_boot, bool encrypt_key);
1306 
1307 /** Disable redo logging and persist the information.
1308 @param[in,out] log redo log */
1309 void log_persist_disable(log_t &log);
1310 
1311 /** Enable redo logging and persist the information.
1312 @param[in,out] log redo log */
1313 void log_persist_enable(log_t &log);
1314 
1315 /** Persist the information that it is safe to restart server.
1316 @param[in,out] log redo log */
1317 void log_persist_crash_safe(log_t &log);
1318 
1319 #else /* !UNIV_HOTBACKUP */
1320 
1321 #ifdef UNIV_DEBUG
1322 
1323 /** Print a log file header.
1324 @param[in] block pointer to the log buffer */
1325 void meb_log_print_file_hdr(byte *block);
1326 
1327 #endif /* UNIV_DEBUG */
1328 
1329 #endif /* !UNIV_HOTBACKUP */
1330 
1331 #include "log0log.ic"
1332 
1333 #endif /* !log0log_h */
INNODB_LOG_EVENTS_MIN
constexpr ulong INNODB_LOG_EVENTS_MIN
Minimum allowed value of innodb_log_events.
Definition: log0log.h:370
lsn_t
uint64_t lsn_t
Type used for all log sequence number storage and arithmetics.
Definition: log0types.h:60
MY_COMPILER_CLANG_WORKAROUND_REF_DOCBUG
#define MY_COMPILER_CLANG_WORKAROUND_REF_DOCBUG()
ignore -Wdocumentation compiler warnings for @see @ref
Definition: my_compiler.h:342
redo_rotate_default_master_key
void redo_rotate_default_master_key()
Rotate default master key for redo log encryption.
Definition: log0write.cc:2902
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.
Definition: log0buf.cc:1118
lsn
static uint64_t lsn
Definition: xcom_base.cc:429
log_persist_disable
void log_persist_disable(log_t &log)
Disable redo logging and persist the information.
Definition: log0chkp.cc:388
log_block_set_data_len
void log_block_set_data_len(byte *log_block, ulint len)
Sets the log block data length.
log_buffer_resize
bool log_buffer_resize(log_t &log, size_t new_size)
Changes size of the log buffer.
Definition: log0log.cc:1063
MLOG_TEST_GROUP_MAX_REC_N
constexpr uint32_t MLOG_TEST_GROUP_MAX_REC_N
Maximum number of MLOG_TEST records in single group of log records.
Definition: log0log.h:392
log_wait_for_space_in_log_buf
void log_wait_for_space_in_log_buf(log_t &log, sn_t end_sn)
Waits until there is free space in the log buffer.
Definition: log0buf.cc:807
log_block_get_checksum
uint32_t log_block_get_checksum(const byte *log_block)
Gets value of a log block checksum field.
log_refresh_stats
void log_refresh_stats(log_t &log)
Refreshes the statistics used to print per-second averages in log_print().
Definition: log0log.cc:998
log_get_checkpoint_age
lsn_t log_get_checkpoint_age(const log_t &log)
Calculates age of current checkpoint as number of bytes since last checkpoint.
log_writer_is_active
bool log_writer_is_active()
Checks if log writer thread is active.
SN_MAX
constexpr sn_t SN_MAX
Ensure, that 64 bits are enough to represent lsn values, when 63 bits are used to represent sn values...
Definition: log0log.h:151
log_block_set_hdr_no
void log_block_set_hdr_no(byte *log_block, uint32_t n)
Sets the log block number stored in the header.
INNODB_LOG_RECENT_CLOSED_SIZE_MIN
constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_MIN
Minimum allowed value of innodb_log_recent_closed_size.
Definition: log0log.h:361
LOG_HEADER_PAD1
constexpr uint32_t LOG_HEADER_PAD1
4 unused (zero-initialized) bytes.
Definition: log0log.h:198
INNODB_LOG_WRITE_AHEAD_SIZE_DEFAULT
constexpr ulong INNODB_LOG_WRITE_AHEAD_SIZE_DEFAULT
Default value of innodb_log_write_ahead_size (in bytes).
Definition: log0log.h:376
log_checkpointer
void log_checkpointer(log_t *log_ptr)
The log checkpointer thread co-routine.
Definition: log0chkp.cc:1028
my_compiler.h
LOG_BLOCK_FIRST_REC_GROUP
constexpr uint32_t LOG_BLOCK_FIRST_REC_GROUP
Offset of the first start of mtr log record group in this log block.
Definition: log0log.h:117
log_write_ahead_resize
void log_write_ahead_resize(log_t &log, size_t new_size)
Resizes the write ahead buffer in the redo log.
Definition: log0log.cc:1080
ut_ad
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:66
INNODB_LOG_WRITE_MAX_SIZE_DEFAULT
constexpr ulint INNODB_LOG_WRITE_MAX_SIZE_DEFAULT
Constants related to server variables (default, min and max values).
Definition: log0log.h:268
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.
Definition: log0log.cc:1013
log_block_set_flush_bit
void log_block_set_flush_bit(byte *log_block, bool value)
Sets the log block flush bit.
INNODB_LOG_BUFFER_SIZE_MIN
constexpr ulong INNODB_LOG_BUFFER_SIZE_MIN
Minimum allowed value of innodb_log_buffer_size.
Definition: log0log.h:343
INNODB_LOG_FLUSH_NOTIFIER_SPIN_DELAY_DEFAULT
constexpr ulong INNODB_LOG_FLUSH_NOTIFIER_SPIN_DELAY_DEFAULT
Default value of innodb_log_flush_notifier_spin_delay (in spin rounds).
Definition: log0log.h:334
INNODB_LOG_WRITER_TIMEOUT_DEFAULT
constexpr ulong INNODB_LOG_WRITER_TIMEOUT_DEFAULT
Default value of innodb_log_writer_timeout (in microseconds).
Definition: log0log.h:283
log_block_get_data_len
uint32_t log_block_get_data_len(const byte *log_block)
Gets a log block data length.
SN_LOCKED
constexpr sn_t SN_LOCKED
The sn bit to express locked state.
Definition: log0log.h:154
log_calc_max_ages
void log_calc_max_ages(log_t &log)
Calculates limits for maximum age of checkpoint and maximum age of the oldest page.
Definition: log0chkp.cc:1176
log_needs_free_check
bool log_needs_free_check()
OS_FILE_LOG_BLOCK_SIZE
#define OS_FILE_LOG_BLOCK_SIZE
The next value should be smaller or equal to the smallest sector size used on any disk.
Definition: os0file.h:182
LOG_HEADER_FORMAT
constexpr uint32_t LOG_HEADER_FORMAT
Offsets used in a log file header.
Definition: log0log.h:195
LOG_CHECKPOINT_EXTRA_FREE
constexpr uint32_t LOG_CHECKPOINT_EXTRA_FREE
Absolute margin for the free space in the log, before a new query step which modifies the database,...
Definition: log0log.h:68
log_stop_background_threads_nowait
void log_stop_background_threads_nowait(log_t &log)
Marks the flag which tells log threads to stop and wakes them.
Definition: log0log.cc:845
handle
void * handle
Definition: engine_loader.c:19
log_print
void log_print(const log_t &log, FILE *file)
Prints information about important lsn values used in the redo log, and some statistics about speed o...
Definition: log0log.cc:939
INNODB_LOG_WRITE_NOTIFIER_TIMEOUT_DEFAULT
constexpr ulong INNODB_LOG_WRITE_NOTIFIER_TIMEOUT_DEFAULT
Default value of innodb_log_write_notifier_timeout (in microseconds).
Definition: log0log.h:331
log_files_real_offset_for_lsn
uint64_t log_files_real_offset_for_lsn(const log_t &log, lsn_t lsn)
Calculates offset within log files, including headers of log files, for the provided lsn value.
Definition: log0write.cc:1299
checkpoint_no_t
uint64_t checkpoint_no_t
Type used for checkpoint numbers (consecutive checkpoints receive a number which is increased by one)...
Definition: log0types.h:77
Wait_stats
Definition: ut0ut.h:893
INNODB_LOG_FLUSH_NOTIFIER_TIMEOUT_DEFAULT
constexpr ulong INNODB_LOG_FLUSH_NOTIFIER_TIMEOUT_DEFAULT
Default value of innodb_log_flush_notifier_timeout (in microseconds).
Definition: log0log.h:337
log_files_write_checkpoint
void log_files_write_checkpoint(log_t &log, lsn_t next_checkpoint_lsn)
Writes the next checkpoint info to header of the first log file.
Definition: log0chkp.cc:502
log_files_header_fill
void log_files_header_fill(byte *buf, lsn_t start_lsn, const char *creator, bool no_logging, bool crash_unsafe)
Fill redo log header.
Definition: log0chkp.cc:301
LOG_HEADER_SET_FLAG
void LOG_HEADER_SET_FLAG(uint32_t &flag, uint32_t bit)
Set a specific bit in flag.
Definition: log0log.h:231
log_calc_concurrency_margin
bool log_calc_concurrency_margin(log_t &log)
Updates concurrency margin.
Definition: log0chkp.cc:1132
log_lsn_validate
bool log_lsn_validate(lsn_t lsn)
Validates a given lsn value.
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.
Definition: log0buf.cc:1265
log_translate_sn_to_lsn
constexpr lsn_t log_translate_sn_to_lsn(lsn_t sn)
Calculates lsn value for given sn value.
value
const string value("\"Value\"")
INNODB_LOG_SPIN_CPU_ABS_LWM_DEFAULT
constexpr ulong INNODB_LOG_SPIN_CPU_ABS_LWM_DEFAULT
Default value of innodb_log_spin_cpu_abs_lwm.
Definition: log0log.h:287
log_buffer_write_completed
void log_buffer_write_completed(log_t &log, const Log_handle &handle, lsn_t start_lsn, lsn_t end_lsn)
Adds a link start_lsn -> end_lsn to the log recent written buffer.
Definition: log0buf.cc:1036
log_block_calc_checksum
uint32_t log_block_calc_checksum(const byte *log_block)
Calculates the checksum for a log block.
true
#define true
Definition: config_static.h:44
LOG_CHECKPOINT_2
constexpr uint32_t LOG_CHECKPOINT_2
Second checkpoint field in the header of the first log file.
Definition: log0log.h:260
LOG_HEADER_CHECK_FLAG
bool LOG_HEADER_CHECK_FLAG(uint32_t flag, uint32_t bit)
Check a specific bit in flag.
Definition: log0log.h:241
key
static const char * key
Definition: suite_stubs.c:14
INNODB_LOG_RECENT_WRITTEN_SIZE_MAX
constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_MAX
Maximum allowed value of innodb_log_recent_written_size.
Definition: log0log.h:355
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.
Definition: log0buf.cc:1192
INNODB_LOG_WRITE_AHEAD_SIZE_MAX
constexpr ulint INNODB_LOG_WRITE_AHEAD_SIZE_MAX
Maximum allowed value of innodb_log_write_ahead_size.
Definition: log0log.h:382
log_files_update_offsets
void log_files_update_offsets(log_t &log, lsn_t lsn)
Updates current_file_lsn and current_file_real_offset to correspond to a given lsn.
Definition: log0write.cc:1329
log_stop_background_threads
void log_stop_background_threads(log_t &log)
Stops all the log background threads.
Definition: log0log.cc:797
LOG_HEADER_FLAG_NO_LOGGING
constexpr uint32_t LOG_HEADER_FLAG_NO_LOGGING
Flag at BIT-1 to indicate if redo logging is disabled or not.
Definition: log0log.h:215
LOG_NO_CHECKSUM_MAGIC
constexpr uint32_t LOG_NO_CHECKSUM_MAGIC
Magic value to use instead of log checksums when they are disabled.
Definition: log0log.h:64
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,...
LOG_CHECKPOINT_LSN
constexpr uint32_t LOG_CHECKPOINT_LSN
Checkpoint lsn.
Definition: log0log.h:175
log_block_set_first_rec_group
void log_block_set_first_rec_group(byte *log_block, uint32_t offset)
Sets an offset to the beginning of the first group of log records in a given log block.
LOG_HEADER_START_LSN
constexpr uint32_t LOG_HEADER_START_LSN
LSN of the start of data in this log file (with format version 1 and 2).
Definition: log0log.h:201
n
int n
Definition: xcom_base.cc:445
log_write_up_to
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:1029
log_test
std::unique_ptr< Log_test > log_test
Represents currently running test of redo log, nullptr otherwise.
Definition: log0test.cc:52
MLOG_TEST_VALUE
constexpr int64_t MLOG_TEST_VALUE
Value to which MLOG_TEST records should sum up within a group.
Definition: log0log.h:386
log_sys_close
void log_sys_close()
Free the log system data structures.
Definition: log0log.cc:667
INNODB_LOG_WAIT_FOR_FLUSH_SPIN_HWM_DEFAULT
constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_SPIN_HWM_DEFAULT
Default value of innodb_log_wait_for_flush_spin_hwm (in microseconds).
Definition: log0log.h:314
MAX_LOG_FILE_NAME
constexpr uint32_t MAX_LOG_FILE_NAME
Definition: log0log.h:61
log_set_dict_max_allowed_checkpoint_lsn
void log_set_dict_max_allowed_checkpoint_lsn(log_t &log, lsn_t max_lsn)
Updates the field log.dict_max_allowed_checkpoint_lsn.
Definition: log0chkp.cc:1280
log_buffer_flush_order_lag
lsn_t log_buffer_flush_order_lag(const log_t &log)
LOG_BLOCK_MAX_NO
constexpr uint32_t LOG_BLOCK_MAX_NO
Maximum allowed block's number (stored in hdr_no).
Definition: log0log.h:101
log_flush_notifier
void log_flush_notifier(log_t *log_ptr)
The log flush notifier thread co-routine.
Definition: log0write.cc:2660
log_buffer_set_first_record_group
void log_buffer_set_first_record_group(log_t &log, const Log_handle &handle, 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 ...
Definition: log0buf.cc:1137
log_block_get_checkpoint_no
uint32_t log_block_get_checkpoint_no(const byte *log_block)
Gets a log block checkpoint number field (4 lowest bytes).
log_writer
void log_writer(log_t *log_ptr)
The log writer thread co-routine.
Definition: log0write.cc:2130
log_checkpointer_is_active
bool log_checkpointer_is_active()
Checks if log checkpointer thread is active.
INNODB_LOG_CHECKPOINT_EVERY_DEFAULT
constexpr ulong INNODB_LOG_CHECKPOINT_EVERY_DEFAULT
Default value of innodb_log_checkpointer_every (in milliseconds).
Definition: log0log.h:271
INNODB_LOG_SPIN_CPU_PCT_HWM_DEFAULT
constexpr uint INNODB_LOG_SPIN_CPU_PCT_HWM_DEFAULT
Default value of innodb_log_spin_cpu_pct_hwm.
Definition: log0log.h:291
log_sys
log_t * log_sys
Redo log system (singleton).
Definition: log0log.cc:373
LOG_HEADER_FLAG_MAX
constexpr uint32_t LOG_HEADER_FLAG_MAX
Maximum BIT position number.
Definition: log0log.h:223
LSN_MAX
constexpr lsn_t LSN_MAX
Maximum possible lsn value is slightly higher than the maximum sn value, because lsn sequence enumera...
Definition: log0log.h:160
LOG_CHECKPOINT_1
constexpr uint32_t LOG_CHECKPOINT_1
First checkpoint field in the log header.
Definition: log0log.h:254
MLOG_TEST_REC_OVERHEAD
constexpr uint32_t MLOG_TEST_REC_OVERHEAD
Bytes consumed by MLOG_TEST record with an empty payload.
Definition: log0log.h:395
log_set_dict_persist_margin
void log_set_dict_persist_margin(log_t &log, sn_t margin)
Updates log.dict_persist_margin and recompute free check limit.
Definition: log0chkp.cc:1273
log0types.h
dyn0buf.h
log_make_latest_checkpoint
bool log_make_latest_checkpoint(log_t &log)
Make a checkpoint at the current lsn.
Definition: log0chkp.cc:770
LOG_CHECKPOINT_OFFSET
constexpr uint32_t LOG_CHECKPOINT_OFFSET
Offset within the log files, which corresponds to checkpoint lsn.
Definition: log0log.h:179
INNODB_LOG_WAIT_FOR_FLUSH_SPIN_DELAY_DEFAULT
constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_SPIN_DELAY_DEFAULT
Default value of innodb_log_wait_for_flush_spin_delay (in spin rounds).
Definition: log0log.h:311
LOG_ENCRYPTION
constexpr uint32_t LOG_ENCRYPTION
Log Encryption information in redo log header.
Definition: log0log.h:257
log_block_get_flush_bit
bool log_block_get_flush_bit(const byte *log_block)
Gets a log block flush bit.
log_block_store_checksum
void log_block_store_checksum(byte *log_block)
Stores a 4-byte checksum to the trailer checksum field of a log block.
log_control_writer_threads
void log_control_writer_threads(log_t &log)
Pause/Resume the log writer threads based on innodb_log_writer_threads value.
Definition: log0log.cc:918
log_update_buf_limit
void log_update_buf_limit(log_t &log)
Updates limit used when writing to log buffer.
Definition: log0buf.cc:793
log_checksum_algorithm_ptr
log_checksum_func_t log_checksum_algorithm_ptr
Pointer to the log checksum calculation function.
Definition: log0log.cc:61
log_t
Redo log - single data structure with state of the redo log system.
Definition: log0types.h:133
log_sys_init
bool log_sys_init(uint32_t n_files, uint64_t file_size, space_id_t space_id)
Initializes the log system.
Definition: log0log.cc:486
INNODB_LOG_RECENT_WRITTEN_SIZE_MIN
constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_MIN
Minimum allowed value of innodb_log_recent_written_size.
Definition: log0log.h:352
log_start
void log_start(log_t &log, checkpoint_no_t checkpoint_no, lsn_t checkpoint_lsn, lsn_t start_lsn)
Starts the initialized redo log system using a provided checkpoint_lsn and current lsn.
Definition: log0log.cc:596
log_buffer_x_lock_exit
void log_buffer_x_lock_exit(log_t &log)
Releases the log buffer x-lock.
Definition: log0buf.cc:635
log_block_convert_lsn_to_no
uint32_t log_block_convert_lsn_to_no(lsn_t lsn)
Converts a lsn to a log block number.
log_write_notifier
void log_write_notifier(log_t *log_ptr)
The log write notifier thread co-routine.
Definition: log0write.cc:2542
LOG_POOL_CHECKPOINT_RATIO_ASYNC
constexpr uint32_t LOG_POOL_CHECKPOINT_RATIO_ASYNC
Controls asynchronous making of a new checkpoint.
Definition: log0log.h:78
log_persist_enable
void log_persist_enable(log_t &log)
Enable redo logging and persist the information.
Definition: log0chkp.cc:375
sn_t
uint64_t sn_t
Type used for sn values, which enumerate bytes of data stored in the log.
Definition: log0types.h:70
log_file_header_fill_encryption
bool log_file_header_fill_encryption(byte *buf, byte *key, byte *iv, bool is_boot, bool encrypt_key)
Writes encryption information to log header.
Definition: log0write.cc:2843
uint
unsigned int uint
Definition: uca-dump.cc:29
log_start_background_threads
void log_start_background_threads(log_t &log)
Starts all the log background threads.
Definition: log0log.cc:757
LOG_POOL_PREFLUSH_RATIO_ASYNC
constexpr uint32_t LOG_POOL_PREFLUSH_RATIO_ASYNC
Controls asynchronous preflushing of modified buffer pages.
Definition: log0log.h:85
INNODB_LOG_RECENT_WRITTEN_SIZE_DEFAULT
constexpr ulong INNODB_LOG_RECENT_WRITTEN_SIZE_DEFAULT
Default value of innodb_log_recent_written_size (in bytes).
Definition: log0log.h:349
LOG_BLOCK_FLUSH_BIT_MASK
constexpr uint32_t LOG_BLOCK_FLUSH_BIT_MASK
Mask used to get the highest bit in the hdr_no field.
Definition: log0log.h:98
LOG_POOL_PREFLUSH_RATIO_SYNC
constexpr uint32_t LOG_POOL_PREFLUSH_RATIO_SYNC
Controls synchronous preflushing of modified buffer pages.
Definition: log0log.h:81
LOG_HEADER_FLAGS
constexpr uint32_t LOG_HEADER_FLAGS
32 BITs flag
Definition: log0log.h:212
INNODB_LOG_WRITE_AHEAD_SIZE_MIN
constexpr ulong INNODB_LOG_WRITE_AHEAD_SIZE_MIN
Minimum allowed value of innodb_log_write_ahead_size.
Definition: log0log.h:379
LOG_BLOCK_TRL_SIZE
constexpr uint32_t LOG_BLOCK_TRL_SIZE
Size of the log block footer (trailer) in bytes.
Definition: log0log.h:134
log_get_lsn
lsn_t log_get_lsn(const log_t &log)
Gets the current lsn value.
log_create_first_checkpoint
void log_create_first_checkpoint(log_t &log, lsn_t lsn)
Creates the first checkpoint ever in the log files.
Definition: log0chkp.cc:645
rules_table_service::end
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:188
log_block_get_first_rec_group
uint32_t log_block_get_first_rec_group(const byte *log_block)
Gets an offset to the beginning of the first group of log records in a given log block.
INNODB_LOG_RECENT_CLOSED_SIZE_DEFAULT
constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_DEFAULT
Default value of innodb_log_recent_closed_size (in bytes).
Definition: log0log.h:358
INNODB_LOG_WRITE_NOTIFIER_SPIN_DELAY_DEFAULT
constexpr ulong INNODB_LOG_WRITE_NOTIFIER_SPIN_DELAY_DEFAULT
Default value of innodb_log_write_notifier_spin_delay (in spin rounds).
Definition: log0log.h:328
log_free_check_wait
void log_free_check_wait(log_t &log)
Waits until there is free space in log files which includes concurrency margin required for all threa...
Definition: log0chkp.cc:1303
log_flush_notifier_is_active
bool log_flush_notifier_is_active()
Checks if log flush notifier thread is active.
INNODB_LOG_FLUSHER_SPIN_DELAY_DEFAULT
constexpr ulong INNODB_LOG_FLUSHER_SPIN_DELAY_DEFAULT
Default value of innodb_log_flusher_spin_delay (in spin rounds).
Definition: log0log.h:321
log_persist_crash_safe
void log_persist_crash_safe(log_t &log)
Persist the information that it is safe to restart server.
Definition: log0chkp.cc:404
consts::FILE
const std::string FILE("FILE")
LOG_CHECKPOINT_NO
constexpr uint32_t LOG_CHECKPOINT_NO
Checkpoint number.
Definition: log0log.h:167
log_rotate_encryption
bool log_rotate_encryption()
Rotate the redo log encryption It will re-encrypt the redo log encryption metadata and write it to re...
Definition: log0write.cc:2891
log_translate_lsn_to_sn
lsn_t log_translate_lsn_to_sn(lsn_t lsn)
Calculates sn value for given lsn value.
log_request_checkpoint
void log_request_checkpoint(log_t &log, bool sync, lsn_t lsn)
Requests a sharp checkpoint write for provided or greater lsn.
buf
Definition: buf0block_hint.cc:29
log_buffer_flush_to_disk
void log_buffer_flush_to_disk(log_t &log, bool sync=true)
Write to the log file up to the last log entry.
Definition: log0buf.cc:1170
log_buffer_sync_in_background
void log_buffer_sync_in_background()
Writes the log buffer to the log file.
Definition: log0buf.cc:1179
log_write_notifier_is_active
bool log_write_notifier_is_active()
Checks if log write notifier thread is active.
log_files_real_offset
uint64_t log_files_real_offset(const log_t &log, uint64_t offset)
Calculates offset within log files, including headers of log files.
Definition: log0write.cc:1292
log_block_set_checksum
void log_block_set_checksum(byte *log_block, uint32_t checksum)
Sets value of a log block checksum field.
INNODB_LOG_WAIT_FOR_WRITE_SPIN_DELAY_DEFAULT
constexpr ulong INNODB_LOG_WAIT_FOR_WRITE_SPIN_DELAY_DEFAULT
Default value of innodb_log_wait_for_write_spin_delay (in spin rounds).
Definition: log0log.h:303
LOG_CHECKPOINT_FREE_PER_THREAD
constexpr uint32_t LOG_CHECKPOINT_FREE_PER_THREAD
Per thread margin for the free space in the log, before a new query step which modifies the database,...
Definition: log0log.h:74
log_wait_for_space
void log_wait_for_space(log_t &log, sn_t end_sn)
Waits until there is free space for range of sn values ending at the provided sn, in both the log buf...
LOG_BLOCK_HDR_NO
constexpr uint32_t LOG_BLOCK_HDR_NO
Block number which must be > 0 and is allowed to wrap around at 1G.
Definition: log0log.h:95
MY_COMPILER_DIAGNOSTIC_PUSH
#define MY_COMPILER_DIAGNOSTIC_PUSH()
Definition: my_compiler.h:295
LOG_HEADER_CREATOR
constexpr uint32_t LOG_HEADER_CREATOR
A null-terminated string which will contain either the string 'MEB' and the MySQL version if the log ...
Definition: log0log.h:206
log_write_encryption
bool log_write_encryption(byte *key, byte *iv, bool is_boot)
Write the encryption info into the log file header(the 3rd block).
Definition: log0write.cc:2859
INNODB_LOG_RECENT_CLOSED_SIZE_MAX
constexpr ulong INNODB_LOG_RECENT_CLOSED_SIZE_MAX
Maximum allowed value of innodb_log_recent_closed_size.
Definition: log0log.h:364
LOG_HEADER_FLAG_CRASH_UNSAFE
constexpr uint32_t LOG_HEADER_FLAG_CRASH_UNSAFE
Flag at BIT-2 to indicate if server is not recoverable on crash.
Definition: log0log.h:220
log_free_check
void log_free_check()
Any database operation should call this when it has modified more than about 4 pages.
log_buffer_dirty_pages_added_up_to_lsn
lsn_t log_buffer_dirty_pages_added_up_to_lsn(const log_t &log)
log0test.h
log_flusher_is_active
bool log_flusher_is_active()
Checks if log flusher thread is active.
LOG_CHECKPOINT_LOG_BUF_SIZE
constexpr uint32_t LOG_CHECKPOINT_LOG_BUF_SIZE
Size of the log buffer, when the checkpoint write was started.
Definition: log0log.h:188
INNODB_LOG_EVENTS_DEFAULT
constexpr ulong INNODB_LOG_EVENTS_DEFAULT
Default value of innodb_log_events (number of events).
Definition: log0log.h:367
log_files_downgrade
void log_files_downgrade(log_t &log)
Changes format of redo files to previous format version.
Definition: log0chkp.cc:446
LOG_START_LSN
constexpr lsn_t LOG_START_LSN
The counting of lsn's starts from this value: this must be non-zero.
Definition: log0log.h:88
INNODB_LOG_BUFFER_SIZE_MAX
constexpr ulong INNODB_LOG_BUFFER_SIZE_MAX
Maximum allowed value of innodb_log_buffer_size.
Definition: log0log.h:346
Log_handle
Definition: log0types.h:125
file
Definition: os0file.h:85
INNODB_LOG_FLUSHER_TIMEOUT_DEFAULT
constexpr ulong INNODB_LOG_FLUSHER_TIMEOUT_DEFAULT
Default value of innodb_log_flusher_timeout (in microseconds).
Definition: log0log.h:325
LOG_BLOCK_DATA_SIZE
constexpr uint32_t LOG_BLOCK_DATA_SIZE
Size of log block's data fragment (where actual data is stored).
Definition: log0log.h:140
log_block_calc_checksum_none
uint32_t log_block_calc_checksum_none(const byte *log_block)
Calculates the checksum for a log block using the "no-op" algorithm.
INNODB_LOG_BUFFER_SIZE_DEFAULT
constexpr ulong INNODB_LOG_BUFFER_SIZE_DEFAULT
Default value of innodb_log_buffer_size (in bytes).
Definition: log0log.h:340
log_buffer_ready_for_write_lsn
lsn_t log_buffer_ready_for_write_lsn(const log_t &log)
LOG_FILE_HDR_SIZE
constexpr uint32_t LOG_FILE_HDR_SIZE
Size of log file's header.
Definition: log0log.h:263
LOG_HEADER_CREATOR_END
constexpr uint32_t LOG_HEADER_CREATOR_END
End of the log file creator field.
Definition: log0log.h:209
space_id_t
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
LOG_BLOCK_HDR_SIZE
constexpr uint32_t LOG_BLOCK_HDR_SIZE
Size of the log block's header in bytes.
Definition: log0log.h:125
log_position_unlock
void log_position_unlock(log_t &log)
Unlock the locked redo log.
Definition: log0log.cc:1256
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,...
file_size
static size_t file_size
Definition: mysql_config_editor.cc:70
log_buffer_write
lsn_t log_buffer_write(log_t &log, const Log_handle &handle, const byte *str, size_t str_len, lsn_t start_lsn)
Writes data to the log buffer.
Definition: log0buf.cc:897
log_update_limits
void log_update_limits(log_t &log)
Updates limits related to free space in redo log files: log.available_for_checkpoint_lsn and log....
Definition: log0chkp.cc:1267
log_block_calc_checksum_crc32
uint32_t log_block_calc_checksum_crc32(const byte *log_block)
Calculates the checksum for a log block using the MySQL 5.7 algorithm.
dblwr::n_files
ulong n_files
Number of files to use for the double write buffer.
Definition: buf0dblwr.cc:76
log_get_free_check_capacity
lsn_t log_get_free_check_capacity(const log_t &log)
Computes capacity of redo log available until log_free_check() reaches point where it needs to wait.
Definition: log0chkp.cc:1294
LOG_BLOCK_CHECKSUM
constexpr uint32_t LOG_BLOCK_CHECKSUM
4 byte checksum of the log block contents.
Definition: log0log.h:131
log_flusher
void log_flusher(log_t *log_ptr)
The log flusher thread co-routine.
Definition: log0write.cc:2400
log_get_max_modified_age_async
lsn_t log_get_max_modified_age_async(const log_t &log)
When the oldest dirty page age exceeds this value, we start an asynchronous preflush of dirty pages.
Definition: log0chkp.cc:1334
log_background_threads_active_validate
void log_background_threads_active_validate(const log_t &log)
Validates that all the log background threads are active.
Definition: log0log.cc:741
log_sync_flush_lsn
lsn_t log_sync_flush_lsn(log_t &log)
Computes lsn up to which sync flush should be done or returns 0 if there is no need to execute sync f...
Definition: log0chkp.cc:835
log_wake_threads
void log_wake_threads(log_t &log)
Wakes up all log threads which are alive.
Definition: log0log.cc:851
log_buffer_x_lock_enter
void log_buffer_x_lock_enter(log_t &log)
Acquires the log buffer x-lock.
Definition: log0buf.cc:550
sync0rw.h
log_files_size_offset
uint64_t log_files_size_offset(const log_t &log, uint64_t offset)
Calculates offset within log files, excluding headers of log files.
Definition: log0write.cc:1286
INNODB_LOG_WAIT_FOR_FLUSH_TIMEOUT_DEFAULT
constexpr ulong INNODB_LOG_WAIT_FOR_FLUSH_TIMEOUT_DEFAULT
Default value of innodb_log_wait_for_flush_timeout (in microseconds).
Definition: log0log.h:317
INNODB_LOG_EVENTS_MAX
constexpr ulong INNODB_LOG_EVENTS_MAX
Maximum allowed value of innodb_log_events.
Definition: log0log.h:373
LOG_BLOCK_CHECKPOINT_NO
constexpr uint32_t LOG_BLOCK_CHECKPOINT_NO
4 lower bytes of the value of log_sys->next_checkpoint_no when the log block was last written to: if ...
Definition: log0log.h:122
log_checksum_func_t
std::atomic< uint32_t(*)(const byte *log_block)> log_checksum_func_t
Function used to calculate checksums of log blocks.
Definition: log0types.h:84
INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT
constexpr ulong INNODB_LOG_WRITER_SPIN_DELAY_DEFAULT
Default value of innodb_log_writer_spin_delay (in spin rounds).
Definition: log0log.h:279
log_background_threads_inactive_validate
void log_background_threads_inactive_validate(const log_t &log)
Validates that all the log background threads are inactive.
Definition: log0log.cc:749
LOG_HEADER_SIZE
constexpr uint32_t LOG_HEADER_SIZE
Current total size of LOG header.
Definition: log0log.h:226
log_position_lock
void log_position_lock(log_t &log)
Lock redo log.
Definition: log0log.cc:1250
log_position_collect_lsn_info
void log_position_collect_lsn_info(const log_t &log, lsn_t *current_lsn, lsn_t *checkpoint_lsn)
Collect coordinates in the locked redo log.
Definition: log0log.cc:1262
LOG_BLOCK_HDR_DATA_LEN
constexpr uint32_t LOG_BLOCK_HDR_DATA_LEN
Number of bytes written to this block (also header bytes).
Definition: log0log.h:104
log_read_encryption
bool log_read_encryption()
Definition: log0write.cc:2778
log_buffer_reserve
Log_handle log_buffer_reserve(log_t &log, size_t len)
Reserves space in the redo log for following write operations.
Definition: log0buf.cc:834
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,...
Definition: log0buf.cc:1101
log_background_write_threads_active_validate
void log_background_write_threads_active_validate(const log_t &log)
Validates that the log writer, flusher threads are active.
Definition: log0log.cc:734
MY_COMPILER_DIAGNOSTIC_POP
#define MY_COMPILER_DIAGNOSTIC_POP()
Definition: my_compiler.h:296
LOG_BLOCK_ENCRYPT_BIT_MASK
constexpr uint32_t LOG_BLOCK_ENCRYPT_BIT_MASK
Mask used to get the highest bit in the data len field, this bit is to indicate if this block is encr...
Definition: log0log.h:108
log_block_get_hdr_no
uint32_t log_block_get_hdr_no(const byte *log_block)
Gets a log block number stored in the header.
MLOG_TEST_MAX_REC_LEN
constexpr uint32_t MLOG_TEST_MAX_REC_LEN
Maximum size of single MLOG_TEST record (in bytes).
Definition: log0log.h:389
flag
static int flag
Definition: hp_test1.cc:39
log_files_header_read
void log_files_header_read(log_t &log, uint32_t header)
Reads a log file header page to log.checkpoint_buf.
Definition: log0chkp.cc:360
INNODB_LOG_WAIT_FOR_WRITE_TIMEOUT_DEFAULT
constexpr ulong INNODB_LOG_WAIT_FOR_WRITE_TIMEOUT_DEFAULT
Default value of innodb_log_wait_for_write_timeout (in microseconds).
Definition: log0log.h:306
log_increase_concurrency_margin
void log_increase_concurrency_margin(log_t &log)
Increase concurrency_margin used inside log_free_check() calls.
Definition: log0chkp.cc:1234
log_block_set_checkpoint_no
void log_block_set_checkpoint_no(byte *log_block, uint64_t no)
Sets a log block checkpoint number field (4 lowest bytes).
log_writer_thread_active_validate
void log_writer_thread_active_validate(const log_t &log)
Validates that the log writer thread is active.
Definition: log0log.cc:730
log_files_header_flush
void log_files_header_flush(log_t &log, uint32_t nth_file, lsn_t start_lsn)
Writes a log file header to the log file space.
Definition: log0chkp.cc:327
log_get_checkpoint_lsn
lsn_t log_get_checkpoint_lsn(const log_t &log)
Gets the last checkpoint lsn stored and flushed to disk.
ib_logfile_basename
constexpr const char *const ib_logfile_basename
Prefix for name of log file, e.g.
Definition: log0log.h:58