MySQL 26.7.0
Source Code Documentation
dependency_tracker_single_predecessor_example.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_DEPENDENCY_TRACKER_H
25#define MYSQL_SCHEDULER_DEPENDENCY_TRACKER_H
26
27#include <cassert>
28#include <condition_variable>
29#include <memory>
30#include <mutex>
31#include <optional>
32#include <unordered_map>
33#include <unordered_set>
34#include <vector>
43
44namespace mysql::scheduler {
45
46/// An example of Dependency Tracker implementation that tracks a single
47/// task predecessor. Used only for excercising the tracker interface.
49 public:
54
55 /// Representation of a dependency
56 struct Dependency {
57 /// Task identifier
59 /// Task predecessor
60 std::optional<Task_id> predecessor;
61 /// Task can have many successors
62 std::vector<Task_id> successors;
63 };
64
66
67 /// @brief add_dependency
68 /// @details Function adds dependency if valid
69 /// @param predecessor Predecessor task ID
70 /// @param successor Successor task ID
71 /// @retval true Dependency added successfully
72 /// @retval false Failed to add dependency
73 [[nodiscard]] bool add_dependency(const Task_id_type &predecessor,
74 const Task_id_type &successor) override;
75
76 /// @brief Register task in the system to prevent adding dependencies on
77 /// non-existing tasks and adding active dependencies on tasks that are
78 /// already finished
79 [[nodiscard]] bool activate_task(const Task_id &task) override;
80
81 /// @brief check_ready
82 /// @details Function checks whether a task is ready for execution, without
83 /// locking the object (load)
84 /// @param task Task ID
85 /// @return true - dependencies of task are met, false - not met, second is
86 [[nodiscard]] bool check_ready(const Task_id &task) override;
87
88 /// @brief Task is finished, mark all dependencies of this task as met
89 /// @param task Identifier of a task that finished its execution
90 /// @param is_finished Whether the task has finished execution
91 /// @return Vector of task IDs whose dependencies changed, since this class
92 /// implementation supports 1 predecessor, this will be a vector of tasks
93 /// IDs ready to execute
94 [[nodiscard]] std::vector<Task_id> mark_dependency_met(
95 const Task_id &task, bool is_finished) override;
96
97 /// @brief Get the list of tasks that depend on the given task
98 /// @param task The task ID
99 /// @return Vector of successor task IDs
100 std::vector<Task_id> get_successors(const Task_id &task);
101
102 private:
104 /// Registry of task dependencies. Concurrency is covered by internal
105 /// representation of the registry.
107};
108
109} // namespace mysql::scheduler
110
111#endif // MYSQL_SCHEDULER_DEPENDENCY_TRACKER_H
MySQL wrapper for a mutex, template which may be specialized with a specific implementation of a mute...
Definition: mutex_wrapper.h:38
Base interface for a dependency tracker.
Definition: base_dependency_tracker.h:53
An example of Dependency Tracker implementation that tracks a single task predecessor.
Definition: dependency_tracker_single_predecessor_example.h:48
bool activate_task(const Task_id &task) override
Register task in the system to prevent adding dependencies on non-existing tasks and adding active de...
Definition: dependency_tracker_single_predecessor_example.cpp:49
std::vector< Task_id > mark_dependency_met(const Task_id &task, bool is_finished) override
Task is finished, mark all dependencies of this task as met.
Definition: dependency_tracker_single_predecessor_example.cpp:66
Dependency_tracker_single_predecessor()
Definition: dependency_tracker_single_predecessor_example.cpp:29
bool check_ready(const Task_id &task) override
check_ready
Definition: dependency_tracker_single_predecessor_example.cpp:53
bool add_dependency(const Task_id_type &predecessor, const Task_id_type &successor) override
add_dependency
Definition: dependency_tracker_single_predecessor_example.cpp:32
std::vector< Task_id > get_successors(const Task_id &task)
Get the list of tasks that depend on the given task.
Definition: dependency_tracker_single_predecessor_example.cpp:77
Dependencies_registry m_dependencies
Registry of task dependencies.
Definition: dependency_tracker_single_predecessor_example.h:106
concurrency::Mutex_key Mt_key
Definition: dependency_tracker_single_predecessor_example.h:52
concurrency::Stage_key St_key
Definition: dependency_tracker_single_predecessor_example.h:53
Represents the identifier of a task ingested by the scheduler,.
Definition: task_id.h:41
PSI_stage_key Stage_key
Definition: stage_srv.h:35
Mutex_wrapper Mutex
Definition: mutex_srv.h:40
PSI_mutex_key Mutex_key
Definition: mutex_srv.h:41
Definition: base_dependency_tracker.h:41
Representation of a dependency.
Definition: dependency_tracker_single_predecessor_example.h:56
Task_id task_id
Task identifier.
Definition: dependency_tracker_single_predecessor_example.h:58
std::optional< Task_id > predecessor
Task predecessor.
Definition: dependency_tracker_single_predecessor_example.h:60
std::vector< Task_id > successors
Task can have many successors.
Definition: dependency_tracker_single_predecessor_example.h:62