24#ifndef BINLOG_LOG_SANITIZER_IMPL_HPP
25#define BINLOG_LOG_SANITIZER_IMPL_HPP
29#include "mysqld_error.h"
40template <
class Type_reader>
42 const std::list<std::string> &list_of_files,
45 for (
auto rit = list_of_files.rbegin(); rit != list_of_files.rend(); ++rit) {
51 if (rit != list_of_files.rbegin() && this->m_has_valid_pos) {
60 ss <<
"Removed " << *rem_it
62 <<
" ; removing file from disk";
65 }
while (rem_it != list_of_files.rbegin());
72template <
class Type_reader>
84template <
class Type_reader>
86 if (!reader.is_open()) {
95template <
class Type_reader>
98 Scope_guard close_at_end([&reader]() { reader.close(); });
100 if (!reader.is_open()) {
101 if (reader.open(
filename.c_str())) {
105 close_at_end.release();
109 close_at_end.release();
115 std::shared_ptr<Log_event> ev;
119 bool contains_finished_transaction =
false;
123 while (istream >> ev) {
124 bool is_source_event = !ev->is_relay_log_event() ||
126 switch (ev->get_type_code()) {
141 if (is_source_event) {
158 ev->get_type_code() !=
167 if (rev->new_log_ident !=
nullptr) {
176 contains_finished_transaction =
true;
180 if (istream.has_error()) {
182 switch (istream.get_status()) {
183 case Status_t::out_of_memory:
188 case Status_t::exceeds_max_size:
193 case Status_t::corrupted:
195 case Status_t::success:
197 case Status_t::truncated:
202 if ((reader.position() != this->m_valid_pos || istream.has_error()) &&
205 std::stringstream ss;
206 ss <<
"The following log needs truncation:" <<
filename;
207 ss <<
" ; read up to: " << reader.position();
210 return contains_finished_transaction;
const char * get_index_fname()
Definition: binlog.h:884
A Query event is written to the binary log whenever the database is modified on the master,...
Definition: log_event.h:1296
A Lambda to be called at scope exit.
Definition: scope_guard.h:55
Similar to Xid_log_event except that.
Definition: log_event.h:1832
This is the subclass of Xid_event defined in libbinlogevent, An XID event is generated for a commit o...
Definition: log_event.h:1781
Stream class that yields Log_event objects from a source.
Definition: decompressing_event_object_istream.h:68
mysql::binlog::event::compression::Decompress_status Status_t
Definition: decompressing_event_object_istream.h:77
bool m_has_valid_source_pos
Indicator on whether a valid source position has been found in the log file.
Definition: log_sanitizer.h:220
bool m_has_valid_pos
Indicator on whether a valid position has been found in the log file.
Definition: log_sanitizer.h:216
bool process_one_log(Type_reader &reader, const std::string &filename)
Reads and validates one log file.
Definition: log_sanitizer_impl.hpp:96
virtual PSI_memory_key & get_memory_key() const =0
Function used to obtain memory key for derived classes.
void process_logs(Type_reader &reader)
This function goes through the opened file and searches for a valid position in a binary log file.
Definition: log_sanitizer_impl.hpp:85
void process_xid_event(Xid_log_event const &ev)
Invoked when a Xid_log_event is read from the binary log file reader.
Definition: log_sanitizer.cc:96
bool m_fatal_error
Whether or not the binary log has a fatal error.
Definition: log_sanitizer.h:196
bool is_fatal_error() const
Checks whether the fatal error occurred during log sanitization (OOM / decompression error which we c...
Definition: log_sanitizer.cc:55
bool m_validation_started
Indicates whether validation has started.
Definition: log_sanitizer.h:179
my_off_t m_last_file_size
Last opened file size.
Definition: log_sanitizer.h:223
std::string m_valid_source_file
Currently processed binlog file set in case source rotation event is encountered.
Definition: log_sanitizer.h:188
bool m_in_transaction
Whether or not the event being processed is within a transaction.
Definition: log_sanitizer.h:192
bool m_is_log_truncation_needed
Information on whether log needs to be truncated, i.e.
Definition: log_sanitizer.h:213
bool m_is_malformed
Whether or not the binary log is malformed/corrupted or error occurred.
Definition: log_sanitizer.h:194
my_off_t m_valid_source_pos
Position of the last binlog event that ended a transaction (source position which corresponds to m_va...
Definition: log_sanitizer.h:185
void process_xa_prepare_event(XA_prepare_log_event const &ev)
Invoked when a XA_prepare_log_event is read from the binary log file reader.
Definition: log_sanitizer.cc:112
std::string m_valid_file
Last log file containing finished transaction.
Definition: log_sanitizer.h:190
void process_query_event(Query_log_event const &ev)
Invoked when a Query_log_event is read from the binary log file reader.
Definition: log_sanitizer.cc:65
my_off_t m_valid_pos
Position of the last binlog/relay log event that ended a transaction.
Definition: log_sanitizer.h:182
std::string m_failure_message
Textual representation of the encountered failure.
Definition: log_sanitizer.h:198
When a binary log file exceeds a size limit, a ROTATE_EVENT is written at the end of the file that po...
Definition: control_events.h:117
Stream class that yields Log_event objects, including events contained in Transaction_payload_log_eve...
std::pair< std::list< std::string >, mysql::utils::Error > get_filename_list()
Definition: binlog.cc:1899
int remove_logs_outside_range_from_index(const std::string &first, const std::string &last)
Definition: binlog.cc:5282
#define BIN_LOG_HEADER_SIZE
Definition: binlog_event.h:88
#define my_delete_allow_opened(fname, flags)
Definition: my_sys.h:643
bool is_any_gtid_event(const Log_event *evt)
Definition: log_event.h:4570
bool is_session_control_event(Log_event *evt)
Check if the given event is a session control event, one of User_var_event, Intvar_event or Rand_even...
Definition: log_event.h:4584
MYSQL_PLUGIN_IMPORT ulong server_id
Definition: log_event.h:118
#define LogErr(severity, ecode,...)
Definition: log_builtins.h:856
#define MYF(v)
Definition: my_inttypes.h:97
@ INFORMATION_LEVEL
Definition: my_loglevel.h:45
@ FORMAT_DESCRIPTION_EVENT
Definition: binlog_event.h:304
@ XID_EVENT
Definition: binlog_event.h:305
@ XA_PREPARE_LOG_EVENT
Definition: binlog_event.h:354
@ QUERY_EVENT
Definition: binlog_event.h:292
@ STOP_EVENT
Definition: binlog_event.h:293
@ ROTATE_EVENT
Definition: binlog_event.h:294
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
const char * filename
Definition: pfs_example_component_population.cc:67
mysql::allocators::Memory_resource psi_memory_resource(PSI_memory_key key)
Return a PSI-enabled Memory_resource using the given key.
Definition: psi_memory_resource.cc:29
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61