MySQL 9.4.0
Source Code Documentation
mysql_task_monitor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025, 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>
37
38namespace mrs {
39namespace database {
40
42 public:
45 using PoolManagerRef = std::shared_ptr<PoolManager>;
46
48
49 void call_async(
50 CachedSession session, PoolManagerRef session_pool,
51 std::list<std::string> preamble, std::string script,
52 std::list<std::string> postamble,
53 std::function<std::list<std::string>(const std::exception &)> on_error,
54 const std::string &task_id);
55
56 public:
57 void start();
58 void stop();
59 void reset();
60
61 private:
62 struct Task {
63 // holds a ref to the pool that owns session, so it's not released
64 // while the Task is executing in another thread
67 std::list<std::string> preamble;
68 std::string script;
69 std::list<std::string> postamble;
70 std::list<std::string> error;
71 std::function<std::list<std::string>(const std::exception &)> on_error;
72
73 std::string task_id;
74 bool failed = false;
75 };
76
78
79 std::thread thread_;
81
82 std::mutex tasks_mutex_;
83 std::list<Task> tasks_;
84
85 void run();
86
87 bool update_task(Task &task);
88};
89
90} // namespace database
91} // namespace mrs
92
93#endif // ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_MYSQL_TASK_MONITOR_H_
Definition: wait_variable.h:34
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:41
void reset()
Definition: mysql_task_monitor.cc:56
std::list< Task > tasks_
Definition: mysql_task_monitor.h:83
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:82
State
Definition: mysql_task_monitor.h:77
@ k_check_tasks
Definition: mysql_task_monitor.h:77
@ k_initializing
Definition: mysql_task_monitor.h:77
@ k_running
Definition: mysql_task_monitor.h:77
@ k_stopped
Definition: mysql_task_monitor.h:77
std::shared_ptr< PoolManager > PoolManagerRef
Definition: mysql_task_monitor.h:45
WaitableVariable< State > state_
Definition: mysql_task_monitor.h:80
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:79
Definition: authorize_manager.h:48
Definition: mysql_task_monitor.h:62
std::function< std::list< std::string >(const std::exception &)> on_error
Definition: mysql_task_monitor.h:71
std::string task_id
Definition: mysql_task_monitor.h:73
bool failed
Definition: mysql_task_monitor.h:74
std::string script
Definition: mysql_task_monitor.h:68
CachedSession session
Definition: mysql_task_monitor.h:66
PoolManagerRef session_pool_ref
Definition: mysql_task_monitor.h:65
std::list< std::string > preamble
Definition: mysql_task_monitor.h:67
std::list< std::string > error
Definition: mysql_task_monitor.h:70
std::list< std::string > postamble
Definition: mysql_task_monitor.h:69