MySQL 26.7.0
Source Code Documentation
relay_log_deleter.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_RELAY_LOG_DELETER_H
25#define MYSQL_CSA_RELAY_LOG_DELETER_H
26
27#include <atomic>
28#include <iostream>
29#include <memory>
30#include <string>
33
34namespace mysql::csa {
35
36class Relay_log_deleter;
37
38/// @brief Represents a shared reference to Relay_log_deleter. See explanation
39/// below.
40using Relay_log_deleter_handle = std::shared_ptr<Relay_log_deleter>;
41
42/// @brief Class responsible for removing relay log file,
43/// when the last handle to this deleter is released. To know if we are
44/// allowed to delete this relay log file, we need to track its subscribers
45/// and the number of successfull subscribers. If these two numbers are
46/// equal and the last reference to the Relay_log_deleter is released, we
47/// are allowed to remove the relay log. Otherwise, deleter won't remove the
48/// file.
49/// Object of this class is created by relay log metadata reader. Each event
50/// batch in a transaction will contain shared reference to this object. When
51/// event batch is successfully processed, i.e., job done notified in
52/// @see Fetchable_transaction::set_success callback, it will release
53/// reference to the Relay_log_deleter (in destructor).
54/// Another subscriber of the relay log file
55/// deleter is the relay log reader, which must hold reference until the file
56/// changes or closes.
58 public:
59 /// @brief Constructor that initializes metadata needed for relay log
60 /// deletion.
61 /// @param rl_file_name Referenced relay log filename
62 /// @param purger Relay log purger pointer
63 Relay_log_deleter(const std::string &rl_file_name,
65 /// @brief Destructor that removes the relay log file when the last reference
66 /// is released.
68 /// @brief Adds a subscriber to handled relay log file
69 void add_subscriber();
70 /// @brief Notifies that subscriber succeeded
72 /// @brief Handled file name accessor
73 /// @return Handled file name
74 const std::string &get_file_name() const;
75
76 private:
77 /// @brief Physically removes relay log file from disk and index file
78 void remove_handled_relay_log() const;
79 /// @brief Relay log name handled by this deleter
80 std::string m_rl_file_name{""};
81 /// With below variables we track relay log file subscribers and the number of
82 /// successful subscribers. If the number of subscribers is equal to
83 /// the number of successful subscribers, we may remove the relay log.
84 /// Inverse logic could be implemented with one atomic flag, however, this
85 /// way we would not know if some transaction was killed without setting an
86 /// error state (TBC).
87 std::atomic<std::size_t> m_subscribers{0};
88 /// The number of successful subscribers (see above)
89 std::atomic<std::size_t> m_successfull_subscribers{0};
90 /// Pointer to the relay log purger
92};
93
94} // namespace mysql::csa
95
96#endif // MYSQL_CSA_RELAY_LOG_DELETER_H
Class responsible for removing relay log file, when the last handle to this deleter is released.
Definition: relay_log_deleter.h:57
std::atomic< std::size_t > m_successfull_subscribers
The number of successful subscribers (see above)
Definition: relay_log_deleter.h:89
void remove_handled_relay_log() const
Physically removes relay log file from disk and index file.
Definition: relay_log_deleter.cpp:46
void set_subscriber_success()
Notifies that subscriber succeeded.
Definition: relay_log_deleter.cpp:42
~Relay_log_deleter()
Destructor that removes the relay log file when the last reference is released.
Definition: relay_log_deleter.cpp:33
void add_subscriber()
Adds a subscriber to handled relay log file.
Definition: relay_log_deleter.cpp:40
std::atomic< std::size_t > m_subscribers
With below variables we track relay log file subscribers and the number of successful subscribers.
Definition: relay_log_deleter.h:87
Relay_log_deleter(const std::string &rl_file_name, Log_purge_controller_sptr purger)
Constructor that initializes metadata needed for relay log deletion.
Definition: relay_log_deleter.cpp:29
Log_purge_controller_sptr m_purger
Pointer to the relay log purger.
Definition: relay_log_deleter.h:91
std::string m_rl_file_name
Relay log name handled by this deleter.
Definition: relay_log_deleter.h:80
const std::string & get_file_name() const
Handled file name accessor.
Definition: relay_log_deleter.cpp:50
Definition: channel.cpp:28
std::shared_ptr< Relay_log_deleter > Relay_log_deleter_handle
Represents a shared reference to Relay_log_deleter.
Definition: relay_log_deleter.h:40
std::shared_ptr< Log_purge_controller > Log_purge_controller_sptr
Definition: log_purge_controller.h:35
Experimental API header.