MySQL 8.4.13
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
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 a 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@param[in] can_decrypt whether decryption may be attempted for encrypted
289 blocks; an encrypted block returns DB_IO_DECRYPT_FAIL
290 when this is false
291@return DB_SUCCESS or error */
293 os_offset_t read_offset, size_t read_size,
294 byte *buf, bool can_decrypt = true);
295
296/** @} */
297
298/**************************************************/ /**
299
300 @name Log - files creation/deletion, path computation.
301
302 *******************************************************/
303
304/** @{ */
305
306/** Provides path to directory with redo log files.
307@param[in] ctx context within which files exist
308@return path to #innodb_redo directory */
309std::string log_directory_path(const Log_files_context &ctx);
310
311/** Provides name of the log file with the given file id, e.g. '#ib_redo0'.
312@param[in] ctx context within which files exist
313@param[in] file_id id of the log file
314@return file name */
315std::string log_file_name(const Log_files_context &ctx, Log_file_id file_id);
316
317/** Provides full path to the log file, e.g. '/data/#innodb_redo/#ib_redo2'.
318@param[in] ctx context within which files exist
319@param[in] file_id id of the log file
320@return path to the log file (including file name) */
321std::string log_file_path(const Log_files_context &ctx, Log_file_id file_id);
322
323/** Provides full path to the temporary log file,
324e.g. '/data/#innodb_redo/#ib_redo2_tmp'.
325@param[in] ctx context within which files exist
326@param[in] file_id id of the file
327@return path to the temporary log file (including file name) */
329 Log_file_id file_id);
330
331/** List existing log files in the directory (does not include unused files).
332@param[in] ctx context within which files exist
333@param[out] ret identifiers of existing log files
334@return DB_SUCCESS or DB_ERROR */
337
338/** List existing unused log files in the directory.
339@param[in] ctx context within which files exist
340@param[out] ret identifiers of existing unused log files
341@return DB_SUCCESS or DB_ERROR */
344
345/** Renames the unused file to another unused file.
346@param[in] ctx context within which files exist
347@param[in] old_unused_file_id id of file to rename
348@param[in] new_unused_file_id new file id
349@return DB_SUCCESS or DB_ERROR */
351 Log_file_id old_unused_file_id,
352 Log_file_id new_unused_file_id);
353
354/** Renames a temporary log file to the non-temporary log file.
355@param[in] ctx context within which files exist
356@param[in] file_id id of the file to rename
357@return DB_SUCCESS or DB_ERROR */
359 Log_file_id file_id);
360
361/** Renames a non-temporary log file to the temporary log file.
362@param[in] ctx context within which files exist
363@param[in] file_id id of the file to rename
364@return DB_SUCCESS or DB_ERROR */
366 Log_file_id file_id);
367
368/** Removes a temporary log file, if it existed.
369@param[in] ctx context within which files exist
370@param[in] file_id id of the file to remove
371@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
373 Log_file_id file_id);
374
375/** Removes all temporary log files in the directory. When failed to
376remove a file, stops and returns error. In such case the last element
377of the returned identifiers of files, represents the file for which
378error has been encountered when trying to remove it.
379@param[in] ctx context within which files exist
380@return first: DB_SUCCESS or DB_ERROR
381 second: identifiers of files for which remove has been called */
382std::pair<dberr_t, ut::vector<Log_file_id>> log_remove_unused_files(
383 const Log_files_context &ctx);
384
385/** Removes a log file, if it existed.
386@param[in] ctx context within which files exist
387@param[in] file_id id of the file to remove
388@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
390
391/** Removes a single existing log file (if it existed).
392@param[in] ctx context within which files exist
393@return first: DB_SUCCESS, DB_NOT_FOUND or DB_ERROR
394 second: id of the removed file (if removed) */
395std::pair<dberr_t, Log_file_id> log_remove_file(const Log_files_context &ctx);
396
397/** Removes existing log files. When failed to remove a file, stops and
398returns error. In such case the last element of the returned identifiers
399of files, represents the file for which error has been encountered when
400trying to remove it.
401@param[in] ctx context within which files exist
402@return first: DB_SUCCESS or DB_ERROR
403 second: identifiers of files for which remove has been called */
404std::pair<dberr_t, ut::vector<Log_file_id>> log_remove_files(
405 const Log_files_context &ctx);
406
407/** Creates a new temporary log file and resizes the file to the given size.
408@param[in] ctx context within which files exist
409@param[in] file_id id of the file to create
410@param[in] size_in_bytes size of the file, in bytes
411@return DB_SUCCESS or DB_ERROR */
413 Log_file_id file_id, os_offset_t size_in_bytes);
414
415/** Resizes an existing temporary log file to the given size.
416@param[in] ctx context within which files exist
417@param[in] file_id id of the file to resize
418@param[in] size_in_bytes requested size of the file, in bytes
419@return DB_SUCCESS, DB_NOT_FOUND, DB_OUT_OF_DISK_SPACE or DB_ERROR */
421 Log_file_id file_id, os_offset_t size_in_bytes);
422
423/** Resizes an existing log file to the given size.
424@param[in] ctx context within which files exist
425@param[in] file_id id of the file to resize
426@param[in] size_in_bytes requested size of the file, in bytes
427@return DB_SUCCESS, DB_NOT_FOUND, DB_OUT_OF_DISK_SPACE or DB_ERROR */
429 os_offset_t size_in_bytes);
430
431/** Searches for all possible log files existing on disk in the log directory.
432Performs only very minimal validation of the files, checking if files could be
433opened and have valid file size.
434@param[in] ctx context within which files exist
435@param[in] read_only true: check file permissions only for reading,
436 false: check for both reading and writing
437@param[out] found list of <file_id, size of file> for each file found
438@return DB_SUCCESS, DB_NOT_FOUND or DB_ERROR */
441
442/** Generate unique identifier for the redo log files.
443@return random uuid > 0 */
445
446/** @} */
447
448/**************************************************/ /**
449
450 @name Log - log blocks format.
451
452 *******************************************************/
453
454/** @{ */
455
456/* Definition of inline functions. */
457
458/** Gets a log block number stored in the header. The number corresponds
459to lsn range for data stored in the block.
460
461During recovery, when a next block is being parsed, a next range of lsn
462values is expected to be read. This corresponds to a log block number
463increased by one (modulo LOG_BLOCK_MAX_NO). However, if an unexpected
464number is read from the header, it is then considered the end of the
465redo log and recovery is finished. In such case, the next block is most
466likely an empty block or a block from the past, because the redo log
467files might be reused.
468
469@param[in] log_block log block (may be invalid or empty block)
470@return log block number stored in the block header */
471inline uint32_t log_block_get_hdr_no(const byte *log_block) {
472 return ~LOG_BLOCK_FLUSH_BIT_MASK &
474}
475
476/** Sets the log block number stored in the header.
477NOTE that this must be set before the flush bit!
478
479@param[in,out] log_block log block
480@param[in] n log block number: must be in (0, 1G] */
481inline void log_block_set_hdr_no(byte *log_block, uint32_t n) {
482 ut_a(n > 0);
485 mach_write_to_4(log_block + LOG_BLOCK_HDR_NO, n);
486}
487
488/** Gets a log block data length.
489@param[in] log_block log block
490@return log block data length measured as a byte offset from the block start */
491inline uint32_t log_block_get_data_len(const byte *log_block) {
492 return mach_read_from_2(log_block + LOG_BLOCK_HDR_DATA_LEN);
493}
494
495/** Sets the log block data length.
496@param[in,out] log_block log block
497@param[in] len data length (@see log_block_get_data_len) */
498inline void log_block_set_data_len(byte *log_block, uint32_t len) {
499 mach_write_to_2(log_block + LOG_BLOCK_HDR_DATA_LEN, len);
500}
501
502/** Gets an offset to the beginning of the first group of log records
503in a given log block.
504@param[in] log_block log block
505@return first mtr log record group byte offset from the block start,
5060 if none. */
507inline uint32_t log_block_get_first_rec_group(const byte *log_block) {
509}
510
511/** Sets an offset to the beginning of the first group of log records
512in a given log block.
513@param[in,out] log_block log block
514@param[in] offset offset, 0 if none */
515inline void log_block_set_first_rec_group(byte *log_block, uint32_t offset) {
516 mach_write_to_2(log_block + LOG_BLOCK_FIRST_REC_GROUP, offset);
517}
518
519/** Gets a log block epoch_no. For details: @see LOG_BLOCK_EPOCH_NO.
520@param[in] log_block log block
521@return epoch number */
522inline uint32_t log_block_get_epoch_no(const byte *log_block) {
523 return mach_read_from_4(log_block + LOG_BLOCK_EPOCH_NO);
524}
525
526/** Sets a log block epoch_no. For details: @see LOG_BLOCK_EPOCH_NO.
527@param[in,out] log_block log block
528@param[in] no epoch number */
529inline void log_block_set_epoch_no(byte *log_block, uint32_t no) {
530 mach_write_to_4(log_block + LOG_BLOCK_EPOCH_NO, no);
531}
532
533/** Converts a lsn to a log block epoch number.
534For details @see LOG_BLOCK_EPOCH_NO.
535@param[in] lsn lsn of a byte within the block
536@return log block epoch number, it is > 0 */
538 return 1 +
539 static_cast<uint32_t>(lsn / OS_FILE_LOG_BLOCK_SIZE / LOG_BLOCK_MAX_NO);
540}
541
542/** Converts a lsn to a log block number. Consecutive log blocks have
543consecutive numbers (unless the sequence wraps). It is guaranteed that
544the calculated number is greater than zero.
545
546@param[in] lsn lsn of a byte within the block
547@return log block number, it is > 0 and <= 1G */
549 return 1 +
550 static_cast<uint32_t>(lsn / OS_FILE_LOG_BLOCK_SIZE % LOG_BLOCK_MAX_NO);
551}
552
553/** Calculates the checksum for a log block.
554@param[in] log_block log block
555@return checksum */
556inline uint32_t log_block_calc_checksum(const byte *log_block) {
557 return log_checksum_algorithm_ptr.load()(log_block);
558}
559
560/** Calculates the checksum for a log block using the MySQL 5.7 algorithm.
561@param[in] log_block log block
562@return checksum */
563inline uint32_t log_block_calc_checksum_crc32(const byte *log_block) {
565}
566
567/** Calculates the checksum for a log block using the "no-op" algorithm.
568@return checksum */
569inline uint32_t log_block_calc_checksum_none(const byte *) {
571}
572
573/** Gets value of a log block checksum field.
574@param[in] log_block log block
575@return checksum */
576inline uint32_t log_block_get_checksum(const byte *log_block) {
577 return mach_read_from_4(log_block + OS_FILE_LOG_BLOCK_SIZE -
579}
580
581/** Sets value of a log block checksum field.
582@param[in,out] log_block log block
583@param[in] checksum checksum */
584inline void log_block_set_checksum(byte *log_block, uint32_t checksum) {
586 checksum);
587}
588
589/** Stores a 4-byte checksum to the trailer checksum field of a log block.
590This is used before writing the log block to disk. The checksum in a log
591block is used in recovery to check the consistency of the log block.
592@param[in] log_block log block (completely filled in!) */
593inline void log_block_store_checksum(byte *log_block) {
594 log_block_set_checksum(log_block, log_block_calc_checksum(log_block));
595}
596
597/** Gets value of a log block encrypt bit (true or false).
598@param[in] log_block log block
599@return true iff encrypt bit is set */
600inline bool log_block_get_encrypt_bit(const byte *log_block) {
603 return true;
604 }
605
606 return false;
607}
608
609/** Sets value of a log block encrypt bit (true or false).
610@param[in] log_block log block to modify
611@param[in] val the value to set (true or false) */
612inline void log_block_set_encrypt_bit(byte *log_block, bool val) {
613 uint32_t field;
614
615 field = mach_read_from_2(log_block + LOG_BLOCK_HDR_DATA_LEN);
616
617 if (val) {
618 field = field | LOG_BLOCK_ENCRYPT_BIT_MASK;
619 } else {
620 field = field & ~LOG_BLOCK_ENCRYPT_BIT_MASK;
621 }
622
623 mach_write_to_2(log_block + LOG_BLOCK_HDR_DATA_LEN, field);
624}
625
626/** Serializes the log data block header to the redo log block buffer which
627already contains redo log data (must have the redo data before this call).
628@param[in] header the header to serialize
629@param[out] buf the buffer containing the redo log block with the data */
631 byte *buf) {
637}
638
639/** Deserializes the log data block header stored in the buffer.
640@param[in] buf the buffer to deserialize
641@param[out] header the deserialized header
642@return true iff checksum is correct */
644 Log_data_block_header &header) {
650}
651
652/** @} */
653
654#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
dberr_t log_data_blocks_read(Log_file_handle &file_handle, os_offset_t read_offset, size_t read_size, byte *buf, bool can_decrypt=true)
Reads log blocks with redo records from the log file, starting at the given offset.
Definition: log0files_io.cc:676
void log_block_set_epoch_no(byte *log_block, uint32_t no)
Sets a log block epoch_no.
Definition: log0files_io.h:529
void log_block_set_data_len(byte *log_block, uint32_t len)
Sets the log block data length.
Definition: log0files_io.h:498
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
uint32_t log_block_calc_checksum(const byte *log_block)
Calculates the checksum for a log block.
Definition: log0files_io.h:556
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:612
uint32_t log_block_get_hdr_no(const byte *log_block)
Gets a log block number stored in the header.
Definition: log0files_io.h:471
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:643
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:600
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:491
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:584
uint32_t log_block_get_checksum(const byte *log_block)
Gets value of a log block checksum field.
Definition: log0files_io.h:576
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:593
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:569
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:481
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:507
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:522
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:537
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:563
uint32_t log_block_convert_lsn_to_hdr_no(lsn_t lsn)
Converts a lsn to a log block number.
Definition: log0files_io.h:548
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:515
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:630
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:2879
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