MySQL 26.7.0
Source Code Documentation
fetchable_transaction.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_FETCHABLE_TRANSACTION_H
25#define MYSQL_CSA_FETCHABLE_TRANSACTION_H
26
27#include <atomic>
28#include <condition_variable>
29#include <memory>
30#include <mutex>
31#include <optional>
32#include <string>
33
37
38namespace mysql::csa {
39
40/// @brief Opaque for transaction, that is able to fetch itself in parts
41/// from the storage on demand.
42/// Function to fetch an event is supplied by the specific
43/// storage implementation.
45 public:
47
48 /// @brief Fetch function is supplied by a specific storage implementation
53
54 /// @brief Destructor
55 virtual ~Fetchable_transaction();
56
57 /// Fetches consecutive events from the storage, until done or error occurs
58 /// @return Managed event object in case it was successfully fetched from
59 /// the storage, empty object in case stream is done or error occurred
60 bool wait_next();
61 std::optional<Managed_event> fetch_next();
62
63 /// @brief Returs true when fetching failed
64 /// @return True when fetching failed, false otherwise
65 bool is_fetching_error() const;
66
67 /// @brief Checks current status of the object
68 /// @return True when fetching is completed, false otherwise
69 bool is_fetching_done() const;
70
71 /// @brief Checks whether fetching stopped because the metadata stream was
72 /// truncated.
73 /// @return True when fetching stopped on truncation, false otherwise
74 bool is_truncated() const;
75 /// Returns the maximum event length published for this transaction.
76 std::size_t get_max_event_length() const;
77
78 /// @brief Reset the status of the Featchable job allowing it to be
79 /// re-read from the storage
80 /// @param all When true, internal object states must be reset
81 void reset_fetching(bool all);
82
83 /// @brief Accesses fetch error message
84 /// @return Fetch error information
85 std::string get_fetch_error_msg() const;
86
87 /// @brief Returns information on whether this is actual transaction
88 /// (transaction starting with a GTID)
89 bool is_trx() const;
90
91 /// Marks that transaction committed succesfully, success callback
92 void set_success();
93
94 /// @brief Obtains non-owning pointer to current FDE
95 /// @return Non-owning pointer to current FDE
97
98 /// Mark that fetching is successfully done, even if transaction was
99 /// not fully read
100 void set_fetching_done();
101
102 /// Appends a new fetchable batch for this transaction.
104
105 /// Seals transaction metadata stream. No more batches will be appended.
107 /// Updates the maximum event length published for this transaction.
108 void update_max_event_length(std::size_t event_length);
109
110 /// Marks transaction metadata stream as truncated.
112
113 private:
114 /// Waits until a current batch becomes available or fetching reaches a
115 /// terminal state.
116 /// @return Current batch pointer or nullptr in terminal state.
118 /// Advances to the next batch if the current one has finished.
119 /// @param event_batch Current batch being processed.
120 /// @retval true The whole transaction finished.
121 /// @retval false There may still be more events or batches to fetch.
123 /// Iterates over event sets, picking a correct batch
124 std::optional<Event_set_fetchable *> get_current_event_batch_unsafe();
125 /// Detailed error message if error appears
126 std::string m_error_message;
127 /// Internal status of event
129 /// True when the consumer-side fetch stream reached a terminal state.
130 bool m_is_done{false};
131 /// True when reader has finished appending batches.
132 bool m_is_complete{false};
133 /// Maximum event length published for this transaction.
134 std::atomic<std::size_t> m_max_event_length{0};
135 /// True when reader marked metadata stream as truncated.
136 std::atomic<bool> m_is_truncated{false};
137 /// Guard for concurrent producer (reader) and consumer (worker).
138 mutable std::mutex m_mutex;
139 /// Notification for appended batches / terminal state updates.
140 std::condition_variable m_cv;
141 /// Object used to fetch transaction events from the storage
143 /// Currently processed event batch iterator
144 Event_set_fetchable_list::iterator m_current_batch_it;
145};
146
147} // namespace mysql::csa
148
149#endif // MYSQL_CSA_FETCHABLE_TRANSACTION_H
For binlog version 4.
Definition: log_event.h:1558
Represents metadata of a set of events, capable of being fetched from a storage.
Definition: event_set_fetchable.h:55
Opaque for transaction, that is able to fetch itself in parts from the storage on demand.
Definition: fetchable_transaction.h:44
std::size_t get_max_event_length() const
Returns the maximum event length published for this transaction.
Definition: fetchable_transaction.cpp:159
bool is_fetching_error() const
Returs true when fetching failed.
Definition: fetchable_transaction.cpp:144
Fetchable_transaction(Fetchable_transaction &&)=delete
Fetchable_transaction()
Fetch function is supplied by a specific storage implementation.
Definition: fetchable_transaction.cpp:28
std::mutex m_mutex
Guard for concurrent producer (reader) and consumer (worker).
Definition: fetchable_transaction.h:138
std::atomic< bool > m_is_truncated
True when reader marked metadata stream as truncated.
Definition: fetchable_transaction.h:136
Event_set_fetchable_list m_event_set_batches
Object used to fetch transaction events from the storage.
Definition: fetchable_transaction.h:142
void set_fetching_truncated()
Marks transaction metadata stream as truncated.
Definition: fetchable_transaction.cpp:202
std::string get_fetch_error_msg() const
Accesses fetch error message.
Definition: fetchable_transaction.cpp:211
std::optional< Managed_event > fetch_next()
Definition: fetchable_transaction.cpp:87
virtual ~Fetchable_transaction()
Destructor.
Definition: fetchable_transaction.cpp:49
bool m_is_complete
True when reader has finished appending batches.
Definition: fetchable_transaction.h:132
void update_max_event_length(std::size_t event_length)
Updates the maximum event length published for this transaction.
Definition: fetchable_transaction.cpp:193
void reset_fetching(bool all)
Reset the status of the Featchable job allowing it to be re-read from the storage.
Definition: fetchable_transaction.cpp:51
bool advance_finished_batch_unsafe(Event_set_fetchable *event_batch)
Advances to the next batch if the current one has finished.
Definition: fetchable_transaction.cpp:241
bool is_truncated() const
Checks whether fetching stopped because the metadata stream was truncated.
Definition: fetchable_transaction.cpp:155
void set_success()
Marks that transaction committed succesfully, success callback.
Definition: fetchable_transaction.cpp:40
Event_set_fetchable_list::iterator m_current_batch_it
Currently processed event batch iterator.
Definition: fetchable_transaction.h:144
Format_description_log_event * get_fde()
Obtains non-owning pointer to current FDE.
Definition: fetchable_transaction.cpp:63
std::string m_error_message
Detailed error message if error appears.
Definition: fetchable_transaction.h:126
bool is_fetching_done() const
Checks current status of the object.
Definition: fetchable_transaction.cpp:150
std::optional< Event_set_fetchable * > get_current_event_batch_unsafe()
Iterates over event sets, picking a correct batch.
Definition: fetchable_transaction.cpp:256
void append_batch(Event_set_fetchable_ptr batch)
Appends a new fetchable batch for this transaction.
Definition: fetchable_transaction.cpp:171
void set_fetching_complete()
Seals transaction metadata stream. No more batches will be appended.
Definition: fetchable_transaction.cpp:182
Return_status m_status
Internal status of event.
Definition: fetchable_transaction.h:128
Event_set_fetchable * wait_for_current_batch()
Waits until a current batch becomes available or fetching reaches a terminal state.
Definition: fetchable_transaction.cpp:216
std::atomic< std::size_t > m_max_event_length
Maximum event length published for this transaction.
Definition: fetchable_transaction.h:134
bool is_trx() const
Returns information on whether this is actual transaction (transaction starting with a GTID)
Definition: fetchable_transaction.cpp:78
void set_fetching_done()
Mark that fetching is successfully done, even if transaction was not fully read.
Definition: fetchable_transaction.cpp:163
Fetchable_transaction(const Fetchable_transaction &)=delete
bool m_is_done
True when the consumer-side fetch stream reached a terminal state.
Definition: fetchable_transaction.h:130
bool wait_next()
Fetches consecutive events from the storage, until done or error occurs.
Definition: fetchable_transaction.cpp:119
std::condition_variable m_cv
Notification for appended batches / terminal state updates.
Definition: fetchable_transaction.h:140
Definition: channel.cpp:28
std::unique_ptr< Event_set_fetchable > Event_set_fetchable_ptr
Unique pointer to a specific implementation of Event_set_fetchable (no need to share).
Definition: event_set_fetchable.h:39
std::list< Event_set_fetchable_ptr > Event_set_fetchable_list
List of Event_set_fetchable pointers, each able to fetch a whole transaction from the storage.
Definition: event_set_fetchable.h:43
Return_status
Simple, strongly-typed enumeration to indicate internal status: ok, error.
Definition: return_status.h:40
Experimental API header.