Debian Codegraph @

storage/innobase/log/log0pre_8_0_30.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 1995, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /**************************************************/ /**
29 @file log/log0pre_8_0_30.cc
30
31 Redo log - functions related to redo formats before 8.0.30.
32
33 *******************************************************/
34
35 /* std::ostringstream */
36 #include <sstream>
37
38 #include "log0files_io.h"
39 #include "log0pre_8_0_30.h"
40 #include "log0types.h"
41 #include "mach0data.h"
42
43 namespace log_pre_8_0_30 {
44
45 static os_offset_t compute_size_offset(os_offset_t file_size,
46 os_offset_t real_offset) {
47 const auto files_before = real_offset / file_size;
48 return real_offset - LOG_FILE_HDR_SIZE * (1 + files_before);
49 }
50
51 static os_offset_t compute_real_offset(os_offset_t file_size,
52 os_offset_t size_offset) {
53 const auto files_before = size_offset / (file_size - LOG_FILE_HDR_SIZE);
54 return size_offset + LOG_FILE_HDR_SIZE * (1 + files_before);
55 }
56
57 os_offset_t compute_real_offset_for_lsn(size_t n_files, os_offset_t file_size,
58 lsn_t some_file_lsn,
59 os_offset_t some_file_offset,
60 lsn_t requested_lsn) {
61 os_offset_t size_offset;
62 os_offset_t size_capacity;
63 os_offset_t delta;
64
65 size_capacity = n_files * (file_size - LOG_FILE_HDR_SIZE);
66
67 if (requested_lsn >= some_file_lsn) {
68 delta = requested_lsn - some_file_lsn;
69 delta = delta % size_capacity;
70 } else {
71 /* Special case because lsn and offset are unsigned. */
72 delta = some_file_lsn - requested_lsn;
73 delta = size_capacity - delta % size_capacity;
74 }
75
76 size_offset = compute_size_offset(file_size, some_file_offset);
77 size_offset = (size_offset + delta) % size_capacity;
78
79 return compute_real_offset(file_size, size_offset);
80 }
81
82 bool checkpoint_header_deserialize(const byte *buf, Checkpoint_header &header) {
83 header.m_checkpoint_no = mach_read_from_8(buf + FIELD_CHECKPOINT_NO);
84
85 header.m_checkpoint_lsn = mach_read_from_8(buf + FIELD_CHECKPOINT_LSN);
86
87 header.m_checkpoint_offset = mach_read_from_8(buf + FIELD_CHECKPOINT_OFFSET);
88
89 header.m_log_buf_size = mach_read_from_8(buf + FIELD_CHECKPOINT_LOG_BUF_SIZE);
90
91 return log_header_checksum_is_ok(buf);
92 }
93
94 std::string file_name(Log_file_id file_id) {
95 ut_a(file_id <= FILE_MAX_ID);
96 std::ostringstream str;
97 str << FILE_BASE_NAME << file_id;
98 return str.str();
99 }
100
101 bool files_validate_format(const Log_files_context &files_ctx,
102 const ut::vector<Log_file_id_and_header> &files,
103 Log_format &format) {
104 ut_a(!files.empty());
105 const auto first_file = files.front();
106 if (first_file.m_id == 0) {
107 if (first_file.m_header.m_format < to_int(Log_format::VERSION_8_0_30)) {
108 format = static_cast<Log_format>(first_file.m_header.m_format);
109 return true;
110 }
111 const auto file_path = log_file_path(files_ctx, 0);
112 ib::error(ER_IB_MSG_LOG_FILE_FORMAT_TOO_NEW, file_path.c_str(),
113 ulong{first_file.m_header.m_format});
114 return false;
115 } else {
116 const auto directory = log_directory_path(files_ctx);
117 ib::error(ER_IB_MSG_LOG_PRE_8_0_30_MISSING_FILE0, directory.c_str());
118 return false;
119 }
120 }
121
122 } // namespace log_pre_8_0_30