MySQL 26.7.0
Source Code Documentation
commit_order_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_COMMIT_ORDER_CLOCK_H
25#define MYSQL_SCHEDULER_COMMIT_ORDER_CLOCK_H
26
27#include <atomic>
28#include <cstdint>
29#include <functional>
30#include <limits>
31#include <ostream>
32
35
36namespace mysql::scheduler {
37
39 public:
40 using Time_point_t = uint64_t;
41
42 /// Constructor
43 /// @param start_point Clock start point (set as now time)
44 Commit_order_clock(Time_point_t start_point = 0);
45
46 /// @brief Gets clock start time
47 /// @return Start time
48 Time_point_t start_time() const override;
49
50 /// @brief Gets current time, i.e. current processing window value
51 /// @return Current time, i.e. current processing window value
52 Time_point_t now() const override;
53
54 /// @brief Subscribes a task to \a time processing window
55 /// @param task_id Unused task ID
56 /// @param time Time window to which a task will be subscribed
57 /// @return True if task has been subscribed, false otherwise
58 bool add_time(Task_id task_id, Time_point_t time) override;
59
60 /// @brief Notify that task finished execution. Called by asynchronous workers
61 /// executing task. When specific conditions are met, tick will advance the
62 /// internal clock value.
63 /// @param task_id Unused task ID
64 /// @param time Delay value the task was subscribed to
65 /// @return True if time advanced, false otherwise
66 bool tick(Task_id task_id, Time_point_t time) override;
67
68 /// @brief This clock dependency type is start-to-start
71 }
72
73 private:
74 /// Current clock value (now / delay from the start point)
75 std::atomic<Time_point_t> m_clock{0};
76 /// Used to track stalled clock unblocking (clock was twicked by this count)
77 std::atomic<std::size_t> m_twicked_count{0};
78};
79
80} // namespace mysql::scheduler
81
82#endif // MYSQL_SCHEDULER_COMMIT_ORDER_CLOCK_H
Definition: commit_order_clock.h:38
Scheduler_dependency_type get_type() const override
This clock dependency type is start-to-start.
Definition: commit_order_clock.h:69
Time_point_t now() const override
Gets current time, i.e.
Definition: commit_order_clock.cpp:36
uint64_t Time_point_t
Definition: commit_order_clock.h:40
bool tick(Task_id task_id, Time_point_t time) override
Notify that task finished execution.
Definition: commit_order_clock.cpp:46
Commit_order_clock(Time_point_t start_point=0)
Constructor.
Definition: commit_order_clock.cpp:32
bool add_time(Task_id task_id, Time_point_t time) override
Subscribes a task to time processing window.
Definition: commit_order_clock.cpp:44
std::atomic< Time_point_t > m_clock
Current clock value (now / delay from the start point)
Definition: commit_order_clock.h:75
std::atomic< std::size_t > m_twicked_count
Used to track stalled clock unblocking (clock was twicked by this count)
Definition: commit_order_clock.h:77
Time_point_t start_time() const override
Gets clock start time.
Definition: commit_order_clock.cpp:40
Interface for clock implementations scheduler uses to schedule tasks.
Definition: scheduler_clock.h:52
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