MySQL 26.7.0
Source Code Documentation
session_service.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_CSA_SESSION_SERVICE_H
25#define MYSQL_CSA_SESSION_SERVICE_H
26
27#include <memory>
28#include <optional>
34#include "sql/log_event.h" // Log_event
35
36namespace mysql::csa {
37
38class Session_service;
39/// @brief Shared pointer to Session_service
40using Session_service_ptr = std::shared_ptr<Session_service>;
41
42/// @brief Service that provides a free session to executing transactions.
43/// Base class for maintaining session pool available for CSA workers
45 public:
46 /// @brief Alias for task identifier
48
49 /// @brief Virtual destructor
50 virtual ~Session_service() = default;
51 /// @brief Initializes the session service
52 /// @param session_number The number of sessions to add to the initial pool
53 /// @param channel_rli Parent RLI - channel RLI to share common applier config
54 /// @return False if initialization succeeds, true otherwise
55 virtual bool init(std::size_t session_number,
56 Relay_log_info *channel_rli) = 0;
57 /// @brief Deinitializes the session service
58 /// @return False if deinitialization succeeds, true otherwise
59 virtual bool deinit() = 0;
60 /// @brief Obtains session statistics
61 /// @return Upon success, returns corresponding legacy stats. If they are
62 /// unavailable due to e.g. non-existing session id, returns an empty object
63 std::optional<Session_legacy_stats> get_session_stats(std::size_t session_id);
64 /// Obtains the number of all sessions
65 /// @return Number of session in this session pool
66 virtual std::size_t get_session_number();
67 /// Acquires session
68 /// @param id Attach id for the session (internal sequence session id)
69 /// @return Acquired session shared pointer
71 /// @brief Releases a session back to the pool
72 /// @param session Session to return to the session pool
73 /// @param id Session internal ID
74 virtual void release_session(Relay_context_ptr session, Task_id id) = 0;
75 /// Performs clean up of sessions, including rollback
76 void clean_sessions();
77 /// Enables stop error suppression for sessions that have no reported error.
79
80 /// Checks whether session service contains a given THD thread id
81 /// @param thd_id THD thread identifier to check
82 /// @return When true, session service contains THD with a given thd_id.
83 /// False otherwise.
84 bool has_thd_id(unsigned int thd_id) const;
85
86 /// Awakes sessions to faster end execution
87 /// @param force_kill When true, kills THDs
88 void awake_sessions(bool force_kill);
89
90 protected:
91 /// Aggregates all sessions in order to look at specific session data
92 std::unordered_map<std::size_t, Relay_context_ptr> m_all_sessions;
93 /// Captured THD identifiers for easy access
94 std::unordered_set<unsigned int> m_thd_ids;
95};
96
97} // namespace mysql::csa
98
99#endif // MYSQL_CSA_SESSION_SERVICE_H
Definition: rpl_rli.h:208
Service that provides a free session to executing transactions.
Definition: session_service.h:44
virtual Relay_context_ptr acquire_session(Task_id id)=0
Acquires session.
void enable_stop_error_suppression_for_clean_sessions()
Enables stop error suppression for sessions that have no reported error.
Definition: session_service.cpp:66
std::unordered_set< unsigned int > m_thd_ids
Captured THD identifiers for easy access.
Definition: session_service.h:94
virtual bool deinit()=0
Deinitializes the session service.
virtual std::size_t get_session_number()
Obtains the number of all sessions.
Definition: session_service.cpp:28
void awake_sessions(bool force_kill)
Awakes sessions to faster end execution.
Definition: session_service.cpp:72
bool has_thd_id(unsigned int thd_id) const
Checks whether session service contains a given THD thread id.
Definition: session_service.cpp:56
std::unordered_map< std::size_t, Relay_context_ptr > m_all_sessions
Aggregates all sessions in order to look at specific session data.
Definition: session_service.h:92
void clean_sessions()
Performs clean up of sessions, including rollback.
Definition: session_service.cpp:60
virtual ~Session_service()=default
Virtual destructor.
std::optional< Session_legacy_stats > get_session_stats(std::size_t session_id)
Obtains session statistics.
Definition: session_service.cpp:32
virtual bool init(std::size_t session_number, Relay_log_info *channel_rli)=0
Initializes the session service.
virtual void release_session(Relay_context_ptr session, Task_id id)=0
Releases a session back to the pool.
Represents the identifier of a task ingested by the scheduler,.
Definition: task_id.h:41
Binary log event definitions.
Definition: channel.cpp:28
std::shared_ptr< Session_service > Session_service_ptr
Shared pointer to Session_service.
Definition: session_service.h:40
std::shared_ptr< Relay_context > Relay_context_ptr
Definition: relay_context.h:39
Experimental API header.