MySQL 26.7.0
Source Code Documentation
log0common.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2026, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify it under
4the terms of the GNU General Public License, version 2.0, as published by the
5Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
18for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc.,
2251 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#pragma once
26
27#include <cstddef>
28#include <cstdint>
29#include <span>
30
31/* Common definitions and data structures for Redo Log Handler artifacts */
32namespace ib::redo {
33/* We don't assume that Lsn is simply a byte lsn in the Log which conceptually
34is an infinite array of bytes! So for example a range <start_lsn,end_lsn) can
35contain less than end_lsn - start_lsn bytes of actual data. This is actually the
36case for the Redo Log Handler which adds headers and trailers.
37So, what Lsn really is? (Apart from a historical accident...)
38It is a kind of a "handle" which Handler_interface implementation can
39*easily* use to locate a particular location inside the log, guaranteed to be
40monotone w.r.t. to position of these locations.
41Such "handles" are reported by @see write_mtr(..., start_lsn, end_lsn).
42Use @see compute_end_lsn(start_lsn, data_len) to identify the lsn
43corresponding to the log position which is data_len after start_len.
44
45Alternative explanation:
46
47Let's introduce a helper concept of Sequence Number (SN): imagine all the
48bytes of all the mtrs in the log are concatenated into a single sequence, then
49SN would simply be a position of byte in this sequence.
50If we imagine the same data to be interleaved with some padding (block headers
51and footers) then a position in such a padded sequence is the Lsn.
52There are two mappings:
53lsn_to_sn : Lsn -> SN which is non-decreasing
54sn_to_lsn : SN -> Lsn which is strictly increasing
55That is Lsn may increase faster than SN (due to headers and footers between
56actual data).
57For all sn: lsn_to_sn(sn_to_lsn(sn))==sn
58compute_end_lsn(start_lsn, data_len)==sn_to_lsn(lsn_to_sn(start_lsn)+data_len)
59 */
60using Lsn = uint64_t;
61
62/** Additional error constants may be added to the list here, keeping in
63mind the following guidelines about our approach to error handling:
641. If there's an error which looks like a violation of a contract between the
65caller and the Redo Log Handler explained in this documentation - for example:
66passing end_lsn smaller than start_lsn to read(..start_lsn,end_lsn,..) - then
67it should result in a crash (assertion failure) rather than an error, as such
68bugs should be handled at implementation stage, not at runtime.
692. Errors should be used for situations which reasonably could not be
70expected and prevented by the caller, but are rather caused by particular
71situation at runtime: for example trying to write beyond current capacity may
72be an effect of not being aware that somebody has changed the capacity.
733. We acknowledge the gray area between these two. When in doubt, by default
74return an error. Use assertions for things we are sure are bugs in code.
754. We should keep the number of Error constants not too large and not too
76small. We should ask ourselves if the caller can really perform two distinct
77actions in response to two different errors - if the caller doesn't really
78care then it seems better to not introduce the distinction.
795. For human-readable logging, the Redo Log Handler might internally distinguish
80various narrow conditions and report them in different ways. But the Error
81codes here are meant for the caller, not the human operator. So, always ask
82yourself if the code which uses the API really understands the concept the
83error is about and can react to it. While the user may care that a given cloud
84bucket is unreachable, as opposed to having wrong authentication token, what
85the code really cares about is that it was a READ_ERROR.
866. If there is a violation of some code invariant (like it was detected that
87an in-memory data structure pointer is null) it should be an assertion failure
88and crash, as opposed to trying to communicate it to the caller.
897. In future we might want to distinguish between transient errors (for which
90the caller might want to attempt retrying) and permanent errors. For now we
91implicitly assume that all are transient, as otherwise there would be no point
92in reporting them - caller would need to crash/stop anyway. This will evolve
93as we understand better each and every case.
948. There's just one SUCCESS value and it is 0. So, for example if a function
95may succeed in several ways, these should be conveyed by additional output
96argument, so that the error handling pattern is always the same: non-zero
97value means a problem.
989. Same error constant may be used by multiple functions if the name seems to
99fit. (If we ever revisit this, then perhaps we should also have one enum per
100function).
101*/
102enum class Status {
103 SUCCESS = 0,
106 NO_LOG,
121};
122
123using Buffer = std::span<uint8_t>;
124using Const_buffer = std::span<const uint8_t>;
127 size_t count;
128};
129
130} // namespace ib::redo
Definition: log0common.h:32
Status
Additional error constants may be added to the list here, keeping in mind the following guidelines ab...
Definition: log0common.h:102
uint64_t Lsn
Definition: log0common.h:60
std::span< uint8_t > Buffer
Definition: log0common.h:123
std::span< const uint8_t > Const_buffer
Definition: log0common.h:124
Definition: log0common.h:125
Const_buffer const * buffers
Definition: log0common.h:126
size_t count
Definition: log0common.h:127