MySQL 26.7.0
Source Code Documentation
relay_context.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_CONTEXT_H
25#define MYSQL_CSA_RELAY_CONTEXT_H
26
30#include "sql/rpl_rli.h"
31
32namespace cs::apply {
33class Csa_worker_context;
34}
35
36namespace mysql::csa {
37
38class Relay_context;
39using Relay_context_ptr = std::shared_ptr<Relay_context>;
40
41/// Handles and operates the handled session
42/// @see Session
44 public:
50 /// Constructor
51 /// @param id This relay context id
52 /// @param channel_config_rli Channel configuration RLI
53 Relay_context(std::size_t id, Relay_log_info *channel_config_rli);
54 /// Destructor
55 virtual ~Relay_context();
56 /// Obtains associated RLI pointer
57 /// @return RLI pointer from handled session
59 /// Obtains THD identifier
60 /// @return Handled THD identifier
61 unsigned int get_thd_id() const;
62 /// Checks validity
63 /// @return True if valid, false otherwise.
64 bool is_valid();
65 /// Attaches to session. Must succeed.
66 void attach_session();
67 /// Detaches from session
68 void detach_session();
69 /// Obtains session handle
70 /// @return Session reference
72 /// Obtains this relay context id
73 std::size_t get_id() const;
74 /// @brief Sets FDE for this relay context
75 /// @param fde FDE that will be used to apply transactions
77 /// Sets parallel worker context for the next transaction
78 /// @param com Current commit order manager pointer
79 /// @param trx_seq_num Transaction sequence number
80 /// @param worker_id Worker identifier - sequence number
81 /// @param channel_id Channel identifier - string
82 /// @param current_retry Current number of retries
83 /// @param retries_num Allowed number of retries
85 Trx_id trx_seq_num, Worker_id worker_id,
86 const std::string &channel_id,
87 int current_retry, int retries_num);
88 /// @brief if attached to commit order manager, registers parallel worker
89 /// to commit order (using parallel worker context)
91 /// @brief Report error to parent thread
92 /// @param trx_id Applier transaction identifier
93 void report_error(const std::string &trx_id);
94 /// Enables stop error suppression if this context had no reported error.
96 /// Obtain parallel worker context
97 /// @return pointer to object containing worker context
99 /// Clean-up session
100 void clean();
101 /// Awakes sessions to faster end execution
102 /// @param force_kill When true, kills THDs
103 void awake(bool force_kill);
104 /// Attaches to RLI
105 void attach_rli();
106 /// Detaches from RLI
107 void detach_rli();
108 /// Prepares context for retry
109 /// @param current_count Current retries number for this transaction
110 /// @param skip_rollback True if we need to skip rollback (already rolled
111 /// back)
112 void retry_transaction(int current_count, bool skip_rollback);
113 /// Waits for external parallel context rollback
114 /// @return True on failure, false on success
115 bool wait_for_rollback();
116 /// Check if handled context can be retried
117 /// @return True if transaction can be retried, false otherwise
118 bool can_be_retried();
119
120 private:
121 /// A pointer to the relay context. It shall be a dummy context,
122 /// as there is no need to store positions in tables or files,
123 /// since this applier only supports GTIDs
124 std::unique_ptr<Relay_log_info> m_rli;
125 /// Session
127 /// Flag indicating whether this session is currently attached to CSA worker
128 bool m_attached{false};
129 /// Commit order manager
131 /// Parent channel configuration RLI
133 /// This relay context identifier
134 std::size_t m_id{0};
135 /// Pointer to CSA worker context
136 std::unique_ptr<Csa_worker_context> m_csa_worker_context;
137};
138
139} // namespace mysql::csa
140
141#endif // MYSQL_CSA_RELAY_CONTEXT_H
On a replica and only on a replica, this class is responsible for committing the applied transactions...
Definition: rpl_replica_commit_order_manager.h:198
For binlog version 4.
Definition: log_event.h:1558
Definition: rpl_rli.h:208
Class representing the interface for parallel worker context.
Definition: csa_worker_context.h:46
Class representing the interface for parallel worker context.
Definition: parallel_worker_context.h:47
int64_t Trx_id
Definition: parallel_worker_context.h:51
uint64_t Worker_id
Definition: parallel_worker_context.h:52
Handles and operates the handled session.
Definition: relay_context.h:43
std::size_t m_id
This relay context identifier.
Definition: relay_context.h:134
void attach_rli()
Attaches to RLI.
Definition: relay_context.cpp:280
void enable_stop_error_suppression_if_clean()
Enables stop error suppression if this context had no reported error.
Definition: relay_context.cpp:219
std::unique_ptr< Csa_worker_context > m_csa_worker_context
Pointer to CSA worker context.
Definition: relay_context.h:136
Session m_session
Session.
Definition: relay_context.h:126
Relay_log_info * get_relay_log_info()
Obtains associated RLI pointer.
Definition: relay_context.cpp:204
void awake(bool force_kill)
Awakes sessions to faster end execution.
Definition: relay_context.cpp:217
bool m_attached
Flag indicating whether this session is currently attached to CSA worker.
Definition: relay_context.h:128
cs::apply::Csa_worker_context * get_parallel_worker_context()
Obtain parallel worker context.
Definition: relay_context.cpp:263
bool wait_for_rollback()
Waits for external parallel context rollback.
Definition: relay_context.cpp:292
void report_error(const std::string &trx_id)
Report error to parent thread.
Definition: relay_context.cpp:158
Parallel_worker_context::Worker_id Worker_id
Definition: relay_context.h:49
virtual ~Relay_context()
Destructor.
Definition: relay_context.cpp:197
Commit_order_manager * m_commit_order_manager
Commit order manager.
Definition: relay_context.h:130
void set_fde(Format_description_log_event *fde)
Sets FDE for this relay context.
Definition: relay_context.cpp:228
void detach_session()
Detaches from session.
Definition: relay_context.cpp:267
bool is_valid()
Checks validity.
Definition: relay_context.cpp:272
Relay_context(std::size_t id, Relay_log_info *channel_config_rli)
Constructor.
Definition: relay_context.cpp:40
Session & get_session()
Obtains session handle.
Definition: relay_context.h:71
Parallel_worker_context::Trx_id Trx_id
Definition: relay_context.h:48
void detach_rli()
Detaches from RLI.
Definition: relay_context.cpp:286
void register_to_commit_order()
if attached to commit order manager, registers parallel worker to commit order (using parallel worker...
Definition: relay_context.cpp:255
unsigned int get_thd_id() const
Obtains THD identifier.
Definition: relay_context.cpp:274
std::unique_ptr< Relay_log_info > m_rli
A pointer to the relay context.
Definition: relay_context.h:124
cs::apply::Parallel_worker_context_ptr Parallel_worker_context_ptr
Definition: relay_context.h:46
std::size_t get_id() const
Obtains this relay context id.
Definition: relay_context.cpp:278
Relay_log_info * m_channel_config_rli
Parent channel configuration RLI.
Definition: relay_context.h:132
void set_parallel_worker_context(Commit_order_manager *com, Trx_id trx_seq_num, Worker_id worker_id, const std::string &channel_id, int current_retry, int retries_num)
Sets parallel worker context for the next transaction.
Definition: relay_context.cpp:237
void retry_transaction(int current_count, bool skip_rollback)
Prepares context for retry.
Definition: relay_context.cpp:313
bool can_be_retried()
Check if handled context can be retried.
Definition: relay_context.cpp:306
void attach_session()
Attaches to session. Must succeed.
Definition: relay_context.cpp:232
void clean()
Clean-up session.
Definition: relay_context.cpp:206
Wraps up THD object and provides simple function to manage its execution within CSA.
Definition: session.h:34
static uint64_t current_count
Definition: gcs_psi.cc:186
Definition: applier_version.h:27
std::unique_ptr< Parallel_worker_context > Parallel_worker_context_ptr
Definition: parallel_worker_context.h:40
Definition: channel.cpp:28
std::shared_ptr< Relay_context > Relay_context_ptr
Definition: relay_context.h:39
Commit_order_manager::Parallel_worker_context Parallel_worker_context
Definition: rpl_replica_commit_order_manager.cc:50