forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.cc
More file actions
5362 lines (4536 loc) · 188 KB
/
plugin.cc
File metadata and controls
5362 lines (4536 loc) · 188 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2014, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <cassert>
#include <sstream>
#include <mysql/components/services/log_builtins.h>
#include <mysql/service_rpl_transaction_write_set.h>
#include "mutex_lock.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "plugin/group_replication/include/autorejoin.h"
#include "plugin/group_replication/include/consistency_manager.h"
#include "plugin/group_replication/include/gcs_mysql_network_provider.h"
#include "plugin/group_replication/include/mysql_version_gcs_protocol_map.h"
#include "plugin/group_replication/include/observer_server_actions.h"
#include "plugin/group_replication/include/observer_server_state.h"
#include "plugin/group_replication/include/observer_trans.h"
#include "plugin/group_replication/include/perfschema/pfs.h"
#include "plugin/group_replication/include/pipeline_stats.h"
#include "plugin/group_replication/include/plugin.h"
#include "plugin/group_replication/include/plugin_handlers/consensus_leaders_handler.h"
#include "plugin/group_replication/include/plugin_handlers/member_actions_handler.h"
#include "plugin/group_replication/include/plugin_variables.h"
#include "plugin/group_replication/include/plugin_variables/recovery_endpoints.h"
#include "plugin/group_replication/include/services/message_service/message_service.h"
#include "plugin/group_replication/include/services/status_service/status_service.h"
#include "plugin/group_replication/include/sql_service/sql_service_interface.h"
#include "plugin/group_replication/include/thread/mysql_thread.h"
#include "plugin/group_replication/include/udf/udf_registration.h"
#include "plugin/group_replication/include/udf/udf_utils.h"
#ifndef NDEBUG
#include "plugin/group_replication/include/services/notification/impl/gms_listener_test.h"
#endif
using std::string;
/*
Variables that are only accessible inside plugin.cc.
*/
static struct plugin_local_variables lv;
/*
Plugin options variables that are only accessible inside plugin.cc.
*/
static struct plugin_options_variables ov;
/*
Log service log_bi and log_bs are extern variables.
*/
SERVICE_TYPE(log_builtins) * log_bi;
SERVICE_TYPE(log_builtins_string) * log_bs;
/*
Plugin modules.
plugin.cc class pointers that are accessible on all plugin files,
that is, are declared as extern on plugin.h.
These pointers will be initialized on plugin_group_replication_init()
or plugin_group_replication_start().
*/
/** The plugin applier */
Applier_module *applier_module = nullptr;
/** The plugin recovery module */
Recovery_module *recovery_module = nullptr;
/** The plugin group communication module */
Gcs_operations *gcs_module = nullptr;
/** The registry module */
Registry_module_interface *registry_module = nullptr;
/** The observation module for group events */
Group_events_observation_manager *group_events_observation_manager = nullptr;
/** The channel observation modules */
Channel_observation_manager_list *channel_observation_manager_list = nullptr;
/** The Single primary channel observation module */
Asynchronous_channels_state_observer *asynchronous_channels_state_observer =
nullptr;
/** The transaction observation module */
Group_transaction_observation_manager *group_transaction_observation_manager =
nullptr;
/** Transactions latch */
Wait_ticket<my_thread_id> *transactions_latch = nullptr;
/** The plugin transaction consistency manager */
Transaction_consistency_manager *transaction_consistency_manager = nullptr;
/** Class to coordinate access to the plugin stop lock */
Shared_writelock *shared_plugin_stop_lock = nullptr;
/** Initialization thread for server starts */
Delayed_initialization_thread *delayed_initialization_thread = nullptr;
/** The transaction handler for network partitions */
Group_partition_handling *group_partition_handler = nullptr;
/** The handler for transaction killing when an error or partition happens */
Blocked_transaction_handler *blocked_transaction_handler = nullptr;
/** The coordinator for group actions */
Group_action_coordinator *group_action_coordinator = nullptr;
/** The primary election handler */
Primary_election_handler *primary_election_handler = nullptr;
/** The thread that handles the auto-rejoin process */
Autorejoin_thread *autorejoin_module = nullptr;
/** The handler to invoke clone */
Remote_clone_handler *remote_clone_handler = nullptr;
/** The thread that handles the message service process */
Message_service_handler *message_service_handler = nullptr;
/** Handle validation of advertised recovery endpoints */
Advertised_recovery_endpoints *advertised_recovery_endpoints = nullptr;
Member_actions_handler *member_actions_handler = nullptr;
/** Handle tasks on mysql_thread */
Mysql_thread *mysql_thread_handler = nullptr;
/**
Dedicated mysql_thread to enable `read_only` and `super_read_only`
since these are blocking operations.
If we did use `mysql_thread_handler` that would block all other
other operations until read modes operations complete.
*/
Mysql_thread *mysql_thread_handler_read_only_mode = nullptr;
/** Module with the acquired server services on plugin install */
Server_services_references *server_services_references_module = nullptr;
Plugin_gcs_events_handler *events_handler = nullptr;
Plugin_gcs_view_modification_notifier *view_change_notifier = nullptr;
/* Group management information */
Group_member_info_manager_interface *group_member_mgr = nullptr;
Group_member_info *local_member_info = nullptr;
/*Compatibility management*/
Compatibility_module *compatibility_mgr = nullptr;
/* Runtime error service */
SERVICE_TYPE_NO_CONST(mysql_runtime_error) *mysql_runtime_error_service =
nullptr;
Consensus_leaders_handler *consensus_leaders_handler = nullptr;
/* Performance schema module */
static gr::perfschema::Perfschema_module *perfschema_module = nullptr;
static bool initialize_perfschema_module();
static void finalize_perfschema_module();
/*
Internal auxiliary functions signatures.
*/
static bool check_uuid_against_rpl_channel_settings(const char *str);
static int check_group_name_string(const char *str, bool is_var_update = false);
static int check_recovery_ssl_string(const char *str, const char *var_name,
bool is_var_update = false);
static int check_if_server_properly_configured();
static bool init_group_sidno();
static void initialize_ssl_option_map();
static bool initialize_registry_module();
static bool finalize_registry_module();
static int check_flow_control_min_quota_long(longlong value,
bool is_var_update = false);
static int check_flow_control_min_recovery_quota_long(
longlong value, bool is_var_update = false);
static int check_flow_control_max_quota_long(longlong value,
bool is_var_update = false);
static int check_view_change_uuid_string(const char *str,
bool is_var_update = false);
int configure_group_communication();
int build_gcs_parameters(Gcs_interface_parameters ¶ms);
int configure_group_member_manager();
bool check_async_channel_running_on_secondary();
int configure_compatibility_manager();
int initialize_recovery_module();
int configure_and_start_applier_module();
void initialize_asynchronous_channels_observer();
void initialize_group_partition_handler();
int start_group_communication();
int leave_group_and_terminate_plugin_modules(
gr_modules::mask modules_to_terminate, char **error_message);
int leave_group();
int terminate_applier_module();
int terminate_recovery_module();
void terminate_asynchronous_channels_observer();
void set_auto_increment_handler_values();
static void option_deprecation_warning(MYSQL_THD thd, const char *old_name,
const char *new_name) {
push_deprecated_warn(thd, old_name, new_name);
}
static void check_deprecated_variables() {
MYSQL_THD thd = lv.plugin_is_auto_starting_on_install ? nullptr : current_thd;
if (ov.ip_whitelist_var != nullptr &&
strcmp(ov.ip_whitelist_var, "AUTOMATIC")) {
option_deprecation_warning(thd, "group_replication_ip_whitelist",
"group_replication_ip_allowlist");
}
if (ov.recovery_completion_policy_var != RECOVERY_POLICY_WAIT_EXECUTED) {
push_deprecated_warn_no_replacement(
thd, "group_replication_recovery_complete_at");
}
if (ov.view_change_uuid_var != nullptr &&
strcmp(ov.view_change_uuid_var, "AUTOMATIC")) {
push_deprecated_warn_no_replacement(thd,
"group_replication_view_change_uuid");
}
}
static const char *get_ip_allowlist() {
std::string whitelist(ov.ip_whitelist_var);
std::string allowlist(ov.ip_allowlist_var);
std::transform(whitelist.begin(), whitelist.end(), whitelist.begin(),
::tolower);
std::transform(allowlist.begin(), allowlist.end(), allowlist.begin(),
::tolower);
return allowlist.compare("automatic")
? ov.ip_allowlist_var // ip_allowlist_var is set
: whitelist.compare("automatic")
? ov.ip_whitelist_var // ip_whitelist_var is set
: ov.ip_allowlist_var; // both are not set
}
/*
Auxiliary public functions.
*/
void *get_plugin_pointer() { return lv.plugin_info_ptr; }
Checkable_rwlock *get_plugin_running_lock() { return lv.plugin_running_lock; }
mysql_mutex_t *get_plugin_applier_module_initialize_terminate_lock() {
return &lv.plugin_applier_module_initialize_terminate_mutex;
}
bool plugin_is_group_replication_running() {
return lv.group_replication_running;
}
bool plugin_is_group_replication_cloning() {
return lv.group_replication_cloning;
}
bool is_plugin_auto_starting_on_non_bootstrap_member() {
return !ov.bootstrap_group_var && lv.plugin_is_auto_starting_on_boot;
}
bool is_plugin_configured_and_starting() {
return lv.group_member_mgr_configured;
}
int plugin_group_replication_set_retrieved_certification_info(void *info) {
return recovery_module->set_retrieved_cert_info(info);
}
rpl_sidno get_group_sidno() {
assert(lv.group_sidno > 0);
return lv.group_sidno;
}
rpl_sidno get_view_change_sidno() {
assert(lv.view_change_sidno > 0);
return lv.view_change_sidno;
}
bool get_plugin_is_stopping() { return lv.plugin_is_stopping; }
bool get_wait_on_engine_initialization() {
return lv.wait_on_engine_initialization;
}
void enable_server_shutdown_status() { lv.server_shutdown_status = true; }
bool get_server_shutdown_status() { return lv.server_shutdown_status; }
void set_plugin_is_setting_read_mode(bool value) {
lv.plugin_is_setting_read_mode = value;
}
bool get_plugin_is_setting_read_mode() {
return lv.plugin_is_setting_read_mode;
}
const char *get_group_name_var() { return ov.group_name_var; }
const char *get_view_change_uuid_var() { return ov.view_change_uuid_var; }
ulong get_exit_state_action_var() { return ov.exit_state_action_var; }
ulong get_flow_control_mode_var() { return ov.flow_control_mode_var; }
long get_flow_control_certifier_threshold_var() {
return ov.flow_control_certifier_threshold_var;
}
long get_flow_control_applier_threshold_var() {
return ov.flow_control_applier_threshold_var;
}
long get_flow_control_min_quota_var() { return ov.flow_control_min_quota_var; }
long get_flow_control_min_recovery_quota_var() {
return ov.flow_control_min_recovery_quota_var;
}
long get_flow_control_max_quota_var() { return ov.flow_control_max_quota_var; }
int get_flow_control_member_quota_percent_var() {
return ov.flow_control_member_quota_percent_var;
}
int get_flow_control_period_var() { return ov.flow_control_period_var; }
int get_flow_control_hold_percent_var() {
return ov.flow_control_hold_percent_var;
}
int get_flow_control_release_percent_var() {
return ov.flow_control_release_percent_var;
}
ulong get_components_stop_timeout_var() {
return ov.components_stop_timeout_var;
}
ulong get_communication_stack_var() { return ov.communication_stack_var; }
bool is_autorejoin_enabled() { return ov.autorejoin_tries_var > 0U; }
uint get_number_of_autorejoin_tries() { return ov.autorejoin_tries_var; }
ulonglong get_rejoin_timeout() { return lv.rejoin_timeout; }
bool get_allow_single_leader() {
if (lv.allow_single_leader_latch.first)
return lv.allow_single_leader_latch.second;
else
return ov.allow_single_leader_var;
}
/**
* @brief Callback implementation of
* handle_group_replication_incoming_connection. This is the entry point for
* new MySQL connections that are directed to GCS
*
* @param thd THD object of the connection
* @param fd File descriptor of the connections
* @param ssl_ctx SSL data of the connection
*/
void handle_group_replication_incoming_connection(THD *thd, int fd,
SSL *ssl_ctx) {
auto *new_connection = new Network_connection(fd, ssl_ctx);
new_connection->has_error = false;
Gcs_mysql_network_provider *mysql_provider =
gcs_module->get_mysql_network_provider();
if (mysql_provider) {
mysql_provider->set_new_connection(thd, new_connection);
}
}
/**
Set condition to block or unblock the calling threads
@param[in] cond if the threads should be blocked or not
*/
void set_wait_on_start_process(bool cond) {
lv.online_wait_mutex->set_wait_lock(cond);
}
/**
Blocks the calling thread
*/
enum_wait_on_start_process_result initiate_wait_on_start_process() {
// block the thread
lv.online_wait_mutex->start_waitlock();
#ifndef NDEBUG
DBUG_EXECUTE_IF("group_replication_wait_thread_for_server_online", {
const char act[] =
"now wait_for signal.continue_applier_thread NO_CLEAR_EVENT";
assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
});
#endif
return lv.wait_on_start_process;
}
/**
Release all the blocked threads
*/
void terminate_wait_on_start_process(enum_wait_on_start_process_result abort) {
lv.plugin_is_auto_starting_on_boot = false;
lv.wait_on_start_process = abort;
// unblocked waiting threads
lv.online_wait_mutex->end_wait_lock();
}
static void finalize_perfschema_module() {
if (nullptr != perfschema_module) {
perfschema_module->finalize();
delete perfschema_module;
perfschema_module = nullptr;
}
}
static bool initialize_perfschema_module() {
if (nullptr != perfschema_module) {
return true; /* purecov: inspected */
}
perfschema_module = new gr::perfschema::Perfschema_module{};
if (nullptr == perfschema_module) {
return true; /* purecov: inspected */
}
if (perfschema_module->initialize()) {
/* purecov: begin inspected */
finalize_perfschema_module();
return true;
/* purecov: end */
}
return false;
}
static bool initialize_registry_module() {
return (!(registry_module = new Registry_module()) ||
registry_module->initialize());
}
static bool finalize_registry_module() {
int res = false;
if (registry_module) {
res = registry_module->finalize();
delete registry_module;
registry_module = nullptr;
}
return res;
}
/*
Plugin interface.
*/
struct st_mysql_group_replication group_replication_descriptor = {
MYSQL_GROUP_REPLICATION_INTERFACE_VERSION,
plugin_group_replication_start,
plugin_group_replication_stop,
plugin_is_group_replication_running,
plugin_is_group_replication_cloning,
plugin_group_replication_set_retrieved_certification_info,
plugin_get_connection_status,
plugin_get_group_members,
plugin_get_group_member_stats,
plugin_get_group_members_number,
};
bool plugin_get_connection_status(
const GROUP_REPLICATION_CONNECTION_STATUS_CALLBACKS &callbacks) {
char *channel_name = applier_module_channel_name;
return get_connection_status(callbacks, ov.group_name_var, channel_name,
plugin_is_group_replication_running());
}
bool plugin_get_group_members(
uint index, const GROUP_REPLICATION_GROUP_MEMBERS_CALLBACKS &callbacks) {
char *channel_name = applier_module_channel_name;
return get_group_members_info(index, callbacks, channel_name);
}
/*
If the local member is already OFFLINE but still has the previous
membership because is waiting for the leave view, do not report
the other members.
*/
uint plugin_get_group_members_number() {
bool unitialized_or_offline = group_member_mgr == nullptr ||
local_member_info == nullptr ||
local_member_info->get_recovery_status() ==
Group_member_info::MEMBER_OFFLINE;
return unitialized_or_offline
? 1
: (uint)group_member_mgr->get_number_of_members();
}
bool plugin_get_group_member_stats(
uint index,
const GROUP_REPLICATION_GROUP_MEMBER_STATS_CALLBACKS &callbacks) {
char *channel_name = applier_module_channel_name;
return get_group_member_stats(index, callbacks, channel_name);
}
int plugin_group_replication_start(char **error_message) {
DBUG_TRACE;
if (lv.plugin_is_being_uninstalled) {
std::string err_msg("Group Replication plugin is being uninstalled.");
*error_message =
(char *)my_malloc(PSI_NOT_INSTRUMENTED, err_msg.length() + 1, MYF(0));
strcpy(*error_message, err_msg.c_str());
return GROUP_REPLICATION_COMMAND_FAILURE;
}
Checkable_rwlock::Guard g(*lv.plugin_running_lock,
Checkable_rwlock::WRITE_LOCK);
int error = 0;
std::string debug_options;
DBUG_EXECUTE_IF("group_replication_wait_on_start", {
const char act[] =
"now signal signal.start_waiting wait_for signal.start_continue";
assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
});
if (plugin_is_group_replication_running()) {
error = GROUP_REPLICATION_ALREADY_RUNNING;
goto err;
}
if (check_if_server_properly_configured()) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (check_group_name_string(ov.group_name_var)) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (check_view_change_uuid_string(ov.view_change_uuid_var)) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (check_recovery_ssl_string(ov.recovery_ssl_ca_var, "ssl_ca") ||
check_recovery_ssl_string(ov.recovery_ssl_capath_var, "ssl_capath") ||
check_recovery_ssl_string(ov.recovery_ssl_cert_var, "ssl_cert_pointer") ||
check_recovery_ssl_string(ov.recovery_ssl_cipher_var,
"ssl_cipher_pointer") ||
check_recovery_ssl_string(ov.recovery_ssl_key_var, "ssl_key_pointer") ||
check_recovery_ssl_string(ov.recovery_ssl_crl_var, "ssl_crl_pointer") ||
check_recovery_ssl_string(ov.recovery_ssl_crlpath_var,
"ssl_crlpath_pointer") ||
check_recovery_ssl_string(ov.recovery_public_key_path_var,
"public_key_path") ||
check_recovery_ssl_string(ov.recovery_tls_version_var, "tls_version") ||
check_recovery_ssl_string(ov.recovery_tls_ciphersuites_var,
"tls_ciphersuites")) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (!ov.start_group_replication_at_boot_var && !server_engine_initialized()) {
LogPluginErr(ERROR_LEVEL,
ER_GRP_RPL_FAILED_TO_START_WITH_INVALID_SERVER_ID);
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (ov.force_members_var != nullptr && strlen(ov.force_members_var) > 0) {
LogPluginErr(ERROR_LEVEL, ER_GRP_RPL_FORCE_MEMBERS_MUST_BE_EMPTY,
ov.force_members_var);
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (check_flow_control_min_quota_long(ov.flow_control_min_quota_var)) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (check_flow_control_min_recovery_quota_long(
ov.flow_control_min_recovery_quota_var)) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (check_flow_control_max_quota_long(ov.flow_control_max_quota_var)) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (init_group_sidno()) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR; /* purecov: inspected */
goto err;
}
if (advertised_recovery_endpoints->check(
ov.advertise_recovery_endpoints_var,
!server_engine_initialized()
? Advertised_recovery_endpoints::enum_log_context::ON_BOOT
: Advertised_recovery_endpoints::enum_log_context::ON_START)) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
LogPluginErr(SYSTEM_LEVEL, ER_GRP_RPL_IS_STARTING);
DBUG_EXECUTE_IF("register_gms_listener_example",
{ register_listener_service_gr_example(); });
/*
The debug options is also set/verified here because if it was set during
the server start, it was not set/verified due to the plugin life-cycle.
For that reason, we have to call set_debug_options here as well to set/
validate the information in the communication_debug_options_var. Note,
however, that the option variable is not automatically set to a valid
value if the validation fails.
*/
debug_options.assign(ov.communication_debug_options_var);
if (gcs_module->set_debug_options(debug_options)) {
error = GROUP_REPLICATION_CONFIGURATION_ERROR; /* purecov: inspected */
goto err;
}
check_deprecated_variables();
assert(transactions_latch->empty());
// Reset the single-leader latch flag
lv.allow_single_leader_latch.first = false;
// Reset the coordinator in case there was a previous stop.
group_action_coordinator->reset_coordinator_process();
// GR delayed initialization.
if (!server_engine_initialized()) {
lv.wait_on_engine_initialization = true;
lv.plugin_is_auto_starting_on_install = false;
delayed_initialization_thread = new Delayed_initialization_thread();
if (delayed_initialization_thread->launch_initialization_thread()) {
/* purecov: begin inspected */
LogPluginErr(ERROR_LEVEL,
ER_GRP_RPL_PLUGIN_STRUCT_INIT_NOT_POSSIBLE_ON_SERVER_START);
delete delayed_initialization_thread;
delayed_initialization_thread = nullptr;
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
/* purecov: end */
}
goto err; // leave the decision for later
}
error = initialize_plugin_and_join(PSESSION_DEDICATED_THREAD, nullptr);
if (!error) {
LogPluginErr(SYSTEM_LEVEL, ER_GRP_RPL_HAS_STARTED);
}
return error;
err:
if (error) {
// end wait for thread waiting for server to start
terminate_wait_on_start_process();
} else {
LogPluginErr(SYSTEM_LEVEL, ER_GRP_RPL_HAS_STARTED);
}
return error;
}
int initialize_plugin_and_join(
enum_plugin_con_isolation sql_api_isolation,
Delayed_initialization_thread *delayed_init_thd) {
DBUG_TRACE;
lv.plugin_running_lock->assert_some_wrlock();
int error = 0;
// Avoid unnecessary operations
bool enabled_super_read_only = false;
bool read_only_mode = false, super_read_only_mode = false;
bool write_set_limits_set = false;
/*
Despite START GROUP_REPLICATION do not depend on the SQL API,
other operations, like distributed recovery through clone, do
depend, as such we do validate early that SQL API is operational.
*/
Sql_service_command_interface sql_command_interface;
if (sql_command_interface.establish_session_connection(
sql_api_isolation, GROUPREPL_USER, lv.plugin_info_ptr)) {
error = 1;
goto err;
}
/**
We redo the check for the group name here when starting on boot as only
now the information about channels and the
assign_gtids_to_anonymous_transactions is available.
*/
if (lv.plugin_is_auto_starting_on_boot) {
if (check_uuid_against_rpl_channel_settings(ov.group_name_var)) {
LogPluginErr(ERROR_LEVEL,
ER_GRP_RPL_GRP_NAME_IS_SAME_AS_ANONYMOUS_TO_GTID_UUID,
ov.group_name_var);
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
if (check_uuid_against_rpl_channel_settings(ov.view_change_uuid_var)) {
LogPluginErr(
ERROR_LEVEL,
ER_GRP_RPL_VIEW_CHANGE_UUID_IS_SAME_AS_ANONYMOUS_TO_GTID_UUID,
ov.group_name_var);
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
}
}
// GCS interface.
if ((error = gcs_module->initialize())) goto err; /* purecov: inspected */
get_read_mode_state(&read_only_mode, &super_read_only_mode);
/*
At this point in the code, set the super_read_only mode here on the
server to protect recovery and version module of the Group Replication.
This can only be done on START command though, on installs there are
deadlock issues.
*/
if (!lv.plugin_is_auto_starting_on_install) {
if (enable_server_read_mode()) {
/* purecov: begin inspected */
error = 1;
LogPluginErr(ERROR_LEVEL,
ER_GRP_RPL_FAILED_TO_ENABLE_SUPER_READ_ONLY_MODE);
goto err;
/* purecov: end */
}
} else {
/*
This flag is used to prevent that a GCS thread that's setting the read
mode and a simultaneous uninstall command block.
If the plugin is installed with autostart, the following actions occur:
1) The install invokes start.
2) Start cannot set the read mode because it is inside the install
(server MDL locks issue).
3) Start delays the read mode setting to the view installation.
4) The view is installed, so the start terminates and the install
returns.
5) Then, some user requests the plugin to uninstall.
6) The uninstall command will take a MDL lock.
7) This causes the GCS thread that was setting the read mode to block.
8) Ultimately, the uninstall command blocks because GCS is not able to
set the read mode.
*/
lv.plugin_is_setting_read_mode = true;
}
enabled_super_read_only = true;
if (delayed_init_thd) delayed_init_thd->signal_read_mode_ready();
require_full_write_set(true);
set_write_set_memory_size_limit(get_transaction_size_limit());
write_set_limits_set = true;
// Setup GCS.
if ((error = configure_group_communication())) {
LogPluginErr(ERROR_LEVEL, ER_GRP_RPL_FAILED_TO_INIT_COMMUNICATION_ENGINE);
goto err;
}
if ((error = initialize_plugin_modules(gr_modules::all_modules))) goto err;
DBUG_EXECUTE_IF("group_replication_before_joining_the_group", {
const char act[] =
"now signal signal.group_join_waiting "
"wait_for signal.continue_group_join";
assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
});
if ((error = start_group_communication())) {
LogPluginErr(ERROR_LEVEL, ER_GRP_RPL_FAILED_TO_START_COMMUNICATION_ENGINE);
goto err;
}
if (view_change_notifier->wait_for_view_modification()) {
if (!view_change_notifier->is_cancelled()) {
// Only log a error when a view modification was not cancelled.
LogPluginErr(ERROR_LEVEL, ER_GRP_RPL_TIMEOUT_ON_VIEW_AFTER_JOINING_GRP);
}
error = view_change_notifier->get_error();
gcs_module->remove_view_notifer(view_change_notifier);
goto err;
}
gcs_module->remove_view_notifer(view_change_notifier);
transaction_consistency_manager->register_transaction_observer();
transaction_consistency_manager->plugin_started();
if (register_gr_message_service_send()) {
/* purecov: begin inspected */
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
/* purecov: end */
}
if (member_actions_handler->acquire_send_service()) {
/* purecov: begin inspected */
error = GROUP_REPLICATION_CONFIGURATION_ERROR;
goto err;
/* purecov: end */
}
lv.group_replication_running = true;
lv.plugin_is_stopping = false;
log_primary_member_details();
err:
if (error) {
lv.plugin_is_setting_read_mode = false;
lv.group_member_mgr_configured = false;
// Unblock the possible stuck delayed thread
if (delayed_init_thd) delayed_init_thd->signal_read_mode_ready();
DBUG_EXECUTE_IF("group_replication_wait_before_leave_on_error", {
const char act[] =
"now signal signal.wait_leave_process "
"wait_for signal.continue_leave_process";
assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
});
member_actions_handler->release_send_service();
unregister_gr_message_service_send();
auto modules_to_terminate = gr_modules::all_modules;
modules_to_terminate.reset(gr_modules::ASYNC_REPL_CHANNELS);
modules_to_terminate.reset(gr_modules::BINLOG_DUMP_THREAD_KILL);
leave_group_and_terminate_plugin_modules(modules_to_terminate, nullptr);
if (write_set_limits_set) {
// Remove server constraints on write set collection
update_write_set_memory_size_limit(0);
require_full_write_set(false);
}
if (!lv.server_shutdown_status && server_engine_initialized() &&
enabled_super_read_only) {
set_read_mode_state(read_only_mode, super_read_only_mode);
}
assert(transactions_latch->empty());
// Inform the transaction observer that we won't apply any further backlog
// (because we are erroring out).
if (primary_election_handler) {
primary_election_handler->notify_election_end();
delete primary_election_handler;
primary_election_handler = nullptr;
}
}
lv.plugin_is_auto_starting_on_install = false;
return error;
}
int configure_group_member_manager() {
DBUG_TRACE;
char *hostname = nullptr;
char *uuid = nullptr;
uint port = 0U;
uint server_version = 0U;
uint admin_port = 0U;
get_server_parameters(&hostname, &port, &uuid, &server_version, &admin_port);
/*
Ensure that group communication interfaces are initialized
and ready to use, since plugin can leave the group on errors
but continue to be active.
*/
std::string gcs_local_member_identifier;
if (gcs_module->get_local_member_identifier(gcs_local_member_identifier)) {
/* purecov: begin inspected */
LogPluginErr(ERROR_LEVEL,
ER_GRP_RPL_FAILED_TO_CALL_GRP_COMMUNICATION_INTERFACE);
return GROUP_REPLICATION_COMMUNICATION_LAYER_SESSION_ERROR;
/* purecov: end */
}
if (!strcmp(uuid, ov.group_name_var)) {
LogPluginErr(ERROR_LEVEL,
ER_GRP_RPL_MEMBER_SERVER_UUID_IS_INCOMPATIBLE_WITH_GRP, uuid,
ov.group_name_var);
return GROUP_REPLICATION_CONFIGURATION_ERROR;
}
if (!strcmp(uuid, ov.view_change_uuid_var)) {
LogPluginErr(
ERROR_LEVEL,
ER_GRP_RPL_GRP_VIEW_CHANGE_UUID_IS_INCOMPATIBLE_WITH_SERVER_UUID,
ov.view_change_uuid_var, uuid);
return GROUP_REPLICATION_CONFIGURATION_ERROR;
}
// Configure Group Member Manager
lv.plugin_version = server_version;
uint32 local_version = lv.plugin_version;
DBUG_EXECUTE_IF("group_replication_compatibility_higher_major_version",
{ local_version = lv.plugin_version + (0x010000); };);
DBUG_EXECUTE_IF("group_replication_compatibility_higher_minor_version",
{ local_version = lv.plugin_version + (0x000100); };);
DBUG_EXECUTE_IF("group_replication_compatibility_higher_patch_version",
{ local_version = lv.plugin_version + (0x000001); };);
DBUG_EXECUTE_IF("group_replication_compatibility_lower_major_version",
{ local_version = lv.plugin_version - (0x010000); };);
DBUG_EXECUTE_IF("group_replication_compatibility_lower_minor_version",
{ local_version = lv.plugin_version - (0x000100); };);
DBUG_EXECUTE_IF("group_replication_compatibility_lower_patch_version",
{ local_version = lv.plugin_version - (0x000001); };);
DBUG_EXECUTE_IF("group_replication_compatibility_restore_version",
{ local_version = lv.plugin_version; };);
DBUG_EXECUTE_IF("group_replication_legacy_election_version",
{ local_version = 0x080012; };);
DBUG_EXECUTE_IF("group_replication_legacy_election_version2",
{ local_version = 0x080015; };);
DBUG_EXECUTE_IF("group_replication_version_8_0_28",
{ local_version = 0x080028; };);
DBUG_EXECUTE_IF("group_replication_version_8_0_35",
{ local_version = 0x080035; };);
DBUG_EXECUTE_IF("group_replication_version_clone_not_supported",
{ local_version = 0x080036; };);
Member_version local_member_plugin_version(local_version);
DBUG_EXECUTE_IF("group_replication_force_member_uuid", {
uuid = const_cast<char *>("cccccccc-cccc-cccc-cccc-cccccccccccc");
};);
// Initialize or update local_member_info.
if (local_member_info != nullptr) {
local_member_info->update(
hostname, port, uuid, lv.write_set_extraction_algorithm,
gcs_local_member_identifier, Group_member_info::MEMBER_OFFLINE,
local_member_plugin_version, ov.gtid_assignment_block_size_var,
Group_member_info::MEMBER_ROLE_SECONDARY, ov.single_primary_mode_var,
ov.enforce_update_everywhere_checks_var, ov.member_weight_var,
lv.gr_lower_case_table_names, lv.gr_default_table_encryption,
ov.advertise_recovery_endpoints_var, ov.view_change_uuid_var,
get_allow_single_leader());
} else {
local_member_info = new Group_member_info(
hostname, port, uuid, lv.write_set_extraction_algorithm,
gcs_local_member_identifier, Group_member_info::MEMBER_OFFLINE,
local_member_plugin_version, ov.gtid_assignment_block_size_var,
Group_member_info::MEMBER_ROLE_SECONDARY, ov.single_primary_mode_var,
ov.enforce_update_everywhere_checks_var, ov.member_weight_var,
lv.gr_lower_case_table_names, lv.gr_default_table_encryption,
ov.advertise_recovery_endpoints_var, ov.view_change_uuid_var,
get_allow_single_leader());
}
#ifndef NDEBUG
DBUG_EXECUTE_IF("group_replication_skip_encode_default_table_encryption", {
local_member_info->skip_encode_default_table_encryption = true;
});
DBUG_EXECUTE_IF("group_replication_skip_encode_view_change_uuid", {
local_member_info->m_skip_encode_view_change_uuid = true;
});
#endif
// Update membership info of member itself
if (group_member_mgr != nullptr) group_member_mgr->update(local_member_info);
// Create the membership info visible for the group
else
group_member_mgr = new Group_member_info_manager(local_member_info);
lv.group_member_mgr_configured = true;