MySQL 26.7.0
Source Code Documentation
event_file_metadata.h
Go to the documentation of this file.
1// Copyright (c) 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
24#ifndef MYSQL_CSA_STORAGE_RELAY_LOG_EVENT_FILE_METADATA_H
25#define MYSQL_CSA_STORAGE_RELAY_LOG_EVENT_FILE_METADATA_H
26
27#include <functional>
28#include <memory>
29#include <string>
30#include "sql/binlog_reader.h"
31
32namespace mysql::csa {
33
34/// @brief Represents basic event metadata: type and length
36 public:
39 /// @brief Construct
41 const std::string &file_name, std::size_t file_position,
42 Log_event *ev)
43 : m_event_metadata(ev_meta),
45 m_file_postion(file_position),
46 m_event(ev) {}
48 const std::string &file_name, std::size_t file_position,
49 Log_event *ev, std::optional<Event_payload> data)
50 : m_event_metadata(ev_meta),
52 m_file_postion(file_position),
53 m_event(ev),
54 m_data(data) {}
55 /// @brief Construct
57 const std::string &file_name, std::size_t file_position,
58 const std::string &query, bool is_atomic_ddl,
59 Log_event *ev)
60 : m_event_metadata(ev_meta),
62 m_file_postion(file_position),
65 m_event(ev) {}
66 /// @brief Event length accessor
67 /// @return Event length
68 std::size_t get_length() const { return m_event_metadata.get_length(); }
69 /// @brief Event type accessor
70 /// @return Event type
71 Type get_type() const { return m_event_metadata.get_type(); }
72 /// @brief Event location accessor
73 /// @return Log event file location: file name
74 std::string get_file_name() const { return m_file_name; }
75 /// @brief Event location accessor
76 /// @return Log event file location: file position
77 std::size_t get_file_pos() const { return m_file_postion; }
78 /// @brief Returns information on whether this event is ignorable
79 /// @return True if event may be ignored
80 bool is_ignorable() const { return m_event_metadata.is_ignorable(); }
81 /// @brief Returns query string if type is QUERY_LOG_EVENT, otherwise,
82 /// empty string
83 /// @return query string if type is QUERY_LOG_EVENT, otherwise, empty string
84 const std::string &get_query() const { return m_query; }
85 /// @brief Is atomic DDL flag if any
86 bool is_atomic_ddl() const { return m_is_atomic_ddl; }
87 /// @brief We allow to construct empty objects, this function returns true
88 /// in case object was initialized with data
89 /// @return True in case object was initialized with data, false otherwise
90 bool is_valid() const { return m_event_metadata.is_valid(); }
91 /// @brief Compares two events and returns true if they are placed in
92 /// the same location
93 /// @return True in case files are in the same location, false otherwise
94 bool is_in_same_file(const Event_file_metadata &arg) const {
95 return is_valid() && arg.is_valid() &&
96 (arg.m_file_name == this->m_file_name);
97 }
98
99 bool has_payload() const { return m_data.has_value(); }
100 bool has_event() const { return m_event.operator bool(); }
101 const Event_payload &get_payload() const { return m_data.value(); }
102
103 std::shared_ptr<Log_event> get_event() { return m_event; }
104
106 m_file_name = "";
107 m_file_postion = 0;
108 }
109
110 private:
111 /// @brief Log event metadata
113 /// @brief Log event file location: file name
114 std::string m_file_name;
115 /// @brief Log event file location: file position
116 std::size_t m_file_postion;
117 /// Query is needed to check transaction boundary,
118 /// filled if type is QUERY_LOG_EVENT
119 std::string m_query{""};
120 /// "is atomic DDL" flag, filled if type is QUERY_LOG_EVENT
121 bool m_is_atomic_ddl{false};
122 /// Decoded event, if available
123 std::shared_ptr<Log_event> m_event;
124 /// Payload raw data, if any
125 std::optional<Event_payload> m_data;
126};
127
128} // namespace mysql::csa
129
130#endif // MYSQL_CSA_STORAGE_RELAY_LOG_DATA_SOURCE_H
Represents basic event metadata: type and length.
Definition: binlog_reader.h:30
Type get_type() const
Event type accessor.
Definition: binlog_reader.h:45
std::size_t get_length() const
Event length accessor.
Definition: binlog_reader.h:42
bool is_valid() const
We allow to construct empty objects, this function returns true in case object was initialized with d...
Definition: binlog_reader.h:52
bool is_ignorable() const
Returns information on whether this event is ignorable.
Definition: binlog_reader.h:48
This is the abstract base class for binary log events.
Definition: log_event.h:539
Represents basic event metadata: type and length.
Definition: event_file_metadata.h:35
std::string get_file_name() const
Event location accessor.
Definition: event_file_metadata.h:74
bool is_in_same_file(const Event_file_metadata &arg) const
Compares two events and returns true if they are placed in the same location.
Definition: event_file_metadata.h:94
std::size_t get_file_pos() const
Event location accessor.
Definition: event_file_metadata.h:77
bool is_atomic_ddl() const
Is atomic DDL flag if any.
Definition: event_file_metadata.h:86
std::string m_query
Query is needed to check transaction boundary, filled if type is QUERY_LOG_EVENT.
Definition: event_file_metadata.h:119
Event_file_metadata(const Event_metadata &ev_meta, const std::string &file_name, std::size_t file_position, Log_event *ev)
Construct.
Definition: event_file_metadata.h:40
std::shared_ptr< Log_event > m_event
Decoded event, if available.
Definition: event_file_metadata.h:123
bool has_payload() const
Definition: event_file_metadata.h:99
const Event_payload & get_payload() const
Definition: event_file_metadata.h:101
std::string m_file_name
Log event file location: file name.
Definition: event_file_metadata.h:114
Event_file_metadata(const Event_metadata &ev_meta, const std::string &file_name, std::size_t file_position, const std::string &query, bool is_atomic_ddl, Log_event *ev)
Construct.
Definition: event_file_metadata.h:56
Event_metadata m_event_metadata
Log event metadata.
Definition: event_file_metadata.h:112
std::shared_ptr< Log_event > get_event()
Definition: event_file_metadata.h:103
bool is_valid() const
We allow to construct empty objects, this function returns true in case object was initialized with d...
Definition: event_file_metadata.h:90
Type get_type() const
Event type accessor.
Definition: event_file_metadata.h:71
Event_file_metadata(const Event_metadata &ev_meta, const std::string &file_name, std::size_t file_position, Log_event *ev, std::optional< Event_payload > data)
Definition: event_file_metadata.h:47
bool has_event() const
Definition: event_file_metadata.h:100
bool is_ignorable() const
Returns information on whether this event is ignorable.
Definition: event_file_metadata.h:80
bool m_is_atomic_ddl
"is atomic DDL" flag, filled if type is QUERY_LOG_EVENT
Definition: event_file_metadata.h:121
std::size_t get_length() const
Event length accessor.
Definition: event_file_metadata.h:68
std::size_t m_file_postion
Log event file location: file position.
Definition: event_file_metadata.h:116
const std::string & get_query() const
Returns query string if type is QUERY_LOG_EVENT, otherwise, empty string.
Definition: event_file_metadata.h:84
void clear_file_metadata()
Definition: event_file_metadata.h:105
std::optional< Event_payload > m_data
Payload raw data, if any.
Definition: event_file_metadata.h:125
static char * query
Definition: myisam_ftdump.cc:47
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:45
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:279
Definition: channel.cpp:28
Helper structure used by the reader to aggregate payload and information needed to decode an event.
Definition: binlog_reader.h:91