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