MySQL 26.7.0
Source Code Documentation
log0handler.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2022, 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#pragma once
29
31#include "log0sys_var_handler.h"
32
33namespace ib::redo {
34
35/** The type of metadata that could be handled by the handler */
36enum Metadata_key : uint16_t { HEADER = 0, CHECKPOINT };
37
38#ifndef UNIV_HOTBACKUP
39/* The Redo Log Handler that provides the file based implementation of
40 Handler Interface. It is the default handler used in InnoDB */
41class Handler final : public Handler_interface {
42 public:
43 ~Handler() override;
44
45 [[nodiscard]] Lsn align_down_to_known_boundary(Lsn lsn) override;
46
47 [[nodiscard]] Capabilities get_capabilities() override;
48
49 [[nodiscard]] Status create(Lsn start_lsn) override;
50
51 [[nodiscard]] bool reconfigure(size_t max_threads,
52 size_t reserved_bytes_per_thread) override;
53
54 [[nodiscard]] Capacity_estimate get_capacity_estimate() override;
55
56 void wait_for_space() override;
57
58 [[nodiscard]] bool has_space() override;
59
60 [[nodiscard]] Status start_writing(Lsn lsn) override;
61
62 void stop_writing() override;
63
64 [[nodiscard]] Status start_reading() override;
65
66 [[nodiscard]] Status write_mtr(const Const_buffers &mtr_data, Lsn &start_lsn,
67 Lsn &end_lsn) override;
68
69 [[nodiscard]] Status persist_smaller_than(Lsn end_lsn,
70 Durability desired_guarantee,
71 Origin origin) override;
72
73 [[nodiscard]] Status persist_available(const Origin &origin) override;
74
75 [[nodiscard]] Status store_metadata(uint16_t key,
76 const Metadata_value &value) override;
77
78 [[nodiscard]] Status read(Lsn start_lsn, Buffer &buffer) override;
79
80 [[nodiscard]] Status do_not_need_smaller_than(Lsn needed_lsn) override;
81 [[nodiscard]] Status get_metadata(uint16_t key,
82 Metadata_value &metadata) override;
83
84 [[nodiscard]] Lsn peek_first_unassigned_lsn() override;
85
86 [[nodiscard]] Lsn peek_first_nonpersisted_lsn() override;
87
88 [[nodiscard]] Lsn compute_end_lsn(Lsn start_lsn,
89 size_t data_len) const override;
90
91 [[nodiscard]] Sys_var_handler_interface &config_handler() override;
92
93 private:
94 friend class Sys_var_handler;
96
97 /** The value of max_threads most recently passed to reconfigure */
98 size_t m_max_threads{};
99
100 /** The value of reserved_bytes_per_thread most recently passed to
101 reconfigure */
103
104 /** Recomputes log_sys->m_free_check_limit_lsn. It is private, but used in
105 Sys_var_handler whenever innodb_redo_log_capacity changes, to learn if the
106 configured capacity and number of threads make the margin safe. For similar
107 reason called from `reconfigure(..)`, on startup and when
108 innodb_thread_concurrency changes. But, most of the calls come from
109 do_not_need_smaller_than(x), which is called whenever a checkpoint lsn is
110 bumped or Log Files Governor asks Log_checkpointing to update_limits - this
111 way this Log Handler implementation learns what's the oldest needed lsn, and
112 can bump the m_free_check_limit_lsn accordingly.
113 @return true iff log_concurrency_margin thinks the margin is safe */
114 [[nodiscard]] bool update_free_check_limit();
115};
116
117[[nodiscard]] inline Handler_interface::Capabilities
120 caps.atomic_write = false;
121 caps.supports_clone = true;
122 caps.supports_meb = true;
123 caps.supports_disabling = true;
124 caps.supports_encryption = true;
125 return caps;
126}
127
128#endif /* !UNIV_HOTBACKUP */
129} // namespace ib::redo
130
131#include "univ.i"
132
133/* Following method should be removed as it breaks the API Interface
134abstraction. But needed as of now because we allow REDO block checksum to be
135disabled. Once we remove this flexibility, we can remove following functions. */
136
137/* update the value of last_block_first_rec_group if needed */
139 ib::redo::Lsn old_recovered_lsn, ib::redo::Lsn new_recovered_lsn,
140 ib::redo::Lsn &last_block_first_mtr_boundary);
Definition: ha0sys_var_handler_interface.h:36
This Redo Log Handler interface provides an abstraction over the redo log persistence and publishing ...
Definition: log0handler_interface.h:42
Durability
Used by persist_smaller_than(...desired_guarantee) to let the caller specify the desired guarantee ab...
Definition: log0handler_interface.h:602
Origin
Used by persist_smaller_than(...origin) and persist_available(...origin) to let the caller specify th...
Definition: log0handler_interface.h:591
std::array< unsigned char, METADATA_BLOCK_SIZE > Metadata_value
Definition: log0handler_interface.h:785
Definition: log0handler.h:41
bool update_free_check_limit()
Recomputes log_sys->m_free_check_limit_lsn.
Definition: log0handler.cc:626
Capabilities get_capabilities() override
Query the capabilities of the Redo Log Handler.
Definition: log0handler.h:118
Status start_reading() override
Informs the Redo Log Handler that InnoDB intends to start reading from the log.
Definition: log0handler.cc:155
Status persist_smaller_than(Lsn end_lsn, Durability desired_guarantee, Origin origin) override
A synchronous request for the Redo Log Handler to promise that previously written data is durable at ...
Definition: log0handler.cc:290
bool reconfigure(size_t max_threads, size_t reserved_bytes_per_thread) override
InnoDB uses write_mtr(data,..) in mtr.commit() when a thread still holds latches on pages involved in...
Definition: log0handler.cc:683
Status do_not_need_smaller_than(Lsn needed_lsn) override
Definition: log0handler.cc:677
void stop_writing() override
Informs Redo Log Handler that the caller no longer intends writing to the log.
Definition: log0handler.cc:288
size_t m_reserved_bytes_per_thread
The value of reserved_bytes_per_thread most recently passed to reconfigure.
Definition: log0handler.h:102
Status start_writing(Lsn lsn) override
Informs Redo Log Handler that the caller intends to start writing to the log.
Definition: log0handler.cc:276
void wait_for_space() override
Called from a thread which wishes to pass no more than reserved_bytes_per_thread of data to write_mtr...
Definition: log0handler.cc:741
Status persist_available(const Origin &origin) override
Similar to persist_smaller_than(end_lsn, origin), except that the caller politely asks the Redo Log H...
Definition: log0handler.cc:522
Lsn compute_end_lsn(Lsn start_lsn, size_t data_len) const override
Returns the lsn at the requested position that is the end of the MTR data.
Definition: log0handler.cc:307
Sys_var_handler m_sys_var_handler
Definition: log0handler.h:95
size_t m_max_threads
The value of max_threads most recently passed to reconfigure.
Definition: log0handler.h:98
bool has_space() override
This is a no-wait variant of wait_for_space(), i.e.
Definition: log0handler.cc:777
Lsn align_down_to_known_boundary(Lsn lsn) override
Each call to write_mtr(..., &start_lsn, &end_lsn), or create(start_lsn), declares start_lsn to be a b...
Definition: log0handler.cc:311
Lsn peek_first_nonpersisted_lsn() override
Intuitively returns the largest end_lsn passed to a successfully finished persist_smaller_than(end_ls...
Definition: log0handler.cc:518
Status read(Lsn start_lsn, Buffer &buffer) override
Reads previously persisted portion of the Log starting from start_lsn synchronously.
Definition: log0handler.cc:379
~Handler() override
Definition: log0handler.cc:153
Status create(Lsn start_lsn) override
Request synchronous creation of Log starting at a given start_lsn.
Definition: log0handler.cc:186
Capacity_estimate get_capacity_estimate() override
Used by InnoDB to determine if page cleaning and checkpointing should be speed up,...
Definition: log0handler.cc:612
Lsn peek_first_unassigned_lsn() override
Intuitively returns the largest end_lsn assigned from an write_mtr(..,&end_lsn) call.
Definition: log0handler.cc:517
Sys_var_handler_interface & config_handler() override
Returns the handler to configure the redo log related system variables.
Definition: log0handler.cc:784
Status store_metadata(uint16_t key, const Metadata_value &value) override
Persists synchronously the metadata atomically overwriting the old value for a given key.
Definition: log0handler.cc:528
Status get_metadata(uint16_t key, Metadata_value &metadata) override
Retrieves the previously stored metadata block for a given key.
Definition: log0handler.cc:788
Status write_mtr(const Const_buffers &mtr_data, Lsn &start_lsn, Lsn &end_lsn) override
Request an asynchronous append of the mtr's body's bytes to the log.
Definition: log0handler.cc:208
This class implements the handling of redo log related system variables.
Definition: log0sys_var_handler.h:37
void log_track_changes_of_recovered_lsn(ib::redo::Lsn old_recovered_lsn, ib::redo::Lsn new_recovered_lsn, ib::redo::Lsn &last_block_first_mtr_boundary)
Tracks changes of recovered_lsn and tracks proper values for what first_rec_group should be for conse...
Definition: log0handler.cc:1518
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
Metadata_key
The type of metadata that could be handled by the handler.
Definition: log0handler.h:36
@ HEADER
Definition: log0handler.h:36
@ CHECKPOINT
Definition: log0handler.h:36
std::span< uint8_t > Buffer
Definition: log0common.h:123
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Definition: log0common.h:125
Definition: log0handler_interface.h:56
bool atomic_write
If true, then the implementation supports "atomic writes", which means that if any of the bytes passe...
Definition: log0handler_interface.h:71
bool supports_encryption
True if REDO log encryption is supported.
Definition: log0handler_interface.h:79
bool supports_disabling
Is ALTER INSTANCE DISABLE INNODB REDO_LOG supported?
Definition: log0handler_interface.h:77
bool supports_meb
MEB assumes direct access to files in specific location and format.
Definition: log0handler_interface.h:75
bool supports_clone
CLONE assumes direct access to files in specific location and format.
Definition: log0handler_interface.h:73
Describes the state of the capacity in sufficient detail that InnoDB knows if it should rush with pag...
Definition: log0handler_interface.h:256
Version control for database, common definitions, and include files.
static uint64_t lsn
Definition: xcom_base.cc:446