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