1 /* Copyright (c) 2016, 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 #include "plugin_utils.h"
24 #include "plugin.h"
25
26 using std::vector;
27
Blocked_transaction_handler()28 Blocked_transaction_handler::Blocked_transaction_handler()
29 {
30 mysql_mutex_init(key_GR_LOCK_trx_unlocking, &unblocking_process_lock, MY_MUTEX_INIT_FAST);
31 }
32
~Blocked_transaction_handler()33 Blocked_transaction_handler::~Blocked_transaction_handler()
34 {
35 mysql_mutex_destroy(&unblocking_process_lock);
36 }
37
unblock_waiting_transactions()38 void Blocked_transaction_handler::unblock_waiting_transactions()
39 {
40 mysql_mutex_lock(&unblocking_process_lock);
41 vector<my_thread_id> waiting_threads;
42 certification_latch->get_all_waiting_keys(waiting_threads);
43
44 if (!waiting_threads.empty())
45 {
46 log_message(MY_WARNING_LEVEL,
47 "Due to a plugin error, some transactions can't be certified"
48 " and will now rollback.");
49 }
50
51 vector<my_thread_id>::const_iterator it;
52 for (it= waiting_threads.begin(); it != waiting_threads.end(); it++)
53 {
54 my_thread_id thread_id= (*it);
55 Transaction_termination_ctx transaction_termination_ctx;
56 memset(&transaction_termination_ctx,
57 0, sizeof(transaction_termination_ctx));
58 transaction_termination_ctx.m_thread_id= thread_id;
59 transaction_termination_ctx.m_rollback_transaction= TRUE;
60 transaction_termination_ctx.m_generated_gtid= FALSE;
61 transaction_termination_ctx.m_sidno= -1;
62 transaction_termination_ctx.m_gno= -1;
63 if (set_transaction_ctx(transaction_termination_ctx) ||
64 certification_latch->releaseTicket(thread_id))
65 {
66 //Nothing much we can do
67 log_message(MY_ERROR_LEVEL,
68 "Error when trying to unblock non certified transactions."
69 " Check for consistency errors when restarting the service"); /* purecov: inspected */
70 }
71 }
72 mysql_mutex_unlock(&unblocking_process_lock);
73 }
74
log_primary_member_details()75 void log_primary_member_details()
76 {
77 // Special case to display Primary member details in secondary member logs.
78 if (local_member_info->in_primary_mode() &&
79 (local_member_info->get_role() == Group_member_info::MEMBER_ROLE_SECONDARY))
80 {
81 std::string primary_member_uuid;
82 group_member_mgr->get_primary_member_uuid(primary_member_uuid);
83 Group_member_info* primary_member_info=
84 group_member_mgr->get_group_member_info(primary_member_uuid);
85 if (primary_member_info != NULL)
86 {
87 log_message(MY_INFORMATION_LEVEL,
88 "This server is working as secondary member with primary "
89 "member address %s:%u.",
90 primary_member_info->get_hostname().c_str(),
91 primary_member_info->get_port());
92 delete primary_member_info;
93 }
94 }
95 }
96
abort_plugin_process(const char * message)97 void abort_plugin_process(const char *message)
98 {
99 log_message(MY_ERROR_LEVEL, "The plugin encountered a critical error and will abort: %s", message);
100 #if !defined(NDEBUG)
101 DBUG_SUICIDE();
102 #endif
103 abort();
104 }
105