MySQL 26.7.0
Source Code Documentation
task_exec_job.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_TASK_EXEC_JOB_H
25#define MYSQL_CSA_TASK_EXEC_JOB_H
26
27#include <iostream>
28#include <string>
33
34namespace mysql::csa {
35
36/// @brief A task that executes a job in the change streams apply system.
37/// It handles job execution, potential retries on failures, and error
38/// management.
40 public:
41 /// @brief Type alias for the task result from the mysql scheduler.
43 /// @brief Type alias for the session service in change streams apply.
45 /// @brief Type alias for the statistics monitor instance for the channel
47
48 /// @brief Checks if task executed with an error - this function is called
49 /// by Scheduler to get task status
50 bool is_error() const;
51
52 /// @brief Constructor
53 /// @param job Job handle created by the job provider
54 /// @param job_id Job id assigned by the job provider
55 /// @param session_service Handle to session service, providing sessions
56 /// to which this job can attach.
57 /// @param stat_monitor Statistic monitoring object
58 /// @param stop_ref If retried, this flag will be checked to determine
59 /// whether applier has been stopped. Otherwise, we skip this check for
60 /// performance
61 Task_exec_job(Job_ptr job, uint64_t job_id,
62 Session_service_ptr session_service,
63 Stat_monitor_ref stat_monitor, std::atomic<bool> &stop_ref);
64
65 /// @brief This function executes a job. If job fails and can be retried,
66 /// job is reexecuted. In case retry fails or is not possible, error is
67 /// written into the job, function returns an error, causing scheduler
68 /// to stop
69 Task_result operator()(unsigned int thread_id);
70
71 private:
72 /// @brief Function executing a job - internal implementation
73 /// @param job Job pointer
74 /// @param job_id Internal job identifier
75 /// @param thread_id Thread pool worker identifier
76 /// @see operator()
77 Task_result run(Job *job, uint64_t job_id, unsigned int thread_id);
78
79 /// @brief Indicates that a task executed with a non-recoverable error (stop)
80 void set_error();
81
82 /// @brief Internal error flag
83 bool m_is_error{false};
84
85 /// @brief Shared job handle provided by the job provider.
86 std::shared_ptr<Job> m_job;
87 /// @brief Job id assigned by the job provider.
88 uint64_t m_job_id{0};
89 /// @brief Assigned session service handle.
91
92 /// @brief Checks if task has been started
93 bool m_started{false};
94 /// Statistics monitoring object for the current instance
96 /// If retried, this flag will be checked to determine
97 /// whether applier has been stopped. Otherwise, we skip this check for
98 /// performance
99 std::atomic<bool> &m_applier_stop;
100};
101
102} // namespace mysql::csa
103
104#endif // MYSQL_CSA_TASK_EXEC_JOB_H
A job represents a single unit of work applied by worker pool threads.
Definition: job.h:47
A task that executes a job in the change streams apply system.
Definition: task_exec_job.h:39
std::atomic< bool > & m_applier_stop
If retried, this flag will be checked to determine whether applier has been stopped.
Definition: task_exec_job.h:99
void set_error()
Indicates that a task executed with a non-recoverable error (stop)
Definition: task_exec_job.cpp:40
bool m_is_error
Internal error flag.
Definition: task_exec_job.h:83
uint64_t m_job_id
Job id assigned by the job provider.
Definition: task_exec_job.h:88
bool m_started
Checks if task has been started.
Definition: task_exec_job.h:93
Session_service_ptr m_session_service
Assigned session service handle.
Definition: task_exec_job.h:90
Task_result run(Job *job, uint64_t job_id, unsigned int thread_id)
Function executing a job - internal implementation.
Definition: task_exec_job.cpp:66
bool is_error() const
Checks if task executed with an error - this function is called by Scheduler to get task status.
Definition: task_exec_job.cpp:39
scheduler::Statistics_instance_monitor_ref Stat_monitor_ref
Type alias for the statistics monitor instance for the channel.
Definition: task_exec_job.h:46
std::shared_ptr< Job > m_job
Shared job handle provided by the job provider.
Definition: task_exec_job.h:86
Task_exec_job(Job_ptr job, uint64_t job_id, Session_service_ptr session_service, Stat_monitor_ref stat_monitor, std::atomic< bool > &stop_ref)
Constructor.
Definition: task_exec_job.cpp:42
mysql::csa::Session_service_ptr Session_service_ptr
Type alias for the session service in change streams apply.
Definition: task_exec_job.h:44
Task_result operator()(unsigned int thread_id)
This function executes a job.
Definition: task_exec_job.cpp:52
scheduler::Statistics_instance_monitor_ref m_stat_monitor
Statistics monitoring object for the current instance.
Definition: task_exec_job.h:95
static my_thread_id thread_id
Definition: my_thr_init.cc:60
Definition: channel.cpp:28
std::shared_ptr< Session_service > Session_service_ptr
Shared pointer to Session_service.
Definition: session_service.h:40
std::reference_wrapper< Statistics_instance_monitor > Statistics_instance_monitor_ref
Definition: statistics_instance_monitor.h:43
Task_result
Acceptable task state after its execution.
Definition: task_result.h:32