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