MySQL 9.1.0
Source Code Documentation
log0files_io.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2019, 2024, 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
105/** Atomic pointer to the log checksum calculation function. This is actually
106the only remaining "state" of the library. Hopefully can become removed. */
108
109/** Computes checksum of the given header and verifies if the checksum
110is the same as the one stored in that header.
111@param[in] buf header to verify
112@return true iff checksums are the same */
113bool log_header_checksum_is_ok(const byte *buf);
114
115/**************************************************/ /**
116
117 @name Log - file header read/write.
118
119 *******************************************************/
120
121/** @{ */
122
123/** Serializes the log file header to the buffer.
124@param[in] header the header to serialize
125@param[out] buf the allocated buffer */
126void log_file_header_serialize(const Log_file_header &header, byte *buf);
127
128/** Deserializes the log file header stored in the buffer.
129@param[in] buf the buffer to deserialize
130@param[out] header the deserialized header
131@return true iff checksum is correct */
132bool log_file_header_deserialize(const byte *buf, Log_file_header &header);
133
134/** Serializes and writes the log file header to the log file.
135@param[in] file_handle handle for the opened log file
136@param[in] header the file header
137@return DB_SUCCESS or error */
139 const Log_file_header &header);
140
141/** Writes the serialized log file header to the log file.
142@param[in] file_handle handle for the opened log file
143@param[in] buf the serialized file header
144@return DB_SUCCESS or error */
145dberr_t log_file_header_write(Log_file_handle &file_handle, const byte *buf);
146
147/** Reads the serialized log file header to the buffer.
148@param[in] file_handle handle for the opened log file
149@param[out] buf the allocated buffer for read
150@return DB_SUCCESS or error */
152
153/** Reads and deserializes the log file header.
154@param[in] file_handle handle for the opened log file
155@param[out] header the file header read
156@return DB_SUCCESS or error */
158 Log_file_header &header);
159
160/** Sets a specific flag in the mask built of redo log flags.
161@param[in] log_flags mask of log flags
162@param[in] bit bit number to set (flag) */
163void log_file_header_set_flag(Log_flags &log_flags, uint32_t bit);
164
165/** Resets a specific flag in the mask built of redo log flags.
166@param[in] log_flags mask of log flags
167@param[in] bit bit number to set (flag) */
168void log_file_header_reset_flag(Log_flags &log_flags, uint32_t bit);
169
170/** Checks if a specific flag is set in the mask built of redo log flags.
171@param[in] log_flags mask of log flags
172@param[in] bit bit number to check (flag)
173@return true, iff flag is set */
174bool log_file_header_check_flag(Log_flags log_flags, uint32_t bit);
175
176/** @} */
177
178/**************************************************/ /**
179
180 @name Log - encryption header read/write.
181
182 *******************************************************/
183
184/** @{ */
185
186/** Writes the serialized encryption meta data to the log file.
187@param[in] file_handle handle for the opened log file
188@param[in] buf the filled encryption buffer to write
189@return DB_SUCCESS or error */
191 const byte *buf);
192
193/** Reads the serialized encryption meta data from the log file.
194@param[in] file_handle handle for the opened log file
195@param[out] buf the allocated buffer for read
196@return DB_SUCCESS or error */
198
199/** @} */
200
201/**************************************************/ /**
202
203 @name Log - checkpoint header read/write.
204
205 *******************************************************/
206
207/** @{ */
208
209/** Serializes the log checkpoint header to the buffer.
210@param[in] header the header to serialize
211@param[out] buf the allocated buffer */
213 byte *buf);
214
215/** Deserializes the log checkpoint header stored in the buffer.
216@param[in] buf the buffer to deserialize
217@param[out] header the deserialized header
218@return true iff checksum is correct */
220 Log_checkpoint_header &header);
221
222/** Serializes and writes the log checkpoint header to the log file.
223@param[in] file_handle handle for the opened log file
224@param[in] checkpoint_header_no checkpoint header to be written
225@param[in] header the checkpoint header
226@return DB_SUCCESS or error */
228 Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no,
229 const Log_checkpoint_header &header);
230
231/** Writes the serialized checkpoint header to the log file.
232@param[in] file_handle handle for the opened log file
233@param[in] checkpoint_header_no checkpoint header to be written
234@param[in] buf buffer containing the serialized checkpoint
235 header to write
236@return DB_SUCCESS or error */
238 Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no,
239 const byte *buf);
240
241/** Reads the serialized log checkpoint header to the buffer.
242@param[in] file_handle handle for the opened log file
243@param[in] checkpoint_header_no checkpoint header to read
244@param[out] buf the allocated buffer for read
245@return DB_SUCCESS or error */
247 Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no,
248 byte *buf);
249
250/** Reads and deserializes the log checkpoint header.
251@param[in] file_handle handle for the opened log file
252@param[in] checkpoint_header_no checkpoint header to read
253@param[out] header the checkpoint header read
254@return DB_SUCCESS or error */
256 Log_file_handle &file_handle, Log_checkpoint_header_no checkpoint_header_no,
257 Log_checkpoint_header &header);
258
259/** @} */
260
261/**************************************************/ /**
262
263 @name Log functions - data blocks read/write.
264
265 *******************************************************/
266
267/** @{ */
268
269/** Writes the formatted log blocks with redo records to the log file.
270The given log blocks must fit within the same single log file.
271@param[in] file_handle handle for the opened log file
272@param[in] write_offset offset from the beginning of the given file
273@param[in] write_size size of the data to write (must be divisible
274 by OS_FILE_LOG_BLOCK_SIZE)
275@param[in] buf formatted log blocks with the data to write
276@return DB_SUCCESS or error */
278 os_offset_t write_offset, size_t write_size,
279 const byte *buf);
280
281/** Reads log blocks with redo records from the log file, starting at
282the given offset. The log blocks must exist within single log file.
283@param[in] file_handle handle for the opened log file
284@param[in] read_offset offset from the beginning of the given file
285@param[in] read_size size of the data to read (must be divisible
286 by OS_FILE_LOG_BLOCK_SIZE)
287@param[out] buf allocated buffer to fill by the read
288@return DB_SUCCESS or error */
290 os_offset_t read_offset, size_t read_size,
291 byte *buf);
292
293/** @} */
294
295/**************************************************/ /**
296
297 @name Log - files creation/deletion, path computation.
298
299 *******************************************************/
300
301/** @{ */
302
303/** Provides path to directory with redo log files.
304@param[in] ctx context within which files exist
305@return path to #innodb_redo directory */
306std::string log_directory_path(const Log_files_context &ctx);
307
308/** Provides name of the log file with the given file id, e.g. '#ib_redo0'.
309@param[in] ctx context within which files exist
310@param[in] file_id id of the log file
311@return file name */
312std::string log_file_name(const Log_files_context &ctx, Log_file_id file_id);
313
314/** Provides full path to the log file, e.g. '/data/#innodb_redo/#ib_redo2'.
315@param[in] ctx context within which files exist
316@param[in] file_id id of the log file
317@return path to the log file (including file name) */
318std::string log_file_path(const Log_files_context &ctx, Log_file_id file_id);
319
320/** Provides full path to the temporary log file,
321e.g. '/data/#innodb_redo/#ib_redo2_tmp'.
322@param[in] ctx context within which files exist
323@param[in] file_id id of the file
324@return path to the temporary log file (including file name) */
326 Log_file_id file_id);
327
328/** List existing log files in the directory (does not include unused files).
329@param[in] ctx context within which files exist
330@param[out] ret identifiers of existing log files
331@return DB_SUCCESS or DB_ERROR */
334
335/** List existing unused log files in the directory.
336@param[in] ctx context within which files exist
337@param[out] ret identifiers of existing unused log files
338@return DB_SUCCESS or DB_ERROR */
341
342/** Renames the unused file to another unused file.
343@param[in] ctx context within which files exist
344@param[in] old_unused_file_id id of file to rename
345@param[in] new_unused_file_id new file id
346@return DB_SUCCESS or DB_ERROR */
348 Log_file_id old_unused_file_id,
349 Log_file_id new_unused_file_id);
350
351/** Renames a temporary log file to the non-temporary log file.
352@param[in] ctx context within which files exist
353@param[in] file_id id of the file to rename
354@return DB_SUCCESS or DB_ERROR */
356 Log_file_id file_id);
357
358/** Renames a non-temporary log file to the temporary log file.
359@param[in] ctx context within which files exist
360@param[in] file_id id of the file to rename
361@return DB_SUCCESS or DB_ERROR */
363 Log_file_id file_id);
364
365/** Removes a temporary log file, if it existed.
366@param[in] ctx context within which files exist
367@param[in] file_id id of the file to remove
368@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
370 Log_file_id file_id);
371
372/** Removes all temporary log files in the directory. When failed to
373remove a file, stops and returns error. In such case the last element
374of the returned identifiers of files, represents the file for which
375error has been encountered when trying to remove it.
376@param[in] ctx context within which files exist
377@return first: DB_SUCCESS or DB_ERROR
378 second: identifiers of files for which remove has been called */
379std::pair<dberr_t, ut::vector<Log_file_id>> log_remove_unused_files(
380 const Log_files_context &ctx);
381
382/** Removes a log file, if it existed.
383@param[in] ctx context within which files exist
384@param[in] file_id id of the file to remove
385@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
387
388/** Removes a single existing log file (if it existed).
389@param[in] ctx context within which files exist
390@return first: DB_SUCCESS, DB_NOT_FOUND or DB_ERROR
391 second: id of the removed file (if removed) */
392std::pair<dberr_t, Log_file_id> log_remove_file(const Log_files_context &ctx);
393
394/** Removes existing log files. When failed to remove a file, stops and
395returns error. In such case the last element of the returned identifiers
396of files, represents the file for which error has been encountered when
397trying to remove it.
398@param[in] ctx context within which files exist
399@return first: DB_SUCCESS or DB_ERROR
400 second: identifiers of files for which remove has been called */
401std::pair<dberr_t, ut::vector<Log_file_id>> log_remove_files(
402 const Log_files_context &ctx);
403
404/** Creates a new temporary log file and resizes the file to the given size.
405@param[in] ctx context within which files exist
406@param[in] file_id id of the file to create
407@param[in] size_in_bytes size of the file, in bytes
408@return DB_SUCCESS or DB_ERROR */
410 Log_file_id file_id, os_offset_t size_in_bytes);
411
412/** Resizes an existing temporary log file to the given size.
413@param[in] ctx context within which files exist
414@param[in] file_id id of the file to resize
415@param[in] size_in_bytes requested size of the file, in bytes
416@return DB_SUCCESS, DB_NOT_FOUND, DB_OUT_OF_DISK_SPACE or DB_ERROR */
418 Log_file_id file_id, os_offset_t size_in_bytes);
419
420/** Resizes an existing log file to the given size.
421@param[in] ctx context within which files exist
422@param[in] file_id id of the file to resize
423@param[in] size_in_bytes requested size of the file, in bytes
424@return DB_SUCCESS, DB_NOT_FOUND, DB_OUT_OF_DISK_SPACE or DB_ERROR */
426 os_offset_t size_in_bytes);
427
428/** Searches for all possible log files existing on disk in the log directory.
429Performs only very minimal validation of the files, checking if files could be
430opened and have valid file size.
431@param[in] ctx context within which files exist
432@param[in] read_only true: check file permissions only for reading,
433 false: check for both reading and writing
434@param[out] found list of <file_id, size of file> for each file found
435@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
438
439/** Generate unique identifier for the redo log files.
440@return random uuid > 0 */
442
443/** @} */
444
445/**************************************************/ /**
446
447 @name Log - log blocks format.
448
449 *******************************************************/
450
451/** @{ */
452
453/* Definition of inline functions. */
454
455/** Gets a log block number stored in the header. The number corresponds
456to lsn range for data stored in the block.
457
458During recovery, when a next block is being parsed, a next range of lsn
459values is expected to be read. This corresponds to a log block number
460increased by one (modulo LOG_BLOCK_MAX_NO). However, if an unexpected
461number is read from the header, it is then considered the end of the
462redo log and recovery is finished. In such case, the next block is most
463likely an empty block or a block from the past, because the redo log
464files might be reused.
465
466@param[in] log_block log block (may be invalid or empty block)
467@return log block number stored in the block header */
468inline uint32_t log_block_get_hdr_no(const byte *log_block) {
469 return ~LOG_BLOCK_FLUSH_BIT_MASK &
471}
472
473/** Sets the log block number stored in the header.
474NOTE that this must be set before the flush bit!
475
476@param[in,out] log_block log block
477@param[in] n log block number: must be in (0, 1G] */
478inline void log_block_set_hdr_no(byte *log_block, uint32_t n) {
479 ut_a(n > 0);
482 mach_write_to_4(log_block + LOG_BLOCK_HDR_NO, n);
483}
484
485/** Gets a log block data length.
486@param[in] log_block log block
487@return log block data length measured as a byte offset from the block start */
488inline uint32_t log_block_get_data_len(const byte *log_block) {
489 return mach_read_from_2(log_block + LOG_BLOCK_HDR_DATA_LEN);
490}
491
492/** Sets the log block data length.
493@param[in,out] log_block log block
494@param[in] len data length (@see log_block_get_data_len) */
495inline void log_block_set_data_len(byte *log_block, uint32_t len) {
496 mach_write_to_2(log_block + LOG_BLOCK_HDR_DATA_LEN, len);
497}
498
499/** Gets an offset to the beginning of the first group of log records
500in a given log block.
501@param[in] log_block log block
502@return first mtr log record group byte offset from the block start,
5030 if none. */
504inline uint32_t log_block_get_first_rec_group(const byte *log_block) {
506}
507
508/** Sets an offset to the beginning of the first group of log records
509in a given log block.
510@param[in,out] log_block log block
511@param[in] offset offset, 0 if none */
512inline void log_block_set_first_rec_group(byte *log_block, uint32_t offset) {
513 mach_write_to_2(log_block + LOG_BLOCK_FIRST_REC_GROUP, offset);
514}
515
516/** Gets a log block epoch_no. For details: @see LOG_BLOCK_EPOCH_NO.
517@param[in] log_block log block
518@return epoch number */
519inline uint32_t log_block_get_epoch_no(const byte *log_block) {
520 return mach_read_from_4(log_block + LOG_BLOCK_EPOCH_NO);
521}
522
523/** Sets a log block epoch_no. For details: @see LOG_BLOCK_EPOCH_NO.
524@param[in,out] log_block log block
525@param[in] no epoch number */
526inline void log_block_set_epoch_no(byte *log_block, uint32_t no) {
527 mach_write_to_4(log_block + LOG_BLOCK_EPOCH_NO, no);
528}
529
530/** Converts a lsn to a log block epoch number.
531For details @see LOG_BLOCK_EPOCH_NO.
532@param[in] lsn lsn of a byte within the block
533@return log block epoch number, it is > 0 */
535 return 1 +
536 static_cast<uint32_t>(lsn / OS_FILE_LOG_BLOCK_SIZE / LOG_BLOCK_MAX_NO);
537}
538
539/** Converts a lsn to a log block number. Consecutive log blocks have
540consecutive numbers (unless the sequence wraps). It is guaranteed that
541the calculated number is greater than zero.
542
543@param[in] lsn lsn of a byte within the block
544@return log block number, it is > 0 and <= 1G */
546 return 1 +
547 static_cast<uint32_t>(lsn / OS_FILE_LOG_BLOCK_SIZE % LOG_BLOCK_MAX_NO);
548}
549
550/** Calculates the checksum for a log block.
551@param[in] log_block log block
552@return checksum */
553inline uint32_t log_block_calc_checksum(const byte *log_block) {
554 return log_checksum_algorithm_ptr.load()(log_block);
555}
556
557/** Calculates the checksum for a log block using the MySQL 5.7 algorithm.
558@param[in] log_block log block
559@return checksum */
560inline uint32_t log_block_calc_checksum_crc32(const byte *log_block) {
562}
563
564/** Calculates the checksum for a log block using the "no-op" algorithm.
565@return checksum */
566inline uint32_t log_block_calc_checksum_none(const byte *) {
568}
569
570/** Gets value of a log block checksum field.
571@param[in] log_block log block
572@return checksum */
573inline uint32_t log_block_get_checksum(const byte *log_block) {
574 return mach_read_from_4(log_block + OS_FILE_LOG_BLOCK_SIZE -
576}
577
578/** Sets value of a log block checksum field.
579@param[in,out] log_block log block
580@param[in] checksum checksum */
581inline void log_block_set_checksum(byte *log_block, uint32_t checksum) {
583 checksum);
584}
585
586/** Stores a 4-byte checksum to the trailer checksum field of a log block.
587This is used before writing the log block to disk. The checksum in a log
588block is used in recovery to check the consistency of the log block.
589@param[in] log_block log block (completely filled in!) */
590inline void log_block_store_checksum(byte *log_block) {
591 log_block_set_checksum(log_block, log_block_calc_checksum(log_block));
592}
593
594/** Gets value of a log block encrypt bit (true or false).
595@param[in] log_block log block
596@return true iff encrypt bit is set */
597inline bool log_block_get_encrypt_bit(const byte *log_block) {
600 return true;
601 }
602
603 return false;
604}
605
606/** Sets value of a log block encrypt bit (true or false).
607@param[in] log_block log block to modify
608@param[in] val the value to set (true or false) */
609inline void log_block_set_encrypt_bit(byte *log_block, bool val) {
610 uint32_t field;
611
612 field = mach_read_from_2(log_block + LOG_BLOCK_HDR_DATA_LEN);
613
614 if (val) {
615 field = field | LOG_BLOCK_ENCRYPT_BIT_MASK;
616 } else {
617 field = field & ~LOG_BLOCK_ENCRYPT_BIT_MASK;
618 }
619
620 mach_write_to_2(log_block + LOG_BLOCK_HDR_DATA_LEN, field);
621}
622
623/** Serializes the log data block header to the redo log block buffer which
624already contains redo log data (must have the redo data before this call).
625@param[in] header the header to serialize
626@param[out] buf the buffer containing the redo log block with the data */
628 byte *buf) {
634}
635
636/** Deserializes the log data block header stored in the buffer.
637@param[in] buf the buffer to deserialize
638@param[out] header the deserialized header
639@return true iff checksum is correct */
641 Log_data_block_header &header) {
647}
648
649/** @} */
650
651#endif /* !log0files_io_h */
Handle which allows to do reads / writes for the opened file.
Definition: log0types.h:309
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:669
void log_block_set_epoch_no(byte *log_block, uint32_t no)
Sets a log block epoch_no.
Definition: log0files_io.h:526
void log_block_set_data_len(byte *log_block, uint32_t len)
Sets the log block data length.
Definition: log0files_io.h:495
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:974
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:676
uint32_t log_block_calc_checksum(const byte *log_block)
Calculates the checksum for a log block.
Definition: log0files_io.h:553
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:609
uint32_t log_block_get_hdr_no(const byte *log_block)
Gets a log block number stored in the header.
Definition: log0files_io.h:468
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:640
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:917
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:597
std::string log_directory_path(const Log_files_context &ctx)
Provides path to directory with redo log files.
Definition: log0files_io.cc:693
uint32_t log_block_get_data_len(const byte *log_block)
Gets a log block data length.
Definition: log0files_io.h:488
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:622
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:954
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:996
void log_block_set_checksum(byte *log_block, uint32_t checksum)
Sets value of a log block checksum field.
Definition: log0files_io.h:581
uint32_t log_block_get_checksum(const byte *log_block)
Gets value of a log block checksum field.
Definition: log0files_io.h:573
Log_checksum_algorithm_atomic_ptr log_checksum_algorithm_ptr
Atomic pointer to the log checksum calculation function.
Definition: log0files_io.cc:79
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:557
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:539
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:590
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:535
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:866
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:497
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:585
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:883
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:1159
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:566
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:1099
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:730
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:478
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:592
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:504
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:543
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:834
uint32_t log_block_get_epoch_no(const byte *log_block)
Gets a log block epoch_no.
Definition: log0files_io.h:519
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:472
void log_checkpoint_header_serialize(const Log_checkpoint_header &header, byte *buf)
Serializes the log checkpoint header to the buffer.
Definition: log0files_io.cc:576
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:508
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:716
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:876
Log_uuid log_generate_uuid()
Generate unique identifier for the redo log files.
Definition: log0files_io.cc:1188
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:534
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:560
uint32_t log_block_convert_lsn_to_hdr_no(lsn_t lsn)
Converts a lsn to a log block number.
Definition: log0files_io.h:545
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:734
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:512
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:1092
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:911
void log_file_header_serialize(const Log_file_header &header, byte *buf)
Serializes the log file header to the buffer.
Definition: log0files_io.cc:453
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:562
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:828
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:81
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:627
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:2876
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:93
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