MySQL 8.0.39
Source Code Documentation
autorejoin.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef GR_AUTOREJOIN_INCLUDED
25#define GR_AUTOREJOIN_INCLUDED
26
29
30/**
31 Represents and encapsulates the logic responsible for handling the auto-rejoin
32 process within Group Replication. The auto-rejoin process kicks in one of two
33 possible situations: either the member was expelled from the group or the
34 member lost contact to a majority of the group. The auto-rejoin feature must
35 also be explicitly enabled by setting the group_replication_autorejoin_tries
36 sysvar to a value greater than 0.
37
38 This thread will do a busy-wait loop for group_replication_autorejoin_tries
39 number of attempts, waiting 5 minutes between each attempt (this wait is
40 achieved via a timed wait on a conditional variable).
41
42 We execute the auto-rejoin process in its own thead because the join operation
43 of the GCS layer is asynchronous. We cannot actually block while waiting for a
44 confirmation if the server managed to join the group or not. As such, we wait
45 on a callback invoked by an entity that is registered as a GCS event listener.
46
47 @sa Plugin_gcs_events_handler
48*/
50 public:
51 /**
52 Deleted copy ctor.
53 */
55
56 /**
57 Deleted move ctor.
58 */
60
61 /**
62 Deleted assignment operator.
63 */
65
66 /**
67 Deleted move operator.
68 */
70
71 /**
72 Initializes the synchronization primitives of the thread.
73 */
75
76 /**
77 The dtor for the thread will destroy the mutex and cond_var.
78 */
80
81 /**
82 Initializes the auto-rejoin module with a clean slate, i.e. it
83 resets any state/flags that are checked in start_autorejoin().
84
85 @sa start_autorejoin
86 */
87 void init();
88
89 /**
90 Aborts the thread's main loop, effectively killing the thread.
91
92 @return a flag indicating whether or not the auto-rejoin procedure was
93 ongoing at the time the abort was requested.
94 @retval true the auto-rejoin was ongoing
95 @retval false the auto-rejoin wasn't running
96 */
97 bool abort_rejoin();
98
99 /**
100 Starts the process of auto-rejoin, launches the thread that will call
101 attempt_rejoin() until it succeeds or until it reaches a given
102 amount of maximum retries, waiting on a conditional variable each
103 iteration with a given timeout.
104
105 An auto-rejoin can only start if it isn't already running or if the
106 auto-rejoin module is not in the process of being terminated.
107
108 @param[in] attempts the number of attempts we will try to rejoin.
109 @param[in] timeout the time to wait between each retry.
110 @return whether or not we managed to launch the auto-rejoin thread.
111 @retval 0 the thread launched successfully
112 @retval != 0 the thread couldn't be launched
113 @sa mysql_thread_create
114 */
115 int start_autorejoin(uint attempts, ulonglong timeout);
116
117 /**
118 Returns a flag indicating whether or not the auto-rejoin process is ongoing
119 on this thread.
120
121 @return the state of the rejoin process.
122 @retval true if the auto-rejoin is ongoing
123 @retval false otherwise
124 */
126
127 private:
128 /**
129 The thread callback passed onto mysql_thread_create.
130
131 @param[in] arg a pointer to an Autorejoin_thread instance.
132
133 @return Does not return.
134 */
135 static void *launch_thread(void *arg);
136
137 /**
138 The thread handle, i.e. setups and tearsdown the infrastructure for this
139 mysql_thread.
140 */
141 [[noreturn]] void autorejoin_thread_handle();
142
143 /**
144 Handles the busy-wait retry loop.
145 */
147
148 /** the THD handle. */
150 /** the state of the thread. */
152 /** the thread handle. */
154 /** the mutex for controlling access to the thread itself. */
156 /** the cond_var used to signal the thread. */
158 /** flag to indicate whether or not the thread is to be aborted. */
159 std::atomic<bool> m_abort;
160 /**
161 flag that indicates that the auto-rejoin module is in the process of
162 being terminated.
163 */
165 /** the number of attempts for the rejoin. */
167 /** the time to wait in seconds until the next rejoin attempt. */
169};
170
171#endif /* GR_AUTREJOIN_INCLUDED */
Represents and encapsulates the logic responsible for handling the auto-rejoin process within Group R...
Definition: autorejoin.h:49
ulonglong m_rejoin_timeout
the time to wait in seconds until the next rejoin attempt.
Definition: autorejoin.h:168
Autorejoin_thread()
Initializes the synchronization primitives of the thread.
Definition: autorejoin.cc:37
bool m_being_terminated
flag that indicates that the auto-rejoin module is in the process of being terminated.
Definition: autorejoin.h:164
Autorejoin_thread(const Autorejoin_thread &)=delete
Deleted copy ctor.
static void * launch_thread(void *arg)
The thread callback passed onto mysql_thread_create.
Definition: autorejoin.cc:32
thread_state m_autorejoin_thd_state
the state of the thread.
Definition: autorejoin.h:151
bool abort_rejoin()
Aborts the thread's main loop, effectively killing the thread.
Definition: autorejoin.cc:59
int start_autorejoin(uint attempts, ulonglong timeout)
Starts the process of auto-rejoin, launches the thread that will call attempt_rejoin() until it succe...
Definition: autorejoin.cc:104
void init()
Initializes the auto-rejoin module with a clean slate, i.e.
Definition: autorejoin.cc:53
Autorejoin_thread(const Autorejoin_thread &&)=delete
Deleted move ctor.
~Autorejoin_thread()
The dtor for the thread will destroy the mutex and cond_var.
Definition: autorejoin.cc:48
void autorejoin_thread_handle()
The thread handle, i.e.
Definition: autorejoin.cc:249
void execute_rejoin_process()
Handles the busy-wait retry loop.
Definition: autorejoin.cc:160
THD * m_thd
the THD handle.
Definition: autorejoin.h:149
Autorejoin_thread & operator=(const Autorejoin_thread &&)=delete
Deleted move operator.
std::atomic< bool > m_abort
flag to indicate whether or not the thread is to be aborted.
Definition: autorejoin.h:159
Autorejoin_thread & operator=(const Autorejoin_thread &)=delete
Deleted assignment operator.
ulong m_attempts
the number of attempts for the rejoin.
Definition: autorejoin.h:166
mysql_mutex_t m_run_lock
the mutex for controlling access to the thread itself.
Definition: autorejoin.h:155
mysql_cond_t m_run_cond
the cond_var used to signal the thread.
Definition: autorejoin.h:157
my_thread_handle m_handle
the thread handle.
Definition: autorejoin.h:153
bool is_autorejoin_ongoing()
Returns a flag indicating whether or not the auto-rejoin process is ongoing on this thread.
Definition: autorejoin.cc:153
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
unsigned long long int ulonglong
Definition: my_inttypes.h:56
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:496
Definition: my_thread_bits.h:52
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: plugin_utils.h:47
unsigned int uint
Definition: uca9-dump.cc:75