MySQL 26.7.0
Source Code Documentation
log0files_io.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2019, 2026, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/**************************************************/ /**
29 @file include/log0files_io.h
30
31 The log0files_io.{cc,h} is a low-level independent library for IO operations
32 performed directly on redo log files.
33
34 The library provides functions which allow to:
35 - serialize,
36 - deserialize,
37 - read,
38 - or write
39each kind of header stored in redo log files, and individual redo log blocks.
40
41NOTE: Parsing of individual redo records is NOT in scope of this library.
42
43@remarks
44
45Main goal for this library is to make IO operations simpler, no matter what
46is the motivation behind reading or writing fragments of redo log files.
47
48That's why:
49
501. Functions defined in this library form a set of simple independent tools.
51They are state-less (they do not change state of the library, but obviously
52"write" functions might change redo log files).
53
542. For each kind of redo header, three forms of the header are recognized:
55 - structure with typed fields (e.g. struct Log_checkpoint_header),
56 - array of bytes representing the serialized header,
57 - data stored on disk.
58Functions to translate between any two of these forms are provided for each
59kind of header. In order to make life easier (when having to remind yourself
60what was the name for the given function), the following naming convention
61has been defined:
62 - structure -> array of bytes: log_X_header_serialize,
63 - array of bytes -> structure: log_X_header_deserialize,
64 - structure -> disk: log_X_header_write(Log_file_id, ..., const The_struct& ),
65 - disk -> structure: log_X_header_read(Log_file_id, ..., The_struct& ),
66 - array of bytes -> disk: log_X_header_write(Log_file_id, ..., const byte* ),
67 - disk -> array of bytes: log_X_header_read(Log_file_id, ..., byte* ).
68
69@note There is no structure with typed fields for encryption header (yet) and
70for redo data blocks.
71
723. The functions defined in this library MUST NOT depend on log_t or recovery
73implementation, because this library is designed to be lightweight and easy
74to use.
75
76@note
77
78Functions that operate on set of redo files are also part of this library.
79This includes functions to:
80 - build a path to the redo log file with the given id,
81 - list existing redo files,
82 - remove redo files,
83 - create empty redo files,
84 - mark/unmark individual redo files as unused.
85
86*******************************************************/
87
88#ifndef log0files_io_h
89#define log0files_io_h
90
91#include <string>
92
93/* Log_file_header, Log_checkpoint_header, LOG_BLOCK_HDR_NO */
94#include "log0types.h"
95
96/* mach_read_from_X, mach_write_to_X */
97#include "mach0data.h"
98
99/* ut_crc32() */
100#include "ut0crc32.h"
101
102/* ut::vector */
103#include "ut0new.h"
104
106
107/** Atomic pointer to the log checksum calculation function. This is actually
108the only remaining "state" of the library. Hopefully can become removed. */
110
111/** Computes checksum of the given header and verifies if the checksum
112is the same as the one stored in that header.
113@param[in] buf header to verify
114@return true iff checksums are the same */
115bool log_header_checksum_is_ok(const byte *buf);
116
117/**************************************************/ /**
118
119 @name Log - file header read/write.
120
121 *******************************************************/
122
123/** @{ */
124
125/** Serializes the log file header to the buffer.
126@param[in] header the header to serialize
127@param[out] buf the allocated buffer */
128void log_file_header_serialize(const Log_file_header &header, byte *buf);
129
130/** Deserializes the log file header stored in the buffer.
131@param[in] buf the buffer to deserialize
132@param[out] header the deserialized header
133@return true iff checksum is correct */
134bool log_file_header_deserialize(const byte *buf, Log_file_header &header);
135
136/** Serializes and writes the log file header to the log file.
137@param[in] file_handle handle for the opened log file
138@param[in] header the file header
139@return DB_SUCCESS or error */
141 const Log_file_header &header);
142
143/** Writes the serialized log file header to the log file.
144@param[in] file_handle handle for the opened log file
145@param[in] buf the serialized file header
146@return DB_SUCCESS or error */
147dberr_t log_file_header_write(Log_file_handle &file_handle, const byte *buf);
148
149/** Reads the serialized log file header to the buffer.
150@param[in] file_handle handle for the opened log file
151@param[out] buf the allocated buffer for read
152@return DB_SUCCESS or error */
154
155/** Reads and deserializes the log file header.
156@param[in] file_handle handle for the opened log file
157@param[out] header the file header read
158@return DB_SUCCESS or error */
160 Log_file_header &header);
161
162/** Sets a specific flag in the mask built of redo log flags.
163@param[in] log_flags mask of log flags
164@param[in] bit bit number to set (flag) */
165void log_file_header_set_flag(Log_flags &log_flags, uint32_t bit);
166
167/** Resets a specific flag in the mask built of redo log flags.
168@param[in] log_flags mask of log flags
169@param[in] bit bit number to set (flag) */
170void log_file_header_reset_flag(Log_flags &log_flags, uint32_t bit);
171
172/** Checks if a specific flag is set in the mask built of redo log flags.
173@param[in] log_flags mask of log flags
174@param[in] bit bit number to check (flag)
175@return true, iff flag is set */
176bool log_file_header_check_flag(Log_flags log_flags, uint32_t bit);
177
178/** @} */
179
180/**************************************************/ /**
181
182 @name Log - encryption header read/write.
183
184 *******************************************************/
185
186/** @{ */
187
188/** Writes the serialized encryption meta data to the log file.
189@param[in] file_handle handle for the opened log file
190@param[in] buf the filled encryption buffer to write
191@return DB_SUCCESS or error */
193 const byte *buf);
194
195/** Reads the serialized encryption meta data from the log file.
196@param[in] file_handle handle for the opened log file
197@param[out] buf the allocated buffer for read
198@return DB_SUCCESS or error */
200
201/** @} */
202
203/**************************************************/ /**
204
205 @name Log - checkpoint header read/write.
206
207 *******************************************************/
208
209/** @{ */
210
211/** Serializes the log checkpoint header to the buffer.
212@param[in] header the header to serialize
213@param[out] buf the allocated buffer */
215 byte *buf);
216
217/** Deserializes the log checkpoint header stored in the buffer.
218@param[in] buf the buffer to deserialize
219@param[out] header the deserialized header
220@return true iff checksum is correct */
222 Log_checkpoint_header &header);
223
224/** Serializes and writes the log checkpoint header to the log file.
225@param[in] file_handle handle for the opened log file
226@param[in] checkpoint_header_no checkpoint header to be written
227@param[in] header the checkpoint header
228@return DB_SUCCESS or error */
230 Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no,
231 const Log_checkpoint_header &header);
232
233/** Writes the serialized checkpoint header to the log file.
234@param[in] file_handle handle for the opened log file
235@param[in] checkpoint_header_no checkpoint header to be written
236@param[in] buf buffer containing the serialized checkpoint
237 header to write
238@return DB_SUCCESS or error */
240 Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no,
241 const byte *buf);
242
243/** Reads the serialized log checkpoint header to the buffer.
244@param[in] file_handle handle for the opened log file
245@param[in] checkpoint_header_no checkpoint header to read
246@param[out] buf the allocated buffer for read
247@return DB_SUCCESS or error */
249 Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no,
250 byte *buf);
251
252/** Reads and deserializes the log checkpoint header.
253@param[in] file_handle handle for the opened log file
254@param[in] checkpoint_header_no checkpoint header to read
255@param[out] header the checkpoint header read
256@param[out] block to be filled with block containing checkpoint
257@return DB_SUCCESS or error */
259 Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no,
260 Log_checkpoint_header &header,
262
263/** @} */
264
265/**************************************************/ /**
266
267 @name Log functions - data blocks read/write.
268
269 *******************************************************/
270
271/** @{ */
272
273/** Writes the formatted log blocks with redo records to the log file.
274The given log blocks must fit within the same single log file.
275@param[in] file_handle handle for the opened log file
276@param[in] write_offset offset from the beginning of the given file
277@param[in] write_size size of the data to write (must be divisible
278 by OS_FILE_LOG_BLOCK_SIZE)
279@param[in] buf formatted log blocks with the data to write
280@return DB_SUCCESS or error */
282 os_offset_t write_offset, size_t write_size,
283 const byte *buf);
284
285/** Reads log blocks with redo records from the log file, starting at
286the given offset. The log blocks must exist within single log file.
287@param[in] file_handle handle for the opened log file
288@param[in] read_offset offset from the beginning of the given file
289@param[in] read_size size of the data to read (must be divisible
290 by OS_FILE_LOG_BLOCK_SIZE)
291@param[out] buf allocated buffer to fill by the read
292@return DB_SUCCESS or error */
294 os_offset_t read_offset, size_t read_size,
295 byte *buf);
296
297/** @} */
298
299/**************************************************/ /**
300
301 @name Log - files creation/deletion, path computation.
302
303 *******************************************************/
304
305/** @{ */
306
307/** Provides path to directory with redo log files.
308@param[in] ctx context within which files exist
309@return path to #innodb_redo directory */
310std::string log_directory_path(const Log_files_context &ctx);
311
312/** Provides name of the log file with the given file id, e.g. '#ib_redo0'.
313@param[in] ctx context within which files exist
314@param[in] file_id id of the log file
315@return file name */
316std::string log_file_name(const Log_files_context &ctx, Log_file_id file_id);
317
318/** Provides full path to the log file, e.g. '/data/#innodb_redo/#ib_redo2'.
319@param[in] ctx context within which files exist
320@param[in] file_id id of the log file
321@return path to the log file (including file name) */
322std::string log_file_path(const Log_files_context &ctx, Log_file_id file_id);
323
324/** Provides full path to the temporary log file,
325e.g. '/data/#innodb_redo/#ib_redo2_tmp'.
326@param[in] ctx context within which files exist
327@param[in] file_id id of the file
328@return path to the temporary log file (including file name) */
330 Log_file_id file_id);
331
332/** List existing log files in the directory (does not include unused files).
333@param[in] ctx context within which files exist
334@param[out] ret identifiers of existing log files
335@return DB_SUCCESS or DB_ERROR */
338
339/** List existing unused log files in the directory.
340@param[in] ctx context within which files exist
341@param[out] ret identifiers of existing unused log files
342@return DB_SUCCESS or DB_ERROR */
345
346/** Renames the unused file to another unused file.
347@param[in] ctx context within which files exist
348@param[in] old_unused_file_id id of file to rename
349@param[in] new_unused_file_id new file id
350@return DB_SUCCESS or DB_ERROR */
352 Log_file_id old_unused_file_id,
353 Log_file_id new_unused_file_id);
354
355/** Renames a temporary log file to the non-temporary log file.
356@param[in] ctx context within which files exist
357@param[in] file_id id of the file to rename
358@return DB_SUCCESS or DB_ERROR */
360 Log_file_id file_id);
361
362/** Renames a non-temporary log file to the temporary log file.
363@param[in] ctx context within which files exist
364@param[in] file_id id of the file to rename
365@return DB_SUCCESS or DB_ERROR */
367 Log_file_id file_id);
368
369/** Removes a temporary log file, if it existed.
370@param[in] ctx context within which files exist
371@param[in] file_id id of the file to remove
372@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
374 Log_file_id file_id);
375
376/** Removes all temporary log files in the directory. When failed to
377remove a file, stops and returns error. In such case the last element
378of the returned identifiers of files, represents the file for which
379error has been encountered when trying to remove it.
380@param[in] ctx context within which files exist
381@return first: DB_SUCCESS or DB_ERROR
382 second: identifiers of files for which remove has been called */
383std::pair<dberr_t, ut::vector<Log_file_id>> log_remove_unused_files(
384 const Log_files_context &ctx);
385
386/** Removes a log file, if it existed.
387@param[in] ctx context within which files exist
388@param[in] file_id id of the file to remove
389@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
391
392/** Removes a single existing log file (if it existed).
393@param[in] ctx context within which files exist
394@return first: DB_SUCCESS, DB_NOT_FOUND or DB_ERROR
395 second: id of the removed file (if removed) */
396std::pair<dberr_t, Log_file_id> log_remove_file(const Log_files_context &ctx);
397
398/** Removes existing log files. When failed to remove a file, stops and
399returns error. In such case the last element of the returned identifiers
400of files, represents the file for which error has been encountered when
401trying to remove it.
402@param[in] ctx context within which files exist
403@return first: DB_SUCCESS or DB_ERROR
404 second: identifiers of files for which remove has been called */
405std::pair<dberr_t, ut::vector<Log_file_id>> log_remove_files(
406 const Log_files_context &ctx);
407
408/** Creates a new temporary log file and resizes the file to the given size.
409@param[in] ctx context within which files exist
410@param[in] file_id id of the file to create
411@param[in] size_in_bytes size of the file, in bytes
412@return DB_SUCCESS or DB_ERROR */
414 Log_file_id file_id, os_offset_t size_in_bytes);
415
416/** Resizes an existing temporary log file to the given size.
417@param[in] ctx context within which files exist
418@param[in] file_id id of the file to resize
419@param[in] size_in_bytes requested size of the file, in bytes
420@return DB_SUCCESS, DB_NOT_FOUND, DB_OUT_OF_DISK_SPACE or DB_ERROR */
422 Log_file_id file_id, os_offset_t size_in_bytes);
423
424/** Resizes an existing log file to the given size.
425@param[in] ctx context within which files exist
426@param[in] file_id id of the file to resize
427@param[in] size_in_bytes requested size of the file, in bytes
428@return DB_SUCCESS, DB_NOT_FOUND, DB_OUT_OF_DISK_SPACE or DB_ERROR */
430 os_offset_t size_in_bytes);
431
432/** Searches for all possible log files existing on disk in the log directory.
433Performs only very minimal validation of the files, checking if files could be
434opened and have valid file size.
435@param[in] ctx context within which files exist
436@param[in] read_only true: check file permissions only for reading,
437 false: check for both reading and writing
438@param[out] found list of <file_id, size of file> for each file found
439@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
442
443/** Generate unique identifier for the redo log files.
444@return random uuid > 0 */
446
447/** @} */
448
449/**************************************************/ /**
450
451 @name Log - log blocks format.
452
453 *******************************************************/
454
455/** @{ */
456
457/* Definition of inline functions. */
458
459/** Gets a log block number stored in the header. The number corresponds
460to lsn range for data stored in the block.
461
462During recovery, when a next block is being parsed, a next range of lsn
463values is expected to be read. This corresponds to a log block number
464increased by one (modulo LOG_BLOCK_MAX_NO). However, if an unexpected
465number is read from the header, it is then considered the end of the
466redo log and recovery is finished. In such case, the next block is most
467likely an empty block or a block from the past, because the redo log
468files might be reused.
469
470@param[in] log_block log block (may be invalid or empty block)
471@return log block number stored in the block header */
472inline uint32_t log_block_get_hdr_no(const byte *log_block) {
473 return ~LOG_BLOCK_FLUSH_BIT_MASK &
475}
476
477/** Sets the log block number stored in the header.
478NOTE that this must be set before the flush bit!
479
480@param[in,out] log_block log block
481@param[in] n log block number: must be in (0, 1G] */
482inline void log_block_set_hdr_no(byte *log_block, uint32_t n) {
483 ut_a(n > 0);
486 mach_write_to_4(log_block + LOG_BLOCK_HDR_NO, n);
487}
488
489/** Gets a log block data length.
490@param[in] log_block log block
491@return log block data length measured as a byte offset from the block start */
492inline uint32_t log_block_get_data_len(const byte *log_block) {
493 return mach_read_from_2(log_block + LOG_BLOCK_HDR_DATA_LEN);
494}
495
496/** Sets the log block data length.
497@param[in,out] log_block log block
498@param[in] len data length (@see log_block_get_data_len) */
499inline void log_block_set_data_len(byte *log_block, uint32_t len) {
500 mach_write_to_2(log_block + LOG_BLOCK_HDR_DATA_LEN, len);
501}
502
503/** Gets an offset to the beginning of the first group of log records
504in a given log block.
505@param[in] log_block log block
506@return first mtr log record group byte offset from the block start,
5070 if none. */
508inline uint32_t log_block_get_first_rec_group(const byte *log_block) {
510}
511
512/** Sets an offset to the beginning of the first group of log records
513in a given log block.
514@param[in,out] log_block log block
515@param[in] offset offset, 0 if none */
516inline void log_block_set_first_rec_group(byte *log_block, uint32_t offset) {
517 mach_write_to_2(log_block + LOG_BLOCK_FIRST_REC_GROUP, offset);
518}
519
520/** Gets a log block epoch_no. For details: @see LOG_BLOCK_EPOCH_NO.
521@param[in] log_block log block
522@return epoch number */
523inline uint32_t log_block_get_epoch_no(const byte *log_block) {
524 return mach_read_from_4(log_block + LOG_BLOCK_EPOCH_NO);
525}
526
527/** Sets a log block epoch_no. For details: @see LOG_BLOCK_EPOCH_NO.
528@param[in,out] log_block log block
529@param[in] no epoch number */
530inline void log_block_set_epoch_no(byte *log_block, uint32_t no) {
531 mach_write_to_4(log_block + LOG_BLOCK_EPOCH_NO, no);
532}
533
534/** Converts a lsn to a log block epoch number.
535For details @see LOG_BLOCK_EPOCH_NO.
536@param[in] lsn lsn of a byte within the block
537@return log block epoch number, it is > 0 */
539 return 1 +
540 static_cast<uint32_t>(lsn / OS_FILE_LOG_BLOCK_SIZE / LOG_BLOCK_MAX_NO);
541}
542
543/** Converts a lsn to a log block number. Consecutive log blocks have
544consecutive numbers (unless the sequence wraps). It is guaranteed that
545the calculated number is greater than zero.
546
547@param[in] lsn lsn of a byte within the block
548@return log block number, it is > 0 and <= 1G */
550 return 1 +
551 static_cast<uint32_t>(lsn / OS_FILE_LOG_BLOCK_SIZE % LOG_BLOCK_MAX_NO);
552}
553
554/** Calculates the checksum for a log block.
555@param[in] log_block log block
556@return checksum */
557inline uint32_t log_block_calc_checksum(const byte *log_block) {
558 return log_checksum_algorithm_ptr.load()(log_block);
559}
560
561/** Calculates the checksum for a log block using the MySQL 5.7 algorithm.
562@param[in] log_block log block
563@return checksum */
564inline uint32_t log_block_calc_checksum_crc32(const byte *log_block) {
566}
567
568/** Calculates the checksum for a log block using the "no-op" algorithm.
569@return checksum */
570inline uint32_t log_block_calc_checksum_none(const byte *) {
572}
573
574/** Gets value of a log block checksum field.
575@param[in] log_block log block
576@return checksum */
577inline uint32_t log_block_get_checksum(const byte *log_block) {
578 return mach_read_from_4(log_block + OS_FILE_LOG_BLOCK_SIZE -
580}
581
582/** Sets value of a log block checksum field.
583@param[in,out] log_block log block
584@param[in] checksum checksum */
585inline void log_block_set_checksum(byte *log_block, uint32_t checksum) {
587 checksum);
588}
589
590/** Stores a 4-byte checksum to the trailer checksum field of a log block.
591This is used before writing the log block to disk. The checksum in a log
592block is used in recovery to check the consistency of the log block.
593@param[in] log_block log block (completely filled in!) */
594inline void log_block_store_checksum(byte *log_block) {
595 log_block_set_checksum(log_block, log_block_calc_checksum(log_block));
596}
597
598/** Gets value of a log block encrypt bit (true or false).
599@param[in] log_block log block
600@return true iff encrypt bit is set */
601inline bool log_block_get_encrypt_bit(const byte *log_block) {
604 return true;
605 }
606
607 return false;
608}
609
610/** Sets value of a log block encrypt bit (true or false).
611@param[in] log_block log block to modify
612@param[in] val the value to set (true or false) */
613inline void log_block_set_encrypt_bit(byte *log_block, bool val) {
614 uint32_t field;
615
616 field = mach_read_from_2(log_block + LOG_BLOCK_HDR_DATA_LEN);
617
618 if (val) {
619 field = field | LOG_BLOCK_ENCRYPT_BIT_MASK;
620 } else {
621 field = field & ~LOG_BLOCK_ENCRYPT_BIT_MASK;
622 }
623
624 mach_write_to_2(log_block + LOG_BLOCK_HDR_DATA_LEN, field);
625}
626
627/** Serializes the log data block header to the redo log block buffer which
628already contains redo log data (must have the redo data before this call).
629@param[in] header the header to serialize
630@param[out] buf the buffer containing the redo log block with the data */
632 byte *buf) {
638}
639
640/** Deserializes the log data block header stored in the buffer.
641@param[in] buf the buffer to deserialize
642@param[out] header the deserialized header
643@return true iff checksum is correct */
645 Log_data_block_header &header) {
651}
652
653/** @} */
654
655#endif /* !log0files_io_h */
Handle which allows to do reads / writes for the opened file.
Definition: log0types.h:309
std::array< unsigned char, METADATA_BLOCK_SIZE > Metadata_value
Definition: log0handler_interface.h:785
dberr_t
Definition: db0err.h:39
constexpr uint32_t LOG_BLOCK_FLUSH_BIT_MASK
Mask used to get the highest bit in the hdr_no field.
Definition: log0constants.h:257
constexpr uint32_t LOG_BLOCK_HDR_DATA_LEN
Offset to number of bytes written to this block (also header bytes).
Definition: log0constants.h:263
constexpr uint32_t LOG_BLOCK_FIRST_REC_GROUP
Offset to "first_rec_group offset" stored in the log block header.
Definition: log0constants.h:280
constexpr uint32_t LOG_BLOCK_HDR_NO
Offset to hdr_no, which is a log block number and must be > 0.
Definition: log0constants.h:253
constexpr uint32_t LOG_BLOCK_EPOCH_NO
Offset to epoch_no stored in this log block.
Definition: log0constants.h:294
constexpr uint32_t LOG_NO_CHECKSUM_MAGIC
Magic value to use instead of log checksums when they are disabled.
Definition: log0constants.h:150
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: log0constants.h:267
constexpr uint32_t LOG_BLOCK_TRL_SIZE
Size of the log block footer (trailer) in bytes.
Definition: log0constants.h:306
constexpr uint32_t LOG_BLOCK_MAX_NO
Maximum allowed block's number (stored in hdr_no) increased by 1.
Definition: log0constants.h:260
constexpr uint32_t LOG_BLOCK_CHECKSUM
4 byte checksum of the log block contents.
Definition: log0constants.h:303
dberr_t log_data_blocks_write(Log_file_handle &file_handle, os_offset_t write_offset, size_t write_size, const byte *buf)
Writes the formatted log blocks with redo records to the log file.
Definition: log0files_io.cc:648
void log_block_set_epoch_no(byte *log_block, uint32_t no)
Sets a log block epoch_no.
Definition: log0files_io.h:530
void log_block_set_data_len(byte *log_block, uint32_t len)
Sets the log block data length.
Definition: log0files_io.h:499
std::pair< dberr_t, ut::vector< Log_file_id > > log_remove_files(const Log_files_context &ctx)
Removes existing log files.
Definition: log0files_io.cc:949
dberr_t log_data_blocks_read(Log_file_handle &file_handle, os_offset_t read_offset, size_t read_size, byte *buf)
Reads log blocks with redo records from the log file, starting at the given offset.
Definition: log0files_io.cc:655
uint32_t log_block_calc_checksum(const byte *log_block)
Calculates the checksum for a log block.
Definition: log0files_io.h:557
void log_block_set_encrypt_bit(byte *log_block, bool val)
Sets value of a log block encrypt bit (true or false).
Definition: log0files_io.h:613
uint32_t log_block_get_hdr_no(const byte *log_block)
Gets a log block number stored in the header.
Definition: log0files_io.h:472
bool log_data_block_header_deserialize(const byte *buf, Log_data_block_header &header)
Deserializes the log data block header stored in the buffer.
Definition: log0files_io.h:644
std::pair< dberr_t, ut::vector< Log_file_id > > log_remove_unused_files(const Log_files_context &ctx)
Removes all temporary log files in the directory.
Definition: log0files_io.cc:892
bool log_block_get_encrypt_bit(const byte *log_block)
Gets value of a log block encrypt bit (true or false).
Definition: log0files_io.h:601
std::string log_directory_path(const Log_files_context &ctx)
Provides path to directory with redo log files.
Definition: log0files_io.cc:672
uint32_t log_block_get_data_len(const byte *log_block)
Gets a log block data length.
Definition: log0files_io.h:492
dberr_t log_checkpoint_header_read(Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no, byte *buf)
Reads the serialized log checkpoint header to the buffer.
Definition: log0files_io.cc:602
dberr_t log_remove_file(const Log_files_context &ctx, Log_file_id file_id)
Removes a log file, if it existed.
Definition: log0files_io.cc:929
dberr_t log_create_unused_file(const Log_files_context &ctx, Log_file_id file_id, os_offset_t size_in_bytes)
Creates a new temporary log file and resizes the file to the given size.
Definition: log0files_io.cc:971
void log_block_set_checksum(byte *log_block, uint32_t checksum)
Sets value of a log block checksum field.
Definition: log0files_io.h:585
uint32_t log_block_get_checksum(const byte *log_block)
Gets value of a log block checksum field.
Definition: log0files_io.h:577
Log_checksum_algorithm_atomic_ptr log_checksum_algorithm_ptr
Atomic pointer to the log checksum calculation function.
Definition: log0files_io.cc:58
dberr_t log_encryption_header_write(Log_file_handle &file_handle, const byte *buf)
Writes the serialized encryption meta data to the log file.
Definition: log0files_io.cc:537
void log_file_header_reset_flag(Log_flags &log_flags, uint32_t bit)
Resets a specific flag in the mask built of redo log flags.
Definition: log0files_io.cc:519
void log_block_store_checksum(byte *log_block)
Stores a 4-byte checksum to the trailer checksum field of a log block.
Definition: log0files_io.h:594
void log_file_header_set_flag(Log_flags &log_flags, uint32_t bit)
Sets a specific flag in the mask built of redo log flags.
Definition: log0files_io.cc:515
dberr_t log_rename_unused_file(const Log_files_context &ctx, Log_file_id old_unused_file_id, Log_file_id new_unused_file_id)
Renames the unused file to another unused file.
Definition: log0files_io.cc:845
dberr_t log_file_header_write(Log_file_handle &file_handle, const Log_file_header &header)
Serializes and writes the log file header to the log file.
Definition: log0files_io.cc:477
bool log_checkpoint_header_deserialize(const byte *buf, Log_checkpoint_header &header)
Deserializes the log checkpoint header stored in the buffer.
Definition: log0files_io.cc:565
dberr_t log_mark_file_as_unused(const Log_files_context &ctx, Log_file_id file_id)
Renames a non-temporary log file to the temporary log file.
Definition: log0files_io.cc:862
dberr_t log_collect_existing_files(const Log_files_context &ctx, bool read_only, ut::vector< Log_file_id_and_size > &found)
Searches for all possible log files existing on disk in the log directory.
Definition: log0files_io.cc:1137
uint32_t log_block_calc_checksum_none(const byte *)
Calculates the checksum for a log block using the "no-op" algorithm.
Definition: log0files_io.h:570
dberr_t log_resize_file(const Log_files_context &ctx, Log_file_id file_id, os_offset_t size_in_bytes)
Resizes an existing log file to the given size.
Definition: log0files_io.cc:1077
std::string log_file_path(const Log_files_context &ctx, Log_file_id file_id)
Provides full path to the log file, e.g.
Definition: log0files_io.cc:709
void log_block_set_hdr_no(byte *log_block, uint32_t n)
Sets the log block number stored in the header.
Definition: log0files_io.h:482
dberr_t log_checkpoint_header_write(Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no, const Log_checkpoint_header &header)
Serializes and writes the log checkpoint header to the log file.
Definition: log0files_io.cc:572
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.
Definition: log0files_io.h:508
bool log_file_header_check_flag(Log_flags log_flags, uint32_t bit)
Checks if a specific flag is set in the mask built of redo log flags.
Definition: log0files_io.cc:523
dberr_t log_list_existing_files(const Log_files_context &ctx, ut::vector< Log_file_id > &ret)
List existing log files in the directory (does not include unused files).
Definition: log0files_io.cc:813
uint32_t log_block_get_epoch_no(const byte *log_block)
Gets a log block epoch_no.
Definition: log0files_io.h:523
bool log_file_header_deserialize(const byte *buf, Log_file_header &header)
Deserializes the log file header stored in the buffer.
Definition: log0files_io.cc:452
void log_checkpoint_header_serialize(const Log_checkpoint_header &header, byte *buf)
Serializes the log checkpoint header to the buffer.
Definition: log0files_io.cc:556
dberr_t log_file_header_read(Log_file_handle &file_handle, byte *buf)
Reads the serialized log file header to the buffer.
Definition: log0files_io.cc:488
std::string log_file_name(const Log_files_context &ctx, Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0files_io.cc:695
dberr_t log_mark_file_as_in_use(const Log_files_context &ctx, Log_file_id file_id)
Renames a temporary log file to the non-temporary log file.
Definition: log0files_io.cc:855
Log_uuid log_generate_uuid()
Generate unique identifier for the redo log files.
Definition: log0files_io.cc:1166
uint32_t log_block_convert_lsn_to_epoch_no(lsn_t lsn)
Converts a lsn to a log block epoch number.
Definition: log0files_io.h:538
uint32_t log_block_calc_checksum_crc32(const byte *log_block)
Calculates the checksum for a log block using the MySQL 5.7 algorithm.
Definition: log0files_io.h:564
uint32_t log_block_convert_lsn_to_hdr_no(lsn_t lsn)
Converts a lsn to a log block number.
Definition: log0files_io.h:549
std::string log_file_path_for_unused_file(const Log_files_context &ctx, Log_file_id file_id)
Provides full path to the temporary log file, e.g.
Definition: log0files_io.cc:713
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.
Definition: log0files_io.h:516
dberr_t log_resize_unused_file(const Log_files_context &ctx, Log_file_id file_id, os_offset_t size_in_bytes)
Resizes an existing temporary log file to the given size.
Definition: log0files_io.cc:1070
dberr_t log_remove_unused_file(const Log_files_context &ctx, Log_file_id file_id)
Removes a temporary log file, if it existed.
Definition: log0files_io.cc:886
void log_file_header_serialize(const Log_file_header &header, byte *buf)
Serializes the log file header to the buffer.
Definition: log0files_io.cc:433
dberr_t log_encryption_header_read(Log_file_handle &file_handle, byte *buf)
Reads the serialized encryption meta data from the log file.
Definition: log0files_io.cc:542
dberr_t log_list_existing_unused_files(const Log_files_context &ctx, ut::vector< Log_file_id > &ret)
List existing unused log files in the directory.
Definition: log0files_io.cc:807
bool log_header_checksum_is_ok(const byte *buf)
Computes checksum of the given header and verifies if the checksum is the same as the one stored in t...
Definition: log0files_io.cc:60
void log_data_block_header_serialize(const Log_data_block_header &header, byte *buf)
Serializes the log data block header to the redo log block buffer which already contains redo log dat...
Definition: log0files_io.h:631
Redo log basic types.
size_t Log_file_id
Log file id (0 for ib_redo0)
Definition: log0types.h:66
Log_checkpoint_header_no
Enumerates checkpoint headers in the redo log file.
Definition: log0types.h:95
uint32_t Log_uuid
Number which tries to uniquely identify a created set of redo log files.
Definition: log0types.h:76
std::atomic< uint32_t(*)(const byte *log_block)> Log_checksum_algorithm_atomic_ptr
Function used to calculate checksums of log blocks.
Definition: log0types.h:129
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
uint32_t Log_flags
Log flags (stored in file header of log file).
Definition: log0types.h:69
Utilities for converting data from the database file to the machine format.
static uint16_t mach_read_from_2(const byte *b)
The following function is used to fetch data from 2 consecutive bytes.
static uint32_t mach_read_from_4(const byte *b)
The following function is used to fetch data from 4 consecutive bytes.
static void mach_write_to_2(byte *b, ulint n)
The following function is used to store data in two consecutive bytes.
static void mach_write_to_4(byte *b, ulint n)
The following function is used to store data in 4 consecutive bytes.
Definition: buf0block_hint.cc:30
constexpr value_type read_only
Definition: classic_protocol_constants.h:213
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2724
constexpr uint32_t 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:192
uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:87
Meta data stored in one of two checkpoint headers.
Definition: log0types.h:236
Meta data stored in header of a log data block.
Definition: log0types.h:242
uint16_t m_data_len
Offset up to which this block has data inside, computed from the beginning of the block.
Definition: log0types.h:254
uint32_t m_hdr_no
Together with m_epoch_no form unique identifier of this block,.
Definition: log0types.h:250
uint32_t m_epoch_no
Together with m_hdr_no form unique identifier of this block,.
Definition: log0types.h:245
uint16_t m_first_rec_group
Offset to the first mtr starting in this block, or 0 if there is no mtr starting in this block.
Definition: log0types.h:258
Meta data stored in log file header.
Definition: log0types.h:217
Configures path to the root directory, where redo subdirectory might be located (or redo log files if...
Definition: log0types.h:204
CRC32 implementation.
ut_crc32_func_t ut_crc32
Pointer to standard-compliant CRC32-C (using the GF(2) primitive polynomial 0x11EDC6F41) calculation ...
Definition: crc32.cc:101
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...
static uint64_t lsn
Definition: xcom_base.cc:446
int n
Definition: xcom_base.cc:509