MySQL 26.7.0
Source Code Documentation
task_schedule.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_SCHEDULER_TASK_SCHEDULE_H
25#define MYSQL_SCHEDULER_TASK_SCHEDULE_H
26
27#include <atomic>
28#include <chrono>
29#include <cstdint>
30#include <iostream>
31#include <memory>
32#include <string>
33
37
38namespace mysql::scheduler {
39
40class Task_schedule;
41using Task_schedule_ptr = std::shared_ptr<Task_schedule>;
42
43/// @class Task_schedule
44/// @brief Represents task schedule. This is the base class for a schedule
46 public:
47 /// @brief Constructor sets the task delay to a given value
49
50 /// @brief Compare two task schedules to indicate which task should run
51 /// first
52 /// @details Checks whether THIS task has higher priority than a given
53 /// task in terms of time left to the execution
54 /// @param arg Task to compare against
55 /// @param phase Compares task priority for a given phase (phase seqnence
56 /// number)
57 /// @returns true - this task has higher priority than arg task, false -
58 /// this task has lower or equal priority than given task
59 bool has_higher_priority(const Task_schedule &arg, int phase) const;
60
61 /// @brief Determines whether to re-execute this schedule
62 /// @details This function modifies the state of the schedule to next state
63 /// @returns true - Task will be executed in the future, false - task
64 /// fulfilled its schedule and won't be executed
65 /// @note TBI in derived
66 virtual bool next() = 0;
67
68 /// @brief Obtain task clock
69 virtual const Scheduler_clock_ptr &get_clock() const = 0;
70
71 /// @brief Obtain task id
72 virtual const Task_id &get_id() const = 0;
73
74 /// @brief Obtains task execution point as a delay from the clock start
75 /// @details Gets information about task execution time - task delay since
76 /// the beginning of a schedule
77 /// @note TBI in derived
78 virtual const Time_delay_type &get_task_delay() const = 0;
79
80 /// @note TBI in derived
81 virtual bool is_finished() const = 0;
82
83 /// Destructor
84 virtual ~Task_schedule() = default;
85
86 /// @brief Obtain task clock for the given phase (current one by default)
87 /// @return Phase clock reference
88 virtual const Scheduler_clock_ptr &get_phase_clock(unsigned int) const {
89 return get_clock();
90 }
91
92 /// @brief Obtains task execution point as a delay from the clock start, but
93 /// for the given phase (current one by default)
94 /// @details Gets information about task execution time - task delay since
95 /// the beginning of a schedule
96 /// @note TBI in derived
97 virtual const Time_delay_type &get_phase_delay(unsigned int) const {
98 return get_task_delay();
99 }
100
101 /// @brief Returns current phase id (sequence number), 0 by default
102 /// @return Phase sequence number
103 virtual unsigned int get_phase_id() const { return 0; }
104
105 /// @brief Sets the flag indicating that the task was enqueued by the
106 /// scheduler.
108
109 /// @brief Checks if the task was enqueued by the scheduler.
110 /// @return true if enqueued by the scheduler, false otherwise.
112
113 /// @brief Checks if the current phase is ready for execution.
114 /// @return true if phase is ready, false otherwise.
115 bool is_phase_ready() const { return m_phase_ready.load(); }
116
117 /// @brief Sets the phase ready flag to true.
118 void set_phase_ready() { m_phase_ready.store(true); }
119
120 private:
121 /// Flag indicating that a phase is ready to be executed
122 std::atomic<bool> m_phase_ready{false};
123 /// Flag inicating that phase will be enqueued by worker
125};
126
127} // namespace mysql::scheduler
128
129#endif // MYSQL_SCHEDULER_TASK_SCHEDULE_H
Represents the identifier of a task ingested by the scheduler,.
Definition: task_id.h:41
Represents task schedule.
Definition: task_schedule.h:45
bool has_higher_priority(const Task_schedule &arg, int phase) const
Compare two task schedules to indicate which task should run first.
Definition: task_schedule.cpp:33
virtual const Task_id & get_id() const =0
Obtain task id.
virtual const Scheduler_clock_ptr & get_clock() const =0
Obtain task clock.
bool is_enqueued_by_scheduler() const
Checks if the task was enqueued by the scheduler.
Definition: task_schedule.h:111
virtual ~Task_schedule()=default
Destructor.
virtual const Time_delay_type & get_task_delay() const =0
Obtains task execution point as a delay from the clock start.
Task_schedule()
Constructor sets the task delay to a given value.
Definition: task_schedule.cpp:31
virtual bool is_finished() const =0
virtual const Time_delay_type & get_phase_delay(unsigned int) const
Obtains task execution point as a delay from the clock start, but for the given phase (current one by...
Definition: task_schedule.h:97
void set_enqueued_by_scheduler()
Sets the flag indicating that the task was enqueued by the scheduler.
Definition: task_schedule.h:107
void set_phase_ready()
Sets the phase ready flag to true.
Definition: task_schedule.h:118
virtual bool next()=0
Determines whether to re-execute this schedule.
virtual unsigned int get_phase_id() const
Returns current phase id (sequence number), 0 by default.
Definition: task_schedule.h:103
bool is_phase_ready() const
Checks if the current phase is ready for execution.
Definition: task_schedule.h:115
bool m_enqueued_by_worker
Flag inicating that phase will be enqueued by worker.
Definition: task_schedule.h:124
virtual const Scheduler_clock_ptr & get_phase_clock(unsigned int) const
Obtain task clock for the given phase (current one by default)
Definition: task_schedule.h:88
std::atomic< bool > m_phase_ready
Flag indicating that a phase is ready to be executed.
Definition: task_schedule.h:122
Definition: base_dependency_tracker.h:41
std::shared_ptr< Task_schedule > Task_schedule_ptr
Definition: task_schedule.h:41
std::uint64_t Time_delay_type
Time points are created as a delay from a specific start time (clock relative measure)
Definition: time.h:39
std::shared_ptr< Scheduler_clock > Scheduler_clock_ptr
Definition: scheduler_clock.h:36