MySQL 26.7.0
Source Code Documentation
scheduler_clock.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_SCHEDULER_CLOCK_H
25#define MYSQL_SCHEDULER_SCHEDULER_CLOCK_H
26
27#include <cstdint>
28#include <limits>
29#include <memory>
30#include <ostream>
32
33namespace mysql::scheduler {
34
35class Scheduler_clock;
36using Scheduler_clock_ptr = std::shared_ptr<Scheduler_clock>;
37
39
40/// When unblocking, we tweak clock by this count
41inline constexpr std::size_t clock_unblock_delta{4};
42
43/// @brief Interface for clock implementations scheduler uses to
44/// schedule tasks.
45/// @details
46/// Tasks are subscribing for execution at specific time window by calling
47/// the 'subscribe' method.
48/// A task is ready for execution, when its execution time, i.e.
49/// parameter of the 'subscribe' method, is equal or greater than current time
50/// point, determined by the 'now' method.
51/// When task finished its execution, it must call the 'tick' method.
53 public:
54 using Time_point_t = uint64_t;
55
56 /// Destructor
57 virtual ~Scheduler_clock() = default;
58
59 /// @brief Gets current time delay, i.e. current processing window value
60 /// @return Current time, i.e. current processing window value
61 virtual Time_point_t now() const = 0;
62
63 /// @brief Gets clock starting point, i.e. first delay
64 /// @return clock start point
65 virtual Time_point_t start_time() const = 0;
66
67 /// @brief Subscribes a task to \a time processing window, delay since
68 /// beginning of a schedule
69 /// @param task_id ID of the task being subscribed
70 /// @param time Time window to which a task will be subscribed
71 /// @return True if task has been subscribed, false otherwise
72 virtual bool add_time(Task_id task_id, Time_point_t time) = 0;
73
74 /// @brief Notify that task finished execution. Called by asynchronous workers
75 /// executing task. When specific conditions are met, tick will advance the
76 /// internal clock value.
77 /// @param task_id ID of the task that finished execution
78 /// @param time Delay value the task was subscribed to
79 /// @return True if clock advanced its time
80 virtual bool tick(Task_id task_id, Time_point_t time) = 0;
81
82 /// @brief Returns property of a clock - information on whether this clock
83 /// is steered by task ticks or advances independently
84 virtual bool advances_independently() const { return false; }
85
86 /// @brief Maintenance function for unblocking the clock
87 virtual bool try_unblock() { return true; }
88
89 /// @brief Typical scheduler clock dependency type is end to start
92 }
93};
94
95} // namespace mysql::scheduler
96
97#endif // MYSQL_SCHEDULER_SCHEDULER_CLOCK_H
Interface for clock implementations scheduler uses to schedule tasks.
Definition: scheduler_clock.h:52
virtual bool tick(Task_id task_id, Time_point_t time)=0
Notify that task finished execution.
uint64_t Time_point_t
Definition: scheduler_clock.h:54
virtual Scheduler_dependency_type get_type() const
Typical scheduler clock dependency type is end to start.
Definition: scheduler_clock.h:90
virtual Time_point_t now() const =0
Gets current time delay, i.e.
virtual Time_point_t start_time() const =0
Gets clock starting point, i.e.
virtual bool add_time(Task_id task_id, Time_point_t time)=0
Subscribes a task to time processing window, delay since beginning of a schedule.
virtual bool advances_independently() const
Returns property of a clock - information on whether this clock is steered by task ticks or advances ...
Definition: scheduler_clock.h:84
virtual ~Scheduler_clock()=default
Destructor.
virtual bool try_unblock()
Maintenance function for unblocking the clock.
Definition: scheduler_clock.h:87
Represents the identifier of a task ingested by the scheduler,.
Definition: task_id.h:41
Definition: base_dependency_tracker.h:41
Scheduler_dependency_type
Definition: scheduler_clock.h:38
constexpr std::size_t clock_unblock_delta
When unblocking, we tweak clock by this count.
Definition: scheduler_clock.h:41
std::shared_ptr< Scheduler_clock > Scheduler_clock_ptr
Definition: scheduler_clock.h:36