MySQL 26.7.0
Source Code Documentation
sync_transaction_provider.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_SYNC_TRANSACTION_PROVIDER_H
25#define MYSQL_CSA_SYNC_TRANSACTION_PROVIDER_H
26
27#include <fstream>
28#include <functional>
29#include <memory>
30#include <optional>
31
39#include "sql/binlog.h"
44
45namespace mysql::csa {
46
47class Sync_transaction_provider;
49 std::unique_ptr<Sync_transaction_provider>;
50
51/// Implementation of 'Transaction_provider' interface.
52/// This implementation uses the relay log reader to read consecutive
53/// events from the relay log. Data is read from prefetched stream.
54/// Main methods are:
55/// - start : runs asynchronous thread fetching transactions from the relay log
56/// - stop : stops execution and blocks until thread is joined
57/// - next : blocks until fetching the next transaction, stop or timeout
58/// when outside of transaction boundary
59/// - is_stopped : Checks whether stop has been requested (externally or by
60/// the parent thread)
62 public:
63 /// @param instance_id Instance (channel) id
64 /// @param rli Pointer to relay log info structure
65 /// @param max_read_event_bytes The maximum number of bytes in a transaction
66 /// which reader can read, decode and cache
67 /// @param max_read_payload_bytes The maximum number of bytes in a transaction
68 /// which reader can read and cache payload
69 Sync_transaction_provider(int instance_id, Relay_log_info *rli,
70 std::size_t max_read_event_bytes,
71 std::size_t max_read_payload_bytes);
72
73 /// Starts asynchronous thread that decodes jobs from the stream
74 void start() override;
75 /// Stops provider and wakes blocked reader calls.
76 void stop() override;
77 /// Completes provider shutdown from the owner thread (transaction receiver).
78 /// Requires stop to have been called first; otherwise it is a no-op.
79 void finish() override;
80
81 /// Consumes the next Job, blocks until fetched
82 /// @retval Job smart pointer
83 /// @retval Empty pointer in case stop has been requested (check with
84 /// 'is_stopped') or we timed out waiting for event. In case we timed out,
85 /// we return an empty pointer to wake up parent thread for a while, so that
86 /// it can do some maintenance activities, such as checking status or
87 /// checking statistics
88 Job_ptr next() override;
89
90 /// Checks if stop has been requested
91 /// @return True if stop has been requested internally (error) or externally
92 /// (log wait for update)
93 bool is_stopped() const override;
94
95 /// @brief Check if provider has an error
96 /// @return True in case an error occurred, false otherwise
97 bool is_error() const override;
98
99 private:
100 /// Variable to gracefully stop the thread
101 std::atomic<bool> m_is_stopped{false};
102
103 /// Pointer to channel rli object
105
106 /// Shared reader object
108
109 /// Statistics monitoring object
111};
112
113} // namespace mysql::csa
114
115#endif // MYSQL_CSA_SYNC_TRANSACTION_PROVIDER_H
Definition: rpl_rli.h:208
A job represents a single unit of work applied by worker pool threads.
Definition: job.h:47
Implementation of 'Transaction_provider' interface.
Definition: sync_transaction_provider.h:61
Job_ptr next() override
Consumes the next Job, blocks until fetched.
Definition: sync_transaction_provider.cpp:71
bool is_error() const override
Check if provider has an error.
Definition: sync_transaction_provider.cpp:48
Sync_transaction_provider(int instance_id, Relay_log_info *rli, std::size_t max_read_event_bytes, std::size_t max_read_payload_bytes)
Definition: sync_transaction_provider.cpp:38
bool is_stopped() const override
Checks if stop has been requested.
Definition: sync_transaction_provider.cpp:67
void stop() override
Stops provider and wakes blocked reader calls.
Definition: sync_transaction_provider.cpp:52
Reader_sptr m_reader
Shared reader object.
Definition: sync_transaction_provider.h:107
std::atomic< bool > m_is_stopped
Variable to gracefully stop the thread.
Definition: sync_transaction_provider.h:101
Relay_log_info * m_rli
Pointer to channel rli object.
Definition: sync_transaction_provider.h:104
scheduler::Statistics_instance_monitor_ref m_stat_monitor
Statistics monitoring object.
Definition: sync_transaction_provider.h:110
void finish() override
Completes provider shutdown from the owner thread (transaction receiver).
Definition: sync_transaction_provider.cpp:57
void start() override
Starts asynchronous thread that decodes jobs from the stream.
Definition: sync_transaction_provider.cpp:46
Interface for all transaction providers.
Definition: transaction_provider.h:45
Definition: channel.cpp:28
std::shared_ptr< Reader > Reader_sptr
Shared reader type.
Definition: reader.h:38
std::unique_ptr< Sync_transaction_provider > Sync_transaction_provider_sptr
Definition: sync_transaction_provider.h:49
std::reference_wrapper< Statistics_instance_monitor > Statistics_instance_monitor_ref
Definition: statistics_instance_monitor.h:43
Experimental API header.