MySQL 8.4.2
Source Code Documentation
persistent_dynamic_loader_imp.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_SERVER_PERSISTENT_DYNAMIC_LOADER_H
25#define MYSQL_SERVER_PERSISTENT_DYNAMIC_LOADER_H
26
30#include <atomic>
31#include <map>
32
33#include "my_inttypes.h"
34
35/*
36 This header file is used in mysql_server component, which is not
37 server-enabled, and can't have following declaration acquired by including
38 mysql headers.
39*/
40
41bool persistent_dynamic_loader_init(void *thd);
43
44/**
45 Allows to wrap another Service Implementation of the Dynamic Loader service
46 and add ability to store a list of groups of loaded components. It reacts on
47 successful invocations of the underlying Dynamic Loader Service Implementation
48 methods load() and unload() and saves changes. It also loads during the start
49 of the MySQL Server all groups of the Components that were still loaded on
50 last MySQL Server shutdown, they are loaded in order of the original loads.
51 It assumes that components does not any not fully-deterministic loads of
52 another Components, which would break dependencies if they are decided to load
53 other Components than last time. The list of groups of Components is stored in
54 the 'mysql.component' table. It is valid to unload only part of the group of
55 the previously loaded group of Components. In such a situation, as long as all
56 dependencies are met, which is assured by the underlying Service
57 Implementation, the rest of Components in group should load successfully after
58 the MySQL Server restart.
59*/
61 public:
62 /**
63 Initializes persistence store, loads all groups of components registered in
64 component table. Shouldn't be called multiple times. We assume the order
65 specified by group ID is correct one. This should be assured by dynamic
66 loader as long as it will not allow to unload the component that has
67 dependency on, in case there would be a possibility to switch that
68 dependency to other component that is not to be unloaded. If this is
69 assured, then it will not be possible for components with lower group IDs
70 to have a dependency on component with higher group ID, even after state is
71 restored in this initialization method.
72
73 @param thdp Current thread execution context
74 @return Status of performed operation
75 @retval false success
76 @retval true failure
77 */
78 static bool init(void *thdp);
79 /**
80 De-initializes persistence loader.
81 */
82 static void deinit();
83
84 /**
85 Initialisation status of persistence loader. An helper function.
86 */
87 static bool initialized();
88
89 public: /* service implementations */
90 /**
91 Loads specified group of components by URN, initializes them and
92 registers all service implementations present in these components.
93 Assures all dependencies will be met after loading specified components.
94 The dependencies may be circular, in such case it's necessary to specify
95 all components on cycle to load in one batch. From URNs specified the
96 scheme part of URN (part before "://") is extracted and used to acquire
97 service implementation of scheme component loader service for specified
98 scheme. If the loading process successes then a group of Components by their
99 URN is added to the component table.
100
101 @param thd_ptr Current thread execution context.
102 @param urns List of URNs of Components to load.
103 @param component_count Number of Components on list to load.
104 @return Status of performed operation
105 @retval false success
106 @retval true failure
107 */
108 static DEFINE_BOOL_METHOD(load, (void *thd_ptr, const char *urns[],
109 int component_count));
110
111 /**
112 Unloads specified group of Components by URN, deinitializes them and
113 unregisters all service implementations present in these components.
114 Assumes, although does not check it, all dependencies of not unloaded
115 components will still be met after unloading specified components.
116 The dependencies may be circular, in such case it's necessary to specify
117 all components on cycle to unload in one batch. From URNs specified the
118 scheme part of URN (part before "://") is extracted and used to acquire
119 service implementation of scheme component loader service for specified
120 scheme. URN specified should be identical to ones specified in load()
121 method, i.e. all letters must have the same case. If the unloading process
122 successes then a group of Components by their URN is added to the component
123 table.
124
125 @param thd_ptr Current thread execution context.
126 @param urns List of URNs of components to unload.
127 @param component_count Number of components on list to unload.
128 @return Status of performed operation
129 @retval false success
130 @retval true failure
131 */
132 static DEFINE_BOOL_METHOD(unload, (void *thd_ptr, const char *urns[],
133 int component_count));
134
135 /**
136 @brief Removes the entries from the in-memory cache
137
138 This is a "private method" of the persisted loader that's used in the
139 same component.
140 @param urns the entries to remove
141 @param component_count the count of entries to remove.
142 @retval number of entried actually erased from the memory cache
143 */
144 static int remove_from_cache(const char *urns[], int component_count);
145
146 private:
147 /**
148 Stores last group ID used in component table. It is initialized on init()
149 on component table scan with maximum group ID used in table.
150 */
151 static std::atomic<uint64> s_group_id;
152 /**
153 Stores mapping of component URNs to their component_id used in component
154 table, to ease row deletion.
155 */
156 static std::map<std::string, uint64> component_id_by_urn;
157 /**
158 Indicates the initialization status of dynamic loader persistence.
159 */
160 static bool is_initialized;
161
162 /**
163 Serializes access to @ref component_id_by_urn
164 */
166};
167
168#endif /* MYSQL_SERVER_PERSISTENT_DYNAMIC_LOADER_H */
Allows to wrap another Service Implementation of the Dynamic Loader service and add ability to store ...
Definition: persistent_dynamic_loader_imp.h:60
static mysql_service_status_t load(void *thd_ptr, const char *urns[], int component_count) noexcept
Loads specified group of components by URN, initializes them and registers all service implementation...
Definition: persistent_dynamic_loader.cc:371
static mysql_service_status_t unload(void *thd_ptr, const char *urns[], int component_count) noexcept
Unloads specified group of Components by URN, deinitializes them and unregisters all service implemen...
Definition: persistent_dynamic_loader.cc:477
static bool is_initialized
Indicates the initialization status of dynamic loader persistence.
Definition: persistent_dynamic_loader_imp.h:160
static std::map< std::string, uint64 > component_id_by_urn
Stores mapping of component URNs to their component_id used in component table, to ease row deletion.
Definition: persistent_dynamic_loader_imp.h:156
static bool init(void *thdp)
Initializes persistence store, loads all groups of components registered in component table.
Definition: persistent_dynamic_loader.cc:210
static int remove_from_cache(const char *urns[], int component_count)
Removes the entries from the in-memory cache.
Definition: persistent_dynamic_loader.cc:342
static bool initialized()
Initialisation status of persistence loader.
Definition: persistent_dynamic_loader.cc:338
static mysql_mutex_t component_id_by_urn_mutex
Serializes access to component_id_by_urn.
Definition: persistent_dynamic_loader_imp.h:165
static void deinit()
De-initializes persistence loader.
Definition: persistent_dynamic_loader.cc:324
static std::atomic< uint64 > s_group_id
Stores last group ID used in component table.
Definition: persistent_dynamic_loader_imp.h:151
Some integer typedefs for easier portability.
void persistent_dynamic_loader_deinit()
Definition: persistent_dynamic_loader.cc:585
bool persistent_dynamic_loader_init(void *thd)
Initializes persistence store, loads all groups of components registered in component table.
Definition: persistent_dynamic_loader.cc:580
Instrumentation helpers for mutexes.
Specifies macros to define Service Implementations.
#define DEFINE_BOOL_METHOD(name, args)
A short macro to define method that returns bool, which is the most common case.
Definition: service_implementation.h:88
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50