MySQL 26.7.0
Source Code Documentation
task_id.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_ID_H
25#define MYSQL_SCHEDULER_TASK_ID_H
26
27#include <cassert>
28#include <functional>
29#include <future>
30#include <iostream>
31#include <memory>
32#include <ostream>
33#include <string>
34#include <thread>
35
36namespace mysql::scheduler {
37
38/// @brief Represents the identifier of a task ingested by the scheduler,
39/// @details Uses an internal sequence number for lightweight, format-agnostic
40/// tracking.
41class Task_id {
42 public:
43 /// @brief Creates scheduler task identifier using given id
44 /// @note Uses an internal sequence number as a lightweight identifier,
45 /// decoupling the scheduler from specific replication formats (e.g.,
46 /// streaming where events may lack traditional identifiers or represent
47 /// partial units).
48 /// @param id Internally assigned sequence number
49 Task_id(std::size_t id);
50
51 /// @brief Compares tasks ids
52 /// @param other Task id to compare against
53 /// @return True if this task has lower number than other (was created before)
54 bool operator<(const Task_id &other) const;
55
56 /// @brief Returns an information on whether task id has been set to a valid
57 /// id
58 /// @return True in case identifier has been set; false otherwise
59 bool is_valid() const { return m_is_valid; }
60
61 uint64_t get() const { return m_id; }
62
63 /// @brief Comparison operator required by unordered set/unordered map...
64 bool operator==(const Task_id &src) const;
65
66 friend class Scheduler;
67
68 /// @brief Streaming operator
69 friend std::ostream &operator<<(std::ostream &os, const Task_id &obj);
70
71 protected:
72 private:
73 /// Internal transaction identifier
74 std::size_t m_id;
75 /// Id validity, false means that id has not been set
76 bool m_is_valid = false;
77};
78
79} // namespace mysql::scheduler
80
81namespace std {
82template <>
83struct hash<mysql::scheduler::Task_id> {
84 /// @brief Returns hash for Task_id
85 /// @param id Task identifier
86 size_t operator()(const mysql::scheduler::Task_id &id) const noexcept {
87 assert(id.is_valid());
88 return std::hash<std::size_t>()(id.get());
89 }
90};
91} // namespace std
92
93#endif // MYSQL_SCHEDULER_TASK_ID_H
Main scheduling class.
Definition: scheduler.h:66
Represents the identifier of a task ingested by the scheduler,.
Definition: task_id.h:41
friend std::ostream & operator<<(std::ostream &os, const Task_id &obj)
Streaming operator.
Definition: task_id.cpp:37
bool operator<(const Task_id &other) const
Compares tasks ids.
Definition: task_id.cpp:46
Task_id(std::size_t id)
Creates scheduler task identifier using given id.
Definition: task_id.cpp:31
uint64_t get() const
Definition: task_id.h:61
bool m_is_valid
Id validity, false means that id has not been set.
Definition: task_id.h:76
bool operator==(const Task_id &src) const
Comparison operator required by unordered set/unordered map...
Definition: task_id.cpp:33
std::size_t m_id
Internal transaction identifier.
Definition: task_id.h:74
bool is_valid() const
Returns an information on whether task id has been set to a valid id.
Definition: task_id.h:59
bool is_valid(const dd::Spatial_reference_system *srs, const Geometry *g, const char *func_name, bool *is_valid) noexcept
Decides if a geometry is valid.
Definition: is_valid.cc:95
Definition: base_dependency_tracker.h:41
Definition: instrumented_condition_variable.h:32
Define std::hash<Gtid>.
Definition: gtid.h:355
size_t operator()(const mysql::scheduler::Task_id &id) const noexcept
Returns hash for Task_id.
Definition: task_id.h:86