MySQL 9.7.0
Source Code Documentation
mysql_task_monitor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025, 2026, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_MYSQL_TASK_MONITOR_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_MYSQL_TASK_MONITOR_H_
28
29#include <list>
30#include <memory>
31#include <string>
32#include <thread>
33
35
39
40namespace mrs {
41namespace database {
42
44 public:
47 using PoolManagerRef = std::shared_ptr<PoolManager>;
48
49 public:
51
52 void call_async(
53 CachedSession session, PoolManagerRef session_pool,
54 std::list<std::string> preamble, std::string script,
55 std::list<std::string> postamble,
56 std::function<std::list<std::string>(const std::exception &)> on_error,
57 const std::string &task_id);
58
59 public:
60 void start();
61 void stop();
62 void reset();
63
64 private:
65 template <typename T>
67
68 struct Task {
69 // holds a ref to the pool that owns session, so it's not released
70 // while the Task is executing in another thread
73 std::list<std::string> preamble;
74 std::string script;
75 std::list<std::string> postamble;
76 std::list<std::string> error;
77 std::function<std::list<std::string>(const std::exception &)> on_error;
78
79 std::string task_id;
80 bool failed = false;
81 };
82
84
85 std::thread thread_;
86
88
89 std::mutex tasks_mutex_;
90 std::list<Task> tasks_;
91
92 void run();
93
94 bool update_task(Task &task);
95};
96
97} // namespace database
98} // namespace mrs
99
100#endif // ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_MYSQL_TASK_MONITOR_H_
Definition: cache_manager.h:41
Definition: mysql_fixed_pool_manager.h:40
MySqlFixedCacheManagerImpl::CachedObject CachedObject
Definition: mysql_fixed_pool_manager.h:45
Definition: mysql_task_monitor.h:43
void reset()
Definition: mysql_task_monitor.cc:56
std::list< Task > tasks_
Definition: mysql_task_monitor.h:90
void start()
Definition: mysql_task_monitor.cc:40
void run()
Definition: mysql_task_monitor.cc:61
~MysqlTaskMonitor()
Definition: mysql_task_monitor.cc:38
std::mutex tasks_mutex_
Definition: mysql_task_monitor.h:89
State
Definition: mysql_task_monitor.h:83
@ k_check_tasks
Definition: mysql_task_monitor.h:83
@ k_initializing
Definition: mysql_task_monitor.h:83
@ k_running
Definition: mysql_task_monitor.h:83
@ k_stopped
Definition: mysql_task_monitor.h:83
std::shared_ptr< PoolManager > PoolManagerRef
Definition: mysql_task_monitor.h:47
WaitableVariable< State > state_
Definition: mysql_task_monitor.h:87
void call_async(CachedSession session, PoolManagerRef session_pool, std::list< std::string > preamble, std::string script, std::list< std::string > postamble, std::function< std::list< std::string >(const std::exception &)> on_error, const std::string &task_id)
Definition: mysql_task_monitor.cc:99
void stop()
Definition: mysql_task_monitor.cc:47
bool update_task(Task &task)
Definition: mysql_task_monitor.cc:113
std::thread thread_
Definition: mysql_task_monitor.h:85
Definition: wait_variable.h:37
Definition: authorize_manager.h:48
Definition: mysql_task_monitor.h:68
std::function< std::list< std::string >(const std::exception &)> on_error
Definition: mysql_task_monitor.h:77
std::string task_id
Definition: mysql_task_monitor.h:79
bool failed
Definition: mysql_task_monitor.h:80
std::string script
Definition: mysql_task_monitor.h:74
CachedSession session
Definition: mysql_task_monitor.h:72
PoolManagerRef session_pool_ref
Definition: mysql_task_monitor.h:71
std::list< std::string > preamble
Definition: mysql_task_monitor.h:73
std::list< std::string > error
Definition: mysql_task_monitor.h:76
std::list< std::string > postamble
Definition: mysql_task_monitor.h:75