MySQL 26.7.0
Source Code Documentation
parallel_worker_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_CS_APPLY_PARALLEL_WORKER_CONTEXT_H
25#define MYSQL_CS_APPLY_PARALLEL_WORKER_CONTEXT_H
26
27#include <cstdint>
28#include <memory>
29#include <string>
31
32class Relay_log_info;
33class THD;
34class MDL_context;
36
37namespace cs::apply {
38
40using Parallel_worker_context_ptr = std::unique_ptr<Parallel_worker_context>;
41
42/// @brief Class representing the interface for parallel worker context. It
43/// accesses basic information like worker id, transaction id, channel id and
44/// other functionatlities needed by the commit order manager.
45/// @note This context is needed to disconnect Slave_worker class from
46/// execution path, Slave_worker implements Parallel_worker_context interface
48 public:
50 virtual ~Parallel_worker_context() = default;
51 using Trx_id = int64_t;
52 using Worker_id = uint64_t;
53 using Channel_id = std::string;
54
55 /// @brief Indicates that commit order deadlock has been found
56 /// @param for_self When true, a thread reports for its own
57 virtual void report_commit_order_deadlock(bool for_self = false) = 0;
58 /// @brief Checks if commit order deadlock has been found
59 /// @return True if commit order deadlock has been found, false otherwise
60 virtual bool found_commit_order_deadlock() const = 0;
61 /// @brief Resets commit order deadlock
62 virtual void reset_commit_order_deadlock() = 0;
63 /// @brief Checks if arg parallel worker executes transaction coming from
64 /// the same channel
65 virtual bool is_same_channel(const Parallel_worker_context *other) const = 0;
66 /// @brief Returns transaction id (we use sequence number)
67 /// @return transaction id
68 virtual THD *get_transaction_ctx() = 0;
69 /// @brief Obtains worker metrics
70 /// @return Reference to worker metrics object
72 /// @brief Returns worker id
73 /// @return Worker identifier
74 virtual Worker_id get_worker_id() const = 0;
75 /// @brief Obtains MDL context needed for commit
76 /// @return MDL context
78 /// @brief Returns information on whether THD transaction can be retried
79 /// @return true if transaction can be retried
80 virtual bool can_be_retried(THD *thd) = 0;
81 /// @brief Obtain transaction id (sequence number)
82 /// @return Transaction sequence number
83 virtual Trx_id get_trx_id() = 0;
84 /// @brief Get "for channel" id. Builds string in flight when needed
85 /// Pass true as boolean argument if upper case is needed
86 /// @return "for channel" string
87 virtual const char *get_for_channel_id(bool) const { return ""; }
88 /// Checks whether this worker is CSA worker
89 /// @return true for CSA parallel worker context. False otherwise
90 virtual bool is_csa() const { return false; }
91};
92
93} // namespace cs::apply
94
95#endif // MYSQL_CS_APPLY_PARALLEL_WORKER_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
Context of the owner of metadata locks.
Definition: mdl.h:1415
Definition: rpl_rli.h:208
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Class representing the interface for parallel worker context.
Definition: parallel_worker_context.h:47
virtual ~Parallel_worker_context()=default
virtual const char * get_for_channel_id(bool) const
Get "for channel" id.
Definition: parallel_worker_context.h:87
virtual THD * get_transaction_ctx()=0
Returns transaction id (we use sequence number)
virtual MDL_context * get_mdl_context()=0
Obtains MDL context needed for commit.
virtual bool can_be_retried(THD *thd)=0
Returns information on whether THD transaction can be retried.
virtual void reset_commit_order_deadlock()=0
Resets commit order deadlock.
int64_t Trx_id
Definition: parallel_worker_context.h:51
virtual void report_commit_order_deadlock(bool for_self=false)=0
Indicates that commit order deadlock has been found.
virtual bool is_same_channel(const Parallel_worker_context *other) const =0
Checks if arg parallel worker executes transaction coming from the same channel.
virtual bool is_csa() const
Checks whether this worker is CSA worker.
Definition: parallel_worker_context.h:90
virtual Trx_id get_trx_id()=0
Obtain transaction id (sequence number)
virtual bool found_commit_order_deadlock() const =0
Checks if commit order deadlock has been found.
virtual instruments::Worker_metrics & get_worker_metrics()=0
Obtains worker metrics.
virtual Worker_id get_worker_id() const =0
Returns worker id.
std::string Channel_id
Definition: parallel_worker_context.h:53
uint64_t Worker_id
Definition: parallel_worker_context.h:52
Abstract class for classes that contain metrics related to transaction execution in applier workers.
Definition: worker_metrics.h:34
Definition: applier_version.h:27
std::unique_ptr< Parallel_worker_context > Parallel_worker_context_ptr
Definition: parallel_worker_context.h:40