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