1 /* Copyright (c) 2014, 2021, 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 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 Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef PLUGIN_INCLUDE
24 #define PLUGIN_INCLUDE
25 
26 #include "applier.h"
27 #include "recovery.h"
28 #include "channel_observation_manager.h"
29 #include "ps_information.h"
30 
31 #include <mysql/gcs/gcs_interface.h>
32 #include "gcs_event_handlers.h"
33 #include "gcs_view_modification_notifier.h"
34 #include "compatibility_module.h"
35 #include "auto_increment.h"
36 #include "read_mode_handler.h"
37 #include "delayed_plugin_initialization.h"
38 #include "gcs_operations.h"
39 #include "asynchronous_channels_state_observer.h"
40 #include "group_partition_handling.h"
41 
42 #include "plugin_constants.h"
43 #include "plugin_server_include.h"
44 #include <mysql/plugin.h>
45 #include <mysql/plugin_group_replication.h>
46 
47 //Definition of system var structures
48 
49 //Definition of system vars structure for access their information in the plugin
50 struct st_mysql_sys_var
51 {
52   MYSQL_PLUGIN_VAR_HEADER;
53 };
54 typedef st_mysql_sys_var SYS_VAR;
55 
56 /**
57   An enum that represents the possible values of the
58   group_replication_exit_state_action sysvar.
59 */
60 enum enum_exit_state_action {
61   /**
62     When configured to READ_ONLY, the server will go into super_read_only mode
63     and enter the ERROR GR state.
64   */
65   EXIT_STATE_ACTION_READ_ONLY = 0,
66   /** When configured to ABORT_SERVER, the server will abort(). */
67   EXIT_STATE_ACTION_ABORT_SERVER
68 };
69 
70 //Plugin variables
71 extern const char *group_replication_plugin_name;
72 extern char *group_name_var;
73 extern rpl_sidno group_sidno;
74 extern bool wait_on_engine_initialization;
75 extern bool server_shutdown_status;
76 extern const char *available_bindings_names[];
77 //Flag to register server rest master command invocations
78 extern bool known_server_reset;
79 //Certification latch
80 extern Wait_ticket<my_thread_id> *certification_latch;
81 extern ulong exit_state_action_var;
82 
83 //The modules
84 extern Gcs_operations *gcs_module;
85 extern Applier_module *applier_module;
86 extern Recovery_module *recovery_module;
87 extern Group_member_info_manager_interface *group_member_mgr;
88 extern Channel_observation_manager *channel_observation_manager;
89 extern Asynchronous_channels_state_observer
90         *asynchronous_channels_state_observer;
91 //Lock for the applier and recovery module to prevent the race between STOP
92 //Group replication and ongoing transactions.
93 extern Shared_writelock *shared_plugin_stop_lock;
94 extern Delayed_initialization_thread *delayed_initialization_thread;
95 
96 //Auxiliary Functionality
97 extern Plugin_gcs_events_handler* events_handler;
98 extern Plugin_gcs_view_modification_notifier* view_change_notifier;
99 extern Group_member_info* local_member_info;
100 extern Compatibility_module* compatibility_mgr;
101 extern Group_partition_handling* group_partition_handler;
102 extern Blocked_transaction_handler* blocked_transaction_handler;
103 
104 //Plugin global methods
105 bool server_engine_initialized();
106 void *get_plugin_pointer();
107 mysql_mutex_t* get_plugin_running_lock();
108 int initialize_plugin_and_join(enum_plugin_con_isolation sql_api_isolation,
109                                Delayed_initialization_thread *delayed_init_thd);
110 void register_server_reset_master();
111 bool get_allow_local_lower_version_join();
112 bool get_allow_local_disjoint_gtids_join();
113 ulong get_transaction_size_limit();
114 bool is_plugin_waiting_to_set_server_read_mode();
115 
116 //Plugin public methods
117 int plugin_group_replication_init(MYSQL_PLUGIN plugin_info);
118 int plugin_group_replication_deinit(void *p);
119 int plugin_group_replication_start();
120 int plugin_group_replication_stop();
121 bool plugin_is_group_replication_running();
122 bool get_plugin_is_stopping();
123 bool plugin_get_connection_status(
124     const GROUP_REPLICATION_CONNECTION_STATUS_CALLBACKS& callbacks);
125 bool plugin_get_group_members(
126     uint index, const GROUP_REPLICATION_GROUP_MEMBERS_CALLBACKS& callbacks);
127 bool plugin_get_group_member_stats(
128     const GROUP_REPLICATION_GROUP_MEMBER_STATS_CALLBACKS& callbacks);
129 uint plugin_get_group_members_number();
130 /**
131   Method to set retrieved certification info from a recovery channel extracted
132   from a given View_change event
133 
134   @note a copy of the certification info is made here.
135 
136   @param info   the given view_change_event.
137 */
138 int plugin_group_replication_set_retrieved_certification_info(void* info);
139 
140 #endif /* PLUGIN_INCLUDE */
141