MySQL 26.7.0
Source Code Documentation
base_dependency_tracker.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_BASE_DEPENDENCY_TRACKER_H
25#define MYSQL_SCHEDULER_BASE_DEPENDENCY_TRACKER_H
26
27#include <cassert>
28#include <condition_variable>
29#include <list>
30#include <memory>
31#include <mutex>
32#include <unordered_map>
33#include <unordered_set>
34#include <vector>
40
42
43/// @brief Base interface for a dependency tracker. Allows for:
44/// - Registering a task in a dependency tracker (activate_task)
45/// - Setting a dependency between one task and the other (add_dependency);
46/// this method is typically called by a scheduling thread
47/// - Checking if dependency of a task were already satisfied (check_ready);
48/// this method is typically called by a worker / scheduling thread which
49/// checks whether a task is ready to be executed
50/// - Marking that dependencies of a concrete task were satisfied
51/// (mark_dependency_met). This method is typically called by a worker that
52/// finished executing its task
54 public:
57
58 /// @brief add_dependency
59 /// @details Function adds dependency if valid
60 /// @param predecessor Predecessor task ID
61 /// @param successor Successor task ID
62 /// @retval true Dependency added successfully
63 /// @retval false Failed to add dependency
64 [[nodiscard]] virtual bool add_dependency(const Task_id_type &predecessor,
65 const Task_id_type &successor) = 0;
66
67 /// @brief Register task in the system to prevent adding dependencies on
68 /// non-existing tasks and adding active dependencies on tasks that are
69 /// already finished
70 [[nodiscard]] virtual bool activate_task(const Task_id &task) = 0;
71
72 /// @brief check_ready
73 /// @details Function checks whether a task is ready for execution
74 /// @param task Task ID
75 /// @return true - dependencies of task are met, false - not met, second is
76 [[nodiscard]] virtual bool check_ready(const Task_id &task) = 0;
77
78 /// @brief Task is finished, mark all dependencies of this task as met
79 /// @param task Identifier of a task that finished its execution
80 /// @param is_finished Whether the task has finished execution
81 /// @return Vector of task IDs whose dependencies changed
82 [[nodiscard]] virtual std::vector<Task_id> mark_dependency_met(
83 const Task_id &task, bool is_finished) = 0;
84
85 /// @brief Destructor
86 virtual ~Base_dependency_tracker() = default;
87};
88
89using Dependency_tracker_ptr = std::unique_ptr<Base_dependency_tracker>;
90
91} // namespace mysql::scheduler
92
93#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
virtual ~Base_dependency_tracker()=default
Destructor.
virtual bool check_ready(const Task_id &task)=0
check_ready
virtual bool add_dependency(const Task_id_type &predecessor, const Task_id_type &successor)=0
add_dependency
virtual bool activate_task(const Task_id &task)=0
Register task in the system to prevent adding dependencies on non-existing tasks and adding active de...
virtual std::vector< Task_id > mark_dependency_met(const Task_id &task, bool is_finished)=0
Task is finished, mark all dependencies of this task as met.
Represents the identifier of a task ingested by the scheduler,.
Definition: task_id.h:41
Mutex_wrapper Mutex
Definition: mutex_srv.h:40
Definition: base_dependency_tracker.h:41
std::unique_ptr< Base_dependency_tracker > Dependency_tracker_ptr
Definition: base_dependency_tracker.h:89