MySQL 26.7.0
Source Code Documentation
binlog_ofile.h
Go to the documentation of this file.
1/* Copyright (c) 2024, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23#ifndef BINLOG_OFILE_H_INCLUDED
24#define BINLOG_OFILE_H_INCLUDED
25
26#include "my_inttypes.h"
28#include "sql/basic_ostream.h"
29#include "sql/binlog.h"
30
31/**
32 Logical binlog file which wraps and hides the detail of lower layer storage
33 implementation. Binlog code just use this class to control real storage
34 */
36 public:
37 ~Binlog_ofile() override;
38
39 /**
40 Opens the binlog file. It opens the lower layer storage.
41
42 @param[in] log_file_key The PSI_file_key for this stream
43 @param[in] binlog_name The file to be opened
44 @param[in] flags The flags used by IO_CACHE.
45 @param[in] existing True if opening the file, false if creating a new one.
46
47 @retval false Success
48 @retval true Error
49 */
50 [[nodiscard]] bool open(
52 PSI_file_key log_file_key,
53#endif
54 const char *binlog_name, myf flags, bool existing = false);
55
56 /**
57 Opens an existing binlog file. It opens the lower layer storage reusing the
58 existing file password if needed.
59
60 @param[in] log_file_key The PSI_file_key for this stream
61 @param[in] binlog_name The file to be opened
62 @param[in] flags The flags used by IO_CACHE.
63
64 @retval std::unique_ptr A Binlog_ofile object pointer.
65 @retval nullptr Error.
66 */
67 [[nodiscard]] static std::unique_ptr<MYSQL_BIN_LOG::Binlog_ofile>
70 PSI_file_key log_file_key,
71#endif
72 const char *binlog_name, myf flags);
73
74 virtual void close();
75
76 /**
77 Writes data into storage and maintains binlog position.
78
79 @param[in] buffer the data will be written
80 @param[in] length the length of the data
81
82 @retval false Success
83 @retval true Error
84 */
85 [[nodiscard]] virtual bool write(const unsigned char *buffer,
86 my_off_t length) override;
87
88 /**
89 Updates some bytes in the binlog file. If is only used for clearing
90 LOG_EVENT_BINLOG_IN_USE_F.
91
92 @param[in] buffer the data will be written
93 @param[in] length the length of the data
94 @param[in] offset the offset of the bytes will be updated
95
96 @retval false Success
97 @retval true Error
98 */
99 [[nodiscard]] virtual bool update(const unsigned char *buffer,
100 my_off_t length, my_off_t offset);
101
102 /**
103 Truncates some data at the end of the binlog file.
104
105 @param[in] offset where the binlog file will be truncated to.
106
107 @retval false Success
108 @retval true Error
109 */
110 [[nodiscard]] virtual bool truncate(my_off_t offset);
111
112 [[nodiscard]] virtual bool flush();
113 [[nodiscard]] virtual bool sync();
114 [[nodiscard]] virtual bool flush_and_sync();
115 [[nodiscard]] virtual my_off_t position();
116 [[nodiscard]] virtual bool is_empty();
117 [[nodiscard]] virtual bool is_open();
118
119 /**
120 Returns the encrypted header size of the binary log file.
121
122 @retval 0 The file is not encrypted.
123 @retval >0 The encryption header size.
124 */
125 [[nodiscard]] virtual int get_encrypted_header_size();
126
127 /**
128 Returns the real file size.
129
130 While position() returns the "file size" from the plain binary log events
131 stream point of view, this function considers the encryption header when it
132 exists.
133
134 @return The real file size considering the encryption header.
135 */
136 [[nodiscard]] virtual my_off_t get_real_file_size();
137
138 /**
139 Get the pipeline head.
140
141 @retval Returns the pipeline head or nullptr.
142 */
143 [[nodiscard]] virtual std::unique_ptr<Truncatable_ostream>
145
146 /**
147 Check if the log file is encrypted.
148
149 @retval True if the log file is encrypted.
150 @retval False if the log file is not encrypted.
151 */
152 [[nodiscard]] virtual bool is_encrypted();
153
154 /**
155 Set that the log file is encrypted.
156 */
157 virtual void set_encrypted();
158
159 private:
162 std::unique_ptr<Truncatable_ostream> m_pipeline_head;
163 bool m_encrypted = false;
164};
165
166#endif /* BINLOG_OFILE_H_INCLUDED */
The abstract class for basic output streams which provides write operation.
Definition: basic_ostream.h:36
Logical binlog file which wraps and hides the detail of lower layer storage implementation.
Definition: binlog_ofile.h:35
virtual void close()
Definition: binlog_ofile.cc:125
virtual bool is_empty()
Definition: binlog_ofile.cc:160
virtual void set_encrypted()
Set that the log file is encrypted.
Definition: binlog_ofile.cc:180
bool open(PSI_file_key log_file_key, const char *binlog_name, myf flags, bool existing=false)
Opens the binlog file.
Definition: binlog_ofile.cc:36
virtual bool is_encrypted()
Check if the log file is encrypted.
Definition: binlog_ofile.cc:178
std::unique_ptr< Truncatable_ostream > m_pipeline_head
Definition: binlog_ofile.h:162
virtual bool is_open()
Definition: binlog_ofile.cc:161
virtual bool sync()
Definition: binlog_ofile.cc:157
virtual bool update(const unsigned char *buffer, my_off_t length, my_off_t offset)
Updates some bytes in the binlog file.
Definition: binlog_ofile.cc:141
virtual bool flush()
Definition: binlog_ofile.cc:156
virtual bool flush_and_sync()
Definition: binlog_ofile.cc:158
my_off_t m_position
Definition: binlog_ofile.h:160
int m_encrypted_header_size
Definition: binlog_ofile.h:161
virtual int get_encrypted_header_size()
Returns the encrypted header size of the binary log file.
Definition: binlog_ofile.cc:165
virtual my_off_t position()
Definition: binlog_ofile.cc:159
virtual bool truncate(my_off_t offset)
Truncates some data at the end of the binlog file.
Definition: binlog_ofile.cc:148
bool m_encrypted
Definition: binlog_ofile.h:163
~Binlog_ofile() override
Definition: binlog_ofile.cc:30
virtual bool write(const unsigned char *buffer, my_off_t length) override
Writes data into storage and maintains binlog position.
Definition: binlog_ofile.cc:131
virtual std::unique_ptr< Truncatable_ostream > get_pipeline_head()
Get the pipeline head.
Definition: binlog_ofile.cc:174
virtual my_off_t get_real_file_size()
Returns the real file size.
Definition: binlog_ofile.cc:169
static std::unique_ptr< MYSQL_BIN_LOG::Binlog_ofile > open_existing(PSI_file_key log_file_key, const char *binlog_name, myf flags)
Opens an existing binlog file.
Definition: binlog_ofile.cc:75
unsigned int PSI_file_key
Instrumented file key.
Definition: psi_file_bits.h:48
static int flags[50]
Definition: hp_test1.cc:40
Some integer typedefs for easier portability.
int myf
Definition: my_inttypes.h:94
ulonglong my_off_t
Definition: my_inttypes.h:72
#define HAVE_PSI_INTERFACE
Definition: my_psi_config.h:39
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Performance schema instrumentation interface.